Skip to content

Commit 482a708

Browse files
rescript
1 parent ea81aef commit 482a708

File tree

1 file changed

+23
-34
lines changed

1 file changed

+23
-34
lines changed

src/languages/rescript.js

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
1-
import { insertBefore } from '../util/language-util.js';
2-
31
/** @type {import('../types.d.ts').LanguageProto<'rescript'>} */
42
export default {
53
id: 'rescript',
64
alias: 'res',
75
grammar () {
8-
const rescript = {
6+
return {
97
'comment': {
108
pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
119
greedy: true,
1210
},
1311
'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+
},
1434
'string': {
1535
pattern: /"(?:\\(?:\r\n|[\s\S])|[^\\\r\n"])*"/,
1636
greedy: true,
@@ -41,36 +61,5 @@ export default {
4161
/\.{3}|:[:=]?|\|>|->|=(?:==?|>)?|<=?|>=?|[|^?'#!~`]|[+\-*\/]\.?|\b(?:asr|land|lor|lsl|lsr|lxor|mod)\b/,
4262
'punctuation': /[(){}[\],;.]/,
4363
};
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;
7164
},
7265
};
73-
74-
/**
75-
* @typedef {import('../types.d.ts').Grammar} Grammar
76-
*/

0 commit comments

Comments
 (0)