|
1 | | -import { insertBefore } from '../util/language-util.js'; |
2 | 1 | import clike from './clike.js'; |
3 | 2 |
|
4 | 3 | /** @type {import('../types.d.ts').LanguageProto<'fsharp'>} */ |
5 | 4 | export default { |
6 | 5 | id: 'fsharp', |
7 | 6 | base: clike, |
8 | 7 | optional: 'xml-doc', |
9 | | - grammar ({ base, getOptionalLanguage }) { |
10 | | - insertBefore(base, 'keyword', { |
11 | | - 'preprocessor': { |
12 | | - pattern: /(^[\t ]*)#.*/m, |
13 | | - lookbehind: true, |
14 | | - alias: 'property', |
15 | | - inside: { |
16 | | - 'directive': { |
17 | | - pattern: /(^#)\b(?:else|endif|if|light|line|nowarn)\b/, |
18 | | - lookbehind: true, |
19 | | - alias: 'keyword', |
20 | | - }, |
21 | | - }, |
22 | | - }, |
23 | | - }); |
24 | | - insertBefore(base, 'punctuation', { |
25 | | - 'computation-expression': { |
26 | | - pattern: /\b[_a-z]\w*(?=\s*\{)/i, |
27 | | - alias: 'keyword', |
28 | | - }, |
29 | | - }); |
30 | | - insertBefore(base, 'string', { |
31 | | - 'annotation': { |
32 | | - pattern: /\[<.+?>\]/, |
33 | | - greedy: true, |
34 | | - inside: { |
35 | | - 'punctuation': /^\[<|>\]$/, |
36 | | - 'class-name': { |
37 | | - pattern: /^\w+$|(^|;\s*)[A-Z]\w*(?=\()/, |
38 | | - lookbehind: true, |
39 | | - }, |
40 | | - 'annotation-content': { |
41 | | - pattern: /[\s\S]+/, |
42 | | - inside: 'fsharp', |
43 | | - }, |
44 | | - }, |
45 | | - }, |
46 | | - 'char': { |
47 | | - pattern: |
48 | | - /'(?:[^\\']|\\(?:.|\d{3}|x[a-fA-F\d]{2}|u[a-fA-F\d]{4}|U[a-fA-F\d]{8}))'B?/, |
49 | | - greedy: true, |
50 | | - }, |
51 | | - }); |
52 | | - |
53 | | - insertBefore(base, 'comment', { |
54 | | - 'doc-comment': getOptionalLanguage('xml-doc')?.slash, |
55 | | - }); |
56 | | - |
| 8 | + grammar ({ getOptionalLanguage }) { |
57 | 9 | return { |
58 | 10 | 'comment': [ |
59 | 11 | { |
@@ -90,6 +42,55 @@ export default { |
90 | 42 | ], |
91 | 43 | 'operator': |
92 | 44 | /([<>~&^])\1\1|([*.:<>&])\2|<-|->|[!=:]=|<?\|{1,3}>?|\??(?:<=|>=|<>|[-+*/%=<>])\??|[!?^&]|~[+~-]|:>|:\?>?/, |
| 45 | + $insert: { |
| 46 | + 'preprocessor': { |
| 47 | + $before: 'keyword', |
| 48 | + pattern: /(^[\t ]*)#.*/m, |
| 49 | + lookbehind: true, |
| 50 | + alias: 'property', |
| 51 | + inside: { |
| 52 | + 'directive': { |
| 53 | + pattern: /(^#)\b(?:else|endif|if|light|line|nowarn)\b/, |
| 54 | + lookbehind: true, |
| 55 | + alias: 'keyword', |
| 56 | + }, |
| 57 | + }, |
| 58 | + }, |
| 59 | + 'computation-expression': { |
| 60 | + $before: 'punctuation', |
| 61 | + pattern: /\b[_a-z]\w*(?=\s*\{)/i, |
| 62 | + alias: 'keyword', |
| 63 | + }, |
| 64 | + 'annotation': { |
| 65 | + $before: 'string', |
| 66 | + pattern: /\[<.+?>\]/, |
| 67 | + greedy: true, |
| 68 | + inside: { |
| 69 | + 'punctuation': /^\[<|>\]$/, |
| 70 | + 'class-name': { |
| 71 | + pattern: /^\w+$|(^|;\s*)[A-Z]\w*(?=\()/, |
| 72 | + lookbehind: true, |
| 73 | + }, |
| 74 | + 'annotation-content': { |
| 75 | + pattern: /[\s\S]+/, |
| 76 | + inside: 'fsharp', |
| 77 | + }, |
| 78 | + }, |
| 79 | + }, |
| 80 | + 'char': { |
| 81 | + $before: 'string', |
| 82 | + pattern: |
| 83 | + /'(?:[^\\']|\\(?:.|\d{3}|x[a-fA-F\d]{2}|u[a-fA-F\d]{4}|U[a-fA-F\d]{8}))'B?/, |
| 84 | + greedy: true, |
| 85 | + }, |
| 86 | + }, |
| 87 | + $insertBefore: { |
| 88 | + 'comment': { |
| 89 | + 'doc-comment': /** @type {import('../types.d.ts').GrammarTokens} */ ( |
| 90 | + getOptionalLanguage('xml-doc') |
| 91 | + )?.slash, |
| 92 | + }, |
| 93 | + }, |
93 | 94 | }; |
94 | 95 | }, |
95 | 96 | }; |
0 commit comments