Skip to content

Commit 2a6e27c

Browse files
LeaVerouDmitrySharabin
authored andcommitted
Ditch the rest symbol in favor of the $rest special property
1 parent acff03f commit 2a6e27c

31 files changed

+100
-139
lines changed

src/core/tokenize/tokenize.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { rest } from '../../shared/symbols';
21
import { LinkedList } from '../linked-list';
32
import singleton from '../prism';
43
import { _matchGrammar } from './match';
@@ -36,10 +35,10 @@ export function tokenize (this: Prism, text: string, grammar: Grammar): TokenStr
3635
return customTokenize(text, grammar, prism);
3736
}
3837

39-
let restGrammar = resolve(prism.components, grammar[rest]);
38+
let restGrammar = resolve(prism.components, grammar.$rest);
4039
while (restGrammar) {
4140
grammar = { ...grammar, ...restGrammar };
42-
restGrammar = resolve(prism.components, restGrammar[rest]);
41+
restGrammar = resolve(prism.components, restGrammar.$rest);
4342
}
4443

4544
const tokenList = new LinkedList<string | Token>();

src/languages/asciidoc.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { rest } from '../shared/symbols';
21
import type { Grammar, GrammarToken, LanguageProto } from '../types';
32

43
export default {
@@ -22,7 +21,7 @@ export default {
2221
pattern: /'(?:[^'\\]|\\.)*'/,
2322
inside: {
2423
'punctuation': /^'|'$/,
25-
[rest]: placeholder,
24+
$rest: placeholder,
2625
},
2726
},
2827
'string': /"(?:[^"\\]|\\.)*"/,
@@ -51,31 +50,31 @@ export default {
5150
pattern: /(^|[^\\])[|!]=*/,
5251
lookbehind: true,
5352
},
54-
[rest]: placeholder,
53+
$rest: placeholder,
5554
},
5655
},
5756

5857
'passthrough-block': {
5958
pattern: /^(\+{4,})$[\s\S]*?^\1$/m,
6059
inside: {
6160
'punctuation': /^\++|\++$/,
62-
[rest]: placeholder,
61+
$rest: placeholder,
6362
},
6463
},
6564
// Literal blocks and listing blocks
6665
'literal-block': {
6766
pattern: /^(-{4,}|\.{4,})$[\s\S]*?^\1$/m,
6867
inside: {
6968
'punctuation': /^(?:-+|\.+)|(?:-+|\.+)$/,
70-
[rest]: placeholder,
69+
$rest: placeholder,
7170
},
7271
},
7372
// Sidebar blocks, quote blocks, example blocks and open blocks
7473
'other-block': {
7574
pattern: /^(--|\*{4,}|_{4,}|={4,})$[\s\S]*?^\1$/m,
7675
inside: {
7776
'punctuation': /^(?:-+|\*+|_+|=+)|(?:-+|\*+|_+|=+)$/,
78-
[rest]: placeholder,
77+
$rest: placeholder,
7978
},
8079
},
8180

@@ -102,7 +101,7 @@ export default {
102101
alias: 'important',
103102
inside: {
104103
'punctuation': /^(?:\.|=+)|(?:=+|-+|~+|\^+|\++)$/,
105-
[rest]: placeholder,
104+
$rest: placeholder,
106105
},
107106
},
108107
'attribute-entry': {
@@ -215,23 +214,23 @@ export default {
215214
function copyFromAsciiDoc (...keys: (keyof typeof asciidoc)[]) {
216215
const o: Grammar = {};
217216
for (const key of keys) {
218-
o[key] = asciidoc[key];
217+
o[key] = asciidoc[key] as GrammarToken;
219218
}
220219
return o;
221220
}
222221

223-
attributes.inside['interpreted'].inside[rest] = copyFromAsciiDoc(
222+
attributes.inside['interpreted'].inside.$rest = copyFromAsciiDoc(
224223
'macro',
225224
'inline',
226225
'replacement',
227226
'entity'
228227
);
229228

230-
asciidoc['passthrough-block'].inside[rest] = copyFromAsciiDoc('macro');
229+
asciidoc['passthrough-block'].inside.$rest = copyFromAsciiDoc('macro');
231230

232-
asciidoc['literal-block'].inside[rest] = copyFromAsciiDoc('callout');
231+
asciidoc['literal-block'].inside.$rest = copyFromAsciiDoc('callout');
233232

234-
asciidoc['table'].inside[rest] = copyFromAsciiDoc(
233+
asciidoc['table'].inside.$rest = copyFromAsciiDoc(
235234
'comment-block',
236235
'passthrough-block',
237236
'literal-block',
@@ -254,7 +253,7 @@ export default {
254253
'line-continuation'
255254
);
256255

257-
asciidoc['other-block'].inside[rest] = copyFromAsciiDoc(
256+
asciidoc['other-block'].inside.$rest = copyFromAsciiDoc(
258257
'table',
259258
'list-punctuation',
260259
'indented-block',
@@ -272,7 +271,7 @@ export default {
272271
'line-continuation'
273272
);
274273

275-
asciidoc['title'].inside[rest] = copyFromAsciiDoc(
274+
asciidoc['title'].inside.$rest = copyFromAsciiDoc(
276275
'macro',
277276
'inline',
278277
'replacement',

src/languages/aspnet.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { insertBefore } from '../shared/language-util';
2-
import { rest } from '../shared/symbols';
32
import csharp from './csharp';
43
import markup from './markup';
54
import type { Grammar, GrammarToken, LanguageProto } from '../types';
@@ -30,15 +29,15 @@ export default {
3029
pattern: /<%\s*?[$=%#:]{0,2}|%>/,
3130
alias: 'tag',
3231
},
33-
[rest]: 'csharp',
34-
},
32+
$rest: 'csharp',
33+
} as unknown as Grammar,
3534
},
3635
});
3736

3837
const tag = aspnet['tag'] as GrammarToken & {
3938
inside: { 'attr-value': { inside: Grammar } };
4039
};
41-
pageDirectiveInside[rest] = tag.inside;
40+
pageDirectiveInside.$rest = tag.inside;
4241

4342
// Regexp copied from markup, with a negative look-ahead added
4443
tag.pattern =

src/languages/bison.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { insertBefore } from '../shared/language-util';
2-
import { rest } from '../shared/symbols';
32
import c from './c';
4-
import type { LanguageProto } from '../types';
3+
import type { Grammar, LanguageProto } from '../types';
54

65
export default {
76
id: 'bison',
@@ -32,8 +31,8 @@ export default {
3231
'punctuation': /<|>/,
3332
},
3433
},
35-
[rest]: c,
36-
},
34+
$rest: c,
35+
} as unknown as Grammar,
3736
},
3837
'comment': c.comment,
3938
'string': c.string,

src/languages/css.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { insertBefore } from '../shared/language-util';
2-
import { rest } from '../shared/symbols';
3-
import type { LanguageProto } from '../types';
2+
import type { Grammar, LanguageProto } from '../types';
43

54
export default {
65
id: 'css',
@@ -33,8 +32,8 @@ export default {
3332
pattern: /(^|[^\w-])(?:and|not|only|or)(?![\w-])/,
3433
lookbehind: true,
3534
},
36-
[rest]: 'css',
37-
},
35+
$rest: 'css',
36+
} as unknown as Grammar,
3837
},
3938
'url': {
4039
// https://drafts.csswg.org/css-values-3/#urls

src/languages/elixir.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { rest } from '../shared/symbols';
2-
import type { LanguageProto } from '../types';
1+
import type { Grammar, LanguageProto } from '../types';
32

43
export default {
54
id: 'elixir',
@@ -12,8 +11,8 @@ export default {
1211
pattern: /^#\{|\}$/,
1312
alias: 'punctuation',
1413
},
15-
[rest]: 'elixir',
16-
},
14+
$rest: 'elixir',
15+
} as unknown as Grammar,
1716
},
1817
};
1918

src/languages/ftl.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { embeddedIn } from '../shared/languages/templating';
2-
import { rest } from '../shared/symbols';
32
import markup from './markup';
43
import type { Grammar, LanguageProto } from '../types';
54

@@ -40,7 +39,7 @@ export default {
4039
pattern: /^\$\{|\}$/,
4140
alias: 'punctuation',
4241
},
43-
[rest]: null as Grammar[typeof rest], // see below
42+
$rest: null as Grammar['$rest'], // see below
4443
},
4544
},
4645
},
@@ -69,7 +68,7 @@ export default {
6968
'punctuation': /[,;.:()[\]{}]/,
7069
};
7170

72-
stringInterpolation.inside.interpolation.inside[rest] = ftl;
71+
stringInterpolation.inside.interpolation.inside.$rest = ftl as Grammar['$rest'];
7372

7473
return {
7574
'ftl-comment': {

src/languages/icu-message-format.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { rest } from '../shared/symbols';
2-
import type { LanguageProto } from '../types';
1+
import type { Grammar, LanguageProto } from '../types';
32

43
export default {
54
id: 'icu-message-format',
@@ -81,7 +80,7 @@ export default {
8180
'number': /\S+/,
8281
},
8382
},
84-
[rest]: 'icu-message-format',
83+
$rest: 'icu-message-format',
8584
},
8685
},
8786
'plural-style': {
@@ -138,7 +137,7 @@ export default {
138137
alias: 'string',
139138
},
140139
'punctuation': /,/,
141-
},
140+
} as unknown as Grammar,
142141
},
143142
'argument-delimiter': {
144143
pattern: /./,

src/languages/inform7.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { rest } from '../shared/symbols';
21
import type { Grammar, LanguageProto } from '../types';
32

43
export default {
@@ -15,7 +14,7 @@ export default {
1514
pattern: /\[|\]/,
1615
alias: 'punctuation',
1716
},
18-
[rest]: null as Grammar[typeof rest],
17+
$rest: null as Grammar['$rest'],
1918
},
2019
},
2120
},
@@ -65,13 +64,13 @@ export default {
6564
'punctuation': /[.,:;(){}]/,
6665
};
6766

68-
inform7['string'].inside['substitution'].inside[rest] = {
67+
inform7['string'].inside['substitution'].inside.$rest = {
6968
...inform7,
7069
'text': {
7170
pattern: /\S(?:\s*\S)*/,
7271
alias: 'comment',
7372
},
74-
};
73+
} as Grammar['$rest'];
7574

7675
return inform7;
7776
},

src/languages/javascript.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { insertBefore } from '../shared/language-util';
22
import { JS_TEMPLATE, JS_TEMPLATE_INTERPOLATION } from '../shared/languages/patterns';
3-
import { rest } from '../shared/symbols';
43
import { toArray } from '../util/iterables';
54
import clike from './clike';
6-
import type { LanguageProto } from '../types';
5+
import type { Grammar, LanguageProto } from '../types';
76

87
export default {
98
id: 'javascript',
@@ -188,11 +187,11 @@ export default {
188187
pattern: /^\$\{|\}$/,
189188
alias: 'punctuation',
190189
},
191-
[rest]: 'javascript',
190+
$rest: 'javascript',
192191
},
193192
},
194193
'string': /[\s\S]+/,
195-
},
194+
} as unknown as Grammar,
196195
},
197196
],
198197
'string-property': {

0 commit comments

Comments
 (0)