|
1 | | -import { insertBefore } from '../util/language-util.js'; |
2 | | - |
3 | 1 | /** @type {import('../types.d.ts').LanguageProto<'rescript'>} */ |
4 | 2 | export default { |
5 | 3 | id: 'rescript', |
6 | 4 | alias: 'res', |
7 | 5 | grammar () { |
8 | | - const rescript = { |
| 6 | + return { |
9 | 7 | 'comment': { |
10 | 8 | pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/, |
11 | 9 | greedy: true, |
12 | 10 | }, |
13 | 11 | 'char': { pattern: /'(?:[^\r\n\\]|\\(?:.|\w+))'/, greedy: true }, |
| 12 | + 'template-string': { |
| 13 | + pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/, |
| 14 | + greedy: true, |
| 15 | + inside: { |
| 16 | + 'template-punctuation': { |
| 17 | + pattern: /^`|`$/, |
| 18 | + alias: 'string', |
| 19 | + }, |
| 20 | + 'interpolation': { |
| 21 | + pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/, |
| 22 | + lookbehind: true, |
| 23 | + inside: { |
| 24 | + 'interpolation-punctuation': { |
| 25 | + pattern: /^\$\{|\}$/, |
| 26 | + alias: 'tag', |
| 27 | + }, |
| 28 | + $rest: 'rescript', |
| 29 | + }, |
| 30 | + }, |
| 31 | + 'string': /[\s\S]+/, |
| 32 | + }, |
| 33 | + }, |
14 | 34 | 'string': { |
15 | 35 | pattern: /"(?:\\(?:\r\n|[\s\S])|[^\\\r\n"])*"/, |
16 | 36 | greedy: true, |
@@ -41,36 +61,5 @@ export default { |
41 | 61 | /\.{3}|:[:=]?|\|>|->|=(?:==?|>)?|<=?|>=?|[|^?'#!~`]|[+\-*\/]\.?|\b(?:asr|land|lor|lsl|lsr|lxor|mod)\b/, |
42 | 62 | 'punctuation': /[(){}[\],;.]/, |
43 | 63 | }; |
44 | | - |
45 | | - insertBefore(rescript, 'string', { |
46 | | - 'template-string': { |
47 | | - pattern: /`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/, |
48 | | - greedy: true, |
49 | | - inside: { |
50 | | - 'template-punctuation': { |
51 | | - pattern: /^`|`$/, |
52 | | - alias: 'string', |
53 | | - }, |
54 | | - 'interpolation': { |
55 | | - pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/, |
56 | | - lookbehind: true, |
57 | | - inside: /** @type {Grammar} */ ({ |
58 | | - 'interpolation-punctuation': { |
59 | | - pattern: /^\$\{|\}$/, |
60 | | - alias: 'tag', |
61 | | - }, |
62 | | - $rest: /** @type {Grammar['$rest']} */ ('rescript'), |
63 | | - }), |
64 | | - }, |
65 | | - 'string': /[\s\S]+/, |
66 | | - }, |
67 | | - }, |
68 | | - }); |
69 | | - |
70 | | - return rescript; |
71 | 64 | }, |
72 | 65 | }; |
73 | | - |
74 | | -/** |
75 | | - * @typedef {import('../types.d.ts').Grammar} Grammar |
76 | | - */ |
0 commit comments