limn-hl 0.2.0 → 0.2.1
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 +5 -5
- package/dist/detect.js +145 -77
- package/dist/generated/detect.d.ts +2 -5
- package/dist/generated/detect.js +3 -2406
- package/dist/generated/grammars.js +196 -181
- package/dist/vm/compile.js +14 -11
- package/dist/vm/format.d.ts +10 -5
- package/dist/vm/format.js +8 -5
- package/dist/vm/pat.js +163 -48
- package/dist/vm/quoted.js +43 -1
- package/dist/vm/scan.js +6 -6
- package/package.json +1 -1
package/dist/vm/compile.js
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
QF_ESCAPES,
|
|
34
34
|
QF_HAS_PREFIX,
|
|
35
35
|
QF_MULTILINE,
|
|
36
|
+
QF_PREFIX_FOLD,
|
|
36
37
|
QF_RAW,
|
|
37
38
|
STAY_TRANS,
|
|
38
39
|
TR_POP_RECONSUME,
|
|
@@ -45,6 +46,7 @@ import {
|
|
|
45
46
|
WF_HAS_EXTRA_CONT,
|
|
46
47
|
WF_HAS_FALLBACK,
|
|
47
48
|
WF_HAS_KWD_CALL_PAT,
|
|
49
|
+
WF_HAS_KWD_TRANS,
|
|
48
50
|
WF_HAS_PRE_PAT,
|
|
49
51
|
WF_HAS_WORD_TRANS
|
|
50
52
|
} from "./format.js";
|
|
@@ -65,17 +67,12 @@ function readTrans(rd) {
|
|
|
65
67
|
function readWordTrans(rd, strs) {
|
|
66
68
|
const cnt = rd.code[rd.p++];
|
|
67
69
|
const wt = [];
|
|
68
|
-
let kwdTrans = STAY_TRANS;
|
|
69
70
|
for (let i = 0;i < cnt; i++) {
|
|
70
71
|
const word = strs[rd.code[rd.p++]];
|
|
71
72
|
const trans = readTrans(rd);
|
|
72
|
-
|
|
73
|
-
kwdTrans = trans;
|
|
74
|
-
} else {
|
|
75
|
-
wt.push({ word, trans });
|
|
76
|
-
}
|
|
73
|
+
wt.push({ word, trans });
|
|
77
74
|
}
|
|
78
|
-
return
|
|
75
|
+
return wt;
|
|
79
76
|
}
|
|
80
77
|
function compileVM(spec) {
|
|
81
78
|
const byteCC = ensureByteCC();
|
|
@@ -145,7 +142,10 @@ function compileVM(spec) {
|
|
|
145
142
|
if (sub16 & WF_HAS_FALLBACK)
|
|
146
143
|
fallbackKind = rd.code[rd.p++];
|
|
147
144
|
if (sub16 & WF_HAS_WORD_TRANS) {
|
|
148
|
-
|
|
145
|
+
wordTrans = readWordTrans(rd, strings);
|
|
146
|
+
}
|
|
147
|
+
if (sub16 & WF_HAS_KWD_TRANS) {
|
|
148
|
+
kwdTrans = readTrans(rd);
|
|
149
149
|
}
|
|
150
150
|
if (sub16 & WF_HAS_PRE_PAT) {
|
|
151
151
|
preGuard = masks[rd.code[rd.p++]];
|
|
@@ -170,8 +170,10 @@ function compileVM(spec) {
|
|
|
170
170
|
quoteByte = rd.code[rd.p++];
|
|
171
171
|
emit = rd.code[rd.p++];
|
|
172
172
|
sub8 = rd.code[rd.p++];
|
|
173
|
-
if (sub8 & QF_HAS_PREFIX)
|
|
174
|
-
|
|
173
|
+
if (sub8 & QF_HAS_PREFIX) {
|
|
174
|
+
const sIdx = rd.code[rd.p++];
|
|
175
|
+
open = sub8 & QF_PREFIX_FOLD ? stringsLower[sIdx] : strings[sIdx];
|
|
176
|
+
}
|
|
175
177
|
break;
|
|
176
178
|
case OP_COMMENT:
|
|
177
179
|
sub8 = rd.code[rd.p++];
|
|
@@ -381,7 +383,8 @@ function compileVM(spec) {
|
|
|
381
383
|
patCode,
|
|
382
384
|
rules,
|
|
383
385
|
modes,
|
|
384
|
-
embeds: spec.embeds ?? []
|
|
386
|
+
embeds: spec.embeds ?? [],
|
|
387
|
+
startMode: spec.startMode ?? 0
|
|
385
388
|
};
|
|
386
389
|
}
|
|
387
390
|
export function buildVMGrammar(spec) {
|
package/dist/vm/format.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface VMWordTableSpec {
|
|
|
15
15
|
export interface VMSpec {
|
|
16
16
|
readonly name: string;
|
|
17
17
|
readonly aliases?: readonly string[];
|
|
18
|
+
readonly startMode?: number;
|
|
18
19
|
readonly tables?: readonly VMWordTableSpec[];
|
|
19
20
|
readonly strings?: readonly string[];
|
|
20
21
|
readonly masks?: readonly string[];
|
|
@@ -50,12 +51,12 @@ export declare const PAT_OP_CAP_RUN = 18;
|
|
|
50
51
|
export declare const PAT_OP_SCAN_CAP_CLOSE = 19;
|
|
51
52
|
export declare const PAT_OP_LINE_CONT_LIMIT = 20;
|
|
52
53
|
export declare const PAT_OP_SET_LIMIT = 21;
|
|
53
|
-
export declare const
|
|
54
|
+
export declare const PAT_OP_TABLE_HAS = 22;
|
|
54
55
|
export declare const PAT_OP_STD_NUM = 23;
|
|
55
|
-
export declare const
|
|
56
|
-
export declare const
|
|
57
|
-
export declare const
|
|
58
|
-
export declare const
|
|
56
|
+
export declare const PAT_OP_SKIP_TO_LIMIT = 24;
|
|
57
|
+
export declare const PAT_OP_SCAN_ESCAPE = 25;
|
|
58
|
+
export declare const PAT_OP_EMIT_TABLE = 26;
|
|
59
|
+
export declare const PAT_OP_SCAN_INDENT_BLOCK = 27;
|
|
59
60
|
export declare const CC_ALPHA: number;
|
|
60
61
|
export declare const CC_DIGIT: number;
|
|
61
62
|
export declare const CC_UNDER: number;
|
|
@@ -81,6 +82,7 @@ export declare const WF_HAS_WORD_TRANS: number;
|
|
|
81
82
|
export declare const WF_HAS_PRE_PAT: number;
|
|
82
83
|
export declare const WF_HAS_AFTER_PAT: number;
|
|
83
84
|
export declare const WF_HAS_KWD_CALL_PAT: number;
|
|
85
|
+
export declare const WF_HAS_KWD_TRANS: number;
|
|
84
86
|
export declare const NF_DOT_LEADING: number;
|
|
85
87
|
export declare const QF_MULTILINE: number;
|
|
86
88
|
export declare const QF_RAW: number;
|
|
@@ -88,6 +90,8 @@ export declare const QF_ESCAPES: number;
|
|
|
88
90
|
export declare const QF_TRIPLE: number;
|
|
89
91
|
export declare const QF_HAS_PREFIX: number;
|
|
90
92
|
export declare const QF_COLON_KEY: number;
|
|
93
|
+
export declare const QF_DOUBLED_QUOTE: number;
|
|
94
|
+
export declare const QF_PREFIX_FOLD: number;
|
|
91
95
|
export declare const CF_BLOCK: number;
|
|
92
96
|
export declare const CF_NESTED: number;
|
|
93
97
|
export declare const CF_EMIT_TODO: number;
|
|
@@ -242,6 +246,7 @@ export interface CompiledVM {
|
|
|
242
246
|
readonly rules: readonly VMRule[];
|
|
243
247
|
readonly modes: readonly CompiledMode[];
|
|
244
248
|
readonly embeds: ReadonlyArray<() => Grammar>;
|
|
249
|
+
readonly startMode: number;
|
|
245
250
|
}
|
|
246
251
|
export interface ExecResult {
|
|
247
252
|
end: number;
|
package/dist/vm/format.js
CHANGED
|
@@ -36,12 +36,12 @@ export const PAT_OP_CAP_RUN = 18;
|
|
|
36
36
|
export const PAT_OP_SCAN_CAP_CLOSE = 19;
|
|
37
37
|
export const PAT_OP_LINE_CONT_LIMIT = 20;
|
|
38
38
|
export const PAT_OP_SET_LIMIT = 21;
|
|
39
|
-
export const
|
|
39
|
+
export const PAT_OP_TABLE_HAS = 22;
|
|
40
40
|
export const PAT_OP_STD_NUM = 23;
|
|
41
|
-
export const
|
|
42
|
-
export const
|
|
43
|
-
export const
|
|
44
|
-
export const
|
|
41
|
+
export const PAT_OP_SKIP_TO_LIMIT = 24;
|
|
42
|
+
export const PAT_OP_SCAN_ESCAPE = 25;
|
|
43
|
+
export const PAT_OP_EMIT_TABLE = 26;
|
|
44
|
+
export const PAT_OP_SCAN_INDENT_BLOCK = 27;
|
|
45
45
|
export const CC_ALPHA = 1 << 0;
|
|
46
46
|
export const CC_DIGIT = 1 << 1;
|
|
47
47
|
export const CC_UNDER = 1 << 2;
|
|
@@ -67,6 +67,7 @@ export const WF_HAS_WORD_TRANS = 1 << 5;
|
|
|
67
67
|
export const WF_HAS_PRE_PAT = 1 << 6;
|
|
68
68
|
export const WF_HAS_AFTER_PAT = 1 << 7;
|
|
69
69
|
export const WF_HAS_KWD_CALL_PAT = 1 << 8;
|
|
70
|
+
export const WF_HAS_KWD_TRANS = 1 << 9;
|
|
70
71
|
export const NF_DOT_LEADING = 1 << 0;
|
|
71
72
|
export const QF_MULTILINE = 1 << 0;
|
|
72
73
|
export const QF_RAW = 1 << 1;
|
|
@@ -74,6 +75,8 @@ export const QF_ESCAPES = 1 << 2;
|
|
|
74
75
|
export const QF_TRIPLE = 1 << 3;
|
|
75
76
|
export const QF_HAS_PREFIX = 1 << 4;
|
|
76
77
|
export const QF_COLON_KEY = 1 << 5;
|
|
78
|
+
export const QF_DOUBLED_QUOTE = 1 << 6;
|
|
79
|
+
export const QF_PREFIX_FOLD = 1 << 7;
|
|
77
80
|
export const CF_BLOCK = 1 << 0;
|
|
78
81
|
export const CF_NESTED = 1 << 1;
|
|
79
82
|
export const CF_EMIT_TODO = 1 << 2;
|
package/dist/vm/pat.js
CHANGED
|
@@ -22,16 +22,16 @@ import {
|
|
|
22
22
|
PAT_OP_LOOK,
|
|
23
23
|
PAT_OP_MARK,
|
|
24
24
|
PAT_OP_NOT_CLASS,
|
|
25
|
-
PAT_OP_NOT_IN_LINE,
|
|
26
25
|
PAT_OP_RET,
|
|
27
26
|
PAT_OP_SCAN_CAP_CLOSE,
|
|
28
27
|
PAT_OP_SCAN_ESCAPE,
|
|
28
|
+
PAT_OP_SCAN_INDENT_BLOCK,
|
|
29
29
|
PAT_OP_SET_LIMIT,
|
|
30
30
|
PAT_OP_SKIP_TO_LIMIT,
|
|
31
31
|
PAT_OP_SPAN,
|
|
32
32
|
PAT_OP_SPAN_NOT,
|
|
33
33
|
PAT_OP_STD_NUM,
|
|
34
|
-
|
|
34
|
+
PAT_OP_TABLE_HAS,
|
|
35
35
|
PAT_OP_UNTIL,
|
|
36
36
|
skipCodePoint
|
|
37
37
|
} from "./format.js";
|
|
@@ -107,7 +107,7 @@ function trimRightHSpace(src, a, b) {
|
|
|
107
107
|
}
|
|
108
108
|
return b;
|
|
109
109
|
}
|
|
110
|
-
const PAT_SLOTS =
|
|
110
|
+
const PAT_SLOTS = 16;
|
|
111
111
|
const PAT_MAX_DEPTH = 32;
|
|
112
112
|
const PAT_POOL = PAT_SLOTS * PAT_MAX_DEPTH;
|
|
113
113
|
const poolMarks = new Int32Array(PAT_POOL);
|
|
@@ -137,21 +137,21 @@ export function runPat(src, startPos, limit, capStart, capEnd, startOff, cm, e)
|
|
|
137
137
|
const base = usePool ? patDepth * PAT_SLOTS : 0;
|
|
138
138
|
if (usePool)
|
|
139
139
|
patDepth++;
|
|
140
|
-
const marks = usePool ? poolMarks : new Int32Array(
|
|
141
|
-
const actA = e !== undefined ? usePool ? poolActA : new Int32Array(
|
|
142
|
-
const actB = e !== undefined ? usePool ? poolActB : new Int32Array(
|
|
143
|
-
const actKind = e !== undefined ? usePool ? poolActKind : new Uint8Array(
|
|
144
|
-
const actMode = e !== undefined ? usePool ? poolActMode : new Uint8Array(
|
|
145
|
-
const actArg1 = e !== undefined ? usePool ? poolActArg1 : new Uint8Array(
|
|
146
|
-
const actArg2 = e !== undefined ? usePool ? poolActArg2 : new Uint8Array(
|
|
147
|
-
const actFlags = e !== undefined ? usePool ? poolActFlags : new Uint8Array(
|
|
140
|
+
const marks = usePool ? poolMarks : new Int32Array(PAT_SLOTS);
|
|
141
|
+
const actA = e !== undefined ? usePool ? poolActA : new Int32Array(PAT_SLOTS) : undefined;
|
|
142
|
+
const actB = e !== undefined ? usePool ? poolActB : new Int32Array(PAT_SLOTS) : undefined;
|
|
143
|
+
const actKind = e !== undefined ? usePool ? poolActKind : new Uint8Array(PAT_SLOTS) : undefined;
|
|
144
|
+
const actMode = e !== undefined ? usePool ? poolActMode : new Uint8Array(PAT_SLOTS) : undefined;
|
|
145
|
+
const actArg1 = e !== undefined ? usePool ? poolActArg1 : new Uint8Array(PAT_SLOTS) : undefined;
|
|
146
|
+
const actArg2 = e !== undefined ? usePool ? poolActArg2 : new Uint8Array(PAT_SLOTS) : undefined;
|
|
147
|
+
const actFlags = e !== undefined ? usePool ? poolActFlags : new Uint8Array(PAT_SLOTS) : undefined;
|
|
148
148
|
let nActs = 0;
|
|
149
|
-
const btCur = usePool ? poolBtCur : new Int32Array(
|
|
150
|
-
const btLim = usePool ? poolBtLim : new Int32Array(
|
|
151
|
-
const btCS = usePool ? poolBtCS : new Int32Array(
|
|
152
|
-
const btCE = usePool ? poolBtCE : new Int32Array(
|
|
153
|
-
const btPC = usePool ? poolBtPC : new Uint16Array(
|
|
154
|
-
const btNA = usePool ? poolBtNA : new Uint8Array(
|
|
149
|
+
const btCur = usePool ? poolBtCur : new Int32Array(PAT_SLOTS);
|
|
150
|
+
const btLim = usePool ? poolBtLim : new Int32Array(PAT_SLOTS);
|
|
151
|
+
const btCS = usePool ? poolBtCS : new Int32Array(PAT_SLOTS);
|
|
152
|
+
const btCE = usePool ? poolBtCE : new Int32Array(PAT_SLOTS);
|
|
153
|
+
const btPC = usePool ? poolBtPC : new Uint16Array(PAT_SLOTS);
|
|
154
|
+
const btNA = usePool ? poolBtNA : new Uint8Array(PAT_SLOTS);
|
|
155
155
|
let sp = 0;
|
|
156
156
|
while (true) {
|
|
157
157
|
const op = code[pc++];
|
|
@@ -159,6 +159,39 @@ export function runPat(src, startPos, limit, capStart, capEnd, startOff, cm, e)
|
|
|
159
159
|
switch (op) {
|
|
160
160
|
case PAT_OP_RET:
|
|
161
161
|
if (e !== undefined && actA !== undefined) {
|
|
162
|
+
for (let i = 1;i < nActs; i++) {
|
|
163
|
+
const bi = base + i;
|
|
164
|
+
const a = actA[bi];
|
|
165
|
+
if (actA[bi - 1] <= a)
|
|
166
|
+
continue;
|
|
167
|
+
const b = actB[bi];
|
|
168
|
+
const k = actKind[bi];
|
|
169
|
+
const mo = actMode[bi];
|
|
170
|
+
const a1 = actArg1[bi];
|
|
171
|
+
const a2 = actArg2[bi];
|
|
172
|
+
const fl = actFlags[bi];
|
|
173
|
+
let j = i - 1;
|
|
174
|
+
while (j >= 0 && actA[base + j] > a) {
|
|
175
|
+
const dst = base + j + 1;
|
|
176
|
+
const srcIdx = base + j;
|
|
177
|
+
actA[dst] = actA[srcIdx];
|
|
178
|
+
actB[dst] = actB[srcIdx];
|
|
179
|
+
actKind[dst] = actKind[srcIdx];
|
|
180
|
+
actMode[dst] = actMode[srcIdx];
|
|
181
|
+
actArg1[dst] = actArg1[srcIdx];
|
|
182
|
+
actArg2[dst] = actArg2[srcIdx];
|
|
183
|
+
actFlags[dst] = actFlags[srcIdx];
|
|
184
|
+
j--;
|
|
185
|
+
}
|
|
186
|
+
const dst = base + j + 1;
|
|
187
|
+
actA[dst] = a;
|
|
188
|
+
actB[dst] = b;
|
|
189
|
+
actKind[dst] = k;
|
|
190
|
+
actMode[dst] = mo;
|
|
191
|
+
actArg1[dst] = a1;
|
|
192
|
+
actArg2[dst] = a2;
|
|
193
|
+
actFlags[dst] = fl;
|
|
194
|
+
}
|
|
162
195
|
for (let i = 0;i < nActs; i++) {
|
|
163
196
|
const idx = base + i;
|
|
164
197
|
const a = actA[idx];
|
|
@@ -291,15 +324,6 @@ export function runPat(src, startPos, limit, capStart, capEnd, startOff, cm, e)
|
|
|
291
324
|
else if (kind === 2)
|
|
292
325
|
ok = cur === 0;
|
|
293
326
|
else if (kind === 3)
|
|
294
|
-
ok = cur === 0 || !isDigit(src.charCodeAt(cur - 1));
|
|
295
|
-
else if (kind === 4) {
|
|
296
|
-
if (cur === 0)
|
|
297
|
-
ok = true;
|
|
298
|
-
else {
|
|
299
|
-
const p = src.charCodeAt(cur - 1);
|
|
300
|
-
ok = p === 10 || p === 32 || p === 9;
|
|
301
|
-
}
|
|
302
|
-
} else if (kind === 5)
|
|
303
327
|
ok = cur >= limit || isWordSpace(src.charCodeAt(cur));
|
|
304
328
|
if (!ok)
|
|
305
329
|
failed = true;
|
|
@@ -314,7 +338,7 @@ export function runPat(src, startPos, limit, capStart, capEnd, startOff, cm, e)
|
|
|
314
338
|
break;
|
|
315
339
|
}
|
|
316
340
|
}
|
|
317
|
-
if (sp <
|
|
341
|
+
if (sp < PAT_SLOTS) {
|
|
318
342
|
const idx = base + sp;
|
|
319
343
|
btCur[idx] = cur;
|
|
320
344
|
btLim[idx] = limit;
|
|
@@ -373,7 +397,7 @@ export function runPat(src, startPos, limit, capStart, capEnd, startOff, cm, e)
|
|
|
373
397
|
if (b <= a)
|
|
374
398
|
failed = true;
|
|
375
399
|
}
|
|
376
|
-
if (!failed && actA !== undefined && nActs <
|
|
400
|
+
if (!failed && actA !== undefined && nActs < PAT_SLOTS) {
|
|
377
401
|
const idx = base + nActs;
|
|
378
402
|
actA[idx] = a;
|
|
379
403
|
actB[idx] = b;
|
|
@@ -405,7 +429,7 @@ export function runPat(src, startPos, limit, capStart, capEnd, startOff, cm, e)
|
|
|
405
429
|
else
|
|
406
430
|
k = fb;
|
|
407
431
|
}
|
|
408
|
-
if (!failed && actA !== undefined && nActs <
|
|
432
|
+
if (!failed && actA !== undefined && nActs < PAT_SLOTS) {
|
|
409
433
|
const idx = base + nActs;
|
|
410
434
|
actA[idx] = a;
|
|
411
435
|
actB[idx] = b;
|
|
@@ -422,7 +446,7 @@ export function runPat(src, startPos, limit, capStart, capEnd, startOff, cm, e)
|
|
|
422
446
|
const mode = code[pc++];
|
|
423
447
|
const arg1 = code[pc++];
|
|
424
448
|
const arg2 = code[pc++];
|
|
425
|
-
if (actA !== undefined && nActs <
|
|
449
|
+
if (actA !== undefined && nActs < PAT_SLOTS) {
|
|
426
450
|
const idx = base + nActs;
|
|
427
451
|
actA[idx] = a;
|
|
428
452
|
actB[idx] = b;
|
|
@@ -592,7 +616,7 @@ export function runPat(src, startPos, limit, capStart, capEnd, startOff, cm, e)
|
|
|
592
616
|
marks[base + bodyEndSlot] = bodyEnd;
|
|
593
617
|
marks[base + closeEndSlot] = closeEnd;
|
|
594
618
|
cur = closeEnd;
|
|
595
|
-
} else {
|
|
619
|
+
} else if (mode === 2) {
|
|
596
620
|
const nl = src.indexOf(`
|
|
597
621
|
`, cur);
|
|
598
622
|
const le = nl >= 0 && nl < limit ? nl : limit;
|
|
@@ -610,6 +634,35 @@ export function runPat(src, startPos, limit, capStart, capEnd, startOff, cm, e)
|
|
|
610
634
|
marks[base + bodyEndSlot] = marks[base];
|
|
611
635
|
marks[base + closeEndSlot] = cur;
|
|
612
636
|
}
|
|
637
|
+
} else {
|
|
638
|
+
const stripB = arg0;
|
|
639
|
+
let bodyEnd = limit;
|
|
640
|
+
let closeEnd = limit;
|
|
641
|
+
let pos = cur;
|
|
642
|
+
while (pos < limit) {
|
|
643
|
+
const nl = src.indexOf(`
|
|
644
|
+
`, pos);
|
|
645
|
+
const le = nl >= 0 && nl < limit ? nl : limit;
|
|
646
|
+
let j = pos;
|
|
647
|
+
if (stripB !== 0) {
|
|
648
|
+
while (j < le && src.charCodeAt(j) === stripB)
|
|
649
|
+
j++;
|
|
650
|
+
}
|
|
651
|
+
let contentEnd = le;
|
|
652
|
+
if (contentEnd > j && src.charCodeAt(contentEnd - 1) === 13)
|
|
653
|
+
contentEnd--;
|
|
654
|
+
if (contentEnd - j === capLen && src.startsWith(capStr, j)) {
|
|
655
|
+
bodyEnd = pos;
|
|
656
|
+
closeEnd = le;
|
|
657
|
+
break;
|
|
658
|
+
}
|
|
659
|
+
if (le === limit)
|
|
660
|
+
break;
|
|
661
|
+
pos = le + 1;
|
|
662
|
+
}
|
|
663
|
+
marks[base + bodyEndSlot] = bodyEnd;
|
|
664
|
+
marks[base + closeEndSlot] = closeEnd;
|
|
665
|
+
cur = closeEnd;
|
|
613
666
|
}
|
|
614
667
|
break;
|
|
615
668
|
}
|
|
@@ -632,17 +685,12 @@ export function runPat(src, startPos, limit, capStart, capEnd, startOff, cm, e)
|
|
|
632
685
|
limit = cur + maxBytes;
|
|
633
686
|
break;
|
|
634
687
|
}
|
|
635
|
-
case
|
|
688
|
+
case PAT_OP_TABLE_HAS: {
|
|
636
689
|
const tIdx = code[pc++];
|
|
637
690
|
const a = marks[base + code[pc++]];
|
|
638
691
|
const b = marks[base + code[pc++]];
|
|
639
|
-
|
|
640
|
-
const otherOff = code[pc++] | code[pc++] << 8;
|
|
641
|
-
const k = cm.tables[tIdx].lookupSpan(src, a, b);
|
|
642
|
-
if (k === TokenKind.Plain)
|
|
692
|
+
if (cm.tables[tIdx].lookupSpan(src, a, b) === TokenKind.Plain)
|
|
643
693
|
failed = true;
|
|
644
|
-
else
|
|
645
|
-
pc = k === TokenKind.Keyword ? kwdOff : otherOff;
|
|
646
694
|
break;
|
|
647
695
|
}
|
|
648
696
|
case PAT_OP_STD_NUM: {
|
|
@@ -662,21 +710,88 @@ export function runPat(src, startPos, limit, capStart, capEnd, startOff, cm, e)
|
|
|
662
710
|
cur = end > limit ? limit : end;
|
|
663
711
|
}
|
|
664
712
|
break;
|
|
665
|
-
case
|
|
666
|
-
|
|
667
|
-
|
|
713
|
+
case PAT_OP_SKIP_TO_LIMIT:
|
|
714
|
+
cur = limit;
|
|
715
|
+
break;
|
|
716
|
+
case PAT_OP_SCAN_INDENT_BLOCK: {
|
|
717
|
+
const startSlot = code[pc++];
|
|
718
|
+
const endSlot = code[pc++];
|
|
719
|
+
let hdrEnd = cur;
|
|
720
|
+
if (hdrEnd > 0 && src.charCodeAt(hdrEnd - 1) === 10)
|
|
721
|
+
hdrEnd--;
|
|
722
|
+
let hdrStart = hdrEnd;
|
|
723
|
+
while (hdrStart > 0 && src.charCodeAt(hdrStart - 1) !== 10)
|
|
724
|
+
hdrStart--;
|
|
725
|
+
let parentIndent = 0;
|
|
726
|
+
while (hdrStart + parentIndent < hdrEnd && src.charCodeAt(hdrStart + parentIndent) === 32) {
|
|
727
|
+
parentIndent++;
|
|
728
|
+
}
|
|
729
|
+
while (hdrStart + parentIndent + 1 < hdrEnd && src.charCodeAt(hdrStart + parentIndent) === 45 && src.charCodeAt(hdrStart + parentIndent + 1) === 32) {
|
|
730
|
+
let q = hdrStart + parentIndent + 1;
|
|
731
|
+
while (q < hdrEnd && src.charCodeAt(q) === 32)
|
|
732
|
+
q++;
|
|
733
|
+
if (q < hdrEnd && src.charCodeAt(q) !== 124 && src.charCodeAt(q) !== 62) {
|
|
734
|
+
parentIndent = q - hdrStart;
|
|
735
|
+
} else {
|
|
736
|
+
break;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
let minIndent = -1;
|
|
740
|
+
if (capEnd === capStart + 1) {
|
|
741
|
+
const d = src.charCodeAt(capStart);
|
|
742
|
+
if (d >= 49 && d <= 57)
|
|
743
|
+
minIndent = parentIndent + (d - 48);
|
|
744
|
+
}
|
|
745
|
+
let firstStart = -1;
|
|
746
|
+
let lastContentEnd = cur;
|
|
747
|
+
let pos = cur;
|
|
748
|
+
while (pos < limit) {
|
|
668
749
|
const nl = src.indexOf(`
|
|
669
|
-
`,
|
|
750
|
+
`, pos);
|
|
670
751
|
const le = nl >= 0 && nl < limit ? nl : limit;
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
752
|
+
let indent = 0;
|
|
753
|
+
while (pos + indent < le && src.charCodeAt(pos + indent) === 32)
|
|
754
|
+
indent++;
|
|
755
|
+
let k = pos + indent;
|
|
756
|
+
while (k < le) {
|
|
757
|
+
const ch = src.charCodeAt(k);
|
|
758
|
+
if (ch !== 32 && ch !== 9 && ch !== 13)
|
|
759
|
+
break;
|
|
760
|
+
k++;
|
|
761
|
+
}
|
|
762
|
+
if (k === le) {
|
|
763
|
+
if (le === limit)
|
|
764
|
+
break;
|
|
765
|
+
pos = le + 1;
|
|
766
|
+
continue;
|
|
767
|
+
}
|
|
768
|
+
if (minIndent < 0) {
|
|
769
|
+
if (indent <= parentIndent)
|
|
770
|
+
break;
|
|
771
|
+
minIndent = indent;
|
|
772
|
+
} else if (indent < minIndent) {
|
|
773
|
+
break;
|
|
774
|
+
}
|
|
775
|
+
let contentEnd = le;
|
|
776
|
+
if (contentEnd > pos && src.charCodeAt(contentEnd - 1) === 13)
|
|
777
|
+
contentEnd--;
|
|
778
|
+
if (firstStart < 0)
|
|
779
|
+
firstStart = pos + indent;
|
|
780
|
+
lastContentEnd = contentEnd;
|
|
781
|
+
if (le === limit)
|
|
782
|
+
break;
|
|
783
|
+
pos = le + 1;
|
|
784
|
+
}
|
|
785
|
+
if (firstStart < 0) {
|
|
786
|
+
marks[base + startSlot] = cur;
|
|
787
|
+
marks[base + endSlot] = cur;
|
|
788
|
+
} else {
|
|
789
|
+
marks[base + startSlot] = firstStart;
|
|
790
|
+
marks[base + endSlot] = lastContentEnd;
|
|
791
|
+
cur = lastContentEnd;
|
|
674
792
|
}
|
|
675
793
|
break;
|
|
676
794
|
}
|
|
677
|
-
case PAT_OP_SKIP_TO_LIMIT:
|
|
678
|
-
cur = limit;
|
|
679
|
-
break;
|
|
680
795
|
default:
|
|
681
796
|
if (usePool)
|
|
682
797
|
patDepth--;
|
package/dist/vm/quoted.js
CHANGED
|
@@ -2,10 +2,13 @@ import { scanEscape } from "../cursor.js";
|
|
|
2
2
|
import { TokenKind } from "../token.js";
|
|
3
3
|
import {
|
|
4
4
|
execRes,
|
|
5
|
+
matchPrefixFold,
|
|
5
6
|
QF_COLON_KEY,
|
|
7
|
+
QF_DOUBLED_QUOTE,
|
|
6
8
|
QF_ESCAPES,
|
|
7
9
|
QF_HAS_PREFIX,
|
|
8
10
|
QF_MULTILINE,
|
|
11
|
+
QF_PREFIX_FOLD,
|
|
9
12
|
QF_RAW,
|
|
10
13
|
QF_TRIPLE,
|
|
11
14
|
skipHSpace
|
|
@@ -22,8 +25,9 @@ export function execQuoted(src, pos, r, e) {
|
|
|
22
25
|
const q = r.quoteByte;
|
|
23
26
|
let bodyPos = pos + 1;
|
|
24
27
|
if (sub & QF_HAS_PREFIX) {
|
|
25
|
-
if (!src.startsWith(r.open, pos))
|
|
28
|
+
if (sub & QF_PREFIX_FOLD ? !matchPrefixFold(src, pos, r.open) : !src.startsWith(r.open, pos)) {
|
|
26
29
|
return false;
|
|
30
|
+
}
|
|
27
31
|
const qPos = pos + r.open.length;
|
|
28
32
|
if (qPos >= n || src.charCodeAt(qPos) !== q)
|
|
29
33
|
return false;
|
|
@@ -41,6 +45,11 @@ export function execQuoted(src, pos, r, e) {
|
|
|
41
45
|
execRes.tr = r.trans;
|
|
42
46
|
return true;
|
|
43
47
|
}
|
|
48
|
+
if (sub & QF_DOUBLED_QUOTE) {
|
|
49
|
+
execRes.end = scanDoubledQuoted(src, pos, bodyPos, q, multiline, escapes, r.emit, e);
|
|
50
|
+
execRes.tr = r.trans;
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
44
53
|
if (raw) {
|
|
45
54
|
const end = scanRawQuoted(src, bodyPos, q, multiline);
|
|
46
55
|
const kind = sub & QF_COLON_KEY ? quotedColonKind(src, end, r.emit) : r.emit;
|
|
@@ -53,6 +62,39 @@ export function execQuoted(src, pos, r, e) {
|
|
|
53
62
|
execRes.tr = r.trans;
|
|
54
63
|
return true;
|
|
55
64
|
}
|
|
65
|
+
function scanDoubledQuoted(src, start, bodyPos, q, multiline, escapes, kind, e) {
|
|
66
|
+
const n = src.length;
|
|
67
|
+
let segStart = start;
|
|
68
|
+
let i = bodyPos;
|
|
69
|
+
while (i < n) {
|
|
70
|
+
const c = src.charCodeAt(i);
|
|
71
|
+
if (c === q) {
|
|
72
|
+
if (i + 1 < n && src.charCodeAt(i + 1) === q) {
|
|
73
|
+
if (escapes) {
|
|
74
|
+
if (i > segStart)
|
|
75
|
+
e.emit(segStart, i, kind);
|
|
76
|
+
e.emit(i, i + 2, TokenKind.Escape);
|
|
77
|
+
i += 2;
|
|
78
|
+
segStart = i;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
i += 2;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
e.emit(segStart, i + 1, kind);
|
|
85
|
+
return i + 1;
|
|
86
|
+
}
|
|
87
|
+
if (c === 10 && !multiline) {
|
|
88
|
+
if (i > segStart)
|
|
89
|
+
e.emit(segStart, i, kind);
|
|
90
|
+
return i;
|
|
91
|
+
}
|
|
92
|
+
i++;
|
|
93
|
+
}
|
|
94
|
+
if (n > segStart)
|
|
95
|
+
e.emit(segStart, n, kind);
|
|
96
|
+
return n;
|
|
97
|
+
}
|
|
56
98
|
export function scanRawQuoted(src, bodyPos, q, multiline) {
|
|
57
99
|
const qStr = String.fromCharCode(q);
|
|
58
100
|
const idx = src.indexOf(qStr, bodyPos);
|
package/dist/vm/scan.js
CHANGED
|
@@ -77,8 +77,8 @@ export function scanVM(src, cm, e) {
|
|
|
77
77
|
const stack = usePool ? scanStackPool : new Uint8Array(SCAN_STACK_SLOTS);
|
|
78
78
|
const modes = cm.modes;
|
|
79
79
|
let sp = 0;
|
|
80
|
-
let mode =
|
|
81
|
-
let m = modes[
|
|
80
|
+
let mode = cm.startMode;
|
|
81
|
+
let m = modes[mode];
|
|
82
82
|
let i = 0;
|
|
83
83
|
let lineStart = true;
|
|
84
84
|
while (i < n) {
|
|
@@ -204,7 +204,7 @@ export function scanVM(src, cm, e) {
|
|
|
204
204
|
for (let ci = 0;ci < chain.length; ci++) {
|
|
205
205
|
if (execRule(src, i, lineStart, cm.rules[chain[ci]], cm, e)) {
|
|
206
206
|
i = execRes.end;
|
|
207
|
-
lineStart =
|
|
207
|
+
lineStart = execRes.end > 0 && src.charCodeAt(execRes.end - 1) === 10;
|
|
208
208
|
if (execRes.tr.op !== TR_STAY) {
|
|
209
209
|
const p = applyTransPacked(mode, stack, stackBase, sp, execRes.tr);
|
|
210
210
|
mode = p & 255;
|
|
@@ -366,7 +366,7 @@ export function scanVM(src, cm, e) {
|
|
|
366
366
|
if (execRule(src, i, lineStart, cm.rules[chain[ci]], cm, e)) {
|
|
367
367
|
if (execRes.end > i) {
|
|
368
368
|
i = execRes.end;
|
|
369
|
-
lineStart =
|
|
369
|
+
lineStart = src.charCodeAt(execRes.end - 1) === 10;
|
|
370
370
|
}
|
|
371
371
|
if (execRes.tr.op !== TR_STAY) {
|
|
372
372
|
const p = applyTransPacked(mode, stack, stackBase, sp, execRes.tr);
|
|
@@ -427,7 +427,7 @@ export function scanVM(src, cm, e) {
|
|
|
427
427
|
if (execRule(src, i, lineStart, cm.rules[act - ACT_DIRECT_BASE], cm, e)) {
|
|
428
428
|
if (execRes.end > i) {
|
|
429
429
|
i = execRes.end;
|
|
430
|
-
lineStart =
|
|
430
|
+
lineStart = src.charCodeAt(execRes.end - 1) === 10;
|
|
431
431
|
}
|
|
432
432
|
if (execRes.tr.op !== TR_STAY) {
|
|
433
433
|
const p = applyTransPacked(mode, stack, stackBase, sp, execRes.tr);
|
|
@@ -443,7 +443,7 @@ export function scanVM(src, cm, e) {
|
|
|
443
443
|
if (execRule(src, i, lineStart, cm.rules[chain[ci]], cm, e)) {
|
|
444
444
|
if (execRes.end > i) {
|
|
445
445
|
i = execRes.end;
|
|
446
|
-
lineStart =
|
|
446
|
+
lineStart = src.charCodeAt(execRes.end - 1) === 10;
|
|
447
447
|
}
|
|
448
448
|
if (execRes.tr.op !== TR_STAY) {
|
|
449
449
|
const p = applyTransPacked(mode, stack, stackBase, sp, execRes.tr);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "limn-hl",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Fast, lightweight, zero-dependency, native multi-target syntax highlighter compiled from one shared grammar spec, with built-in language detection",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|