limn-hl 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +109 -148
- package/dist/detect.d.ts +7 -1
- package/dist/detect.js +592 -502
- package/dist/engine.js +45 -1
- package/dist/generated/detect.d.ts +11 -0
- package/dist/generated/detect.js +2434 -0
- package/dist/generated/grammars.d.ts +119 -0
- package/dist/generated/grammars.js +613 -0
- package/dist/generated/lang.d.ts +6 -0
- package/dist/{lang/index.js → generated/lang.js} +82 -56
- package/dist/{theme/generated.d.ts → generated/themes.d.ts} +3 -1
- package/dist/{theme/generated.js → generated/themes.js} +29 -0
- package/dist/lang.d.ts +1 -0
- package/dist/lang.js +1 -0
- package/dist/render/ansi.d.ts +1 -1
- package/dist/render/html.d.ts +1 -1
- package/dist/{theme/index.d.ts → theme.d.ts} +1 -1
- package/dist/theme.js +1 -0
- package/dist/vm/compile.d.ts +4 -0
- package/dist/vm/compile.js +390 -0
- package/dist/vm/exec.d.ts +3 -0
- package/dist/vm/exec.js +218 -0
- package/dist/vm/format.d.ts +255 -0
- package/dist/vm/format.js +248 -0
- package/dist/vm/index.d.ts +2 -0
- package/dist/vm/index.js +2 -0
- package/dist/vm/pat.d.ts +4 -0
- package/dist/vm/pat.js +701 -0
- package/dist/vm/quoted.d.ts +8 -0
- package/dist/vm/quoted.js +190 -0
- package/dist/vm/scan.d.ts +3 -0
- package/dist/vm/scan.js +499 -0
- package/dist/wordtable.d.ts +8 -4
- package/dist/wordtable.js +107 -30
- package/package.json +6 -6
- package/dist/lang/clike.d.ts +0 -15
- package/dist/lang/clike.js +0 -35
- package/dist/lang/clike_helpers.d.ts +0 -8
- package/dist/lang/clike_helpers.js +0 -220
- package/dist/lang/code.d.ts +0 -45
- package/dist/lang/code.js +0 -779
- package/dist/lang/config.d.ts +0 -5
- package/dist/lang/config.js +0 -164
- package/dist/lang/css.d.ts +0 -5
- package/dist/lang/css.js +0 -125
- package/dist/lang/docs.d.ts +0 -12
- package/dist/lang/docs.js +0 -462
- package/dist/lang/formats.d.ts +0 -10
- package/dist/lang/formats.js +0 -295
- package/dist/lang/html.d.ts +0 -11
- package/dist/lang/html.js +0 -298
- package/dist/lang/index.d.ts +0 -20
- package/dist/lang/js.d.ts +0 -9
- package/dist/lang/js.js +0 -532
- package/dist/lang/js_helpers.d.ts +0 -7
- package/dist/lang/js_helpers.js +0 -308
- package/dist/lang/json.d.ts +0 -3
- package/dist/lang/json.js +0 -136
- package/dist/lang/markdown.d.ts +0 -3
- package/dist/lang/markdown.js +0 -249
- package/dist/lang/python.d.ts +0 -3
- package/dist/lang/python.js +0 -335
- package/dist/lang/scripting.d.ts +0 -7
- package/dist/lang/scripting.js +0 -216
- package/dist/lang/shell.d.ts +0 -7
- package/dist/lang/shell.js +0 -278
- package/dist/lang/specs_gen.d.ts +0 -66
- package/dist/lang/specs_gen.js +0 -381
- package/dist/lang/terminal.d.ts +0 -9
- package/dist/lang/terminal.js +0 -550
- package/dist/lang/yaml.d.ts +0 -4
- package/dist/lang/yaml.js +0 -176
- package/dist/theme/index.js +0 -1
package/dist/lang/code.js
DELETED
|
@@ -1,779 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
hasCallParen,
|
|
3
|
-
isDigit,
|
|
4
|
-
isIdentCont,
|
|
5
|
-
isIdentStart,
|
|
6
|
-
Cursor,
|
|
7
|
-
emitCommentWithTodo,
|
|
8
|
-
scanEscape,
|
|
9
|
-
scanNumber
|
|
10
|
-
} from "../cursor.js";
|
|
11
|
-
import { Grammar } from "../engine.js";
|
|
12
|
-
import {
|
|
13
|
-
TokenKind,
|
|
14
|
-
WordTable as WordTableClass
|
|
15
|
-
} from "../index.js";
|
|
16
|
-
export function onceGrammar(build) {
|
|
17
|
-
let cached;
|
|
18
|
-
return () => {
|
|
19
|
-
if (cached === undefined) {
|
|
20
|
-
cached = build();
|
|
21
|
-
}
|
|
22
|
-
return cached;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
export function buildWordTable(keywords, types, constants, caseInsensitive) {
|
|
26
|
-
const groups = [];
|
|
27
|
-
if (keywords !== "")
|
|
28
|
-
groups.push({ kind: TokenKind.Keyword, words: keywords });
|
|
29
|
-
if (types !== "")
|
|
30
|
-
groups.push({ kind: TokenKind.Type, words: types });
|
|
31
|
-
if (constants !== "")
|
|
32
|
-
groups.push({ kind: TokenKind.Constant, words: constants });
|
|
33
|
-
return new WordTableClass(caseInsensitive, ...groups);
|
|
34
|
-
}
|
|
35
|
-
export function scanStringDelim(src, start, bodyPos, closeDelim, multiline, raw, escapes, e) {
|
|
36
|
-
const n = src.length;
|
|
37
|
-
if (raw) {
|
|
38
|
-
const idx = src.indexOf(closeDelim, bodyPos);
|
|
39
|
-
if (idx >= 0) {
|
|
40
|
-
let end = idx + closeDelim.length;
|
|
41
|
-
if (!multiline && closeDelim.length === 1) {
|
|
42
|
-
const nl = src.indexOf(`
|
|
43
|
-
`, bodyPos);
|
|
44
|
-
if (nl >= 0 && nl < idx) {
|
|
45
|
-
end = nl;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
e.emit(start, end, TokenKind.String);
|
|
49
|
-
return end;
|
|
50
|
-
}
|
|
51
|
-
let end = n;
|
|
52
|
-
if (!multiline) {
|
|
53
|
-
const nl = src.indexOf(`
|
|
54
|
-
`, bodyPos);
|
|
55
|
-
if (nl >= 0) {
|
|
56
|
-
end = nl;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
e.emit(start, end, TokenKind.String);
|
|
60
|
-
return end;
|
|
61
|
-
}
|
|
62
|
-
let i = bodyPos;
|
|
63
|
-
let segStart = start;
|
|
64
|
-
const closeCode = closeDelim.length === 1 ? closeDelim.charCodeAt(0) : -1;
|
|
65
|
-
while (i < n) {
|
|
66
|
-
const ch = src.charCodeAt(i);
|
|
67
|
-
if (ch === 10 && !multiline) {
|
|
68
|
-
e.emit(segStart, i, TokenKind.String);
|
|
69
|
-
return i;
|
|
70
|
-
}
|
|
71
|
-
if (closeCode >= 0) {
|
|
72
|
-
if (ch === closeCode) {
|
|
73
|
-
i++;
|
|
74
|
-
e.emit(segStart, i, TokenKind.String);
|
|
75
|
-
return i;
|
|
76
|
-
}
|
|
77
|
-
} else if (src.startsWith(closeDelim, i)) {
|
|
78
|
-
i += closeDelim.length;
|
|
79
|
-
e.emit(segStart, i, TokenKind.String);
|
|
80
|
-
return i;
|
|
81
|
-
}
|
|
82
|
-
if (ch === 92) {
|
|
83
|
-
const escEnd = scanEscape(src, i);
|
|
84
|
-
if (escapes) {
|
|
85
|
-
if (i > segStart) {
|
|
86
|
-
e.emit(segStart, i, TokenKind.String);
|
|
87
|
-
}
|
|
88
|
-
e.emit(i, escEnd, TokenKind.Escape);
|
|
89
|
-
segStart = escEnd;
|
|
90
|
-
}
|
|
91
|
-
i = escEnd;
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
i++;
|
|
95
|
-
}
|
|
96
|
-
e.emit(segStart, n, TokenKind.String);
|
|
97
|
-
return n;
|
|
98
|
-
}
|
|
99
|
-
export function tryPrefixIdent(src, pos, extra, kind, e) {
|
|
100
|
-
const n = src.length;
|
|
101
|
-
if (pos + 1 >= n || !isIdentStart(src.charCodeAt(pos + 1))) {
|
|
102
|
-
return 0;
|
|
103
|
-
}
|
|
104
|
-
let end = pos + 2;
|
|
105
|
-
if (extra !== undefined) {
|
|
106
|
-
while (end < n) {
|
|
107
|
-
const ch = src.charCodeAt(end);
|
|
108
|
-
if (isIdentCont(ch) || ch < 256 && extra[ch] !== 0) {
|
|
109
|
-
end++;
|
|
110
|
-
} else {
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
while (end < n && isIdentCont(src.charCodeAt(end))) {
|
|
116
|
-
end++;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
e.emit(pos, end, kind);
|
|
120
|
-
return end;
|
|
121
|
-
}
|
|
122
|
-
const CC_OTHER = 0;
|
|
123
|
-
const CC_SPACE = 1;
|
|
124
|
-
const CC_IDENT = 2;
|
|
125
|
-
const CC_DIGIT = 3;
|
|
126
|
-
const CC_PUNCT = 4;
|
|
127
|
-
const CC_OPER = 5;
|
|
128
|
-
const CC_RULE = 6;
|
|
129
|
-
const CF_IDENT_START = 1 << 0;
|
|
130
|
-
const CF_IDENT_CONT = 1 << 1;
|
|
131
|
-
const CF_CUSTOM = 1 << 2;
|
|
132
|
-
const CF_PREFIX_IDENT = 1 << 3;
|
|
133
|
-
const CF_PUNCT = 1 << 4;
|
|
134
|
-
const CF_OPER = 1 << 5;
|
|
135
|
-
const CF_RULE = 1 << 6;
|
|
136
|
-
const QF_QUOTE = 1 << 0;
|
|
137
|
-
const QF_MULTI = 1 << 1;
|
|
138
|
-
const QF_RAW = 1 << 2;
|
|
139
|
-
const QF_INTERP = 1 << 3;
|
|
140
|
-
const CM_ROOT = 0;
|
|
141
|
-
const CM_AFTER_DOT = 1;
|
|
142
|
-
const CM_TYPE_EXPECT = 2;
|
|
143
|
-
const CM_INTERP_EXPR = 3;
|
|
144
|
-
const CM_INTERP_NESTED = 4;
|
|
145
|
-
const CM_INTERP_STR = 5;
|
|
146
|
-
export function buildCodeGrammar(cfg, ...hooks) {
|
|
147
|
-
const words = buildWordTable(cfg.keywords ?? "", cfg.types ?? "", cfg.constants ?? "", Boolean(cfg.caseInsensitive));
|
|
148
|
-
const hasTypeAfter = Boolean(cfg.typeAfterKeywords);
|
|
149
|
-
const typeAfterWords = hasTypeAfter ? new WordTableClass(Boolean(cfg.caseInsensitive), {
|
|
150
|
-
kind: TokenKind.Keyword,
|
|
151
|
-
words: cfg.typeAfterKeywords
|
|
152
|
-
}) : undefined;
|
|
153
|
-
const dispatch = new Uint8Array(256);
|
|
154
|
-
const charFlags = new Uint8Array(256);
|
|
155
|
-
const quoteFlags = new Uint8Array(256);
|
|
156
|
-
const startExtra = new Uint8Array(256);
|
|
157
|
-
const contExtra = new Uint8Array(256);
|
|
158
|
-
if (cfg.identStartExtra) {
|
|
159
|
-
for (let i = 0;i < cfg.identStartExtra.length; i++) {
|
|
160
|
-
const b = cfg.identStartExtra.charCodeAt(i);
|
|
161
|
-
if (b < 256)
|
|
162
|
-
startExtra[b] = 1;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (cfg.identContExtra) {
|
|
166
|
-
for (let i = 0;i < cfg.identContExtra.length; i++) {
|
|
167
|
-
const b = cfg.identContExtra.charCodeAt(i);
|
|
168
|
-
if (b < 256)
|
|
169
|
-
contExtra[b] = 1;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
for (let b = 0;b < 256; b++) {
|
|
173
|
-
if (isIdentStart(b) || startExtra[b] !== 0) {
|
|
174
|
-
charFlags[b] |= CF_IDENT_START;
|
|
175
|
-
dispatch[b] = CC_IDENT;
|
|
176
|
-
} else if (isDigit(b)) {
|
|
177
|
-
dispatch[b] = CC_DIGIT;
|
|
178
|
-
}
|
|
179
|
-
if (isIdentCont(b) || startExtra[b] !== 0 || contExtra[b] !== 0) {
|
|
180
|
-
charFlags[b] |= CF_IDENT_CONT;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
for (const b of [32, 9, 10, 13]) {
|
|
184
|
-
dispatch[b] = CC_SPACE;
|
|
185
|
-
}
|
|
186
|
-
const punct = "{}()[].,;:";
|
|
187
|
-
for (let i = 0;i < punct.length; i++) {
|
|
188
|
-
const b = punct.charCodeAt(i);
|
|
189
|
-
charFlags[b] |= CF_PUNCT;
|
|
190
|
-
if (dispatch[b] === CC_OTHER)
|
|
191
|
-
dispatch[b] = CC_PUNCT;
|
|
192
|
-
}
|
|
193
|
-
const oper = "+-*/%&|^~!=<>?";
|
|
194
|
-
for (let i = 0;i < oper.length; i++) {
|
|
195
|
-
const b = oper.charCodeAt(i);
|
|
196
|
-
charFlags[b] |= CF_OPER;
|
|
197
|
-
if (dispatch[b] === CC_OTHER)
|
|
198
|
-
dispatch[b] = CC_OPER;
|
|
199
|
-
}
|
|
200
|
-
let prefixCont;
|
|
201
|
-
if (cfg.prefixIdent?.contExtra) {
|
|
202
|
-
prefixCont = new Uint8Array(256);
|
|
203
|
-
for (let i = 0;i < cfg.prefixIdent.contExtra.length; i++) {
|
|
204
|
-
const b = cfg.prefixIdent.contExtra.charCodeAt(i);
|
|
205
|
-
if (b < 256)
|
|
206
|
-
prefixCont[b] = 1;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if (cfg.multilineQuotes) {
|
|
210
|
-
for (let i = 0;i < cfg.multilineQuotes.length; i++) {
|
|
211
|
-
const q = cfg.multilineQuotes.charCodeAt(i);
|
|
212
|
-
if (q < 256)
|
|
213
|
-
quoteFlags[q] |= QF_MULTI;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if (cfg.rawQuotes) {
|
|
217
|
-
for (let i = 0;i < cfg.rawQuotes.length; i++) {
|
|
218
|
-
const q = cfg.rawQuotes.charCodeAt(i);
|
|
219
|
-
if (q < 256)
|
|
220
|
-
quoteFlags[q] |= QF_RAW;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
if (cfg.quotes) {
|
|
224
|
-
for (let i = 0;i < cfg.quotes.length; i++) {
|
|
225
|
-
const q = cfg.quotes.charCodeAt(i);
|
|
226
|
-
if (q < 256) {
|
|
227
|
-
quoteFlags[q] |= QF_QUOTE;
|
|
228
|
-
charFlags[q] |= CF_RULE;
|
|
229
|
-
dispatch[q] = CC_RULE;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (cfg.interpolation) {
|
|
234
|
-
for (let i = 0;i < cfg.interpolation.quotes.length; i++) {
|
|
235
|
-
const q = cfg.interpolation.quotes.charCodeAt(i);
|
|
236
|
-
if (q < 256 && (quoteFlags[q] & (QF_QUOTE | QF_RAW)) === QF_QUOTE) {
|
|
237
|
-
quoteFlags[q] |= QF_INTERP;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
const compiledHooks = [];
|
|
242
|
-
for (const h of hooks) {
|
|
243
|
-
const leadMask = new Uint8Array(256);
|
|
244
|
-
for (let i = 0;i < h.leadBytes.length; i++) {
|
|
245
|
-
const b = h.leadBytes.charCodeAt(i);
|
|
246
|
-
if (b < 256) {
|
|
247
|
-
leadMask[b] = 1;
|
|
248
|
-
charFlags[b] |= CF_CUSTOM | CF_RULE;
|
|
249
|
-
dispatch[b] = CC_RULE;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
compiledHooks.push({ leadMask, scan: h.scan });
|
|
253
|
-
}
|
|
254
|
-
if (cfg.prefixIdent?.prefixes) {
|
|
255
|
-
for (let i = 0;i < cfg.prefixIdent.prefixes.length; i++) {
|
|
256
|
-
const b = cfg.prefixIdent.prefixes.charCodeAt(i);
|
|
257
|
-
if (b < 256) {
|
|
258
|
-
charFlags[b] |= CF_PREFIX_IDENT | CF_RULE;
|
|
259
|
-
dispatch[b] = CC_RULE;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
if (cfg.lineComments) {
|
|
264
|
-
for (const lc of cfg.lineComments) {
|
|
265
|
-
if (lc !== "") {
|
|
266
|
-
const b = lc.charCodeAt(0);
|
|
267
|
-
if (b < 256) {
|
|
268
|
-
charFlags[b] |= CF_RULE;
|
|
269
|
-
dispatch[b] = CC_RULE;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
if (cfg.blockComment && cfg.blockComment[0] !== "") {
|
|
275
|
-
const b = cfg.blockComment[0].charCodeAt(0);
|
|
276
|
-
if (b < 256) {
|
|
277
|
-
charFlags[b] |= CF_RULE;
|
|
278
|
-
dispatch[b] = CC_RULE;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
if (cfg.typeAfterArrow) {
|
|
282
|
-
charFlags[45] |= CF_RULE;
|
|
283
|
-
dispatch[45] = CC_RULE;
|
|
284
|
-
}
|
|
285
|
-
charFlags[46] |= CF_RULE;
|
|
286
|
-
dispatch[46] = CC_RULE;
|
|
287
|
-
const compiled = {
|
|
288
|
-
cfg,
|
|
289
|
-
words,
|
|
290
|
-
hasTypeAfter,
|
|
291
|
-
typeAfterWords,
|
|
292
|
-
hooks: compiledHooks,
|
|
293
|
-
hasCustom: compiledHooks.length > 0,
|
|
294
|
-
hasPrefixIdent: Boolean(cfg.prefixIdent?.prefixes),
|
|
295
|
-
prefixCont,
|
|
296
|
-
dispatch,
|
|
297
|
-
charFlags,
|
|
298
|
-
quoteFlags
|
|
299
|
-
};
|
|
300
|
-
return new Grammar(cfg.name, (src, e) => scanCode(src, compiled, e), ...cfg.aliases ?? []);
|
|
301
|
-
}
|
|
302
|
-
function popMode(stack, sp) {
|
|
303
|
-
if (sp > 0) {
|
|
304
|
-
sp--;
|
|
305
|
-
return [sp, stack[sp]];
|
|
306
|
-
}
|
|
307
|
-
return [0, { kind: CM_ROOT, quote: 0, triple: false, multiline: false }];
|
|
308
|
-
}
|
|
309
|
-
function scanCode(src, c, e) {
|
|
310
|
-
const n = src.length;
|
|
311
|
-
if (n === 0) {
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
const stack = new Array(32);
|
|
315
|
-
let sp = 0;
|
|
316
|
-
let mode = {
|
|
317
|
-
kind: CM_ROOT,
|
|
318
|
-
quote: 0,
|
|
319
|
-
triple: false,
|
|
320
|
-
multiline: false
|
|
321
|
-
};
|
|
322
|
-
stack[0] = mode;
|
|
323
|
-
let i = 0;
|
|
324
|
-
let lineStart = true;
|
|
325
|
-
const cfg = c.cfg;
|
|
326
|
-
const hasTypeExpect = c.hasTypeAfter || Boolean(cfg.typeAfterArrow);
|
|
327
|
-
const { dispatch, charFlags, quoteFlags } = c;
|
|
328
|
-
const interpKind = cfg.interpolation?.kind;
|
|
329
|
-
const emitIdent = () => {
|
|
330
|
-
const start = i;
|
|
331
|
-
i++;
|
|
332
|
-
while (i < n) {
|
|
333
|
-
const b = src.charCodeAt(i);
|
|
334
|
-
if (b < 256 ? (charFlags[b] & CF_IDENT_CONT) !== 0 : true) {
|
|
335
|
-
i++;
|
|
336
|
-
} else {
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
if (cfg.bangMacros && i < n && src.charCodeAt(i) === 33 && (i + 1 >= n || src.charCodeAt(i + 1) !== 61)) {
|
|
341
|
-
i++;
|
|
342
|
-
e.emit(start, i, TokenKind.Func);
|
|
343
|
-
lineStart = false;
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
const kind = c.words.lookupSpan(src, start, i);
|
|
347
|
-
if (kind === TokenKind.Keyword) {
|
|
348
|
-
e.emit(start, i, TokenKind.Keyword);
|
|
349
|
-
if (c.hasTypeAfter && c.typeAfterWords.lookupSpan(src, start, i) === TokenKind.Keyword && sp + 1 < stack.length) {
|
|
350
|
-
sp++;
|
|
351
|
-
mode = {
|
|
352
|
-
kind: CM_TYPE_EXPECT,
|
|
353
|
-
quote: 0,
|
|
354
|
-
triple: false,
|
|
355
|
-
multiline: false
|
|
356
|
-
};
|
|
357
|
-
stack[sp] = mode;
|
|
358
|
-
}
|
|
359
|
-
} else if (kind === TokenKind.Type || kind === TokenKind.Constant) {
|
|
360
|
-
e.emit(start, i, kind);
|
|
361
|
-
} else if (hasCallParen(src, i)) {
|
|
362
|
-
e.emit(start, i, TokenKind.Func);
|
|
363
|
-
}
|
|
364
|
-
lineStart = false;
|
|
365
|
-
};
|
|
366
|
-
const emitPunct = () => {
|
|
367
|
-
const start = i;
|
|
368
|
-
i++;
|
|
369
|
-
if (interpKind !== undefined && mode.kind !== CM_ROOT) {
|
|
370
|
-
const openB = interpKind === "backslashParen" ? 40 : 123;
|
|
371
|
-
const closeB = interpKind === "backslashParen" ? 41 : 125;
|
|
372
|
-
while (i < n) {
|
|
373
|
-
const b = src.charCodeAt(i);
|
|
374
|
-
if (b >= 256 || (charFlags[b] & (CF_PUNCT | CF_RULE)) !== CF_PUNCT || b === openB || b === closeB) {
|
|
375
|
-
break;
|
|
376
|
-
}
|
|
377
|
-
i++;
|
|
378
|
-
}
|
|
379
|
-
} else {
|
|
380
|
-
while (i < n) {
|
|
381
|
-
const b = src.charCodeAt(i);
|
|
382
|
-
if (b >= 256 || (charFlags[b] & (CF_PUNCT | CF_RULE)) !== CF_PUNCT) {
|
|
383
|
-
break;
|
|
384
|
-
}
|
|
385
|
-
i++;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
e.emit(start, i, TokenKind.Punctuation);
|
|
389
|
-
lineStart = false;
|
|
390
|
-
};
|
|
391
|
-
const emitOper = () => {
|
|
392
|
-
const start = i;
|
|
393
|
-
i++;
|
|
394
|
-
while (i < n) {
|
|
395
|
-
const b = src.charCodeAt(i);
|
|
396
|
-
if (b >= 256 || (charFlags[b] & (CF_OPER | CF_RULE)) !== CF_OPER) {
|
|
397
|
-
break;
|
|
398
|
-
}
|
|
399
|
-
i++;
|
|
400
|
-
}
|
|
401
|
-
e.emit(start, i, TokenKind.Operator);
|
|
402
|
-
lineStart = false;
|
|
403
|
-
};
|
|
404
|
-
while (i < n && !e.stopped()) {
|
|
405
|
-
if (mode.kind === CM_AFTER_DOT) {
|
|
406
|
-
while (i < n) {
|
|
407
|
-
const ch = src.charCodeAt(i);
|
|
408
|
-
if (ch === 32 || ch === 9 || ch === 10 || ch === 13) {
|
|
409
|
-
lineStart = ch === 10;
|
|
410
|
-
i++;
|
|
411
|
-
} else {
|
|
412
|
-
break;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
if (i < n) {
|
|
416
|
-
const ch = src.charCodeAt(i);
|
|
417
|
-
if (ch < 256 ? (charFlags[ch] & CF_IDENT_START) !== 0 : true) {
|
|
418
|
-
const start = i;
|
|
419
|
-
i++;
|
|
420
|
-
while (i < n) {
|
|
421
|
-
const b = src.charCodeAt(i);
|
|
422
|
-
if (b < 256 ? (charFlags[b] & CF_IDENT_CONT) !== 0 : true) {
|
|
423
|
-
i++;
|
|
424
|
-
} else {
|
|
425
|
-
break;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
if (hasCallParen(src, i)) {
|
|
429
|
-
e.emit(start, i, TokenKind.Func);
|
|
430
|
-
}
|
|
431
|
-
lineStart = false;
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
[sp, mode] = popMode(stack, sp);
|
|
435
|
-
continue;
|
|
436
|
-
}
|
|
437
|
-
if (mode.kind === CM_TYPE_EXPECT) {
|
|
438
|
-
if (!hasTypeExpect) {
|
|
439
|
-
mode = { kind: CM_ROOT, quote: 0, triple: false, multiline: false };
|
|
440
|
-
continue;
|
|
441
|
-
}
|
|
442
|
-
while (i < n) {
|
|
443
|
-
const ch = src.charCodeAt(i);
|
|
444
|
-
if (ch === 32 || ch === 9 || ch === 10 || ch === 13) {
|
|
445
|
-
lineStart = ch === 10;
|
|
446
|
-
i++;
|
|
447
|
-
} else {
|
|
448
|
-
break;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
if (i < n) {
|
|
452
|
-
const ch = src.charCodeAt(i);
|
|
453
|
-
if (ch < 256 ? (charFlags[ch] & CF_IDENT_START) !== 0 : true) {
|
|
454
|
-
const start = i;
|
|
455
|
-
i++;
|
|
456
|
-
while (i < n) {
|
|
457
|
-
const b = src.charCodeAt(i);
|
|
458
|
-
if (b < 256 ? (charFlags[b] & CF_IDENT_CONT) !== 0 : true) {
|
|
459
|
-
i++;
|
|
460
|
-
} else {
|
|
461
|
-
break;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
const lk = c.words.lookupSpan(src, start, i);
|
|
465
|
-
if (lk === TokenKind.Keyword || lk === TokenKind.Constant) {
|
|
466
|
-
e.emit(start, i, lk);
|
|
467
|
-
} else {
|
|
468
|
-
e.emit(start, i, TokenKind.Type);
|
|
469
|
-
}
|
|
470
|
-
lineStart = false;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
[sp, mode] = popMode(stack, sp);
|
|
474
|
-
continue;
|
|
475
|
-
}
|
|
476
|
-
if (mode.kind === CM_INTERP_STR) {
|
|
477
|
-
if (interpKind === undefined) {
|
|
478
|
-
mode = { kind: CM_ROOT, quote: 0, triple: false, multiline: false };
|
|
479
|
-
continue;
|
|
480
|
-
}
|
|
481
|
-
const ch = src.charCodeAt(i);
|
|
482
|
-
if (mode.triple && i + 2 < n && ch === mode.quote && src.charCodeAt(i + 1) === mode.quote && src.charCodeAt(i + 2) === mode.quote) {
|
|
483
|
-
e.emit(i, i + 3, TokenKind.String);
|
|
484
|
-
i += 3;
|
|
485
|
-
lineStart = false;
|
|
486
|
-
[sp, mode] = popMode(stack, sp);
|
|
487
|
-
continue;
|
|
488
|
-
}
|
|
489
|
-
if (!mode.triple && ch === mode.quote) {
|
|
490
|
-
e.emit(i, i + 1, TokenKind.String);
|
|
491
|
-
i++;
|
|
492
|
-
lineStart = false;
|
|
493
|
-
[sp, mode] = popMode(stack, sp);
|
|
494
|
-
continue;
|
|
495
|
-
}
|
|
496
|
-
if (!mode.multiline && ch === 10) {
|
|
497
|
-
i++;
|
|
498
|
-
lineStart = true;
|
|
499
|
-
[sp, mode] = popMode(stack, sp);
|
|
500
|
-
continue;
|
|
501
|
-
}
|
|
502
|
-
let matchedInterp = false;
|
|
503
|
-
if (interpKind === "dollarBrace") {
|
|
504
|
-
matchedInterp = ch === 36 && i + 1 < n && src.charCodeAt(i + 1) === 123;
|
|
505
|
-
} else if (interpKind === "hashBrace") {
|
|
506
|
-
matchedInterp = ch === 35 && i + 1 < n && src.charCodeAt(i + 1) === 123;
|
|
507
|
-
} else {
|
|
508
|
-
matchedInterp = ch === 92 && i + 1 < n && src.charCodeAt(i + 1) === 40;
|
|
509
|
-
}
|
|
510
|
-
if (matchedInterp) {
|
|
511
|
-
e.emit(i, i + 2, TokenKind.Keyword);
|
|
512
|
-
i += 2;
|
|
513
|
-
lineStart = false;
|
|
514
|
-
if (sp + 1 < stack.length) {
|
|
515
|
-
sp++;
|
|
516
|
-
mode = {
|
|
517
|
-
kind: CM_INTERP_EXPR,
|
|
518
|
-
quote: 0,
|
|
519
|
-
triple: false,
|
|
520
|
-
multiline: false
|
|
521
|
-
};
|
|
522
|
-
stack[sp] = mode;
|
|
523
|
-
}
|
|
524
|
-
continue;
|
|
525
|
-
}
|
|
526
|
-
if (cfg.stringEscapes && ch === 92) {
|
|
527
|
-
const escEnd = scanEscape(src, i);
|
|
528
|
-
e.emit(i, escEnd, TokenKind.Escape);
|
|
529
|
-
i = escEnd;
|
|
530
|
-
lineStart = src.charCodeAt(i - 1) === 10;
|
|
531
|
-
continue;
|
|
532
|
-
}
|
|
533
|
-
const start = i;
|
|
534
|
-
for (;; ) {
|
|
535
|
-
lineStart = src.charCodeAt(i) === 10;
|
|
536
|
-
i++;
|
|
537
|
-
if (i >= n)
|
|
538
|
-
break;
|
|
539
|
-
const b = src.charCodeAt(i);
|
|
540
|
-
if (b === mode.quote || !mode.multiline && b === 10)
|
|
541
|
-
break;
|
|
542
|
-
if (b === 92 && (cfg.stringEscapes || interpKind === "backslashParen"))
|
|
543
|
-
break;
|
|
544
|
-
if (interpKind === "dollarBrace" && b === 36 || interpKind === "hashBrace" && b === 35) {
|
|
545
|
-
break;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
e.emit(start, i, TokenKind.String);
|
|
549
|
-
continue;
|
|
550
|
-
}
|
|
551
|
-
const ch = src.charCodeAt(i);
|
|
552
|
-
if (interpKind !== undefined && mode.kind !== CM_ROOT) {
|
|
553
|
-
const openB = interpKind === "backslashParen" ? 40 : 123;
|
|
554
|
-
const closeB = interpKind === "backslashParen" ? 41 : 125;
|
|
555
|
-
if (ch === openB) {
|
|
556
|
-
e.emit(i, i + 1, TokenKind.Punctuation);
|
|
557
|
-
i++;
|
|
558
|
-
lineStart = false;
|
|
559
|
-
if (sp + 1 < stack.length) {
|
|
560
|
-
sp++;
|
|
561
|
-
mode = {
|
|
562
|
-
kind: CM_INTERP_NESTED,
|
|
563
|
-
quote: 0,
|
|
564
|
-
triple: false,
|
|
565
|
-
multiline: false
|
|
566
|
-
};
|
|
567
|
-
stack[sp] = mode;
|
|
568
|
-
}
|
|
569
|
-
continue;
|
|
570
|
-
}
|
|
571
|
-
if (ch === closeB) {
|
|
572
|
-
e.emit(i, i + 1, mode.kind === CM_INTERP_EXPR ? TokenKind.Keyword : TokenKind.Punctuation);
|
|
573
|
-
i++;
|
|
574
|
-
lineStart = false;
|
|
575
|
-
[sp, mode] = popMode(stack, sp);
|
|
576
|
-
continue;
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
const dc = ch < 256 ? dispatch[ch] : CC_IDENT;
|
|
580
|
-
if (dc === CC_RULE) {
|
|
581
|
-
if (ch === 46 && i + 1 < n && isDigit(src.charCodeAt(i + 1))) {
|
|
582
|
-
const end = scanNumber(src, i);
|
|
583
|
-
e.emit(i, end, TokenKind.Number);
|
|
584
|
-
i = end;
|
|
585
|
-
lineStart = false;
|
|
586
|
-
continue;
|
|
587
|
-
}
|
|
588
|
-
if (c.hasCustom && (charFlags[ch] & CF_CUSTOM) !== 0) {
|
|
589
|
-
let matched = false;
|
|
590
|
-
for (let hIdx = 0;hIdx < c.hooks.length; hIdx++) {
|
|
591
|
-
const hk = c.hooks[hIdx];
|
|
592
|
-
if (hk.leadMask[ch] === 0)
|
|
593
|
-
continue;
|
|
594
|
-
const next = hk.scan(src, i, lineStart, e);
|
|
595
|
-
if (next > i) {
|
|
596
|
-
i = next;
|
|
597
|
-
lineStart = src.charCodeAt(i - 1) === 10;
|
|
598
|
-
matched = true;
|
|
599
|
-
break;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
if (matched)
|
|
603
|
-
continue;
|
|
604
|
-
}
|
|
605
|
-
if (c.hasPrefixIdent && (charFlags[ch] & CF_PREFIX_IDENT) !== 0) {
|
|
606
|
-
const next = tryPrefixIdent(src, i, c.prefixCont, TokenKind.Variable, e);
|
|
607
|
-
if (next > i) {
|
|
608
|
-
i = next;
|
|
609
|
-
lineStart = false;
|
|
610
|
-
continue;
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
if (cfg.lineComments) {
|
|
614
|
-
let matchedLC = false;
|
|
615
|
-
for (const lc of cfg.lineComments) {
|
|
616
|
-
if (src.startsWith(lc, i)) {
|
|
617
|
-
const body = i + lc.length;
|
|
618
|
-
const nl = src.indexOf(`
|
|
619
|
-
`, body);
|
|
620
|
-
const end = nl >= 0 ? nl : n;
|
|
621
|
-
emitCommentWithTodo(src, i, end, e);
|
|
622
|
-
i = end;
|
|
623
|
-
lineStart = false;
|
|
624
|
-
matchedLC = true;
|
|
625
|
-
break;
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
if (matchedLC)
|
|
629
|
-
continue;
|
|
630
|
-
}
|
|
631
|
-
if (cfg.blockComment && cfg.blockComment[0] !== "" && src.startsWith(cfg.blockComment[0], i)) {
|
|
632
|
-
const openS = cfg.blockComment[0];
|
|
633
|
-
const cur = new Cursor(src, i + openS.length);
|
|
634
|
-
if (cfg.nestedBlockComments) {
|
|
635
|
-
cur.scanNestedComment(openS, cfg.blockComment[1]);
|
|
636
|
-
} else {
|
|
637
|
-
cur.scanUntil(cfg.blockComment[1]);
|
|
638
|
-
}
|
|
639
|
-
emitCommentWithTodo(src, i, cur.pos, e);
|
|
640
|
-
i = cur.pos;
|
|
641
|
-
lineStart = i > 0 && src.charCodeAt(i - 1) === 10;
|
|
642
|
-
continue;
|
|
643
|
-
}
|
|
644
|
-
const qf = quoteFlags[ch];
|
|
645
|
-
if ((qf & QF_QUOTE) !== 0) {
|
|
646
|
-
if (cfg.tripleQuotes && i + 2 < n && src.charCodeAt(i + 1) === ch && src.charCodeAt(i + 2) === ch) {
|
|
647
|
-
if ((qf & QF_INTERP) !== 0) {
|
|
648
|
-
e.emit(i, i + 3, TokenKind.String);
|
|
649
|
-
i += 3;
|
|
650
|
-
lineStart = false;
|
|
651
|
-
if (sp + 1 < stack.length) {
|
|
652
|
-
sp++;
|
|
653
|
-
mode = {
|
|
654
|
-
kind: CM_INTERP_STR,
|
|
655
|
-
quote: ch,
|
|
656
|
-
triple: true,
|
|
657
|
-
multiline: true
|
|
658
|
-
};
|
|
659
|
-
stack[sp] = mode;
|
|
660
|
-
}
|
|
661
|
-
} else {
|
|
662
|
-
i = scanStringDelim(src, i, i + 3, src.slice(i, i + 3), true, (qf & QF_RAW) !== 0, Boolean(cfg.stringEscapes), e);
|
|
663
|
-
lineStart = i > 0 && src.charCodeAt(i - 1) === 10;
|
|
664
|
-
}
|
|
665
|
-
continue;
|
|
666
|
-
}
|
|
667
|
-
if ((qf & QF_INTERP) !== 0) {
|
|
668
|
-
e.emit(i, i + 1, TokenKind.String);
|
|
669
|
-
i++;
|
|
670
|
-
lineStart = false;
|
|
671
|
-
if (sp + 1 < stack.length) {
|
|
672
|
-
sp++;
|
|
673
|
-
mode = {
|
|
674
|
-
kind: CM_INTERP_STR,
|
|
675
|
-
quote: ch,
|
|
676
|
-
triple: false,
|
|
677
|
-
multiline: (qf & QF_MULTI) !== 0
|
|
678
|
-
};
|
|
679
|
-
stack[sp] = mode;
|
|
680
|
-
}
|
|
681
|
-
} else {
|
|
682
|
-
i = scanStringDelim(src, i, i + 1, src[i], (qf & QF_MULTI) !== 0, (qf & QF_RAW) !== 0, Boolean(cfg.stringEscapes), e);
|
|
683
|
-
lineStart = i > 0 && src.charCodeAt(i - 1) === 10;
|
|
684
|
-
}
|
|
685
|
-
continue;
|
|
686
|
-
}
|
|
687
|
-
if (cfg.typeAfterArrow && ch === 45 && i + 1 < n && src.charCodeAt(i + 1) === 62) {
|
|
688
|
-
e.emit(i, i + 2, TokenKind.Operator);
|
|
689
|
-
i += 2;
|
|
690
|
-
lineStart = false;
|
|
691
|
-
if (sp + 1 < stack.length) {
|
|
692
|
-
sp++;
|
|
693
|
-
mode = {
|
|
694
|
-
kind: CM_TYPE_EXPECT,
|
|
695
|
-
quote: 0,
|
|
696
|
-
triple: false,
|
|
697
|
-
multiline: false
|
|
698
|
-
};
|
|
699
|
-
stack[sp] = mode;
|
|
700
|
-
}
|
|
701
|
-
continue;
|
|
702
|
-
}
|
|
703
|
-
if (ch === 46) {
|
|
704
|
-
if (i + 2 < n && src.charCodeAt(i + 1) === 46 && src.charCodeAt(i + 2) === 46) {
|
|
705
|
-
e.emit(i, i + 3, TokenKind.Punctuation);
|
|
706
|
-
i += 3;
|
|
707
|
-
} else if (i + 1 < n && src.charCodeAt(i + 1) === 46) {
|
|
708
|
-
e.emit(i, i + 2, TokenKind.Punctuation);
|
|
709
|
-
i += 2;
|
|
710
|
-
} else {
|
|
711
|
-
e.emit(i, i + 1, TokenKind.Punctuation);
|
|
712
|
-
i++;
|
|
713
|
-
if (sp + 1 < stack.length) {
|
|
714
|
-
sp++;
|
|
715
|
-
mode = {
|
|
716
|
-
kind: CM_AFTER_DOT,
|
|
717
|
-
quote: 0,
|
|
718
|
-
triple: false,
|
|
719
|
-
multiline: false
|
|
720
|
-
};
|
|
721
|
-
stack[sp] = mode;
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
lineStart = false;
|
|
725
|
-
continue;
|
|
726
|
-
}
|
|
727
|
-
const cf = charFlags[ch];
|
|
728
|
-
if ((cf & CF_IDENT_START) !== 0) {
|
|
729
|
-
emitIdent();
|
|
730
|
-
} else if ((cf & CF_PUNCT) !== 0) {
|
|
731
|
-
emitPunct();
|
|
732
|
-
} else if ((cf & CF_OPER) !== 0) {
|
|
733
|
-
emitOper();
|
|
734
|
-
} else {
|
|
735
|
-
lineStart = false;
|
|
736
|
-
i++;
|
|
737
|
-
}
|
|
738
|
-
continue;
|
|
739
|
-
}
|
|
740
|
-
if (dc === CC_SPACE) {
|
|
741
|
-
if (ch === 10)
|
|
742
|
-
lineStart = true;
|
|
743
|
-
i++;
|
|
744
|
-
while (i < n) {
|
|
745
|
-
const ws = src.charCodeAt(i);
|
|
746
|
-
if (ws === 10) {
|
|
747
|
-
lineStart = true;
|
|
748
|
-
i++;
|
|
749
|
-
} else if (ws === 32 || ws === 9 || ws === 13) {
|
|
750
|
-
i++;
|
|
751
|
-
} else {
|
|
752
|
-
break;
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
} else if (dc === CC_IDENT) {
|
|
756
|
-
emitIdent();
|
|
757
|
-
} else if (dc === CC_DIGIT) {
|
|
758
|
-
const end = scanNumber(src, i);
|
|
759
|
-
e.emit(i, end, TokenKind.Number);
|
|
760
|
-
i = end;
|
|
761
|
-
lineStart = false;
|
|
762
|
-
} else if (dc === CC_PUNCT) {
|
|
763
|
-
emitPunct();
|
|
764
|
-
} else if (dc === CC_OPER) {
|
|
765
|
-
emitOper();
|
|
766
|
-
} else {
|
|
767
|
-
lineStart = false;
|
|
768
|
-
i++;
|
|
769
|
-
while (i < n) {
|
|
770
|
-
const b = src.charCodeAt(i);
|
|
771
|
-
if (b < 256 && dispatch[b] === CC_OTHER) {
|
|
772
|
-
i++;
|
|
773
|
-
} else {
|
|
774
|
-
break;
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
}
|