parseman 0.58.2 → 0.59.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/dist/analysis/diagnostics.js +344 -130
- package/dist/analysis/diagnostics.js.map +3 -3
- package/dist/cli/index.js +346 -131
- package/dist/cli/index.js.map +3 -3
- package/dist/combinators/dispatch.d.ts.map +1 -1
- package/dist/combinators/field-trivia.d.ts.map +1 -1
- package/dist/combinators/first-set.d.ts.map +1 -1
- package/dist/combinators/keywords.d.ts.map +1 -1
- package/dist/combinators/literal.d.ts.map +1 -1
- package/dist/combinators/node.d.ts.map +1 -1
- package/dist/combinators/regex.d.ts.map +1 -1
- package/dist/combinators/scanTo.d.ts.map +1 -1
- package/dist/combinators/token.d.ts.map +1 -1
- package/dist/compiler/linker.d.ts.map +1 -1
- package/dist/compiler/token-capability.js +28 -4
- package/dist/compiler/token-capability.js.map +2 -2
- package/dist/compiler/token-scanner.d.ts.map +1 -1
- package/dist/cst/capture-buffer.d.ts.map +1 -1
- package/dist/cst/plain.js +69 -0
- package/dist/cst/plain.js.map +6 -0
- package/dist/index.js +350 -138
- package/dist/index.js.map +3 -3
- package/dist/language-service/index.js +29 -5
- package/dist/language-service/index.js.map +3 -3
- package/dist/lead-ranges.d.ts +26 -0
- package/dist/lead-ranges.d.ts.map +1 -0
- package/dist/line-index.d.ts +13 -0
- package/dist/line-index.d.ts.map +1 -1
- package/dist/plugin/entry-supercompiler.d.ts.map +1 -1
- package/dist/plugin/index.js +352 -140
- package/dist/plugin/index.js.map +3 -3
- package/dist/recovery/scan.d.ts.map +1 -1
- package/dist/regex/classes.d.ts +5 -3
- package/dist/regex/classes.d.ts.map +1 -1
- package/dist/regex/first-set.d.ts +7 -1
- package/dist/regex/first-set.d.ts.map +1 -1
- package/dist/run/index.js +14 -4
- package/dist/run/index.js.map +3 -3
- package/dist/spec/index.js +18 -1
- package/dist/spec/index.js.map +2 -2
- package/dist/table/assemble.d.ts.map +1 -1
- package/dist/table/compile-rule-map.d.ts.map +1 -1
- package/dist/table/emit-assembly.d.ts +9 -2
- package/dist/table/emit-assembly.d.ts.map +1 -1
- package/dist/table/emit.d.ts +6 -0
- package/dist/table/emit.d.ts.map +1 -1
- package/dist/table/encode-baseline.d.ts.map +1 -1
- package/dist/table/index.js +330 -129
- package/dist/table/index.js.map +3 -3
- package/dist/table/program.d.ts.map +1 -1
- package/dist/table/run-support.d.ts.map +1 -1
- package/dist/table/scan-shapes.d.ts +1 -1
- package/dist/table/scan-shapes.d.ts.map +1 -1
- package/dist/table/site-labels.d.ts.map +1 -1
- package/dist/table/trivia-gap.d.ts +11 -1
- package/dist/table/trivia-gap.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +2 -1
- package/src/combinators/choice.ts +4 -0
- package/src/combinators/dispatch.ts +2 -1
- package/src/combinators/field-trivia.ts +6 -5
- package/src/combinators/first-set.ts +13 -4
- package/src/combinators/keywords.ts +3 -2
- package/src/combinators/literal.ts +5 -4
- package/src/combinators/node.ts +3 -1
- package/src/combinators/regex.ts +33 -13
- package/src/combinators/scanTo.ts +2 -1
- package/src/combinators/token.ts +3 -6
- package/src/compiler/linker.ts +4 -2
- package/src/compiler/token-scanner.ts +4 -1
- package/src/cst/capture-buffer.ts +13 -5
- package/src/cst/plain.d.ts +35 -0
- package/src/cst/plain.js +74 -0
- package/src/lead-ranges.ts +53 -0
- package/src/line-index.ts +37 -0
- package/src/plugin/entry-supercompiler.ts +3 -2
- package/src/recovery/scan.ts +4 -4
- package/src/regex/classes.ts +22 -7
- package/src/regex/first-set.ts +67 -12
- package/src/table/assemble.ts +75 -38
- package/src/table/compile-rule-map.ts +5 -3
- package/src/table/emit-assembly.ts +69 -32
- package/src/table/emit.ts +9 -1
- package/src/table/encode-baseline.ts +2 -1
- package/src/table/program.ts +2 -1
- package/src/table/run-support.ts +4 -7
- package/src/table/scan-shapes.ts +5 -2
- package/src/table/site-labels.ts +2 -1
- package/src/table/trivia-gap.ts +19 -0
- package/src/version.ts +1 -1
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
// src/lead-ranges.ts
|
|
2
|
+
function rangesHaveLead(ranges, code) {
|
|
3
|
+
for (const r of ranges) if (code >= r.lo && code <= r.hi) return true;
|
|
4
|
+
if (code <= 65535) return false;
|
|
5
|
+
const high = 55296 + (code - 65536 >> 10);
|
|
6
|
+
for (const r of ranges) if (high >= r.lo && high <= r.hi) return true;
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
function leadRanges(ranges) {
|
|
10
|
+
let out;
|
|
11
|
+
for (const r of ranges) {
|
|
12
|
+
const lo = Math.max(r.lo, 55296), hi = Math.min(r.hi, 56319);
|
|
13
|
+
if (lo <= hi) (out ??= [...ranges]).push({ lo: 65536 + (lo - 55296 << 10), hi: 65536 + (hi - 55296 << 10) + 1023 });
|
|
14
|
+
}
|
|
15
|
+
return out ?? ranges;
|
|
16
|
+
}
|
|
17
|
+
function implicitLeadsDropped(ranges) {
|
|
18
|
+
const implied = leadRanges(ranges.filter((r) => r.lo <= 65535)).filter((r) => r.lo > 65535);
|
|
19
|
+
const out = [];
|
|
20
|
+
for (const r of ranges) {
|
|
21
|
+
let pieces = [{ lo: r.lo, hi: r.hi }];
|
|
22
|
+
if (r.hi > 65535) for (const c of implied) {
|
|
23
|
+
pieces = pieces.flatMap((q2) => q2.hi < c.lo || q2.lo > c.hi ? [q2] : [...q2.lo < c.lo ? [{ lo: q2.lo, hi: c.lo - 1 }] : [], ...q2.hi > c.hi ? [{ lo: c.hi + 1, hi: q2.hi }] : []]);
|
|
24
|
+
}
|
|
25
|
+
out.push(...pieces);
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
|
|
1
30
|
// src/combinators/first-set.ts
|
|
2
31
|
function classifyFinalChoice(arms, resolve, activeTrivia) {
|
|
3
32
|
const firstSets = [];
|
|
@@ -59,8 +88,9 @@ function union(a, b) {
|
|
|
59
88
|
function intersects(a, b) {
|
|
60
89
|
if (a.kind === "any" || b.kind === "any") return true;
|
|
61
90
|
if (a.kind === "empty" || b.kind === "empty") return false;
|
|
62
|
-
|
|
63
|
-
|
|
91
|
+
const bs = leadRanges(b.ranges);
|
|
92
|
+
for (const ra of leadRanges(a.ranges)) {
|
|
93
|
+
for (const rb of bs) {
|
|
64
94
|
if (ra.lo <= rb.hi && rb.lo <= ra.hi) return true;
|
|
65
95
|
}
|
|
66
96
|
}
|
|
@@ -76,6 +106,9 @@ function startsFirstSet(combinator, input, pos) {
|
|
|
76
106
|
const code = input.codePointAt(pos);
|
|
77
107
|
if (code === void 0) return false;
|
|
78
108
|
for (const r of fs.ranges) if (code >= r.lo && code <= r.hi) return true;
|
|
109
|
+
if (code <= 65535) return false;
|
|
110
|
+
const high = 55296 + (code - 65536 >> 10);
|
|
111
|
+
for (const r of fs.ranges) if (high >= r.lo && high <= r.hi) return true;
|
|
79
112
|
return false;
|
|
80
113
|
}
|
|
81
114
|
function fromRange(lo, hi) {
|
|
@@ -176,12 +209,13 @@ function narrowBy(acc, constraint) {
|
|
|
176
209
|
if (acc.kind === "any") return constraint;
|
|
177
210
|
if (acc.kind === "empty" || constraint.kind === "empty") return { kind: "empty" };
|
|
178
211
|
const ranges = [];
|
|
179
|
-
|
|
212
|
+
const bs = leadRanges(constraint.ranges);
|
|
213
|
+
for (const a of leadRanges(acc.ranges)) for (const b of bs) {
|
|
180
214
|
const lo = Math.max(a.lo, b.lo);
|
|
181
215
|
const hi = Math.min(a.hi, b.hi);
|
|
182
216
|
if (lo <= hi) ranges.push({ lo, hi });
|
|
183
217
|
}
|
|
184
|
-
return ranges.length === 0 ? { kind: "empty" } : { kind: "ranges", ranges };
|
|
218
|
+
return ranges.length === 0 ? { kind: "empty" } : { kind: "ranges", ranges: implicitLeadsDropped(ranges) };
|
|
185
219
|
}
|
|
186
220
|
function applyAssertion(fs, assertion) {
|
|
187
221
|
return assertion === null ? fs : fs.kind === "empty" ? assertion : narrowBy(fs, assertion);
|
|
@@ -350,6 +384,7 @@ function failAt(ctx, expected, pos) {
|
|
|
350
384
|
}
|
|
351
385
|
|
|
352
386
|
// src/line-index.ts
|
|
387
|
+
import { PlainLineSpan, PlainSpan } from "../cst/plain.js";
|
|
353
388
|
function createLineIndex() {
|
|
354
389
|
return { lineStarts: [0] };
|
|
355
390
|
}
|
|
@@ -402,6 +437,27 @@ function annotateSpan(span, index) {
|
|
|
402
437
|
endColumn: e.col
|
|
403
438
|
};
|
|
404
439
|
}
|
|
440
|
+
var SPAN_KEYS = ["start", "end", "startLine", "startColumn", "endLine", "endColumn"];
|
|
441
|
+
function copySpan(span) {
|
|
442
|
+
let n = 0;
|
|
443
|
+
for (const key in span) {
|
|
444
|
+
if (key !== SPAN_KEYS[n]) return { ...span };
|
|
445
|
+
n++;
|
|
446
|
+
}
|
|
447
|
+
if (n === 2) return new PlainSpan(span.start, span.end);
|
|
448
|
+
if (n === 6 && span.startLine !== void 0 && span.startColumn !== void 0 && span.endLine !== void 0 && span.endColumn !== void 0) {
|
|
449
|
+
return new PlainLineSpan(span.start, span.end, span.startLine, span.startColumn, span.endLine, span.endColumn);
|
|
450
|
+
}
|
|
451
|
+
return { ...span };
|
|
452
|
+
}
|
|
453
|
+
function lineSpanFromContext(span, ctx) {
|
|
454
|
+
if (!ctx.trackLines) return span;
|
|
455
|
+
const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
|
|
456
|
+
if (!index) return span;
|
|
457
|
+
const s = offsetToLineCol(index, span.start);
|
|
458
|
+
const e = offsetToLineCol(index, span.end);
|
|
459
|
+
return new PlainLineSpan(span.start, span.end, s.line, s.col, e.line, e.col);
|
|
460
|
+
}
|
|
405
461
|
function annotateSpanFromLineContext(span, ctx) {
|
|
406
462
|
if (!ctx.trackLines) return span;
|
|
407
463
|
const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
|
|
@@ -409,6 +465,7 @@ function annotateSpanFromLineContext(span, ctx) {
|
|
|
409
465
|
}
|
|
410
466
|
|
|
411
467
|
// src/cst/capture-buffer.ts
|
|
468
|
+
import { PlainBuf, PlainLeaf } from "../cst/plain.js";
|
|
412
469
|
var EMPTY = [];
|
|
413
470
|
var EMPTY_TL = [];
|
|
414
471
|
function cstCaptureActive(ctx) {
|
|
@@ -423,7 +480,7 @@ function beginCstNodeCapture(ctx) {
|
|
|
423
480
|
cap: ctx.captureTrivia,
|
|
424
481
|
buf: ctx._cstBuf
|
|
425
482
|
};
|
|
426
|
-
ctx._cstBuf =
|
|
483
|
+
ctx._cstBuf = new PlainBuf(void 0, void 0, 0);
|
|
427
484
|
ctx._cstChildren = void 0;
|
|
428
485
|
ctx._cstLeaves = void 0;
|
|
429
486
|
ctx._cstRawChildren = void 0;
|
|
@@ -448,12 +505,15 @@ function endCstNodeCapture(ctx, saved) {
|
|
|
448
505
|
ctx.captureTrivia = saved.cap;
|
|
449
506
|
return materialized;
|
|
450
507
|
}
|
|
508
|
+
function isLeaf(v) {
|
|
509
|
+
return typeof v === "object" && v !== null && v._tag === "leaf";
|
|
510
|
+
}
|
|
451
511
|
function pushCstLeaf(ctx, leaf2) {
|
|
452
512
|
if (!ctx.trackLines) {
|
|
453
513
|
pushCstChild(ctx, leaf2, leaf2);
|
|
454
514
|
return;
|
|
455
515
|
}
|
|
456
|
-
const annotated = leaf2 && typeof leaf2 === "object" && leaf2.span ? { ...leaf2, span: annotateSpanFromLineContext(leaf2.span, ctx) } : leaf2;
|
|
516
|
+
const annotated = isLeaf(leaf2) ? new PlainLeaf(leaf2.value, lineSpanFromContext(leaf2.span, ctx)) : leaf2 && typeof leaf2 === "object" && leaf2.span ? { ...leaf2, span: annotateSpanFromLineContext(leaf2.span, ctx) } : leaf2;
|
|
457
517
|
pushCstChild(ctx, annotated, annotated);
|
|
458
518
|
}
|
|
459
519
|
function pushCstChild(ctx, built, rawEntry2) {
|
|
@@ -642,6 +702,7 @@ function assertionFailureExpected(positive, childTag) {
|
|
|
642
702
|
}
|
|
643
703
|
|
|
644
704
|
// src/combinators/keywords.ts
|
|
705
|
+
import { PlainLeaf as PlainLeaf2, PlainSpan as PlainSpan2 } from "../cst/plain.js";
|
|
645
706
|
function escapeRe(s) {
|
|
646
707
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
647
708
|
}
|
|
@@ -690,8 +751,8 @@ function keywords(words, opts = {}) {
|
|
|
690
751
|
const m = re.exec(input);
|
|
691
752
|
if (m === null) return failAt(ctx, directTerminalFailureExpected(def), pos);
|
|
692
753
|
const value = m[0];
|
|
693
|
-
const span =
|
|
694
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
754
|
+
const span = new PlainSpan2(pos, pos + value.length);
|
|
755
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf2(value, span));
|
|
695
756
|
return { ok: true, value, span };
|
|
696
757
|
}
|
|
697
758
|
};
|
|
@@ -717,11 +778,17 @@ function shorthandRanges(ch2) {
|
|
|
717
778
|
if (ch2 === "s") return SPACE_RANGES;
|
|
718
779
|
return [[48, 57], [65, 90], [97, 122], [95, 95]];
|
|
719
780
|
}
|
|
720
|
-
function readUnicodeEscape(body, i) {
|
|
781
|
+
function readUnicodeEscape(body, i, unicode = false) {
|
|
721
782
|
if (body[i] !== "\\" || body[i + 1] !== "u") return null;
|
|
722
783
|
const hex = body.slice(i + 2, i + 6);
|
|
723
784
|
if (!/^[0-9a-fA-F]{4}$/.test(hex)) return null;
|
|
724
|
-
|
|
785
|
+
const cp = Number.parseInt(hex, 16);
|
|
786
|
+
if (unicode && cp >= 55296 && cp <= 56319 && body[i + 6] === "\\" && body[i + 7] === "u") {
|
|
787
|
+
const lowHex = body.slice(i + 8, i + 12);
|
|
788
|
+
const low = /^[0-9a-fA-F]{4}$/.test(lowHex) ? Number.parseInt(lowHex, 16) : -1;
|
|
789
|
+
if (low >= 56320 && low <= 57343) return { cp: 65536 + (cp - 55296 << 10) + (low - 56320), next: i + 12 };
|
|
790
|
+
}
|
|
791
|
+
return { cp, next: i + 6 };
|
|
725
792
|
}
|
|
726
793
|
var META = new Set("()[]{}*+?|^$.".split(""));
|
|
727
794
|
function literalCodePoints(frag) {
|
|
@@ -733,6 +800,7 @@ function literalCodePoints(frag) {
|
|
|
733
800
|
const e = frag[i + 1];
|
|
734
801
|
if (e === void 0) return null;
|
|
735
802
|
if (!(e in CLASS_ESCAPES) && /\w/.test(e)) return null;
|
|
803
|
+
if (e === "0" && frag[i + 2] !== void 0 && frag[i + 2] >= "0" && frag[i + 2] <= "9") return null;
|
|
736
804
|
out.push(e in CLASS_ESCAPES ? CLASS_ESCAPES[e] : e.codePointAt(0));
|
|
737
805
|
i += 2;
|
|
738
806
|
continue;
|
|
@@ -773,14 +841,14 @@ function parseClassOperand(body) {
|
|
|
773
841
|
if (cps && cps.length === 1) return { ranges: [[cps[0], cps[0]]], negated: false };
|
|
774
842
|
return null;
|
|
775
843
|
}
|
|
776
|
-
function parseClassRanges(body) {
|
|
844
|
+
function parseClassRanges(body, unicode = false) {
|
|
777
845
|
const ranges = [];
|
|
778
846
|
let i = 0;
|
|
779
847
|
const readAtom = () => {
|
|
780
848
|
const ch2 = body[i];
|
|
781
849
|
if (ch2 === void 0) return null;
|
|
782
850
|
if (ch2 === "\\") {
|
|
783
|
-
const uni = readUnicodeEscape(body, i);
|
|
851
|
+
const uni = readUnicodeEscape(body, i, unicode);
|
|
784
852
|
if (uni) {
|
|
785
853
|
i = uni.next;
|
|
786
854
|
return { cp: uni.cp };
|
|
@@ -788,13 +856,15 @@ function parseClassRanges(body) {
|
|
|
788
856
|
const e = body[i + 1];
|
|
789
857
|
if (e === void 0) return null;
|
|
790
858
|
i += 2;
|
|
859
|
+
if (e === "0" && body[i] !== void 0 && body[i] >= "0" && body[i] <= "9" || e >= "1" && e <= "9") return null;
|
|
791
860
|
if (e in CLASS_ESCAPES) return { cp: CLASS_ESCAPES[e] };
|
|
792
861
|
if (e === "d" || e === "w" || e === "s") return { set: shorthandRanges(e) };
|
|
793
862
|
if (e >= "a" && e <= "z" || e >= "A" && e <= "Z") return null;
|
|
794
863
|
return { cp: e.codePointAt(0) };
|
|
795
864
|
}
|
|
796
|
-
i
|
|
797
|
-
|
|
865
|
+
const cp = unicode ? body.codePointAt(i) : body.charCodeAt(i);
|
|
866
|
+
i += cp > 65535 ? 2 : 1;
|
|
867
|
+
return { cp };
|
|
798
868
|
};
|
|
799
869
|
while (i < body.length) {
|
|
800
870
|
const lo = readAtom();
|
|
@@ -2408,6 +2478,7 @@ function parse(combinator, input, opts = {}) {
|
|
|
2408
2478
|
}
|
|
2409
2479
|
|
|
2410
2480
|
// src/recovery/scan.ts
|
|
2481
|
+
import { PlainSpan as PlainSpan3 } from "../cst/plain.js";
|
|
2411
2482
|
function probeAt(sentinel, input, pos, ctx) {
|
|
2412
2483
|
const s = {
|
|
2413
2484
|
_probe: ctx._probe,
|
|
@@ -2475,9 +2546,7 @@ function firstSetSentinel(fs) {
|
|
|
2475
2546
|
parse(input, pos) {
|
|
2476
2547
|
const code = pos < input.length ? input.codePointAt(pos) : void 0;
|
|
2477
2548
|
if (code !== void 0) {
|
|
2478
|
-
|
|
2479
|
-
if (code >= r.lo && code <= r.hi) return { ok: true, value: null, span: { start: pos, end: pos } };
|
|
2480
|
-
}
|
|
2549
|
+
if (rangesHaveLead(ranges, code)) return { ok: true, value: null, span: { start: pos, end: pos } };
|
|
2481
2550
|
}
|
|
2482
2551
|
return { ok: false, expected: [], span: { start: pos, end: pos } };
|
|
2483
2552
|
}
|
|
@@ -2486,7 +2555,7 @@ function firstSetSentinel(fs) {
|
|
|
2486
2555
|
function recoverScan(input, from, ctx, sync, expected) {
|
|
2487
2556
|
let scanPos = from;
|
|
2488
2557
|
while (scanPos < input.length && !probeAt(sync, input, scanPos, ctx)) scanPos++;
|
|
2489
|
-
const span =
|
|
2558
|
+
const span = new PlainSpan3(from, scanPos);
|
|
2490
2559
|
if (ctx.trackLines) recordLineRangeFromContext(ctx, input, from, scanPos);
|
|
2491
2560
|
const error = { _tag: "parseError", span: ctx.trackLines ? annotateSpanFromLineContext(span, ctx) : span, expected };
|
|
2492
2561
|
ctx._errors?.push(error);
|
|
@@ -2915,6 +2984,9 @@ function inFirstSet(code, fs) {
|
|
|
2915
2984
|
if (fs.kind === "any") return true;
|
|
2916
2985
|
if (fs.kind === "empty") return false;
|
|
2917
2986
|
for (const r of fs.ranges) if (code >= r.lo && code <= r.hi) return true;
|
|
2987
|
+
if (code <= 65535) return false;
|
|
2988
|
+
const high = 55296 + (code - 65536 >> 10);
|
|
2989
|
+
for (const r of fs.ranges) if (high >= r.lo && high <= r.hi) return true;
|
|
2918
2990
|
return false;
|
|
2919
2991
|
}
|
|
2920
2992
|
function areDisjoint(sets) {
|
|
@@ -2939,17 +3011,18 @@ function buildAsciiDispatch(parsers) {
|
|
|
2939
3011
|
}
|
|
2940
3012
|
|
|
2941
3013
|
// src/combinators/field-trivia.ts
|
|
3014
|
+
import { PlainSpan as PlainSpan4, PlainTriviaField } from "../cst/plain.js";
|
|
2942
3015
|
var LEAD = { at: -1 };
|
|
2943
3016
|
var FIELD_LEADING_TRIVIA = 1;
|
|
2944
3017
|
var FIELD_TRAILING_TRIVIA = 2;
|
|
2945
3018
|
function triviaFieldCapture(name, value, input, start, end, leadFrom, trailEnd) {
|
|
2946
|
-
return
|
|
3019
|
+
return new PlainTriviaField(
|
|
2947
3020
|
name,
|
|
2948
3021
|
value,
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
3022
|
+
new PlainSpan4(start, end),
|
|
3023
|
+
leadFrom >= 0 && leadFrom < start ? input.slice(leadFrom, start) : "",
|
|
3024
|
+
trailEnd > end ? input.slice(end, trailEnd) : ""
|
|
3025
|
+
);
|
|
2953
3026
|
}
|
|
2954
3027
|
function leadsTrivia(p) {
|
|
2955
3028
|
return p._def.tag === "field" && p._def.leadingTrivia === true;
|
|
@@ -3479,7 +3552,7 @@ function rangesHaveNewline(ranges) {
|
|
|
3479
3552
|
return ranges.some(([lo, hi]) => lo <= 10 && 10 <= hi);
|
|
3480
3553
|
}
|
|
3481
3554
|
var BAIL = /* @__PURE__ */ Symbol("regex-bail");
|
|
3482
|
-
function parseRegex(src) {
|
|
3555
|
+
function parseRegex(src, unicode = false, sets = false) {
|
|
3483
3556
|
let i = 0;
|
|
3484
3557
|
const parseAlt = () => {
|
|
3485
3558
|
const arms = [parseSeq()];
|
|
@@ -3549,9 +3622,11 @@ function parseRegex(src) {
|
|
|
3549
3622
|
i++;
|
|
3550
3623
|
return charNode(fromRange(123, 123), false);
|
|
3551
3624
|
// a `{` with nothing to quantify is a literal brace
|
|
3552
|
-
default:
|
|
3553
|
-
i
|
|
3554
|
-
|
|
3625
|
+
default: {
|
|
3626
|
+
const cp = unicode ? src.codePointAt(i) : src.charCodeAt(i);
|
|
3627
|
+
i += cp > 65535 ? 2 : 1;
|
|
3628
|
+
return charNode(fromRange(cp, cp), ch2 === "\n");
|
|
3629
|
+
}
|
|
3555
3630
|
}
|
|
3556
3631
|
};
|
|
3557
3632
|
const parseGroup = () => {
|
|
@@ -3584,6 +3659,32 @@ function parseRegex(src) {
|
|
|
3584
3659
|
let k = i + 1;
|
|
3585
3660
|
const negated = src[k] === "^";
|
|
3586
3661
|
if (negated) k++;
|
|
3662
|
+
if (sets) {
|
|
3663
|
+
let depth = 1;
|
|
3664
|
+
let nested = false;
|
|
3665
|
+
while (k < src.length && depth > 0) {
|
|
3666
|
+
const c = src[k];
|
|
3667
|
+
if (c === "\\") {
|
|
3668
|
+
if (src[k + 1] === "q") nested = true;
|
|
3669
|
+
k += 2;
|
|
3670
|
+
continue;
|
|
3671
|
+
}
|
|
3672
|
+
if (c === "[") {
|
|
3673
|
+
depth++;
|
|
3674
|
+
nested = true;
|
|
3675
|
+
} else if (c === "]") {
|
|
3676
|
+
depth--;
|
|
3677
|
+
if (depth === 0) break;
|
|
3678
|
+
} else if ((c === "-" || c === "&") && src[k + 1] === c) nested = true;
|
|
3679
|
+
k++;
|
|
3680
|
+
}
|
|
3681
|
+
if (src[k] !== "]") throw BAIL;
|
|
3682
|
+
if (nested) {
|
|
3683
|
+
i = k + 1;
|
|
3684
|
+
return charNode(any(), true);
|
|
3685
|
+
}
|
|
3686
|
+
k = i + 1 + (negated ? 1 : 0);
|
|
3687
|
+
}
|
|
3587
3688
|
let body = "";
|
|
3588
3689
|
while (k < src.length && src[k] !== "]") {
|
|
3589
3690
|
if (src[k] === "\\") {
|
|
@@ -3596,7 +3697,7 @@ function parseRegex(src) {
|
|
|
3596
3697
|
}
|
|
3597
3698
|
if (src[k] !== "]") throw BAIL;
|
|
3598
3699
|
i = k + 1;
|
|
3599
|
-
const ranges = parseClassRanges(body);
|
|
3700
|
+
const ranges = parseClassRanges(body, unicode);
|
|
3600
3701
|
if (negated) return charNode(any(), !ranges || !rangesHaveNewline(ranges));
|
|
3601
3702
|
if (!ranges) return charNode(any(), true);
|
|
3602
3703
|
return charNode(rangesToSet(ranges), rangesHaveNewline(ranges));
|
|
@@ -3604,9 +3705,20 @@ function parseRegex(src) {
|
|
|
3604
3705
|
const parseEscape = () => {
|
|
3605
3706
|
const e = src[i + 1];
|
|
3606
3707
|
if (e === void 0) throw BAIL;
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
i
|
|
3708
|
+
const uni = readUnicodeEscape(src, i, unicode);
|
|
3709
|
+
if (uni !== null) {
|
|
3710
|
+
i = uni.next;
|
|
3711
|
+
return charNode(fromRange(uni.cp, uni.cp), uni.cp === 10);
|
|
3712
|
+
}
|
|
3713
|
+
if (e === "u" && src[i + 2] === "{") {
|
|
3714
|
+
const close = src.indexOf("}", i + 3);
|
|
3715
|
+
const hex = close < 0 ? "" : src.slice(i + 3, close);
|
|
3716
|
+
if (!unicode || !/^[0-9a-fA-F]{1,6}$/.test(hex)) {
|
|
3717
|
+
i += 2;
|
|
3718
|
+
return ANY;
|
|
3719
|
+
}
|
|
3720
|
+
const cp = Number.parseInt(hex, 16);
|
|
3721
|
+
i = close + 1;
|
|
3610
3722
|
return charNode(fromRange(cp, cp), cp === 10);
|
|
3611
3723
|
}
|
|
3612
3724
|
if (e === "x" && /^[0-9a-fA-F]{2}$/.test(src.slice(i + 2, i + 4))) {
|
|
@@ -3614,6 +3726,16 @@ function parseRegex(src) {
|
|
|
3614
3726
|
i += 4;
|
|
3615
3727
|
return charNode(fromRange(cp, cp), cp === 10);
|
|
3616
3728
|
}
|
|
3729
|
+
if (e === "c") {
|
|
3730
|
+
const x = src[i + 2];
|
|
3731
|
+
if (x !== void 0 && /^[A-Za-z]$/.test(x)) {
|
|
3732
|
+
const cp = x.charCodeAt(0) % 32;
|
|
3733
|
+
i += 3;
|
|
3734
|
+
return charNode(fromRange(cp, cp), cp === 10);
|
|
3735
|
+
}
|
|
3736
|
+
i += 2;
|
|
3737
|
+
return ANY;
|
|
3738
|
+
}
|
|
3617
3739
|
i += 2;
|
|
3618
3740
|
switch (e) {
|
|
3619
3741
|
case "d":
|
|
@@ -3641,8 +3763,16 @@ function parseRegex(src) {
|
|
|
3641
3763
|
return charNode(fromRange(12, 12), false);
|
|
3642
3764
|
case "v":
|
|
3643
3765
|
return charNode(fromRange(11, 11), false);
|
|
3766
|
+
// `\0` then a digit is a legacy octal escape (`\012` is a newline), not NUL.
|
|
3644
3767
|
case "0":
|
|
3645
|
-
return charNode(fromRange(0, 0), false);
|
|
3768
|
+
return src[i] !== void 0 && src[i] >= "0" && src[i] <= "9" ? ANY : charNode(fromRange(0, 0), false);
|
|
3769
|
+
// A property escape (`\p{…}`/`\P{…}`) matches one character of a class this
|
|
3770
|
+
// analyzer does not enumerate; `\k<name>` is a backreference, which may match empty.
|
|
3771
|
+
case "p":
|
|
3772
|
+
case "P":
|
|
3773
|
+
return charNode(any(), true);
|
|
3774
|
+
case "k":
|
|
3775
|
+
return ANY;
|
|
3646
3776
|
default:
|
|
3647
3777
|
if (e >= "1" && e <= "9") return ANY;
|
|
3648
3778
|
return charNode(fromRange(e.codePointAt(0), e.codePointAt(0)), e === "\n");
|
|
@@ -3716,10 +3846,10 @@ function regexCanMatchEmpty(source) {
|
|
|
3716
3846
|
return true;
|
|
3717
3847
|
}
|
|
3718
3848
|
}
|
|
3719
|
-
function firstSetFromRegex(source) {
|
|
3849
|
+
function firstSetFromRegex(source, flags = "") {
|
|
3720
3850
|
let ast;
|
|
3721
3851
|
try {
|
|
3722
|
-
ast = parseRegex(source);
|
|
3852
|
+
ast = parseRegex(source, flags.includes("u") || flags.includes("v"), flags.includes("v"));
|
|
3723
3853
|
} catch {
|
|
3724
3854
|
return { firstSet: any(), canMatchNewline: true };
|
|
3725
3855
|
}
|
|
@@ -3728,6 +3858,7 @@ function firstSetFromRegex(source) {
|
|
|
3728
3858
|
}
|
|
3729
3859
|
|
|
3730
3860
|
// src/combinators/regex.ts
|
|
3861
|
+
import { PlainLeaf as PlainLeaf3, PlainSpan as PlainSpan5 } from "../cst/plain.js";
|
|
3731
3862
|
var SCAN_BAIL_AT = 64;
|
|
3732
3863
|
function inRanges3(cp, ranges) {
|
|
3733
3864
|
for (let i = 0; i < ranges.length; i++) {
|
|
@@ -3768,8 +3899,18 @@ function shortScanner(source, flags) {
|
|
|
3768
3899
|
return minOne && end === pos ? null : end;
|
|
3769
3900
|
};
|
|
3770
3901
|
}
|
|
3902
|
+
function coversNonAscii(ranges) {
|
|
3903
|
+
let next = 128;
|
|
3904
|
+
for (const r of [...ranges].sort((a, b) => a.lo - b.lo)) {
|
|
3905
|
+
if (r.lo > next) return false;
|
|
3906
|
+
if (r.hi >= next) next = r.hi + 1;
|
|
3907
|
+
if (next > 65535) return true;
|
|
3908
|
+
}
|
|
3909
|
+
return false;
|
|
3910
|
+
}
|
|
3771
3911
|
function asciiCaseFold(fs) {
|
|
3772
3912
|
if (fs.kind !== "ranges") return fs;
|
|
3913
|
+
if (fs.ranges.some((r) => r.hi >= 128) && !coversNonAscii(fs.ranges)) return any();
|
|
3773
3914
|
const ranges = fs.ranges.map((r) => ({ lo: r.lo, hi: r.hi }));
|
|
3774
3915
|
const add = (lo, hi) => {
|
|
3775
3916
|
if (lo <= hi) ranges.push({ lo, hi });
|
|
@@ -3794,7 +3935,7 @@ function regex(pattern, flags = "") {
|
|
|
3794
3935
|
const resolvedFlags = typeof pattern === "string" ? flags : pattern.flags;
|
|
3795
3936
|
const anchored = new RegExp(source, "y" + resolvedFlags.replace(/[gy]/g, ""));
|
|
3796
3937
|
const scan = shortScanner(source, resolvedFlags);
|
|
3797
|
-
const raw = firstSetFromRegex(source);
|
|
3938
|
+
const raw = firstSetFromRegex(source, resolvedFlags);
|
|
3798
3939
|
const firstSet2 = !resolvedFlags.includes("i") ? raw.firstSet : resolvedFlags.includes("u") || resolvedFlags.includes("v") ? any() : asciiCaseFold(raw.firstSet);
|
|
3799
3940
|
const canMatchNewline = raw.canMatchNewline;
|
|
3800
3941
|
const meta = { firstSet: firstSet2, canMatchNewline, isTrivia: false };
|
|
@@ -3830,9 +3971,9 @@ function regex(pattern, flags = "") {
|
|
|
3830
3971
|
if (scanEnd !== void 0) {
|
|
3831
3972
|
if (scanEnd === null) return failAt(ctx, directTerminalFailureExpected(def), pos);
|
|
3832
3973
|
const value = input.slice(pos, scanEnd);
|
|
3833
|
-
const span2 =
|
|
3974
|
+
const span2 = new PlainSpan5(pos, scanEnd);
|
|
3834
3975
|
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, scanEnd);
|
|
3835
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
3976
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf3(value, span2));
|
|
3836
3977
|
return { ok: true, value, span: span2 };
|
|
3837
3978
|
}
|
|
3838
3979
|
anchored.lastIndex = pos;
|
|
@@ -3840,9 +3981,9 @@ function regex(pattern, flags = "") {
|
|
|
3840
3981
|
if (m === null) {
|
|
3841
3982
|
return failAt(ctx, directTerminalFailureExpected(def), pos);
|
|
3842
3983
|
}
|
|
3843
|
-
const span =
|
|
3984
|
+
const span = new PlainSpan5(pos, pos + m[0].length);
|
|
3844
3985
|
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, span.end);
|
|
3845
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
3986
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf3(m[0], span));
|
|
3846
3987
|
return { ok: true, value: m[0], span };
|
|
3847
3988
|
}
|
|
3848
3989
|
};
|
|
@@ -3869,6 +4010,7 @@ function buildLexBodyRecognizer(spec, constants) {
|
|
|
3869
4010
|
}
|
|
3870
4011
|
|
|
3871
4012
|
// src/table/run-support.ts
|
|
4013
|
+
import { PlainLeaf as PlainLeaf4, PlainLineSpan as PlainLineSpan2, PlainSpan as PlainSpan6 } from "../cst/plain.js";
|
|
3872
4014
|
function lineCol(ctx, offset) {
|
|
3873
4015
|
const starts = ctx._lineStarts ?? [0];
|
|
3874
4016
|
let lo = 0, hi = starts.length - 1;
|
|
@@ -3881,18 +4023,14 @@ function lineCol(ctx, offset) {
|
|
|
3881
4023
|
}
|
|
3882
4024
|
function spanLines(ctx, start, end) {
|
|
3883
4025
|
const s = lineCol(ctx, start), e = lineCol(ctx, end);
|
|
3884
|
-
return
|
|
4026
|
+
return new PlainLineSpan2(start, end, s[0], s[1], e[0], e[1]);
|
|
3885
4027
|
}
|
|
3886
4028
|
function rawEntry(v, input, s, e) {
|
|
3887
4029
|
if (typeof v === "object" && v !== null) {
|
|
3888
4030
|
const tg = v._tag;
|
|
3889
4031
|
if (tg === "node" || tg === "leaf" || tg === "parseError") return v;
|
|
3890
4032
|
}
|
|
3891
|
-
return
|
|
3892
|
-
_tag: "leaf",
|
|
3893
|
-
value: typeof v === "string" ? v : typeof v === "object" && v !== null ? input.slice(s, e) : "",
|
|
3894
|
-
span: { start: s, end: e }
|
|
3895
|
-
};
|
|
4033
|
+
return new PlainLeaf4(typeof v === "string" ? v : typeof v === "object" && v !== null ? input.slice(s, e) : "", new PlainSpan6(s, e));
|
|
3896
4034
|
}
|
|
3897
4035
|
function lead(input, pos) {
|
|
3898
4036
|
if (pos >= input.length) return -1;
|
|
@@ -3906,7 +4044,7 @@ function collapseEmpty(ctx, build, input, pos, end, readsRaw) {
|
|
|
3906
4044
|
const collected = ctx._cstBuf !== void 0 || ctx._cstChildren !== void 0;
|
|
3907
4045
|
if (collected) popCstChild(ctx);
|
|
3908
4046
|
const raw = readsRaw ? [rawEntry(void 0, input, pos, end)] : EMPTY_KIDS;
|
|
3909
|
-
const nd = build(EMPTY_KIDS, void 0,
|
|
4047
|
+
const nd = build(EMPTY_KIDS, void 0, new PlainSpan6(pos, end), raw, EMPTY_TRIVIA, void 0);
|
|
3910
4048
|
if (collected) pushCstChild(ctx, nd, ctx._cstBuf?.noRaw === true ? void 0 : rawEntry(nd, input, pos, end));
|
|
3911
4049
|
return nd;
|
|
3912
4050
|
}
|
|
@@ -4576,7 +4714,7 @@ function decodeClassSpec(spec) {
|
|
|
4576
4714
|
function resolveClass(spec) {
|
|
4577
4715
|
const ascii = new Uint8Array(128);
|
|
4578
4716
|
const hi = [];
|
|
4579
|
-
for (const { lo, hi: up } of decodeClassSpec(spec)) {
|
|
4717
|
+
for (const { lo, hi: up } of leadRanges(decodeClassSpec(spec))) {
|
|
4580
4718
|
if (lo < 128) for (let c = lo; c <= Math.min(up, 127); c++) ascii[c] = 1;
|
|
4581
4719
|
if (up >= 128) hi.push(Math.max(lo, 128), up);
|
|
4582
4720
|
}
|
|
@@ -5128,6 +5266,7 @@ function buildReadsState(def) {
|
|
|
5128
5266
|
}
|
|
5129
5267
|
|
|
5130
5268
|
// src/combinators/token.ts
|
|
5269
|
+
import { PlainLeaf as PlainLeaf5 } from "../cst/plain.js";
|
|
5131
5270
|
function semanticLeafValue(_ctx, _input, _start, _end, value) {
|
|
5132
5271
|
return value;
|
|
5133
5272
|
}
|
|
@@ -5181,7 +5320,7 @@ function token(root) {
|
|
|
5181
5320
|
if (!result.ok) return result;
|
|
5182
5321
|
const span = result.span;
|
|
5183
5322
|
const value = input.slice(pos, span.end);
|
|
5184
|
-
if (wasCapturing) pushCstLeaf(ctx,
|
|
5323
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf5(value, span));
|
|
5185
5324
|
return { ok: true, value, span };
|
|
5186
5325
|
}
|
|
5187
5326
|
};
|
|
@@ -5229,11 +5368,7 @@ function makeLeaf(root, fn, sourceCstValue) {
|
|
|
5229
5368
|
}
|
|
5230
5369
|
if (!result.ok) return result;
|
|
5231
5370
|
const value = fn(result.value, result.span);
|
|
5232
|
-
if (wasCapturing) pushCstLeaf(ctx,
|
|
5233
|
-
_tag: "leaf",
|
|
5234
|
-
value: cstValue(ctx, input, pos, result.span.end, value),
|
|
5235
|
-
span: result.span
|
|
5236
|
-
});
|
|
5371
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf5(cstValue(ctx, input, pos, result.span.end, value), result.span));
|
|
5237
5372
|
return { ok: true, value, span: result.span };
|
|
5238
5373
|
}
|
|
5239
5374
|
};
|
|
@@ -6256,6 +6391,7 @@ function buildFieldMap(captures) {
|
|
|
6256
6391
|
}
|
|
6257
6392
|
|
|
6258
6393
|
// src/combinators/dispatch.ts
|
|
6394
|
+
import { PlainLeaf as PlainLeaf6 } from "../cst/plain.js";
|
|
6259
6395
|
function parserUsesRouted(parser2, seen = /* @__PURE__ */ new Set()) {
|
|
6260
6396
|
if (seen.has(parser2)) return false;
|
|
6261
6397
|
seen.add(parser2);
|
|
@@ -6418,6 +6554,7 @@ var OP_NAMES = {
|
|
|
6418
6554
|
};
|
|
6419
6555
|
|
|
6420
6556
|
// src/combinators/node.ts
|
|
6557
|
+
import { PlainNode, PlainSpan as PlainSpan7 } from "../cst/plain.js";
|
|
6421
6558
|
function unwrapChild(child) {
|
|
6422
6559
|
return child !== null && typeof child === "object" && child._tag === "leaf" ? child.value : child;
|
|
6423
6560
|
}
|
|
@@ -6523,7 +6660,7 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
6523
6660
|
const nodeType = def.type ?? missingInferredType();
|
|
6524
6661
|
const cstOutput = cstOutputHost(ctx.build);
|
|
6525
6662
|
const span = ctx.trackLines ? annotateSpanFromLineContext(r.span, ctx) : r.span;
|
|
6526
|
-
const built = unwrap && children2.length === 1 ? unwrapChild(children2[0]) : collapse && children2.length === 1 ? children2[0] : (cstOutput || !build && project === void 0) && ctx.build?._parsemanCstCollapse && children2.length === 1 && rawChildren.length === 1 && ctx.build._parsemanCstCollapse(nodeType, children2[0], children2, rawChildren) ? children2[0] : project !== void 0 ? cstOutput && ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, ctx.state, tags) : projectChild(children2, project, nodeType) : build ? cstOutput && ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, ctx.state, tags) : build(children2, fields, span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, st, tags) :
|
|
6663
|
+
const built = unwrap && children2.length === 1 ? unwrapChild(children2[0]) : collapse && children2.length === 1 ? children2[0] : (cstOutput || !build && project === void 0) && ctx.build?._parsemanCstCollapse && children2.length === 1 && rawChildren.length === 1 && ctx.build._parsemanCstCollapse(nodeType, children2[0], children2, rawChildren) ? children2[0] : project !== void 0 ? cstOutput && ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, ctx.state, tags) : projectChild(children2, project, nodeType) : build ? cstOutput && ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, ctx.state, tags) : build(children2, fields, span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, st, tags) : new PlainNode(nodeType, ctx.trackLines ? copySpan(span) : new PlainSpan7(r.span.start, r.span.end), st ?? null, [...children2]);
|
|
6527
6664
|
const rawEntry2 = isCstChild(built) ? built : { _tag: "leaf", value: typeof built === "string" ? built : typeof built === "object" && built !== null ? input.slice(r.span.start, r.span.end) : "", span };
|
|
6528
6665
|
if (saved.buf !== void 0 || saved.ch !== void 0) {
|
|
6529
6666
|
pushCstChild(ctx, built, rawEntry2);
|
|
@@ -8479,6 +8616,7 @@ function parseSeqParts(source) {
|
|
|
8479
8616
|
cp2 = uni.cp;
|
|
8480
8617
|
i = uni.next;
|
|
8481
8618
|
} else if (e === void 0) return null;
|
|
8619
|
+
else if (e >= "0" && e <= "9" && (e !== "0" || source[i + 2] !== void 0 && source[i + 2] >= "0" && source[i + 2] <= "9")) return null;
|
|
8482
8620
|
else if (e in CLASS_ESCAPES) {
|
|
8483
8621
|
cp2 = CLASS_ESCAPES[e];
|
|
8484
8622
|
i += 2;
|
|
@@ -9028,7 +9166,7 @@ function parseScanShapeCore(source) {
|
|
|
9028
9166
|
return null;
|
|
9029
9167
|
}
|
|
9030
9168
|
function scanShapeFromRegex(source, flags) {
|
|
9031
|
-
if (/[
|
|
9169
|
+
if (/[msuv]/.test(flags)) return null;
|
|
9032
9170
|
if (/i/.test(flags)) return caseFoldShape(source);
|
|
9033
9171
|
return parseScanShape(source);
|
|
9034
9172
|
}
|
|
@@ -9633,7 +9771,7 @@ function triviaLeadRanges(tri, trivia2) {
|
|
|
9633
9771
|
const fs = trivia2[tri]?._meta.firstSet;
|
|
9634
9772
|
if (fs === void 0) return void 0;
|
|
9635
9773
|
if (fs.kind === "empty") return [];
|
|
9636
|
-
return fs.kind === "ranges" && fs.ranges !== void 0 ? fs.ranges : void 0;
|
|
9774
|
+
return fs.kind === "ranges" && fs.ranges !== void 0 ? leadRanges(fs.ranges) : void 0;
|
|
9637
9775
|
}
|
|
9638
9776
|
|
|
9639
9777
|
// src/table/scalar-terminal.ts
|
|
@@ -9991,7 +10129,14 @@ var EMITTED_PARAMS = [
|
|
|
9991
10129
|
"skipDeferredTrivia",
|
|
9992
10130
|
// Appended for the pass-through collapse (`run-support.ts`); old factories
|
|
9993
10131
|
// ignore it.
|
|
9994
|
-
"collapseEmpty"
|
|
10132
|
+
"collapseEmpty",
|
|
10133
|
+
// Appended for constructor-built tree objects (`cst/plain.d.ts`): a `new` call has
|
|
10134
|
+
// no allocation site, so V8 cannot pretenure them. Old factories ignore them.
|
|
10135
|
+
"_SP",
|
|
10136
|
+
"_LF",
|
|
10137
|
+
"_ND",
|
|
10138
|
+
"_FC",
|
|
10139
|
+
"_BUF"
|
|
9995
10140
|
];
|
|
9996
10141
|
var RUNTIME_PRELUDE = `
|
|
9997
10142
|
let _pfScan=null
|
|
@@ -10015,9 +10160,9 @@ if(s!==null)return skipTriviaScanned(s,input,cur,ctx)
|
|
|
10015
10160
|
if(needsDeferredTriviaCommit(ctx))return skipDeferredTrivia(input,cur,ctx)
|
|
10016
10161
|
return advanceTrivia(input,cur,ctx)
|
|
10017
10162
|
}
|
|
10018
|
-
function _pushLeaf(ctx,value,s,e){pushCstLeaf(ctx,
|
|
10163
|
+
function _pushLeaf(ctx,value,s,e){pushCstLeaf(ctx,new _LF(value,new _SP(s,e)))}
|
|
10019
10164
|
function _pushLeafBuf(ctx,value,s,e){
|
|
10020
|
-
const l=
|
|
10165
|
+
const l=new _LF(value,new _SP(s,e))
|
|
10021
10166
|
const b=ctx._cstBuf
|
|
10022
10167
|
if(b.ch!==undefined)b.ch.push(l)
|
|
10023
10168
|
else if(b.single!==undefined){b.ch=[b.single,l];b.single=undefined}
|
|
@@ -10075,7 +10220,7 @@ if(ctx._rootTriviaLog!==undefined&&ctx._rootTriviaLog.length!==rt)ctx._rootTrivi
|
|
|
10075
10220
|
`;
|
|
10076
10221
|
var NO_RAW_RUNTIME_PRELUDE = `
|
|
10077
10222
|
function _pushLeafNoRawBuf(ctx,value,s,e){
|
|
10078
|
-
const l=
|
|
10223
|
+
const l=new _LF(value,new _SP(s,e))
|
|
10079
10224
|
const b=ctx._cstBuf
|
|
10080
10225
|
if(b.ch!==undefined)b.ch.push(l)
|
|
10081
10226
|
else if(b.single!==undefined){b.ch=[b.single,l];b.single=undefined}
|
|
@@ -10163,7 +10308,7 @@ if(ctx._errors!==undefined&&ctx._errors.length!==${t2}er)ctx._errors.length=${t2
|
|
|
10163
10308
|
if (!s.fd && !s.er) return `if(${t2}n)rollbackTriviaAt(ctx,${t2}raw,${t2}tl,${t2}lv,undefined,undefined,${t2}lg,${t2}rt)`;
|
|
10164
10309
|
return `if(${t2}n){rollbackTriviaAt(ctx,${t2}raw,${t2}tl,${t2}lv,${s.fd ? `${t2}fd` : "undefined"},${s.er ? `${t2}er` : "undefined"},${t2}lg,${t2}rt)}`;
|
|
10165
10310
|
}
|
|
10166
|
-
function emitTerm(callee, dst, t2, l, skip) {
|
|
10311
|
+
function emitTerm(callee, dst, t2, l, skip, miss) {
|
|
10167
10312
|
const fast = `const ${t2}v=${callee}(input,cur,ctx)
|
|
10168
10313
|
if(${t2}v===FAIL)return FAIL
|
|
10169
10314
|
${dst}=${t2}v
|
|
@@ -10181,7 +10326,12 @@ if(${t2}v===FAIL)return FAIL
|
|
|
10181
10326
|
${dst}=${t2}v
|
|
10182
10327
|
if(EC.e>${t2}s)cur=EC.e
|
|
10183
10328
|
else{rollbackScannedTriviaAt(ctx,${t2}tl,${t2}stl,${t2}lg,${t2}slg,${t2}rt,${t2}srt)}`;
|
|
10184
|
-
if (l.tri !== TRI_UNKNOWN) return scanned
|
|
10329
|
+
if (l.tri !== TRI_UNKNOWN) return miss === void 0 ? scanned : `const ${t2}c=input.charCodeAt(cur)
|
|
10330
|
+
if(${miss(`${t2}c`)}){
|
|
10331
|
+
${fast}
|
|
10332
|
+
}else{
|
|
10333
|
+
${scanned}
|
|
10334
|
+
}`;
|
|
10185
10335
|
return `if(ctx.trivia===undefined){
|
|
10186
10336
|
${fast}
|
|
10187
10337
|
}else{
|
|
@@ -10237,7 +10387,7 @@ function rebuildPools(cc, fx, disp, plan) {
|
|
|
10237
10387
|
})
|
|
10238
10388
|
};
|
|
10239
10389
|
}
|
|
10240
|
-
function emitAssemblySource(t2, prog, cfg, extraIps = [], staticBuild = false, select) {
|
|
10390
|
+
function emitAssemblySource(t2, prog, cfg, extraIps = [], staticBuild = false, select, scanSinkNeutral = false) {
|
|
10241
10391
|
const { code, k, fx, disp, dsp, triviaLabelled } = t2;
|
|
10242
10392
|
const swapLegal = !cfg.trackLines;
|
|
10243
10393
|
const hostCst = cfg.hostCst;
|
|
@@ -10313,7 +10463,7 @@ function emitAssemblySource(t2, prog, cfg, extraIps = [], staticBuild = false, s
|
|
|
10313
10463
|
const op = code[ip];
|
|
10314
10464
|
sinkBits.set(
|
|
10315
10465
|
ip,
|
|
10316
|
-
op === OP_SCAN ? 3 : (op === OP_FIELD ? 1 : 0) | (op === OP_EXPECT || REC && (op === OP_REP || op === OP_REPV) ? 2 : 0)
|
|
10466
|
+
op === OP_SCAN || !scanSinkNeutral && op === OP_LEX_PROGRAM && t2.lexPrograms[code[ip + 1]].scan !== void 0 ? 3 : (op === OP_FIELD ? 1 : 0) | (op === OP_EXPECT || REC && (op === OP_REP || op === OP_REPV) ? 2 : 0)
|
|
10317
10467
|
);
|
|
10318
10468
|
}
|
|
10319
10469
|
const sinkKids = [];
|
|
@@ -10486,6 +10636,12 @@ return 1
|
|
|
10486
10636
|
return `if(${gateMissTest(child)}){${miss}}
|
|
10487
10637
|
`;
|
|
10488
10638
|
}
|
|
10639
|
+
function triviaMiss(ki) {
|
|
10640
|
+
const leads = triviaLeadRanges(ki, t2.trivia);
|
|
10641
|
+
if (leads === void 0 || leads.length > 16) return void 0;
|
|
10642
|
+
if (leads.length === 0) return (c) => `${c}<55296`;
|
|
10643
|
+
return (c) => `${c}<55296&&!(${leads.map((r) => r.lo === r.hi ? `${c}===${r.lo}` : `(${c}>=${r.lo}&&${c}<=${r.hi})`).join("||")})`;
|
|
10644
|
+
}
|
|
10489
10645
|
function skipFor(l) {
|
|
10490
10646
|
if (l.tri < 0) return "_skipTrivia";
|
|
10491
10647
|
const ki = l.tri;
|
|
@@ -10496,8 +10652,13 @@ return 1
|
|
|
10496
10652
|
const nm = `_sk${skipPool.size}`;
|
|
10497
10653
|
skipPool.set(key, nm);
|
|
10498
10654
|
if (!hasScan) {
|
|
10499
|
-
|
|
10500
|
-
|
|
10655
|
+
const miss = triviaMiss(ki);
|
|
10656
|
+
const pre = miss === void 0 ? "" : `const c=input.charCodeAt(cur)
|
|
10657
|
+
if(${miss("c")})return cur
|
|
10658
|
+
`;
|
|
10659
|
+
skipDefs.push(l.buf ? `function ${nm}(input,cur,ctx){${pre === "" ? "" : `
|
|
10660
|
+
${pre}`}return skipDeferredTrivia(input,cur,ctx)}` : `function ${nm}(input,cur,ctx){
|
|
10661
|
+
${pre}if(needsDeferredTriviaCommit(ctx))return skipDeferredTrivia(input,cur,ctx)
|
|
10501
10662
|
return advanceTrivia(input,cur,ctx)}`);
|
|
10502
10663
|
return nm;
|
|
10503
10664
|
}
|
|
@@ -10736,7 +10897,7 @@ try{return ${child}(input,pos,ctx)}finally{ctx.state=saved}
|
|
|
10736
10897
|
return `${head}
|
|
10737
10898
|
const v=${child}(input,pos,ctx)
|
|
10738
10899
|
if(v===FAIL)return FAIL
|
|
10739
|
-
return ${fn}(v,
|
|
10900
|
+
return ${fn}(v,new _SP(pos,EC.e))
|
|
10740
10901
|
}`;
|
|
10741
10902
|
}
|
|
10742
10903
|
case OP_LABEL: {
|
|
@@ -10757,7 +10918,7 @@ return v
|
|
|
10757
10918
|
const v=${child}(input,pos,ctx)
|
|
10758
10919
|
if(v===FAIL)return FAIL
|
|
10759
10920
|
const f=ctx._fields
|
|
10760
|
-
if(f!==undefined)f.push({name
|
|
10921
|
+
if(f!==undefined)f.push(new _FC(${name},v,new _SP(pos,EC.e)))
|
|
10761
10922
|
return v
|
|
10762
10923
|
}`;
|
|
10763
10924
|
}
|
|
@@ -10782,7 +10943,7 @@ return v
|
|
|
10782
10943
|
return `${head}
|
|
10783
10944
|
const v=${child}(input,pos,ctx)
|
|
10784
10945
|
if(v!==FAIL)return v
|
|
10785
|
-
const err={_tag:'parseError',span:${prog.lines === 1 ? "spanLines(ctx,pos,pos)" : "
|
|
10946
|
+
const err={_tag:'parseError',span:${prog.lines === 1 ? "spanLines(ctx,pos,pos)" : "new _SP(pos,pos)"},expected:${xf}}
|
|
10786
10947
|
const es=ctx._errors
|
|
10787
10948
|
if(es!==undefined)es.push(err)
|
|
10788
10949
|
${REC ? "if(ctx._tolerant===true)captureError(ctx,err)\n" : ""}ctx._fc=false
|
|
@@ -10793,7 +10954,7 @@ return err
|
|
|
10793
10954
|
case OP_ROUTED: {
|
|
10794
10955
|
const fb = code[ip + 1];
|
|
10795
10956
|
const fallback = fb >= 0 ? link(fb) : void 0;
|
|
10796
|
-
const push = `pushCstLeaf(ctx,
|
|
10957
|
+
const push = `pushCstLeaf(ctx,new _LF(it.value,it.span))`;
|
|
10797
10958
|
return `${head}
|
|
10798
10959
|
const it=ctx._routed
|
|
10799
10960
|
if(it===undefined||pos!==it.span.start){
|
|
@@ -10874,8 +11035,8 @@ ctx._triviaLog=sOtl
|
|
|
10874
11035
|
}
|
|
10875
11036
|
if(v===FAIL)return FAIL
|
|
10876
11037
|
const e=EC.e
|
|
10877
|
-
const out=${isToken ? "input.slice(pos,e)" : `${fn}(v,
|
|
10878
|
-
if(wasCap)pushCstLeaf(ctx,{
|
|
11038
|
+
const out=${isToken ? "input.slice(pos,e)" : `${fn}(v,new _SP(pos,e))`}
|
|
11039
|
+
if(wasCap)pushCstLeaf(ctx,new _LF(${capturesSource ? "input.slice(pos,e)" : "out"},new _SP(pos,e)))
|
|
10879
11040
|
EC.e=e
|
|
10880
11041
|
return out
|
|
10881
11042
|
}`;
|
|
@@ -10899,7 +11060,7 @@ ${hasSuffix && (lineFlags & 2) !== 0 ? "if(sm)_trackLines(ctx,input,e)" : ""}
|
|
|
10899
11060
|
${hasSuffix ? `if(!sm){ctx._fe=e;ctx._fx=${suffixExpected};if(ctx._probe!==undefined)failAt(ctx,${suffixExpected},e)}` : ""}
|
|
10900
11061
|
const v=${pending ? "tp?_pfTokValue:" : ""}input.slice(pos,e)
|
|
10901
11062
|
${pending ? "if(tp){_pfTokBody=-1;_pfTokValue=undefined}" : ""}
|
|
10902
|
-
if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,
|
|
11063
|
+
if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
|
|
10903
11064
|
EC.e=e
|
|
10904
11065
|
return v
|
|
10905
11066
|
}`;
|
|
@@ -10938,7 +11099,7 @@ ctx._rootTriviaLog=sRtl
|
|
|
10938
11099
|
}
|
|
10939
11100
|
if(e<0)return FAIL
|
|
10940
11101
|
const v=input.slice(pos,e)
|
|
10941
|
-
if(wasCap)pushCstLeaf(ctx,
|
|
11102
|
+
if(wasCap)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
|
|
10942
11103
|
EC.e=e
|
|
10943
11104
|
return v
|
|
10944
11105
|
}`;
|
|
@@ -10946,7 +11107,7 @@ return v
|
|
|
10946
11107
|
const e=${run}(input,pos,ctx)
|
|
10947
11108
|
if(e<0)return FAIL
|
|
10948
11109
|
const v=input.slice(pos,e)
|
|
10949
|
-
if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,
|
|
11110
|
+
if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
|
|
10950
11111
|
EC.e=e
|
|
10951
11112
|
return v
|
|
10952
11113
|
}`;
|
|
@@ -11060,7 +11221,7 @@ return v
|
|
|
11060
11221
|
}` : `${parts.join("\n")}
|
|
11061
11222
|
}`;
|
|
11062
11223
|
if (n === 1) {
|
|
11063
|
-
parts.push(fused ? projection === 0 ? "return v0" : `return ${fn}([v0],
|
|
11224
|
+
parts.push(fused ? projection === 0 ? "return v0" : `return ${fn}([v0],new _SP(pos,EC.e))` : wantValues ? "return [v0]" : "return undefined");
|
|
11064
11225
|
return close();
|
|
11065
11226
|
}
|
|
11066
11227
|
parts.push("let cur=EC.e");
|
|
@@ -11081,12 +11242,12 @@ return v
|
|
|
11081
11242
|
);
|
|
11082
11243
|
} else {
|
|
11083
11244
|
const callee = leadingTriviaFieldAt(code, k, childIp) ? `(LEAD.at=cur,${kids[i]})` : kids[i];
|
|
11084
|
-
parts.push(holdsGap(code, k, base, n, i, nullable2) ? emitHoldTerm(callee, vn, tmp(), L, skipFor(L)) : emitTerm(callee, vn, tmp(), L, skipFor(L)));
|
|
11245
|
+
parts.push(holdsGap(code, k, base, n, i, nullable2) ? emitHoldTerm(callee, vn, tmp(), L, skipFor(L)) : emitTerm(callee, vn, tmp(), L, skipFor(L), L.tri >= 0 ? triviaMiss(L.tri) : void 0));
|
|
11085
11246
|
}
|
|
11086
11247
|
names.push(vn);
|
|
11087
11248
|
}
|
|
11088
11249
|
parts.push("EC.e=cur");
|
|
11089
|
-
parts.push(fused ? projection >= 0 ? `return ${names[projection]}` : `return ${fn}([${names.join(",")}],
|
|
11250
|
+
parts.push(fused ? projection >= 0 ? `return ${names[projection]}` : `return ${fn}([${names.join(",")}],new _SP(pos,cur))` : wantValues ? `return [${names.join(",")}]` : "return undefined");
|
|
11090
11251
|
return close();
|
|
11091
11252
|
}
|
|
11092
11253
|
case OP_CHOICE: {
|
|
@@ -11345,7 +11506,7 @@ ${spec.match.map((m, i) => `${i === 0 ? "" : "else "}if(${dispatchClaim(m)})arm=
|
|
|
11345
11506
|
const routedCall = (target) => `{const savedRouted=ctx._routed
|
|
11346
11507
|
${emitRollback(m1, L.buf, L.raw, sinks)}
|
|
11347
11508
|
${emitMark(m2, L.buf, L.raw, sinks, false)}
|
|
11348
|
-
ctx._routed={value:key,span:
|
|
11509
|
+
ctx._routed={value:key,span:new _SP(pos,selEnd)}
|
|
11349
11510
|
try{v=${target}(input,pos,ctx)}finally{ctx._routed=savedRouted}
|
|
11350
11511
|
break}`;
|
|
11351
11512
|
const plainCall = (target) => `v=${target}(input,selEnd,ctx);break`;
|
|
@@ -11540,8 +11701,8 @@ return out
|
|
|
11540
11701
|
const end=${recognize}(input,pos)
|
|
11541
11702
|
if(end<0){ctx._fe=pos;ctx._fx=${xf};return FAIL}
|
|
11542
11703
|
const value=${value2}
|
|
11543
|
-
const leaf=
|
|
11544
|
-
const kids=[leaf],rawKids=[leaf],span=
|
|
11704
|
+
const leaf=new _LF(value,new _SP(pos,end))
|
|
11705
|
+
const kids=[leaf],rawKids=[leaf],span=new _SP(pos,end)
|
|
11545
11706
|
EC.e=end
|
|
11546
11707
|
const nd=${build2}(kids,undefined,span,rawKids,EMPTY_TL,undefined)
|
|
11547
11708
|
${L.buf && L.raw === RAW_OMIT ? "_pushNodeNoRawBuf(ctx,nd)" : L.buf && L.raw === RAW_CAPTURE ? "pushCstChild(ctx,nd,rawEntry(nd,input,pos,end))" : staticBuild ? "if(ctx._cstBuf!==undefined||ctx._cstChildren!==undefined)pushCstChild(ctx,nd,ctx._cstBuf!==undefined&&ctx._cstBuf.noRaw===true?undefined:ctx._cstBuf!==undefined||ctx._cstRawChildren!==undefined?rawEntry(nd,input,pos,end):undefined)" : "if(ctx._cstBuf!==undefined||ctx._cstChildren!==undefined)pushCstChild(ctx,nd,rawEntry(nd,input,pos,end))"}
|
|
@@ -11640,7 +11801,7 @@ ctx._cstTriviaLog=sTl
|
|
|
11640
11801
|
ctx.captureTrivia=sCap
|
|
11641
11802
|
if(v===FAIL)return FAIL
|
|
11642
11803
|
const end=EC.e
|
|
11643
|
-
${collapseChildren ? `const nd=captured.length===1?captured[0]:${build}(captured,undefined,
|
|
11804
|
+
${collapseChildren ? `const nd=captured.length===1?captured[0]:${build}(captured,undefined,new _SP(pos,end),EMPTY_CH,EMPTY_TL,undefined)` : `const nd=${build}(captured,${fields ? "fieldMap" : "undefined"},new _SP(pos,end),EMPTY_CH,EMPTY_TL,undefined)`}
|
|
11644
11805
|
${publish}
|
|
11645
11806
|
EC.e=end
|
|
11646
11807
|
return nd
|
|
@@ -11663,20 +11824,20 @@ return nd
|
|
|
11663
11824
|
const direct = `${build}(kids,fieldMap,span,rawKids,${captureWide ? "tlog" : "EMPTY_TL"},st)`;
|
|
11664
11825
|
value = hostCst ? `nd=_pfHost!==undefined?${hostCall}:${direct}` : `nd=${direct}`;
|
|
11665
11826
|
} else {
|
|
11666
|
-
value = `nd=_pfHost!==undefined?_pfHost(${ty},hostKids,fieldMap,span,rawKids,tlog,st,${tags}):{
|
|
11827
|
+
value = `nd=_pfHost!==undefined?_pfHost(${ty},hostKids,fieldMap,span,rawKids,tlog,st,${tags}):new _ND(${ty},span,st??null,kids===EMPTY_CH?kids:[...kids])`;
|
|
11667
11828
|
}
|
|
11668
11829
|
const collapsible = keepChildren && (hostCst || build === void 0 && proj < 0);
|
|
11669
|
-
const openCapture = omitsRaw ? `const buf=
|
|
11830
|
+
const openCapture = omitsRaw ? `const buf=new _BUF(undefined,true,0)
|
|
11670
11831
|
ctx._cstBuf=buf
|
|
11671
11832
|
ctx._cstChildren=undefined
|
|
11672
11833
|
ctx._cstLeaves=undefined
|
|
11673
11834
|
ctx._cstRawChildren=undefined
|
|
11674
|
-
ctx._cstTriviaLog=undefined` : keepChildren ? `const buf=
|
|
11835
|
+
ctx._cstTriviaLog=undefined` : keepChildren ? `const buf=new _BUF(undefined,undefined,0)
|
|
11675
11836
|
ctx._cstBuf=buf
|
|
11676
11837
|
ctx._cstChildren=undefined
|
|
11677
11838
|
ctx._cstLeaves=undefined
|
|
11678
11839
|
ctx._cstRawChildren=undefined
|
|
11679
|
-
ctx._cstTriviaLog=undefined` : `const buf=
|
|
11840
|
+
ctx._cstTriviaLog=undefined` : `const buf=new _BUF(true,undefined,0)
|
|
11680
11841
|
ctx._cstBuf=buf
|
|
11681
11842
|
ctx._cstChildren=undefined
|
|
11682
11843
|
ctx._cstLeaves=undefined
|
|
@@ -11714,7 +11875,7 @@ ctx._cstTriviaLog=sTl
|
|
|
11714
11875
|
ctx.captureTrivia=sCap
|
|
11715
11876
|
if(v===FAIL)return FAIL
|
|
11716
11877
|
const end=EC.e
|
|
11717
|
-
const span=${tracked ? "spanLines(ctx,pos,end)" : "
|
|
11878
|
+
const span=${tracked ? "spanLines(ctx,pos,end)" : "new _SP(pos,end)"}
|
|
11718
11879
|
const st=${readsState ? "ctx.state" : "undefined"}
|
|
11719
11880
|
let nd
|
|
11720
11881
|
${unwrap ? "if(kids.length===1)nd=unwrapChild(kids[0])\nelse " : ""}${collapse ? "if(kids.length===1)nd=kids[0]\nelse " : ""}${collapsible ? `if(_pfHost!==undefined&&_pfHost._parsemanCstCollapse!==undefined&&kids.length===1&&rawKids.length===1&&_pfHost._parsemanCstCollapse(${ty},kids[0],kids,rawKids))nd=kids[0]
|
|
@@ -12001,6 +12162,7 @@ function rebuildLineScan(s, subtree) {
|
|
|
12001
12162
|
}
|
|
12002
12163
|
|
|
12003
12164
|
// src/combinators/literal.ts
|
|
12165
|
+
import { PlainLeaf as PlainLeaf7, PlainSpan as PlainSpan8 } from "../cst/plain.js";
|
|
12004
12166
|
function asciiFoldEq(a, b) {
|
|
12005
12167
|
if (a.length !== b.length) return false;
|
|
12006
12168
|
for (let i = 0; i < a.length; i++) {
|
|
@@ -12058,9 +12220,9 @@ function literal(value, opts = {}) {
|
|
|
12058
12220
|
const code = value.charCodeAt(0);
|
|
12059
12221
|
return function parse3(input, pos, ctx) {
|
|
12060
12222
|
if (input.charCodeAt(pos) === code) {
|
|
12061
|
-
const span =
|
|
12223
|
+
const span = new PlainSpan8(pos, pos + 1);
|
|
12062
12224
|
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, span.end);
|
|
12063
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
12225
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf7(value, span));
|
|
12064
12226
|
return { ok: true, value, span };
|
|
12065
12227
|
}
|
|
12066
12228
|
return failAt(ctx, expected, pos);
|
|
@@ -12072,9 +12234,9 @@ function literal(value, opts = {}) {
|
|
|
12072
12234
|
}
|
|
12073
12235
|
const matchedValue = caseInsensitive ? input.slice(pos, end) : value;
|
|
12074
12236
|
if (caseInsensitive ? asciiFoldEq(matchedValue, value) : input.startsWith(value, pos)) {
|
|
12075
|
-
const span =
|
|
12237
|
+
const span = new PlainSpan8(pos, end);
|
|
12076
12238
|
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, end);
|
|
12077
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
12239
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf7(matchedValue, span));
|
|
12078
12240
|
return { ok: true, value: matchedValue, span };
|
|
12079
12241
|
}
|
|
12080
12242
|
return failAt(ctx, expected, pos);
|
|
@@ -12156,6 +12318,7 @@ function ref() {
|
|
|
12156
12318
|
}
|
|
12157
12319
|
|
|
12158
12320
|
// src/combinators/scanTo.ts
|
|
12321
|
+
import { PlainLeaf as PlainLeaf8, PlainSpan as PlainSpan9 } from "../cst/plain.js";
|
|
12159
12322
|
function resolveScanSkip(explicitSkip, raw, ctx) {
|
|
12160
12323
|
if (raw) return [];
|
|
12161
12324
|
const trivia2 = ctx.trivia;
|
|
@@ -12193,7 +12356,7 @@ function scanTo(sentinel, { skip, raw = false, orEOF = false, recoverAt, stopAt
|
|
|
12193
12356
|
probeCtx._errors = ctx._errors;
|
|
12194
12357
|
const emit = (end) => {
|
|
12195
12358
|
if (end > pos && cstCaptureActive(ctx)) {
|
|
12196
|
-
const leaf2 =
|
|
12359
|
+
const leaf2 = new PlainLeaf8(input.slice(pos, end), new PlainSpan9(pos, end));
|
|
12197
12360
|
pushCstLeaf(ctx, leaf2);
|
|
12198
12361
|
}
|
|
12199
12362
|
};
|
|
@@ -12415,6 +12578,15 @@ function skipDeferredTrivia(input, cur, ctx) {
|
|
|
12415
12578
|
if (plain2) remember(cur, scan, ctx, input, triviaP);
|
|
12416
12579
|
return scan;
|
|
12417
12580
|
}
|
|
12581
|
+
function triviaLeadTable(triviaP) {
|
|
12582
|
+
const fs = triviaP._meta.firstSet;
|
|
12583
|
+
if (fs.kind === "any") return null;
|
|
12584
|
+
const table = new Uint8Array(128);
|
|
12585
|
+
if (fs.kind === "ranges") {
|
|
12586
|
+
for (const r of fs.ranges) for (let c = Math.max(0, r.lo); c <= Math.min(127, r.hi); c++) table[c] = 1;
|
|
12587
|
+
}
|
|
12588
|
+
return table;
|
|
12589
|
+
}
|
|
12418
12590
|
function clearRunEnd(input, cur, ctx, triviaP, plain2) {
|
|
12419
12591
|
const rootKinds = ctx._rootTriviaKindIndex;
|
|
12420
12592
|
const spec = triviaP?._meta.labeledTriviaSpec;
|
|
@@ -12463,6 +12635,9 @@ function clearOf(ranges, input, from, to) {
|
|
|
12463
12635
|
return true;
|
|
12464
12636
|
}
|
|
12465
12637
|
|
|
12638
|
+
// src/table/assemble.ts
|
|
12639
|
+
import { PlainBuf as PlainBuf2, PlainField, PlainLeaf as PlainLeaf9, PlainNode as PlainNode2, PlainSpan as PlainSpan10 } from "../cst/plain.js";
|
|
12640
|
+
|
|
12466
12641
|
// src/table/fail-clean.ts
|
|
12467
12642
|
function passChild(code, ip) {
|
|
12468
12643
|
switch (code[ip]) {
|
|
@@ -12777,7 +12952,7 @@ function assemble(t2, prog, cfg) {
|
|
|
12777
12952
|
const NULLABLE = /* @__PURE__ */ new Map();
|
|
12778
12953
|
const CLEAN = REC ? () => false : failCleanAnalysis(code);
|
|
12779
12954
|
function pushLeaf(ctx, value, s, e) {
|
|
12780
|
-
const lf =
|
|
12955
|
+
const lf = new PlainLeaf9(value, new PlainSpan10(s, e));
|
|
12781
12956
|
pushCstLeaf(ctx, lf);
|
|
12782
12957
|
}
|
|
12783
12958
|
function plainBuildNode(child, build, trailing) {
|
|
@@ -12810,7 +12985,7 @@ function assemble(t2, prog, cfg) {
|
|
|
12810
12985
|
ctx.captureTrivia = sCap;
|
|
12811
12986
|
if (value === FAIL) return FAIL;
|
|
12812
12987
|
const end = EC.e;
|
|
12813
|
-
const span =
|
|
12988
|
+
const span = new PlainSpan10(pos, end);
|
|
12814
12989
|
const node2 = build(kids, void 0, span, rawKids, EMPTY_TL2, void 0);
|
|
12815
12990
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
12816
12991
|
pushCstChild(ctx, node2, rawEntry(node2, input, pos, end));
|
|
@@ -12855,7 +13030,7 @@ function assemble(t2, prog, cfg) {
|
|
|
12855
13030
|
ctx.captureTrivia = sCap;
|
|
12856
13031
|
if (value === FAIL) return FAIL;
|
|
12857
13032
|
const end = EC.e;
|
|
12858
|
-
const node2 = build(captured, void 0,
|
|
13033
|
+
const node2 = build(captured, void 0, new PlainSpan10(pos, end), EMPTY_CH, EMPTY_TL2, void 0);
|
|
12859
13034
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
12860
13035
|
pushCstChild(ctx, node2, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node2, input, pos, end) : void 0);
|
|
12861
13036
|
}
|
|
@@ -12892,7 +13067,7 @@ function assemble(t2, prog, cfg) {
|
|
|
12892
13067
|
ctx.captureTrivia = sCap;
|
|
12893
13068
|
if (value === FAIL) return FAIL;
|
|
12894
13069
|
const end = EC.e;
|
|
12895
|
-
const node2 = build(captured, fieldMap,
|
|
13070
|
+
const node2 = build(captured, fieldMap, new PlainSpan10(pos, end), EMPTY_CH, EMPTY_TL2, void 0);
|
|
12896
13071
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
12897
13072
|
pushCstChild(ctx, node2, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node2, input, pos, end) : void 0);
|
|
12898
13073
|
}
|
|
@@ -12929,7 +13104,7 @@ function assemble(t2, prog, cfg) {
|
|
|
12929
13104
|
ctx.captureTrivia = sCap;
|
|
12930
13105
|
if (value === FAIL) return FAIL;
|
|
12931
13106
|
const end = EC.e;
|
|
12932
|
-
const span =
|
|
13107
|
+
const span = new PlainSpan10(pos, end);
|
|
12933
13108
|
const node2 = kids.length === 1 ? kids[0] : build(kids, void 0, span, rawKids, EMPTY_TL2, void 0);
|
|
12934
13109
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
12935
13110
|
pushCstChild(ctx, node2, rawEntry(node2, input, pos, end));
|
|
@@ -12966,7 +13141,7 @@ function assemble(t2, prog, cfg) {
|
|
|
12966
13141
|
ctx.captureTrivia = sCap;
|
|
12967
13142
|
if (value === FAIL) return FAIL;
|
|
12968
13143
|
const end = EC.e;
|
|
12969
|
-
const node2 = captured.length === 1 ? captured[0] : build(captured, void 0,
|
|
13144
|
+
const node2 = captured.length === 1 ? captured[0] : build(captured, void 0, new PlainSpan10(pos, end), EMPTY_CH, EMPTY_TL2, void 0);
|
|
12970
13145
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
12971
13146
|
pushCstChild(ctx, node2, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node2, input, pos, end) : void 0);
|
|
12972
13147
|
}
|
|
@@ -13075,7 +13250,23 @@ function assemble(t2, prog, cfg) {
|
|
|
13075
13250
|
}
|
|
13076
13251
|
return out;
|
|
13077
13252
|
}
|
|
13253
|
+
const LEAD_TABLES = trivia2.map((tp) => tp === void 0 ? null : triviaLeadTable(tp));
|
|
13254
|
+
let LEAD_OF;
|
|
13255
|
+
let LEAD_TABLE = null;
|
|
13256
|
+
function cannotStartTrivia(input, cur, triviaP) {
|
|
13257
|
+
if (triviaP !== LEAD_OF) {
|
|
13258
|
+
LEAD_OF = triviaP;
|
|
13259
|
+
const slot = trivia2.indexOf(triviaP);
|
|
13260
|
+
LEAD_TABLE = slot >= 0 ? LEAD_TABLES[slot] : triviaLeadTable(triviaP);
|
|
13261
|
+
}
|
|
13262
|
+
const table = LEAD_TABLE;
|
|
13263
|
+
if (table === null) return false;
|
|
13264
|
+
const c = input.charCodeAt(cur);
|
|
13265
|
+
return c < 128 && table[c] === 0;
|
|
13266
|
+
}
|
|
13078
13267
|
function skipTrivia(input, cur, ctx) {
|
|
13268
|
+
const t3 = ctx.trivia;
|
|
13269
|
+
if (t3 !== void 0 && cannotStartTrivia(input, cur, t3)) return cur;
|
|
13079
13270
|
const s = SCAN;
|
|
13080
13271
|
if (s !== null && ctx._triviaLog === void 0 && !(ctx.captureTrivia === true && (ctx._cstBuf !== void 0 || ctx._cstTriviaLog !== void 0))) {
|
|
13081
13272
|
return s(input, cur);
|
|
@@ -13090,7 +13281,8 @@ function assemble(t2, prog, cfg) {
|
|
|
13090
13281
|
const frames = [];
|
|
13091
13282
|
let depth = 0;
|
|
13092
13283
|
function nextTerm(child, input, cur, ctx) {
|
|
13093
|
-
|
|
13284
|
+
const t3 = ctx.trivia;
|
|
13285
|
+
if (t3 === void 0 || cannotStartTrivia(input, cur, t3)) {
|
|
13094
13286
|
const v2 = child(input, cur, ctx);
|
|
13095
13287
|
if (v2 === FAIL) return -1;
|
|
13096
13288
|
TERMV = v2;
|
|
@@ -13119,7 +13311,8 @@ function assemble(t2, prog, cfg) {
|
|
|
13119
13311
|
return cur;
|
|
13120
13312
|
}
|
|
13121
13313
|
function nextTermBuffered(child, input, cur, ctx) {
|
|
13122
|
-
|
|
13314
|
+
const t3 = ctx.trivia;
|
|
13315
|
+
if (t3 === void 0 || cannotStartTrivia(input, cur, t3)) {
|
|
13123
13316
|
const v2 = child(input, cur, ctx);
|
|
13124
13317
|
if (v2 === FAIL) return -1;
|
|
13125
13318
|
TERMV = v2;
|
|
@@ -13381,7 +13574,7 @@ function assemble(t2, prog, cfg) {
|
|
|
13381
13574
|
return (input, pos, selEnd, key, ctx, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot) => {
|
|
13382
13575
|
const savedRouted = ctx._routed;
|
|
13383
13576
|
if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
|
|
13384
|
-
ctx._routed = { value: key, span:
|
|
13577
|
+
ctx._routed = { value: key, span: new PlainSpan10(pos, selEnd) };
|
|
13385
13578
|
let v;
|
|
13386
13579
|
try {
|
|
13387
13580
|
v = child(input, pos, ctx);
|
|
@@ -13814,7 +14007,7 @@ function assemble(t2, prog, cfg) {
|
|
|
13814
14007
|
case OP_EXPECT: {
|
|
13815
14008
|
const child = link(code[ip + 1]);
|
|
13816
14009
|
const xf = fx[code[ip + 2]];
|
|
13817
|
-
const expectSpan = (ctx, pos) => prog.lines === 1 ? spanLines(ctx, pos, pos) :
|
|
14010
|
+
const expectSpan = (ctx, pos) => prog.lines === 1 ? spanLines(ctx, pos, pos) : new PlainSpan10(pos, pos);
|
|
13818
14011
|
if (REC) {
|
|
13819
14012
|
return (input, pos, ctx) => {
|
|
13820
14013
|
const v = child(input, pos, ctx);
|
|
@@ -13846,7 +14039,7 @@ function assemble(t2, prog, cfg) {
|
|
|
13846
14039
|
return (input, pos, ctx) => {
|
|
13847
14040
|
const v = child(input, pos, ctx);
|
|
13848
14041
|
if (v === FAIL) return FAIL;
|
|
13849
|
-
ctx._fields?.push(
|
|
14042
|
+
ctx._fields?.push(new PlainField(name, v, new PlainSpan10(pos, EC.e)));
|
|
13850
14043
|
return v;
|
|
13851
14044
|
};
|
|
13852
14045
|
}
|
|
@@ -13870,7 +14063,7 @@ function assemble(t2, prog, cfg) {
|
|
|
13870
14063
|
return (input, pos, ctx) => {
|
|
13871
14064
|
const v = child(input, pos, ctx);
|
|
13872
14065
|
if (v === FAIL) return FAIL;
|
|
13873
|
-
return fn(v,
|
|
14066
|
+
return fn(v, new PlainSpan10(pos, EC.e));
|
|
13874
14067
|
};
|
|
13875
14068
|
}
|
|
13876
14069
|
case OP_SCAN: {
|
|
@@ -13921,6 +14114,7 @@ function assemble(t2, prog, cfg) {
|
|
|
13921
14114
|
const scopeTrivia = ki < 0 ? void 0 : trivia2[ki];
|
|
13922
14115
|
const scopeLabels = scopeTrivia?._meta.triviaKindLabels;
|
|
13923
14116
|
const scanFor = swapLegal && ki >= 0 && !triviaLabelled[ki] ? triviaScan[ki] : null;
|
|
14117
|
+
const scopeLead = ki < 0 ? null : LEAD_TABLES[ki];
|
|
13924
14118
|
const child = link(code[ip + 2]);
|
|
13925
14119
|
const scopePiece = code[ip] === OP_SCOPE_CAP ? (input, pos, ctx) => {
|
|
13926
14120
|
const saved = ctx.trivia;
|
|
@@ -13928,6 +14122,9 @@ function assemble(t2, prog, cfg) {
|
|
|
13928
14122
|
const savedScan = SCAN;
|
|
13929
14123
|
const savedCap = ctx.captureTrivia;
|
|
13930
14124
|
SCAN = scanFor;
|
|
14125
|
+
const savedLeadOf = LEAD_OF, savedLead = LEAD_TABLE;
|
|
14126
|
+
LEAD_OF = scopeTrivia;
|
|
14127
|
+
LEAD_TABLE = scopeLead;
|
|
13931
14128
|
ctx.trivia = scopeTrivia;
|
|
13932
14129
|
ctx.triviaKindLabels = scopeLabels;
|
|
13933
14130
|
ctx.captureTrivia = true;
|
|
@@ -13936,18 +14133,25 @@ function assemble(t2, prog, cfg) {
|
|
|
13936
14133
|
ctx.trivia = saved;
|
|
13937
14134
|
ctx.triviaKindLabels = savedLabels;
|
|
13938
14135
|
SCAN = savedScan;
|
|
14136
|
+
LEAD_OF = savedLeadOf;
|
|
14137
|
+
LEAD_TABLE = savedLead;
|
|
13939
14138
|
return v;
|
|
13940
14139
|
} : (input, pos, ctx) => {
|
|
13941
14140
|
const saved = ctx.trivia;
|
|
13942
14141
|
const savedLabels = ctx.triviaKindLabels;
|
|
13943
14142
|
const savedScan = SCAN;
|
|
13944
14143
|
SCAN = scanFor;
|
|
14144
|
+
const savedLeadOf = LEAD_OF, savedLead = LEAD_TABLE;
|
|
14145
|
+
LEAD_OF = scopeTrivia;
|
|
14146
|
+
LEAD_TABLE = scopeLead;
|
|
13945
14147
|
ctx.trivia = scopeTrivia;
|
|
13946
14148
|
ctx.triviaKindLabels = scopeLabels;
|
|
13947
14149
|
const v = child(input, pos, ctx);
|
|
13948
14150
|
ctx.trivia = saved;
|
|
13949
14151
|
ctx.triviaKindLabels = savedLabels;
|
|
13950
14152
|
SCAN = savedScan;
|
|
14153
|
+
LEAD_OF = savedLeadOf;
|
|
14154
|
+
LEAD_TABLE = savedLead;
|
|
13951
14155
|
return v;
|
|
13952
14156
|
};
|
|
13953
14157
|
return scopeRootPolicy(scopePiece, code[ip] === OP_SCOPE_PLAIN ? 0 : code[ip + 3]);
|
|
@@ -13963,7 +14167,7 @@ function assemble(t2, prog, cfg) {
|
|
|
13963
14167
|
ctx._fx = ROUTED_FX;
|
|
13964
14168
|
return FAIL;
|
|
13965
14169
|
}
|
|
13966
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
14170
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf9(item.value, item.span));
|
|
13967
14171
|
EC.e = item.span.end;
|
|
13968
14172
|
return item.value;
|
|
13969
14173
|
};
|
|
@@ -14149,7 +14353,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14149
14353
|
if (v === FAIL) return FAIL;
|
|
14150
14354
|
const end = EC.e;
|
|
14151
14355
|
const value = input.slice(pos, end);
|
|
14152
|
-
if (wasCapturing) pushCstLeaf(ctx,
|
|
14356
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
|
|
14153
14357
|
EC.e = end;
|
|
14154
14358
|
return value;
|
|
14155
14359
|
};
|
|
@@ -14183,7 +14387,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14183
14387
|
if (ctx._probe !== void 0) failAt(ctx, suffixExpected, end);
|
|
14184
14388
|
}
|
|
14185
14389
|
const value = input.slice(pos, end);
|
|
14186
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
14390
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
|
|
14187
14391
|
EC.e = end;
|
|
14188
14392
|
return value;
|
|
14189
14393
|
};
|
|
@@ -14226,7 +14430,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14226
14430
|
}
|
|
14227
14431
|
if (end < 0) return FAIL;
|
|
14228
14432
|
const value = input.slice(pos, end);
|
|
14229
|
-
if (wasCapturing) pushCstLeaf(ctx,
|
|
14433
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
|
|
14230
14434
|
EC.e = end;
|
|
14231
14435
|
return value;
|
|
14232
14436
|
};
|
|
@@ -14235,7 +14439,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14235
14439
|
const end = run(input, pos, ctx);
|
|
14236
14440
|
if (end < 0) return FAIL;
|
|
14237
14441
|
const value = input.slice(pos, end);
|
|
14238
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
14442
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
|
|
14239
14443
|
EC.e = end;
|
|
14240
14444
|
return value;
|
|
14241
14445
|
};
|
|
@@ -14268,12 +14472,8 @@ function assemble(t2, prog, cfg) {
|
|
|
14268
14472
|
}
|
|
14269
14473
|
if (v === FAIL) return FAIL;
|
|
14270
14474
|
const end = EC.e;
|
|
14271
|
-
const out = fn(v,
|
|
14272
|
-
if (wasCapturing) pushCstLeaf(ctx,
|
|
14273
|
-
_tag: "leaf",
|
|
14274
|
-
value: op === OP_SOURCE_LEAF && hostCst ? input.slice(pos, end) : out,
|
|
14275
|
-
span: { start: pos, end }
|
|
14276
|
-
});
|
|
14475
|
+
const out = fn(v, new PlainSpan10(pos, end));
|
|
14476
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf9(op === OP_SOURCE_LEAF && hostCst ? input.slice(pos, end) : out, new PlainSpan10(pos, end)));
|
|
14277
14477
|
EC.e = end;
|
|
14278
14478
|
return out;
|
|
14279
14479
|
};
|
|
@@ -14408,7 +14608,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14408
14608
|
const cur = runSyncTerms(input, pos, ctx, values);
|
|
14409
14609
|
if (cur < 0) return FAIL;
|
|
14410
14610
|
EC.e = cur;
|
|
14411
|
-
return projection >= 0 ? values[projection] : fn(values,
|
|
14611
|
+
return projection >= 0 ? values[projection] : fn(values, new PlainSpan10(pos, cur));
|
|
14412
14612
|
};
|
|
14413
14613
|
}
|
|
14414
14614
|
if (wantValues) {
|
|
@@ -14502,7 +14702,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14502
14702
|
const cur = runAdjTerms(input, pos, ctx, values);
|
|
14503
14703
|
if (cur < 0) return FAIL;
|
|
14504
14704
|
EC.e = cur;
|
|
14505
|
-
return projection >= 0 ? values[projection] : fn(values,
|
|
14705
|
+
return projection >= 0 ? values[projection] : fn(values, new PlainSpan10(pos, cur));
|
|
14506
14706
|
};
|
|
14507
14707
|
}
|
|
14508
14708
|
if (wantValues) {
|
|
@@ -14527,7 +14727,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14527
14727
|
return (input, pos, ctx) => {
|
|
14528
14728
|
const v = k0(input, pos, ctx);
|
|
14529
14729
|
if (v === FAIL) return FAIL;
|
|
14530
|
-
return projection === 0 ? v : fn([v],
|
|
14730
|
+
return projection === 0 ? v : fn([v], new PlainSpan10(pos, EC.e));
|
|
14531
14731
|
};
|
|
14532
14732
|
}
|
|
14533
14733
|
if (wantValues) {
|
|
@@ -14552,7 +14752,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14552
14752
|
const cur = step(k1, input, EC.e, ctx);
|
|
14553
14753
|
if (cur < 0) return FAIL;
|
|
14554
14754
|
EC.e = cur;
|
|
14555
|
-
return projection === 0 ? v0 : projection === 1 ? TERMV : fn([v0, TERMV],
|
|
14755
|
+
return projection === 0 ? v0 : projection === 1 ? TERMV : fn([v0, TERMV], new PlainSpan10(pos, cur));
|
|
14556
14756
|
};
|
|
14557
14757
|
}
|
|
14558
14758
|
if (wantValues) {
|
|
@@ -14586,7 +14786,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14586
14786
|
cur = step(k2, input, cur, ctx);
|
|
14587
14787
|
if (cur < 0) return FAIL;
|
|
14588
14788
|
EC.e = cur;
|
|
14589
|
-
return projection === 0 ? v0 : projection === 1 ? v1 : projection === 2 ? TERMV : fn([v0, v1, TERMV],
|
|
14789
|
+
return projection === 0 ? v0 : projection === 1 ? v1 : projection === 2 ? TERMV : fn([v0, v1, TERMV], new PlainSpan10(pos, cur));
|
|
14590
14790
|
};
|
|
14591
14791
|
}
|
|
14592
14792
|
if (wantValues) {
|
|
@@ -14683,7 +14883,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14683
14883
|
const cur = runDirectTerms(input, pos, ctx, values);
|
|
14684
14884
|
if (cur < 0) return FAIL;
|
|
14685
14885
|
EC.e = cur;
|
|
14686
|
-
return projection >= 0 ? values[projection] : fn(values,
|
|
14886
|
+
return projection >= 0 ? values[projection] : fn(values, new PlainSpan10(pos, cur));
|
|
14687
14887
|
};
|
|
14688
14888
|
}
|
|
14689
14889
|
if (wantValues) {
|
|
@@ -15581,10 +15781,10 @@ function assemble(t2, prog, cfg) {
|
|
|
15581
15781
|
return FAIL;
|
|
15582
15782
|
}
|
|
15583
15783
|
const value = regexValue ? input.slice(pos, end) : spec;
|
|
15584
|
-
const leaf2 =
|
|
15784
|
+
const leaf2 = new PlainLeaf9(value, new PlainSpan10(pos, end));
|
|
15585
15785
|
const kids = [leaf2];
|
|
15586
15786
|
const rawKids = [leaf2];
|
|
15587
|
-
const span =
|
|
15787
|
+
const span = new PlainSpan10(pos, end);
|
|
15588
15788
|
EC.e = end;
|
|
15589
15789
|
const nd = build2(kids, void 0, span, rawKids, EMPTY_TL2, void 0);
|
|
15590
15790
|
if (ctx._cstBuf !== void 0 || ctx._cstChildren !== void 0) {
|
|
@@ -15666,7 +15866,7 @@ function assemble(t2, prog, cfg) {
|
|
|
15666
15866
|
const sCh = ctx._cstChildren;
|
|
15667
15867
|
const sCap = ctx.captureTrivia;
|
|
15668
15868
|
const sBuf = ctx._cstBuf;
|
|
15669
|
-
const buf = rawOnly ?
|
|
15869
|
+
const buf = rawOnly ? new PlainBuf2(true, void 0, 0) : omitsRaw ? new PlainBuf2(void 0, true, 0) : new PlainBuf2(void 0, void 0, 0);
|
|
15670
15870
|
ctx._cstBuf = buf;
|
|
15671
15871
|
ctx.captureTrivia = captureWide;
|
|
15672
15872
|
const savedFields = ctx._fields;
|
|
@@ -15688,7 +15888,7 @@ function assemble(t2, prog, cfg) {
|
|
|
15688
15888
|
ctx.captureTrivia = sCap;
|
|
15689
15889
|
if (v === FAIL) return FAIL;
|
|
15690
15890
|
const end = EC.e;
|
|
15691
|
-
const span = tracked ? spanLines(ctx, pos, end) :
|
|
15891
|
+
const span = tracked ? spanLines(ctx, pos, end) : new PlainSpan10(pos, end);
|
|
15692
15892
|
const st = readsState ? ctx.state : void 0;
|
|
15693
15893
|
let nd;
|
|
15694
15894
|
if (unwrap && kids.length === 1) {
|
|
@@ -15712,7 +15912,7 @@ function assemble(t2, prog, cfg) {
|
|
|
15712
15912
|
} else if (host !== void 0) {
|
|
15713
15913
|
nd = host(type, hostKids, fieldMap, span, rawKids, tlog, st, tags);
|
|
15714
15914
|
} else {
|
|
15715
|
-
nd =
|
|
15915
|
+
nd = new PlainNode2(type, span, st ?? null, kids === EMPTY_CH ? kids : [...kids]);
|
|
15716
15916
|
}
|
|
15717
15917
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
15718
15918
|
pushCstChild(ctx, nd, rawEntry(nd, input, pos, end));
|
|
@@ -15738,7 +15938,7 @@ function assemble(t2, prog, cfg) {
|
|
|
15738
15938
|
const at = fe === void 0 || fe < 0 ? pos : fe;
|
|
15739
15939
|
return { ok: false, expected: ctx._fx ?? EMPTY_FX2, span: { start: at, end: at } };
|
|
15740
15940
|
}
|
|
15741
|
-
return { ok: true, value: v, span:
|
|
15941
|
+
return { ok: true, value: v, span: new PlainSpan10(pos, EC.e) };
|
|
15742
15942
|
}
|
|
15743
15943
|
};
|
|
15744
15944
|
}
|
|
@@ -15853,7 +16053,12 @@ function assemble(t2, prog, cfg) {
|
|
|
15853
16053
|
LEAD,
|
|
15854
16054
|
triviaFieldCapture,
|
|
15855
16055
|
skipDeferredTrivia,
|
|
15856
|
-
collapseEmpty
|
|
16056
|
+
collapseEmpty,
|
|
16057
|
+
PlainSpan10,
|
|
16058
|
+
PlainLeaf9,
|
|
16059
|
+
PlainNode2,
|
|
16060
|
+
PlainField,
|
|
16061
|
+
PlainBuf2
|
|
15857
16062
|
);
|
|
15858
16063
|
emitReached = new Set(pre.reached);
|
|
15859
16064
|
if (emitted.ext !== void 0) HYBRID = emitted;
|
|
@@ -15940,7 +16145,12 @@ function assemble(t2, prog, cfg) {
|
|
|
15940
16145
|
LEAD,
|
|
15941
16146
|
triviaFieldCapture,
|
|
15942
16147
|
skipDeferredTrivia,
|
|
15943
|
-
collapseEmpty
|
|
16148
|
+
collapseEmpty,
|
|
16149
|
+
PlainSpan10,
|
|
16150
|
+
PlainLeaf9,
|
|
16151
|
+
PlainNode2,
|
|
16152
|
+
PlainField,
|
|
16153
|
+
PlainBuf2
|
|
15944
16154
|
);
|
|
15945
16155
|
emitReached = em.reached;
|
|
15946
16156
|
} catch (e) {
|
|
@@ -16198,7 +16408,11 @@ function tableRules(source, metadataOrEntry = {}) {
|
|
|
16198
16408
|
return map[entry];
|
|
16199
16409
|
}
|
|
16200
16410
|
|
|
16411
|
+
// src/version.ts
|
|
16412
|
+
var PARSEMAN_VERSION = "0.59.0";
|
|
16413
|
+
|
|
16201
16414
|
// src/table/emit.ts
|
|
16415
|
+
var FACTORY_ARITY_GUARD = `if(arguments.length<${EMITTED_PARAMS.length})throw new Error(${JSON.stringify(`parseman: this parser was printed by parseman ${PARSEMAN_VERSION}; upgrade the parseman runtime to at least that version`)});`;
|
|
16202
16416
|
function jsString(s) {
|
|
16203
16417
|
return JSON.stringify(s);
|
|
16204
16418
|
}
|
|
@@ -16273,7 +16487,7 @@ function emitAssemblies(prog, cfgs) {
|
|
|
16273
16487
|
throw e;
|
|
16274
16488
|
}
|
|
16275
16489
|
const plan = em.plan;
|
|
16276
|
-
out.push(`{key:${key},factory:function(${EMITTED_PARAMS.join(",")}){${em.source}
|
|
16490
|
+
out.push(`{key:${key},factory:function(${EMITTED_PARAMS.join(",")}){${FACTORY_ARITY_GUARD}${em.source}
|
|
16277
16491
|
},plan:{classes:[${plan.classes.map((r) => `[${r.join(",")}]`).join(",")}],armExpected:[${plan.armExpected.map((r) => `[${r.join(",")}]`).join(",")}],masks:[${plan.masks.join(",")}]},reached:[${[...em.reached].join(",")}]}`);
|
|
16278
16492
|
}
|
|
16279
16493
|
return [`a:[${out.join(",")}],`];
|