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
package/dist/cli/index.js
CHANGED
|
@@ -6,6 +6,35 @@ import { resolve, relative, join, extname } from "node:path";
|
|
|
6
6
|
import { pathToFileURL } from "node:url";
|
|
7
7
|
import * as nodeModule from "node:module";
|
|
8
8
|
|
|
9
|
+
// src/lead-ranges.ts
|
|
10
|
+
function rangesHaveLead(ranges, code) {
|
|
11
|
+
for (const r of ranges) if (code >= r.lo && code <= r.hi) return true;
|
|
12
|
+
if (code <= 65535) return false;
|
|
13
|
+
const high = 55296 + (code - 65536 >> 10);
|
|
14
|
+
for (const r of ranges) if (high >= r.lo && high <= r.hi) return true;
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
function leadRanges(ranges) {
|
|
18
|
+
let out;
|
|
19
|
+
for (const r of ranges) {
|
|
20
|
+
const lo = Math.max(r.lo, 55296), hi = Math.min(r.hi, 56319);
|
|
21
|
+
if (lo <= hi) (out ??= [...ranges]).push({ lo: 65536 + (lo - 55296 << 10), hi: 65536 + (hi - 55296 << 10) + 1023 });
|
|
22
|
+
}
|
|
23
|
+
return out ?? ranges;
|
|
24
|
+
}
|
|
25
|
+
function implicitLeadsDropped(ranges) {
|
|
26
|
+
const implied = leadRanges(ranges.filter((r) => r.lo <= 65535)).filter((r) => r.lo > 65535);
|
|
27
|
+
const out = [];
|
|
28
|
+
for (const r of ranges) {
|
|
29
|
+
let pieces = [{ lo: r.lo, hi: r.hi }];
|
|
30
|
+
if (r.hi > 65535) for (const c of implied) {
|
|
31
|
+
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 }] : []]);
|
|
32
|
+
}
|
|
33
|
+
out.push(...pieces);
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
|
|
9
38
|
// src/combinators/first-set.ts
|
|
10
39
|
function classifyFinalChoice(arms, resolve2, activeTrivia) {
|
|
11
40
|
const firstSets = [];
|
|
@@ -67,8 +96,9 @@ function union(a, b) {
|
|
|
67
96
|
function intersects(a, b) {
|
|
68
97
|
if (a.kind === "any" || b.kind === "any") return true;
|
|
69
98
|
if (a.kind === "empty" || b.kind === "empty") return false;
|
|
70
|
-
|
|
71
|
-
|
|
99
|
+
const bs = leadRanges(b.ranges);
|
|
100
|
+
for (const ra of leadRanges(a.ranges)) {
|
|
101
|
+
for (const rb of bs) {
|
|
72
102
|
if (ra.lo <= rb.hi && rb.lo <= ra.hi) return true;
|
|
73
103
|
}
|
|
74
104
|
}
|
|
@@ -84,6 +114,9 @@ function startsFirstSet(combinator, input, pos) {
|
|
|
84
114
|
const code = input.codePointAt(pos);
|
|
85
115
|
if (code === void 0) return false;
|
|
86
116
|
for (const r of fs.ranges) if (code >= r.lo && code <= r.hi) return true;
|
|
117
|
+
if (code <= 65535) return false;
|
|
118
|
+
const high = 55296 + (code - 65536 >> 10);
|
|
119
|
+
for (const r of fs.ranges) if (high >= r.lo && high <= r.hi) return true;
|
|
87
120
|
return false;
|
|
88
121
|
}
|
|
89
122
|
function fromRange(lo, hi) {
|
|
@@ -184,12 +217,13 @@ function narrowBy(acc, constraint) {
|
|
|
184
217
|
if (acc.kind === "any") return constraint;
|
|
185
218
|
if (acc.kind === "empty" || constraint.kind === "empty") return { kind: "empty" };
|
|
186
219
|
const ranges = [];
|
|
187
|
-
|
|
220
|
+
const bs = leadRanges(constraint.ranges);
|
|
221
|
+
for (const a of leadRanges(acc.ranges)) for (const b of bs) {
|
|
188
222
|
const lo = Math.max(a.lo, b.lo);
|
|
189
223
|
const hi = Math.min(a.hi, b.hi);
|
|
190
224
|
if (lo <= hi) ranges.push({ lo, hi });
|
|
191
225
|
}
|
|
192
|
-
return ranges.length === 0 ? { kind: "empty" } : { kind: "ranges", ranges };
|
|
226
|
+
return ranges.length === 0 ? { kind: "empty" } : { kind: "ranges", ranges: implicitLeadsDropped(ranges) };
|
|
193
227
|
}
|
|
194
228
|
function applyAssertion(fs, assertion) {
|
|
195
229
|
return assertion === null ? fs : fs.kind === "empty" ? assertion : narrowBy(fs, assertion);
|
|
@@ -691,6 +725,7 @@ function analyzeChoice(p, d, rule2, resolve2) {
|
|
|
691
725
|
}
|
|
692
726
|
|
|
693
727
|
// src/line-index.ts
|
|
728
|
+
import { PlainLineSpan, PlainSpan } from "../cst/plain.js";
|
|
694
729
|
function createLineIndex() {
|
|
695
730
|
return { lineStarts: [0] };
|
|
696
731
|
}
|
|
@@ -743,6 +778,27 @@ function annotateSpan(span, index) {
|
|
|
743
778
|
endColumn: e.col
|
|
744
779
|
};
|
|
745
780
|
}
|
|
781
|
+
var SPAN_KEYS = ["start", "end", "startLine", "startColumn", "endLine", "endColumn"];
|
|
782
|
+
function copySpan(span) {
|
|
783
|
+
let n = 0;
|
|
784
|
+
for (const key in span) {
|
|
785
|
+
if (key !== SPAN_KEYS[n]) return { ...span };
|
|
786
|
+
n++;
|
|
787
|
+
}
|
|
788
|
+
if (n === 2) return new PlainSpan(span.start, span.end);
|
|
789
|
+
if (n === 6 && span.startLine !== void 0 && span.startColumn !== void 0 && span.endLine !== void 0 && span.endColumn !== void 0) {
|
|
790
|
+
return new PlainLineSpan(span.start, span.end, span.startLine, span.startColumn, span.endLine, span.endColumn);
|
|
791
|
+
}
|
|
792
|
+
return { ...span };
|
|
793
|
+
}
|
|
794
|
+
function lineSpanFromContext(span, ctx) {
|
|
795
|
+
if (!ctx.trackLines) return span;
|
|
796
|
+
const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
|
|
797
|
+
if (!index) return span;
|
|
798
|
+
const s = offsetToLineCol(index, span.start);
|
|
799
|
+
const e = offsetToLineCol(index, span.end);
|
|
800
|
+
return new PlainLineSpan(span.start, span.end, s.line, s.col, e.line, e.col);
|
|
801
|
+
}
|
|
746
802
|
function annotateSpanFromLineContext(span, ctx) {
|
|
747
803
|
if (!ctx.trackLines) return span;
|
|
748
804
|
const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
|
|
@@ -750,6 +806,7 @@ function annotateSpanFromLineContext(span, ctx) {
|
|
|
750
806
|
}
|
|
751
807
|
|
|
752
808
|
// src/cst/capture-buffer.ts
|
|
809
|
+
import { PlainBuf, PlainLeaf } from "../cst/plain.js";
|
|
753
810
|
var EMPTY = [];
|
|
754
811
|
var EMPTY_TL = [];
|
|
755
812
|
function cstCaptureActive(ctx) {
|
|
@@ -764,7 +821,7 @@ function beginCstNodeCapture(ctx) {
|
|
|
764
821
|
cap: ctx.captureTrivia,
|
|
765
822
|
buf: ctx._cstBuf
|
|
766
823
|
};
|
|
767
|
-
ctx._cstBuf =
|
|
824
|
+
ctx._cstBuf = new PlainBuf(void 0, void 0, 0);
|
|
768
825
|
ctx._cstChildren = void 0;
|
|
769
826
|
ctx._cstLeaves = void 0;
|
|
770
827
|
ctx._cstRawChildren = void 0;
|
|
@@ -789,12 +846,15 @@ function endCstNodeCapture(ctx, saved) {
|
|
|
789
846
|
ctx.captureTrivia = saved.cap;
|
|
790
847
|
return materialized;
|
|
791
848
|
}
|
|
849
|
+
function isLeaf(v) {
|
|
850
|
+
return typeof v === "object" && v !== null && v._tag === "leaf";
|
|
851
|
+
}
|
|
792
852
|
function pushCstLeaf(ctx, leaf2) {
|
|
793
853
|
if (!ctx.trackLines) {
|
|
794
854
|
pushCstChild(ctx, leaf2, leaf2);
|
|
795
855
|
return;
|
|
796
856
|
}
|
|
797
|
-
const annotated = leaf2 && typeof leaf2 === "object" && leaf2.span ? { ...leaf2, span: annotateSpanFromLineContext(leaf2.span, ctx) } : leaf2;
|
|
857
|
+
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;
|
|
798
858
|
pushCstChild(ctx, annotated, annotated);
|
|
799
859
|
}
|
|
800
860
|
function pushCstChild(ctx, built, rawEntry2) {
|
|
@@ -987,11 +1047,17 @@ function shorthandRanges(ch2) {
|
|
|
987
1047
|
if (ch2 === "s") return SPACE_RANGES;
|
|
988
1048
|
return [[48, 57], [65, 90], [97, 122], [95, 95]];
|
|
989
1049
|
}
|
|
990
|
-
function readUnicodeEscape(body, i) {
|
|
1050
|
+
function readUnicodeEscape(body, i, unicode = false) {
|
|
991
1051
|
if (body[i] !== "\\" || body[i + 1] !== "u") return null;
|
|
992
1052
|
const hex = body.slice(i + 2, i + 6);
|
|
993
1053
|
if (!/^[0-9a-fA-F]{4}$/.test(hex)) return null;
|
|
994
|
-
|
|
1054
|
+
const cp = Number.parseInt(hex, 16);
|
|
1055
|
+
if (unicode && cp >= 55296 && cp <= 56319 && body[i + 6] === "\\" && body[i + 7] === "u") {
|
|
1056
|
+
const lowHex = body.slice(i + 8, i + 12);
|
|
1057
|
+
const low = /^[0-9a-fA-F]{4}$/.test(lowHex) ? Number.parseInt(lowHex, 16) : -1;
|
|
1058
|
+
if (low >= 56320 && low <= 57343) return { cp: 65536 + (cp - 55296 << 10) + (low - 56320), next: i + 12 };
|
|
1059
|
+
}
|
|
1060
|
+
return { cp, next: i + 6 };
|
|
995
1061
|
}
|
|
996
1062
|
var META = new Set("()[]{}*+?|^$.".split(""));
|
|
997
1063
|
function literalCodePoints(frag) {
|
|
@@ -1003,6 +1069,7 @@ function literalCodePoints(frag) {
|
|
|
1003
1069
|
const e = frag[i + 1];
|
|
1004
1070
|
if (e === void 0) return null;
|
|
1005
1071
|
if (!(e in CLASS_ESCAPES) && /\w/.test(e)) return null;
|
|
1072
|
+
if (e === "0" && frag[i + 2] !== void 0 && frag[i + 2] >= "0" && frag[i + 2] <= "9") return null;
|
|
1006
1073
|
out.push(e in CLASS_ESCAPES ? CLASS_ESCAPES[e] : e.codePointAt(0));
|
|
1007
1074
|
i += 2;
|
|
1008
1075
|
continue;
|
|
@@ -1043,14 +1110,14 @@ function parseClassOperand(body) {
|
|
|
1043
1110
|
if (cps && cps.length === 1) return { ranges: [[cps[0], cps[0]]], negated: false };
|
|
1044
1111
|
return null;
|
|
1045
1112
|
}
|
|
1046
|
-
function parseClassRanges(body) {
|
|
1113
|
+
function parseClassRanges(body, unicode = false) {
|
|
1047
1114
|
const ranges = [];
|
|
1048
1115
|
let i = 0;
|
|
1049
1116
|
const readAtom = () => {
|
|
1050
1117
|
const ch2 = body[i];
|
|
1051
1118
|
if (ch2 === void 0) return null;
|
|
1052
1119
|
if (ch2 === "\\") {
|
|
1053
|
-
const uni = readUnicodeEscape(body, i);
|
|
1120
|
+
const uni = readUnicodeEscape(body, i, unicode);
|
|
1054
1121
|
if (uni) {
|
|
1055
1122
|
i = uni.next;
|
|
1056
1123
|
return { cp: uni.cp };
|
|
@@ -1058,13 +1125,15 @@ function parseClassRanges(body) {
|
|
|
1058
1125
|
const e = body[i + 1];
|
|
1059
1126
|
if (e === void 0) return null;
|
|
1060
1127
|
i += 2;
|
|
1128
|
+
if (e === "0" && body[i] !== void 0 && body[i] >= "0" && body[i] <= "9" || e >= "1" && e <= "9") return null;
|
|
1061
1129
|
if (e in CLASS_ESCAPES) return { cp: CLASS_ESCAPES[e] };
|
|
1062
1130
|
if (e === "d" || e === "w" || e === "s") return { set: shorthandRanges(e) };
|
|
1063
1131
|
if (e >= "a" && e <= "z" || e >= "A" && e <= "Z") return null;
|
|
1064
1132
|
return { cp: e.codePointAt(0) };
|
|
1065
1133
|
}
|
|
1066
|
-
i
|
|
1067
|
-
|
|
1134
|
+
const cp = unicode ? body.codePointAt(i) : body.charCodeAt(i);
|
|
1135
|
+
i += cp > 65535 ? 2 : 1;
|
|
1136
|
+
return { cp };
|
|
1068
1137
|
};
|
|
1069
1138
|
while (i < body.length) {
|
|
1070
1139
|
const lo = readAtom();
|
|
@@ -2367,6 +2436,7 @@ function altStarSource(source) {
|
|
|
2367
2436
|
}
|
|
2368
2437
|
|
|
2369
2438
|
// src/combinators/dispatch.ts
|
|
2439
|
+
import { PlainLeaf as PlainLeaf2 } from "../cst/plain.js";
|
|
2370
2440
|
function parserUsesRouted(parser2, seen = /* @__PURE__ */ new Set()) {
|
|
2371
2441
|
if (seen.has(parser2)) return false;
|
|
2372
2442
|
seen.add(parser2);
|
|
@@ -2435,6 +2505,7 @@ function asciiFoldKey(key) {
|
|
|
2435
2505
|
}
|
|
2436
2506
|
|
|
2437
2507
|
// src/recovery/scan.ts
|
|
2508
|
+
import { PlainSpan as PlainSpan2 } from "../cst/plain.js";
|
|
2438
2509
|
function probeAt(sentinel, input, pos, ctx) {
|
|
2439
2510
|
const s = {
|
|
2440
2511
|
_probe: ctx._probe,
|
|
@@ -2502,9 +2573,7 @@ function firstSetSentinel(fs) {
|
|
|
2502
2573
|
parse(input, pos) {
|
|
2503
2574
|
const code = pos < input.length ? input.codePointAt(pos) : void 0;
|
|
2504
2575
|
if (code !== void 0) {
|
|
2505
|
-
|
|
2506
|
-
if (code >= r.lo && code <= r.hi) return { ok: true, value: null, span: { start: pos, end: pos } };
|
|
2507
|
-
}
|
|
2576
|
+
if (rangesHaveLead(ranges, code)) return { ok: true, value: null, span: { start: pos, end: pos } };
|
|
2508
2577
|
}
|
|
2509
2578
|
return { ok: false, expected: [], span: { start: pos, end: pos } };
|
|
2510
2579
|
}
|
|
@@ -2513,7 +2582,7 @@ function firstSetSentinel(fs) {
|
|
|
2513
2582
|
function recoverScan(input, from, ctx, sync, expected) {
|
|
2514
2583
|
let scanPos = from;
|
|
2515
2584
|
while (scanPos < input.length && !probeAt(sync, input, scanPos, ctx)) scanPos++;
|
|
2516
|
-
const span =
|
|
2585
|
+
const span = new PlainSpan2(from, scanPos);
|
|
2517
2586
|
if (ctx.trackLines) recordLineRangeFromContext(ctx, input, from, scanPos);
|
|
2518
2587
|
const error = { _tag: "parseError", span: ctx.trackLines ? annotateSpanFromLineContext(span, ctx) : span, expected };
|
|
2519
2588
|
ctx._errors?.push(error);
|
|
@@ -2703,6 +2772,7 @@ function failAt(ctx, expected, pos) {
|
|
|
2703
2772
|
}
|
|
2704
2773
|
|
|
2705
2774
|
// src/combinators/keywords.ts
|
|
2775
|
+
import { PlainLeaf as PlainLeaf3, PlainSpan as PlainSpan3 } from "../cst/plain.js";
|
|
2706
2776
|
function escapeRe(s) {
|
|
2707
2777
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2708
2778
|
}
|
|
@@ -2751,8 +2821,8 @@ function keywords(words, opts = {}) {
|
|
|
2751
2821
|
const m = re.exec(input);
|
|
2752
2822
|
if (m === null) return failAt(ctx, directTerminalFailureExpected(def), pos);
|
|
2753
2823
|
const value = m[0];
|
|
2754
|
-
const span =
|
|
2755
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
2824
|
+
const span = new PlainSpan3(pos, pos + value.length);
|
|
2825
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf3(value, span));
|
|
2756
2826
|
return { ok: true, value, span };
|
|
2757
2827
|
}
|
|
2758
2828
|
};
|
|
@@ -3321,7 +3391,7 @@ function rangesHaveNewline(ranges) {
|
|
|
3321
3391
|
return ranges.some(([lo, hi]) => lo <= 10 && 10 <= hi);
|
|
3322
3392
|
}
|
|
3323
3393
|
var BAIL = /* @__PURE__ */ Symbol("regex-bail");
|
|
3324
|
-
function parseRegex(src) {
|
|
3394
|
+
function parseRegex(src, unicode = false, sets = false) {
|
|
3325
3395
|
let i = 0;
|
|
3326
3396
|
const parseAlt = () => {
|
|
3327
3397
|
const arms = [parseSeq()];
|
|
@@ -3391,9 +3461,11 @@ function parseRegex(src) {
|
|
|
3391
3461
|
i++;
|
|
3392
3462
|
return charNode(fromRange(123, 123), false);
|
|
3393
3463
|
// a `{` with nothing to quantify is a literal brace
|
|
3394
|
-
default:
|
|
3395
|
-
i
|
|
3396
|
-
|
|
3464
|
+
default: {
|
|
3465
|
+
const cp = unicode ? src.codePointAt(i) : src.charCodeAt(i);
|
|
3466
|
+
i += cp > 65535 ? 2 : 1;
|
|
3467
|
+
return charNode(fromRange(cp, cp), ch2 === "\n");
|
|
3468
|
+
}
|
|
3397
3469
|
}
|
|
3398
3470
|
};
|
|
3399
3471
|
const parseGroup = () => {
|
|
@@ -3426,6 +3498,32 @@ function parseRegex(src) {
|
|
|
3426
3498
|
let k = i + 1;
|
|
3427
3499
|
const negated = src[k] === "^";
|
|
3428
3500
|
if (negated) k++;
|
|
3501
|
+
if (sets) {
|
|
3502
|
+
let depth = 1;
|
|
3503
|
+
let nested = false;
|
|
3504
|
+
while (k < src.length && depth > 0) {
|
|
3505
|
+
const c = src[k];
|
|
3506
|
+
if (c === "\\") {
|
|
3507
|
+
if (src[k + 1] === "q") nested = true;
|
|
3508
|
+
k += 2;
|
|
3509
|
+
continue;
|
|
3510
|
+
}
|
|
3511
|
+
if (c === "[") {
|
|
3512
|
+
depth++;
|
|
3513
|
+
nested = true;
|
|
3514
|
+
} else if (c === "]") {
|
|
3515
|
+
depth--;
|
|
3516
|
+
if (depth === 0) break;
|
|
3517
|
+
} else if ((c === "-" || c === "&") && src[k + 1] === c) nested = true;
|
|
3518
|
+
k++;
|
|
3519
|
+
}
|
|
3520
|
+
if (src[k] !== "]") throw BAIL;
|
|
3521
|
+
if (nested) {
|
|
3522
|
+
i = k + 1;
|
|
3523
|
+
return charNode(any(), true);
|
|
3524
|
+
}
|
|
3525
|
+
k = i + 1 + (negated ? 1 : 0);
|
|
3526
|
+
}
|
|
3429
3527
|
let body = "";
|
|
3430
3528
|
while (k < src.length && src[k] !== "]") {
|
|
3431
3529
|
if (src[k] === "\\") {
|
|
@@ -3438,7 +3536,7 @@ function parseRegex(src) {
|
|
|
3438
3536
|
}
|
|
3439
3537
|
if (src[k] !== "]") throw BAIL;
|
|
3440
3538
|
i = k + 1;
|
|
3441
|
-
const ranges = parseClassRanges(body);
|
|
3539
|
+
const ranges = parseClassRanges(body, unicode);
|
|
3442
3540
|
if (negated) return charNode(any(), !ranges || !rangesHaveNewline(ranges));
|
|
3443
3541
|
if (!ranges) return charNode(any(), true);
|
|
3444
3542
|
return charNode(rangesToSet(ranges), rangesHaveNewline(ranges));
|
|
@@ -3446,9 +3544,20 @@ function parseRegex(src) {
|
|
|
3446
3544
|
const parseEscape = () => {
|
|
3447
3545
|
const e = src[i + 1];
|
|
3448
3546
|
if (e === void 0) throw BAIL;
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
i
|
|
3547
|
+
const uni = readUnicodeEscape(src, i, unicode);
|
|
3548
|
+
if (uni !== null) {
|
|
3549
|
+
i = uni.next;
|
|
3550
|
+
return charNode(fromRange(uni.cp, uni.cp), uni.cp === 10);
|
|
3551
|
+
}
|
|
3552
|
+
if (e === "u" && src[i + 2] === "{") {
|
|
3553
|
+
const close = src.indexOf("}", i + 3);
|
|
3554
|
+
const hex = close < 0 ? "" : src.slice(i + 3, close);
|
|
3555
|
+
if (!unicode || !/^[0-9a-fA-F]{1,6}$/.test(hex)) {
|
|
3556
|
+
i += 2;
|
|
3557
|
+
return ANY;
|
|
3558
|
+
}
|
|
3559
|
+
const cp = Number.parseInt(hex, 16);
|
|
3560
|
+
i = close + 1;
|
|
3452
3561
|
return charNode(fromRange(cp, cp), cp === 10);
|
|
3453
3562
|
}
|
|
3454
3563
|
if (e === "x" && /^[0-9a-fA-F]{2}$/.test(src.slice(i + 2, i + 4))) {
|
|
@@ -3456,6 +3565,16 @@ function parseRegex(src) {
|
|
|
3456
3565
|
i += 4;
|
|
3457
3566
|
return charNode(fromRange(cp, cp), cp === 10);
|
|
3458
3567
|
}
|
|
3568
|
+
if (e === "c") {
|
|
3569
|
+
const x = src[i + 2];
|
|
3570
|
+
if (x !== void 0 && /^[A-Za-z]$/.test(x)) {
|
|
3571
|
+
const cp = x.charCodeAt(0) % 32;
|
|
3572
|
+
i += 3;
|
|
3573
|
+
return charNode(fromRange(cp, cp), cp === 10);
|
|
3574
|
+
}
|
|
3575
|
+
i += 2;
|
|
3576
|
+
return ANY;
|
|
3577
|
+
}
|
|
3459
3578
|
i += 2;
|
|
3460
3579
|
switch (e) {
|
|
3461
3580
|
case "d":
|
|
@@ -3483,8 +3602,16 @@ function parseRegex(src) {
|
|
|
3483
3602
|
return charNode(fromRange(12, 12), false);
|
|
3484
3603
|
case "v":
|
|
3485
3604
|
return charNode(fromRange(11, 11), false);
|
|
3605
|
+
// `\0` then a digit is a legacy octal escape (`\012` is a newline), not NUL.
|
|
3486
3606
|
case "0":
|
|
3487
|
-
return charNode(fromRange(0, 0), false);
|
|
3607
|
+
return src[i] !== void 0 && src[i] >= "0" && src[i] <= "9" ? ANY : charNode(fromRange(0, 0), false);
|
|
3608
|
+
// A property escape (`\p{…}`/`\P{…}`) matches one character of a class this
|
|
3609
|
+
// analyzer does not enumerate; `\k<name>` is a backreference, which may match empty.
|
|
3610
|
+
case "p":
|
|
3611
|
+
case "P":
|
|
3612
|
+
return charNode(any(), true);
|
|
3613
|
+
case "k":
|
|
3614
|
+
return ANY;
|
|
3488
3615
|
default:
|
|
3489
3616
|
if (e >= "1" && e <= "9") return ANY;
|
|
3490
3617
|
return charNode(fromRange(e.codePointAt(0), e.codePointAt(0)), e === "\n");
|
|
@@ -3558,10 +3685,10 @@ function regexCanMatchEmpty(source) {
|
|
|
3558
3685
|
return true;
|
|
3559
3686
|
}
|
|
3560
3687
|
}
|
|
3561
|
-
function firstSetFromRegex(source) {
|
|
3688
|
+
function firstSetFromRegex(source, flags = "") {
|
|
3562
3689
|
let ast;
|
|
3563
3690
|
try {
|
|
3564
|
-
ast = parseRegex(source);
|
|
3691
|
+
ast = parseRegex(source, flags.includes("u") || flags.includes("v"), flags.includes("v"));
|
|
3565
3692
|
} catch {
|
|
3566
3693
|
return { firstSet: any(), canMatchNewline: true };
|
|
3567
3694
|
}
|
|
@@ -4304,6 +4431,9 @@ function inFirstSet(code, fs) {
|
|
|
4304
4431
|
if (fs.kind === "any") return true;
|
|
4305
4432
|
if (fs.kind === "empty") return false;
|
|
4306
4433
|
for (const r of fs.ranges) if (code >= r.lo && code <= r.hi) return true;
|
|
4434
|
+
if (code <= 65535) return false;
|
|
4435
|
+
const high = 55296 + (code - 65536 >> 10);
|
|
4436
|
+
for (const r of fs.ranges) if (high >= r.lo && high <= r.hi) return true;
|
|
4307
4437
|
return false;
|
|
4308
4438
|
}
|
|
4309
4439
|
function areDisjoint(sets) {
|
|
@@ -4328,17 +4458,18 @@ function buildAsciiDispatch(parsers) {
|
|
|
4328
4458
|
}
|
|
4329
4459
|
|
|
4330
4460
|
// src/combinators/field-trivia.ts
|
|
4461
|
+
import { PlainSpan as PlainSpan4, PlainTriviaField } from "../cst/plain.js";
|
|
4331
4462
|
var LEAD = { at: -1 };
|
|
4332
4463
|
var FIELD_LEADING_TRIVIA = 1;
|
|
4333
4464
|
var FIELD_TRAILING_TRIVIA = 2;
|
|
4334
4465
|
function triviaFieldCapture(name, value, input, start, end, leadFrom, trailEnd) {
|
|
4335
|
-
return
|
|
4466
|
+
return new PlainTriviaField(
|
|
4336
4467
|
name,
|
|
4337
4468
|
value,
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4469
|
+
new PlainSpan4(start, end),
|
|
4470
|
+
leadFrom >= 0 && leadFrom < start ? input.slice(leadFrom, start) : "",
|
|
4471
|
+
trailEnd > end ? input.slice(end, trailEnd) : ""
|
|
4472
|
+
);
|
|
4342
4473
|
}
|
|
4343
4474
|
function leadsTrivia(p) {
|
|
4344
4475
|
return p._def.tag === "field" && p._def.leadingTrivia === true;
|
|
@@ -4854,6 +4985,7 @@ function field(name, combinator, opts) {
|
|
|
4854
4985
|
}
|
|
4855
4986
|
|
|
4856
4987
|
// src/combinators/regex.ts
|
|
4988
|
+
import { PlainLeaf as PlainLeaf4, PlainSpan as PlainSpan5 } from "../cst/plain.js";
|
|
4857
4989
|
var SCAN_BAIL_AT = 64;
|
|
4858
4990
|
function inRanges3(cp, ranges) {
|
|
4859
4991
|
for (let i = 0; i < ranges.length; i++) {
|
|
@@ -4894,8 +5026,18 @@ function shortScanner(source, flags) {
|
|
|
4894
5026
|
return minOne && end === pos ? null : end;
|
|
4895
5027
|
};
|
|
4896
5028
|
}
|
|
5029
|
+
function coversNonAscii(ranges) {
|
|
5030
|
+
let next = 128;
|
|
5031
|
+
for (const r of [...ranges].sort((a, b) => a.lo - b.lo)) {
|
|
5032
|
+
if (r.lo > next) return false;
|
|
5033
|
+
if (r.hi >= next) next = r.hi + 1;
|
|
5034
|
+
if (next > 65535) return true;
|
|
5035
|
+
}
|
|
5036
|
+
return false;
|
|
5037
|
+
}
|
|
4897
5038
|
function asciiCaseFold(fs) {
|
|
4898
5039
|
if (fs.kind !== "ranges") return fs;
|
|
5040
|
+
if (fs.ranges.some((r) => r.hi >= 128) && !coversNonAscii(fs.ranges)) return any();
|
|
4899
5041
|
const ranges = fs.ranges.map((r) => ({ lo: r.lo, hi: r.hi }));
|
|
4900
5042
|
const add = (lo, hi) => {
|
|
4901
5043
|
if (lo <= hi) ranges.push({ lo, hi });
|
|
@@ -4920,7 +5062,7 @@ function regex(pattern, flags = "") {
|
|
|
4920
5062
|
const resolvedFlags = typeof pattern === "string" ? flags : pattern.flags;
|
|
4921
5063
|
const anchored = new RegExp(source, "y" + resolvedFlags.replace(/[gy]/g, ""));
|
|
4922
5064
|
const scan = shortScanner(source, resolvedFlags);
|
|
4923
|
-
const raw = firstSetFromRegex(source);
|
|
5065
|
+
const raw = firstSetFromRegex(source, resolvedFlags);
|
|
4924
5066
|
const firstSet2 = !resolvedFlags.includes("i") ? raw.firstSet : resolvedFlags.includes("u") || resolvedFlags.includes("v") ? any() : asciiCaseFold(raw.firstSet);
|
|
4925
5067
|
const canMatchNewline = raw.canMatchNewline;
|
|
4926
5068
|
const meta = { firstSet: firstSet2, canMatchNewline, isTrivia: false };
|
|
@@ -4956,9 +5098,9 @@ function regex(pattern, flags = "") {
|
|
|
4956
5098
|
if (scanEnd !== void 0) {
|
|
4957
5099
|
if (scanEnd === null) return failAt(ctx, directTerminalFailureExpected(def), pos);
|
|
4958
5100
|
const value = input.slice(pos, scanEnd);
|
|
4959
|
-
const span2 =
|
|
5101
|
+
const span2 = new PlainSpan5(pos, scanEnd);
|
|
4960
5102
|
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, scanEnd);
|
|
4961
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
5103
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf4(value, span2));
|
|
4962
5104
|
return { ok: true, value, span: span2 };
|
|
4963
5105
|
}
|
|
4964
5106
|
anchored.lastIndex = pos;
|
|
@@ -4966,9 +5108,9 @@ function regex(pattern, flags = "") {
|
|
|
4966
5108
|
if (m === null) {
|
|
4967
5109
|
return failAt(ctx, directTerminalFailureExpected(def), pos);
|
|
4968
5110
|
}
|
|
4969
|
-
const span =
|
|
5111
|
+
const span = new PlainSpan5(pos, pos + m[0].length);
|
|
4970
5112
|
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, span.end);
|
|
4971
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
5113
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf4(m[0], span));
|
|
4972
5114
|
return { ok: true, value: m[0], span };
|
|
4973
5115
|
}
|
|
4974
5116
|
};
|
|
@@ -4995,6 +5137,7 @@ function buildLexBodyRecognizer(spec, constants) {
|
|
|
4995
5137
|
}
|
|
4996
5138
|
|
|
4997
5139
|
// src/table/run-support.ts
|
|
5140
|
+
import { PlainLeaf as PlainLeaf5, PlainLineSpan as PlainLineSpan2, PlainSpan as PlainSpan6 } from "../cst/plain.js";
|
|
4998
5141
|
function lineCol(ctx, offset) {
|
|
4999
5142
|
const starts = ctx._lineStarts ?? [0];
|
|
5000
5143
|
let lo = 0, hi = starts.length - 1;
|
|
@@ -5007,18 +5150,14 @@ function lineCol(ctx, offset) {
|
|
|
5007
5150
|
}
|
|
5008
5151
|
function spanLines(ctx, start, end) {
|
|
5009
5152
|
const s = lineCol(ctx, start), e = lineCol(ctx, end);
|
|
5010
|
-
return
|
|
5153
|
+
return new PlainLineSpan2(start, end, s[0], s[1], e[0], e[1]);
|
|
5011
5154
|
}
|
|
5012
5155
|
function rawEntry(v, input, s, e) {
|
|
5013
5156
|
if (typeof v === "object" && v !== null) {
|
|
5014
5157
|
const tg = v._tag;
|
|
5015
5158
|
if (tg === "node" || tg === "leaf" || tg === "parseError") return v;
|
|
5016
5159
|
}
|
|
5017
|
-
return
|
|
5018
|
-
_tag: "leaf",
|
|
5019
|
-
value: typeof v === "string" ? v : typeof v === "object" && v !== null ? input.slice(s, e) : "",
|
|
5020
|
-
span: { start: s, end: e }
|
|
5021
|
-
};
|
|
5160
|
+
return new PlainLeaf5(typeof v === "string" ? v : typeof v === "object" && v !== null ? input.slice(s, e) : "", new PlainSpan6(s, e));
|
|
5022
5161
|
}
|
|
5023
5162
|
function lead(input, pos) {
|
|
5024
5163
|
if (pos >= input.length) return -1;
|
|
@@ -5032,7 +5171,7 @@ function collapseEmpty(ctx, build, input, pos, end, readsRaw) {
|
|
|
5032
5171
|
const collected = ctx._cstBuf !== void 0 || ctx._cstChildren !== void 0;
|
|
5033
5172
|
if (collected) popCstChild(ctx);
|
|
5034
5173
|
const raw = readsRaw ? [rawEntry(void 0, input, pos, end)] : EMPTY_KIDS;
|
|
5035
|
-
const nd = build(EMPTY_KIDS, void 0,
|
|
5174
|
+
const nd = build(EMPTY_KIDS, void 0, new PlainSpan6(pos, end), raw, EMPTY_TRIVIA, void 0);
|
|
5036
5175
|
if (collected) pushCstChild(ctx, nd, ctx._cstBuf?.noRaw === true ? void 0 : rawEntry(nd, input, pos, end));
|
|
5037
5176
|
return nd;
|
|
5038
5177
|
}
|
|
@@ -5702,7 +5841,7 @@ function decodeClassSpec(spec) {
|
|
|
5702
5841
|
function resolveClass(spec) {
|
|
5703
5842
|
const ascii = new Uint8Array(128);
|
|
5704
5843
|
const hi = [];
|
|
5705
|
-
for (const { lo, hi: up } of decodeClassSpec(spec)) {
|
|
5844
|
+
for (const { lo, hi: up } of leadRanges(decodeClassSpec(spec))) {
|
|
5706
5845
|
if (lo < 128) for (let c = lo; c <= Math.min(up, 127); c++) ascii[c] = 1;
|
|
5707
5846
|
if (up >= 128) hi.push(Math.max(lo, 128), up);
|
|
5708
5847
|
}
|
|
@@ -6254,6 +6393,7 @@ function buildReadsState(def) {
|
|
|
6254
6393
|
}
|
|
6255
6394
|
|
|
6256
6395
|
// src/combinators/token.ts
|
|
6396
|
+
import { PlainLeaf as PlainLeaf6 } from "../cst/plain.js";
|
|
6257
6397
|
function semanticLeafValue(_ctx, _input, _start, _end, value) {
|
|
6258
6398
|
return value;
|
|
6259
6399
|
}
|
|
@@ -6307,7 +6447,7 @@ function token(root) {
|
|
|
6307
6447
|
if (!result.ok) return result;
|
|
6308
6448
|
const span = result.span;
|
|
6309
6449
|
const value = input.slice(pos, span.end);
|
|
6310
|
-
if (wasCapturing) pushCstLeaf(ctx,
|
|
6450
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf6(value, span));
|
|
6311
6451
|
return { ok: true, value, span };
|
|
6312
6452
|
}
|
|
6313
6453
|
};
|
|
@@ -6355,11 +6495,7 @@ function makeLeaf(root, fn, sourceCstValue) {
|
|
|
6355
6495
|
}
|
|
6356
6496
|
if (!result.ok) return result;
|
|
6357
6497
|
const value = fn(result.value, result.span);
|
|
6358
|
-
if (wasCapturing) pushCstLeaf(ctx,
|
|
6359
|
-
_tag: "leaf",
|
|
6360
|
-
value: cstValue(ctx, input, pos, result.span.end, value),
|
|
6361
|
-
span: result.span
|
|
6362
|
-
});
|
|
6498
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf6(cstValue(ctx, input, pos, result.span.end, value), result.span));
|
|
6363
6499
|
return { ok: true, value, span: result.span };
|
|
6364
6500
|
}
|
|
6365
6501
|
};
|
|
@@ -6948,6 +7084,7 @@ var OP_NAMES = {
|
|
|
6948
7084
|
};
|
|
6949
7085
|
|
|
6950
7086
|
// src/combinators/node.ts
|
|
7087
|
+
import { PlainNode, PlainSpan as PlainSpan7 } from "../cst/plain.js";
|
|
6951
7088
|
function unwrapChild(child) {
|
|
6952
7089
|
return child !== null && typeof child === "object" && child._tag === "leaf" ? child.value : child;
|
|
6953
7090
|
}
|
|
@@ -7053,7 +7190,7 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
7053
7190
|
const nodeType = def.type ?? missingInferredType();
|
|
7054
7191
|
const cstOutput = cstOutputHost(ctx.build);
|
|
7055
7192
|
const span = ctx.trackLines ? annotateSpanFromLineContext(r.span, ctx) : r.span;
|
|
7056
|
-
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) :
|
|
7193
|
+
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]);
|
|
7057
7194
|
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 };
|
|
7058
7195
|
if (saved.buf !== void 0 || saved.ch !== void 0) {
|
|
7059
7196
|
pushCstChild(ctx, built, rawEntry2);
|
|
@@ -8624,6 +8761,7 @@ function parseSeqParts(source) {
|
|
|
8624
8761
|
cp2 = uni.cp;
|
|
8625
8762
|
i = uni.next;
|
|
8626
8763
|
} else if (e === void 0) return null;
|
|
8764
|
+
else if (e >= "0" && e <= "9" && (e !== "0" || source[i + 2] !== void 0 && source[i + 2] >= "0" && source[i + 2] <= "9")) return null;
|
|
8627
8765
|
else if (e in CLASS_ESCAPES) {
|
|
8628
8766
|
cp2 = CLASS_ESCAPES[e];
|
|
8629
8767
|
i += 2;
|
|
@@ -9173,7 +9311,7 @@ function parseScanShapeCore(source) {
|
|
|
9173
9311
|
return null;
|
|
9174
9312
|
}
|
|
9175
9313
|
function scanShapeFromRegex(source, flags) {
|
|
9176
|
-
if (/[
|
|
9314
|
+
if (/[msuv]/.test(flags)) return null;
|
|
9177
9315
|
if (/i/.test(flags)) return caseFoldShape(source);
|
|
9178
9316
|
return parseScanShape(source);
|
|
9179
9317
|
}
|
|
@@ -9778,7 +9916,7 @@ function triviaLeadRanges(tri, trivia2) {
|
|
|
9778
9916
|
const fs = trivia2[tri]?._meta.firstSet;
|
|
9779
9917
|
if (fs === void 0) return void 0;
|
|
9780
9918
|
if (fs.kind === "empty") return [];
|
|
9781
|
-
return fs.kind === "ranges" && fs.ranges !== void 0 ? fs.ranges : void 0;
|
|
9919
|
+
return fs.kind === "ranges" && fs.ranges !== void 0 ? leadRanges(fs.ranges) : void 0;
|
|
9782
9920
|
}
|
|
9783
9921
|
|
|
9784
9922
|
// src/table/scalar-terminal.ts
|
|
@@ -10136,7 +10274,14 @@ var EMITTED_PARAMS = [
|
|
|
10136
10274
|
"skipDeferredTrivia",
|
|
10137
10275
|
// Appended for the pass-through collapse (`run-support.ts`); old factories
|
|
10138
10276
|
// ignore it.
|
|
10139
|
-
"collapseEmpty"
|
|
10277
|
+
"collapseEmpty",
|
|
10278
|
+
// Appended for constructor-built tree objects (`cst/plain.d.ts`): a `new` call has
|
|
10279
|
+
// no allocation site, so V8 cannot pretenure them. Old factories ignore them.
|
|
10280
|
+
"_SP",
|
|
10281
|
+
"_LF",
|
|
10282
|
+
"_ND",
|
|
10283
|
+
"_FC",
|
|
10284
|
+
"_BUF"
|
|
10140
10285
|
];
|
|
10141
10286
|
var RUNTIME_PRELUDE = `
|
|
10142
10287
|
let _pfScan=null
|
|
@@ -10160,9 +10305,9 @@ if(s!==null)return skipTriviaScanned(s,input,cur,ctx)
|
|
|
10160
10305
|
if(needsDeferredTriviaCommit(ctx))return skipDeferredTrivia(input,cur,ctx)
|
|
10161
10306
|
return advanceTrivia(input,cur,ctx)
|
|
10162
10307
|
}
|
|
10163
|
-
function _pushLeaf(ctx,value,s,e){pushCstLeaf(ctx,
|
|
10308
|
+
function _pushLeaf(ctx,value,s,e){pushCstLeaf(ctx,new _LF(value,new _SP(s,e)))}
|
|
10164
10309
|
function _pushLeafBuf(ctx,value,s,e){
|
|
10165
|
-
const l=
|
|
10310
|
+
const l=new _LF(value,new _SP(s,e))
|
|
10166
10311
|
const b=ctx._cstBuf
|
|
10167
10312
|
if(b.ch!==undefined)b.ch.push(l)
|
|
10168
10313
|
else if(b.single!==undefined){b.ch=[b.single,l];b.single=undefined}
|
|
@@ -10220,7 +10365,7 @@ if(ctx._rootTriviaLog!==undefined&&ctx._rootTriviaLog.length!==rt)ctx._rootTrivi
|
|
|
10220
10365
|
`;
|
|
10221
10366
|
var NO_RAW_RUNTIME_PRELUDE = `
|
|
10222
10367
|
function _pushLeafNoRawBuf(ctx,value,s,e){
|
|
10223
|
-
const l=
|
|
10368
|
+
const l=new _LF(value,new _SP(s,e))
|
|
10224
10369
|
const b=ctx._cstBuf
|
|
10225
10370
|
if(b.ch!==undefined)b.ch.push(l)
|
|
10226
10371
|
else if(b.single!==undefined){b.ch=[b.single,l];b.single=undefined}
|
|
@@ -10308,7 +10453,7 @@ if(ctx._errors!==undefined&&ctx._errors.length!==${t2}er)ctx._errors.length=${t2
|
|
|
10308
10453
|
if (!s.fd && !s.er) return `if(${t2}n)rollbackTriviaAt(ctx,${t2}raw,${t2}tl,${t2}lv,undefined,undefined,${t2}lg,${t2}rt)`;
|
|
10309
10454
|
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)}`;
|
|
10310
10455
|
}
|
|
10311
|
-
function emitTerm(callee, dst, t2, l, skip) {
|
|
10456
|
+
function emitTerm(callee, dst, t2, l, skip, miss) {
|
|
10312
10457
|
const fast = `const ${t2}v=${callee}(input,cur,ctx)
|
|
10313
10458
|
if(${t2}v===FAIL)return FAIL
|
|
10314
10459
|
${dst}=${t2}v
|
|
@@ -10326,7 +10471,12 @@ if(${t2}v===FAIL)return FAIL
|
|
|
10326
10471
|
${dst}=${t2}v
|
|
10327
10472
|
if(EC.e>${t2}s)cur=EC.e
|
|
10328
10473
|
else{rollbackScannedTriviaAt(ctx,${t2}tl,${t2}stl,${t2}lg,${t2}slg,${t2}rt,${t2}srt)}`;
|
|
10329
|
-
if (l.tri !== TRI_UNKNOWN) return scanned
|
|
10474
|
+
if (l.tri !== TRI_UNKNOWN) return miss === void 0 ? scanned : `const ${t2}c=input.charCodeAt(cur)
|
|
10475
|
+
if(${miss(`${t2}c`)}){
|
|
10476
|
+
${fast}
|
|
10477
|
+
}else{
|
|
10478
|
+
${scanned}
|
|
10479
|
+
}`;
|
|
10330
10480
|
return `if(ctx.trivia===undefined){
|
|
10331
10481
|
${fast}
|
|
10332
10482
|
}else{
|
|
@@ -10382,7 +10532,7 @@ function rebuildPools(cc, fx, disp, plan) {
|
|
|
10382
10532
|
})
|
|
10383
10533
|
};
|
|
10384
10534
|
}
|
|
10385
|
-
function emitAssemblySource(t2, prog, cfg, extraIps = [], staticBuild = false, select) {
|
|
10535
|
+
function emitAssemblySource(t2, prog, cfg, extraIps = [], staticBuild = false, select, scanSinkNeutral = false) {
|
|
10386
10536
|
const { code, k, fx, disp, dsp, triviaLabelled } = t2;
|
|
10387
10537
|
const swapLegal = !cfg.trackLines;
|
|
10388
10538
|
const hostCst = cfg.hostCst;
|
|
@@ -10458,7 +10608,7 @@ function emitAssemblySource(t2, prog, cfg, extraIps = [], staticBuild = false, s
|
|
|
10458
10608
|
const op = code[ip];
|
|
10459
10609
|
sinkBits.set(
|
|
10460
10610
|
ip,
|
|
10461
|
-
op === OP_SCAN ? 3 : (op === OP_FIELD ? 1 : 0) | (op === OP_EXPECT || REC && (op === OP_REP || op === OP_REPV) ? 2 : 0)
|
|
10611
|
+
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)
|
|
10462
10612
|
);
|
|
10463
10613
|
}
|
|
10464
10614
|
const sinkKids = [];
|
|
@@ -10631,6 +10781,12 @@ return 1
|
|
|
10631
10781
|
return `if(${gateMissTest(child)}){${miss}}
|
|
10632
10782
|
`;
|
|
10633
10783
|
}
|
|
10784
|
+
function triviaMiss(ki) {
|
|
10785
|
+
const leads = triviaLeadRanges(ki, t2.trivia);
|
|
10786
|
+
if (leads === void 0 || leads.length > 16) return void 0;
|
|
10787
|
+
if (leads.length === 0) return (c) => `${c}<55296`;
|
|
10788
|
+
return (c) => `${c}<55296&&!(${leads.map((r) => r.lo === r.hi ? `${c}===${r.lo}` : `(${c}>=${r.lo}&&${c}<=${r.hi})`).join("||")})`;
|
|
10789
|
+
}
|
|
10634
10790
|
function skipFor(l) {
|
|
10635
10791
|
if (l.tri < 0) return "_skipTrivia";
|
|
10636
10792
|
const ki = l.tri;
|
|
@@ -10641,8 +10797,13 @@ return 1
|
|
|
10641
10797
|
const nm = `_sk${skipPool.size}`;
|
|
10642
10798
|
skipPool.set(key, nm);
|
|
10643
10799
|
if (!hasScan) {
|
|
10644
|
-
|
|
10645
|
-
|
|
10800
|
+
const miss = triviaMiss(ki);
|
|
10801
|
+
const pre = miss === void 0 ? "" : `const c=input.charCodeAt(cur)
|
|
10802
|
+
if(${miss("c")})return cur
|
|
10803
|
+
`;
|
|
10804
|
+
skipDefs.push(l.buf ? `function ${nm}(input,cur,ctx){${pre === "" ? "" : `
|
|
10805
|
+
${pre}`}return skipDeferredTrivia(input,cur,ctx)}` : `function ${nm}(input,cur,ctx){
|
|
10806
|
+
${pre}if(needsDeferredTriviaCommit(ctx))return skipDeferredTrivia(input,cur,ctx)
|
|
10646
10807
|
return advanceTrivia(input,cur,ctx)}`);
|
|
10647
10808
|
return nm;
|
|
10648
10809
|
}
|
|
@@ -10881,7 +11042,7 @@ try{return ${child}(input,pos,ctx)}finally{ctx.state=saved}
|
|
|
10881
11042
|
return `${head}
|
|
10882
11043
|
const v=${child}(input,pos,ctx)
|
|
10883
11044
|
if(v===FAIL)return FAIL
|
|
10884
|
-
return ${fn}(v,
|
|
11045
|
+
return ${fn}(v,new _SP(pos,EC.e))
|
|
10885
11046
|
}`;
|
|
10886
11047
|
}
|
|
10887
11048
|
case OP_LABEL: {
|
|
@@ -10902,7 +11063,7 @@ return v
|
|
|
10902
11063
|
const v=${child}(input,pos,ctx)
|
|
10903
11064
|
if(v===FAIL)return FAIL
|
|
10904
11065
|
const f=ctx._fields
|
|
10905
|
-
if(f!==undefined)f.push({name
|
|
11066
|
+
if(f!==undefined)f.push(new _FC(${name},v,new _SP(pos,EC.e)))
|
|
10906
11067
|
return v
|
|
10907
11068
|
}`;
|
|
10908
11069
|
}
|
|
@@ -10927,7 +11088,7 @@ return v
|
|
|
10927
11088
|
return `${head}
|
|
10928
11089
|
const v=${child}(input,pos,ctx)
|
|
10929
11090
|
if(v!==FAIL)return v
|
|
10930
|
-
const err={_tag:'parseError',span:${prog.lines === 1 ? "spanLines(ctx,pos,pos)" : "
|
|
11091
|
+
const err={_tag:'parseError',span:${prog.lines === 1 ? "spanLines(ctx,pos,pos)" : "new _SP(pos,pos)"},expected:${xf}}
|
|
10931
11092
|
const es=ctx._errors
|
|
10932
11093
|
if(es!==undefined)es.push(err)
|
|
10933
11094
|
${REC ? "if(ctx._tolerant===true)captureError(ctx,err)\n" : ""}ctx._fc=false
|
|
@@ -10938,7 +11099,7 @@ return err
|
|
|
10938
11099
|
case OP_ROUTED: {
|
|
10939
11100
|
const fb = code[ip + 1];
|
|
10940
11101
|
const fallback = fb >= 0 ? link(fb) : void 0;
|
|
10941
|
-
const push = `pushCstLeaf(ctx,
|
|
11102
|
+
const push = `pushCstLeaf(ctx,new _LF(it.value,it.span))`;
|
|
10942
11103
|
return `${head}
|
|
10943
11104
|
const it=ctx._routed
|
|
10944
11105
|
if(it===undefined||pos!==it.span.start){
|
|
@@ -11019,8 +11180,8 @@ ctx._triviaLog=sOtl
|
|
|
11019
11180
|
}
|
|
11020
11181
|
if(v===FAIL)return FAIL
|
|
11021
11182
|
const e=EC.e
|
|
11022
|
-
const out=${isToken ? "input.slice(pos,e)" : `${fn}(v,
|
|
11023
|
-
if(wasCap)pushCstLeaf(ctx,{
|
|
11183
|
+
const out=${isToken ? "input.slice(pos,e)" : `${fn}(v,new _SP(pos,e))`}
|
|
11184
|
+
if(wasCap)pushCstLeaf(ctx,new _LF(${capturesSource ? "input.slice(pos,e)" : "out"},new _SP(pos,e)))
|
|
11024
11185
|
EC.e=e
|
|
11025
11186
|
return out
|
|
11026
11187
|
}`;
|
|
@@ -11044,7 +11205,7 @@ ${hasSuffix && (lineFlags & 2) !== 0 ? "if(sm)_trackLines(ctx,input,e)" : ""}
|
|
|
11044
11205
|
${hasSuffix ? `if(!sm){ctx._fe=e;ctx._fx=${suffixExpected};if(ctx._probe!==undefined)failAt(ctx,${suffixExpected},e)}` : ""}
|
|
11045
11206
|
const v=${pending ? "tp?_pfTokValue:" : ""}input.slice(pos,e)
|
|
11046
11207
|
${pending ? "if(tp){_pfTokBody=-1;_pfTokValue=undefined}" : ""}
|
|
11047
|
-
if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,
|
|
11208
|
+
if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
|
|
11048
11209
|
EC.e=e
|
|
11049
11210
|
return v
|
|
11050
11211
|
}`;
|
|
@@ -11083,7 +11244,7 @@ ctx._rootTriviaLog=sRtl
|
|
|
11083
11244
|
}
|
|
11084
11245
|
if(e<0)return FAIL
|
|
11085
11246
|
const v=input.slice(pos,e)
|
|
11086
|
-
if(wasCap)pushCstLeaf(ctx,
|
|
11247
|
+
if(wasCap)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
|
|
11087
11248
|
EC.e=e
|
|
11088
11249
|
return v
|
|
11089
11250
|
}`;
|
|
@@ -11091,7 +11252,7 @@ return v
|
|
|
11091
11252
|
const e=${run}(input,pos,ctx)
|
|
11092
11253
|
if(e<0)return FAIL
|
|
11093
11254
|
const v=input.slice(pos,e)
|
|
11094
|
-
if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,
|
|
11255
|
+
if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
|
|
11095
11256
|
EC.e=e
|
|
11096
11257
|
return v
|
|
11097
11258
|
}`;
|
|
@@ -11205,7 +11366,7 @@ return v
|
|
|
11205
11366
|
}` : `${parts.join("\n")}
|
|
11206
11367
|
}`;
|
|
11207
11368
|
if (n === 1) {
|
|
11208
|
-
parts.push(fused ? projection === 0 ? "return v0" : `return ${fn}([v0],
|
|
11369
|
+
parts.push(fused ? projection === 0 ? "return v0" : `return ${fn}([v0],new _SP(pos,EC.e))` : wantValues ? "return [v0]" : "return undefined");
|
|
11209
11370
|
return close();
|
|
11210
11371
|
}
|
|
11211
11372
|
parts.push("let cur=EC.e");
|
|
@@ -11226,12 +11387,12 @@ return v
|
|
|
11226
11387
|
);
|
|
11227
11388
|
} else {
|
|
11228
11389
|
const callee = leadingTriviaFieldAt(code, k, childIp) ? `(LEAD.at=cur,${kids[i]})` : kids[i];
|
|
11229
|
-
parts.push(holdsGap(code, k, base, n, i, nullable2) ? emitHoldTerm(callee, vn, tmp(), L, skipFor(L)) : emitTerm(callee, vn, tmp(), L, skipFor(L)));
|
|
11390
|
+
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));
|
|
11230
11391
|
}
|
|
11231
11392
|
names.push(vn);
|
|
11232
11393
|
}
|
|
11233
11394
|
parts.push("EC.e=cur");
|
|
11234
|
-
parts.push(fused ? projection >= 0 ? `return ${names[projection]}` : `return ${fn}([${names.join(",")}],
|
|
11395
|
+
parts.push(fused ? projection >= 0 ? `return ${names[projection]}` : `return ${fn}([${names.join(",")}],new _SP(pos,cur))` : wantValues ? `return [${names.join(",")}]` : "return undefined");
|
|
11235
11396
|
return close();
|
|
11236
11397
|
}
|
|
11237
11398
|
case OP_CHOICE: {
|
|
@@ -11490,7 +11651,7 @@ ${spec.match.map((m, i) => `${i === 0 ? "" : "else "}if(${dispatchClaim(m)})arm=
|
|
|
11490
11651
|
const routedCall = (target) => `{const savedRouted=ctx._routed
|
|
11491
11652
|
${emitRollback(m1, L.buf, L.raw, sinks)}
|
|
11492
11653
|
${emitMark(m2, L.buf, L.raw, sinks, false)}
|
|
11493
|
-
ctx._routed={value:key,span:
|
|
11654
|
+
ctx._routed={value:key,span:new _SP(pos,selEnd)}
|
|
11494
11655
|
try{v=${target}(input,pos,ctx)}finally{ctx._routed=savedRouted}
|
|
11495
11656
|
break}`;
|
|
11496
11657
|
const plainCall = (target) => `v=${target}(input,selEnd,ctx);break`;
|
|
@@ -11685,8 +11846,8 @@ return out
|
|
|
11685
11846
|
const end=${recognize}(input,pos)
|
|
11686
11847
|
if(end<0){ctx._fe=pos;ctx._fx=${xf};return FAIL}
|
|
11687
11848
|
const value=${value2}
|
|
11688
|
-
const leaf=
|
|
11689
|
-
const kids=[leaf],rawKids=[leaf],span=
|
|
11849
|
+
const leaf=new _LF(value,new _SP(pos,end))
|
|
11850
|
+
const kids=[leaf],rawKids=[leaf],span=new _SP(pos,end)
|
|
11690
11851
|
EC.e=end
|
|
11691
11852
|
const nd=${build2}(kids,undefined,span,rawKids,EMPTY_TL,undefined)
|
|
11692
11853
|
${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))"}
|
|
@@ -11785,7 +11946,7 @@ ctx._cstTriviaLog=sTl
|
|
|
11785
11946
|
ctx.captureTrivia=sCap
|
|
11786
11947
|
if(v===FAIL)return FAIL
|
|
11787
11948
|
const end=EC.e
|
|
11788
|
-
${collapseChildren ? `const nd=captured.length===1?captured[0]:${build}(captured,undefined,
|
|
11949
|
+
${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)`}
|
|
11789
11950
|
${publish}
|
|
11790
11951
|
EC.e=end
|
|
11791
11952
|
return nd
|
|
@@ -11808,20 +11969,20 @@ return nd
|
|
|
11808
11969
|
const direct = `${build}(kids,fieldMap,span,rawKids,${captureWide ? "tlog" : "EMPTY_TL"},st)`;
|
|
11809
11970
|
value = hostCst ? `nd=_pfHost!==undefined?${hostCall}:${direct}` : `nd=${direct}`;
|
|
11810
11971
|
} else {
|
|
11811
|
-
value = `nd=_pfHost!==undefined?_pfHost(${ty},hostKids,fieldMap,span,rawKids,tlog,st,${tags}):{
|
|
11972
|
+
value = `nd=_pfHost!==undefined?_pfHost(${ty},hostKids,fieldMap,span,rawKids,tlog,st,${tags}):new _ND(${ty},span,st??null,kids===EMPTY_CH?kids:[...kids])`;
|
|
11812
11973
|
}
|
|
11813
11974
|
const collapsible = keepChildren && (hostCst || build === void 0 && proj < 0);
|
|
11814
|
-
const openCapture = omitsRaw ? `const buf=
|
|
11975
|
+
const openCapture = omitsRaw ? `const buf=new _BUF(undefined,true,0)
|
|
11815
11976
|
ctx._cstBuf=buf
|
|
11816
11977
|
ctx._cstChildren=undefined
|
|
11817
11978
|
ctx._cstLeaves=undefined
|
|
11818
11979
|
ctx._cstRawChildren=undefined
|
|
11819
|
-
ctx._cstTriviaLog=undefined` : keepChildren ? `const buf=
|
|
11980
|
+
ctx._cstTriviaLog=undefined` : keepChildren ? `const buf=new _BUF(undefined,undefined,0)
|
|
11820
11981
|
ctx._cstBuf=buf
|
|
11821
11982
|
ctx._cstChildren=undefined
|
|
11822
11983
|
ctx._cstLeaves=undefined
|
|
11823
11984
|
ctx._cstRawChildren=undefined
|
|
11824
|
-
ctx._cstTriviaLog=undefined` : `const buf=
|
|
11985
|
+
ctx._cstTriviaLog=undefined` : `const buf=new _BUF(true,undefined,0)
|
|
11825
11986
|
ctx._cstBuf=buf
|
|
11826
11987
|
ctx._cstChildren=undefined
|
|
11827
11988
|
ctx._cstLeaves=undefined
|
|
@@ -11859,7 +12020,7 @@ ctx._cstTriviaLog=sTl
|
|
|
11859
12020
|
ctx.captureTrivia=sCap
|
|
11860
12021
|
if(v===FAIL)return FAIL
|
|
11861
12022
|
const end=EC.e
|
|
11862
|
-
const span=${tracked ? "spanLines(ctx,pos,end)" : "
|
|
12023
|
+
const span=${tracked ? "spanLines(ctx,pos,end)" : "new _SP(pos,end)"}
|
|
11863
12024
|
const st=${readsState ? "ctx.state" : "undefined"}
|
|
11864
12025
|
let nd
|
|
11865
12026
|
${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]
|
|
@@ -12146,6 +12307,7 @@ function rebuildLineScan(s, subtree) {
|
|
|
12146
12307
|
}
|
|
12147
12308
|
|
|
12148
12309
|
// src/combinators/literal.ts
|
|
12310
|
+
import { PlainLeaf as PlainLeaf7, PlainSpan as PlainSpan8 } from "../cst/plain.js";
|
|
12149
12311
|
function asciiFoldEq(a, b) {
|
|
12150
12312
|
if (a.length !== b.length) return false;
|
|
12151
12313
|
for (let i = 0; i < a.length; i++) {
|
|
@@ -12203,9 +12365,9 @@ function literal(value, opts = {}) {
|
|
|
12203
12365
|
const code = value.charCodeAt(0);
|
|
12204
12366
|
return function parse3(input, pos, ctx) {
|
|
12205
12367
|
if (input.charCodeAt(pos) === code) {
|
|
12206
|
-
const span =
|
|
12368
|
+
const span = new PlainSpan8(pos, pos + 1);
|
|
12207
12369
|
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, span.end);
|
|
12208
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
12370
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf7(value, span));
|
|
12209
12371
|
return { ok: true, value, span };
|
|
12210
12372
|
}
|
|
12211
12373
|
return failAt(ctx, expected, pos);
|
|
@@ -12217,9 +12379,9 @@ function literal(value, opts = {}) {
|
|
|
12217
12379
|
}
|
|
12218
12380
|
const matchedValue = caseInsensitive ? input.slice(pos, end) : value;
|
|
12219
12381
|
if (caseInsensitive ? asciiFoldEq(matchedValue, value) : input.startsWith(value, pos)) {
|
|
12220
|
-
const span =
|
|
12382
|
+
const span = new PlainSpan8(pos, end);
|
|
12221
12383
|
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, end);
|
|
12222
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
12384
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf7(matchedValue, span));
|
|
12223
12385
|
return { ok: true, value: matchedValue, span };
|
|
12224
12386
|
}
|
|
12225
12387
|
return failAt(ctx, expected, pos);
|
|
@@ -12301,6 +12463,7 @@ function ref() {
|
|
|
12301
12463
|
}
|
|
12302
12464
|
|
|
12303
12465
|
// src/combinators/scanTo.ts
|
|
12466
|
+
import { PlainLeaf as PlainLeaf8, PlainSpan as PlainSpan9 } from "../cst/plain.js";
|
|
12304
12467
|
function resolveScanSkip(explicitSkip, raw, ctx) {
|
|
12305
12468
|
if (raw) return [];
|
|
12306
12469
|
const trivia2 = ctx.trivia;
|
|
@@ -12338,7 +12501,7 @@ function scanTo(sentinel, { skip, raw = false, orEOF = false, recoverAt, stopAt
|
|
|
12338
12501
|
probeCtx._errors = ctx._errors;
|
|
12339
12502
|
const emit = (end) => {
|
|
12340
12503
|
if (end > pos && cstCaptureActive(ctx)) {
|
|
12341
|
-
const leaf2 =
|
|
12504
|
+
const leaf2 = new PlainLeaf8(input.slice(pos, end), new PlainSpan9(pos, end));
|
|
12342
12505
|
pushCstLeaf(ctx, leaf2);
|
|
12343
12506
|
}
|
|
12344
12507
|
};
|
|
@@ -12560,6 +12723,15 @@ function skipDeferredTrivia(input, cur, ctx) {
|
|
|
12560
12723
|
if (plain2) remember(cur, scan, ctx, input, triviaP);
|
|
12561
12724
|
return scan;
|
|
12562
12725
|
}
|
|
12726
|
+
function triviaLeadTable(triviaP) {
|
|
12727
|
+
const fs = triviaP._meta.firstSet;
|
|
12728
|
+
if (fs.kind === "any") return null;
|
|
12729
|
+
const table = new Uint8Array(128);
|
|
12730
|
+
if (fs.kind === "ranges") {
|
|
12731
|
+
for (const r of fs.ranges) for (let c = Math.max(0, r.lo); c <= Math.min(127, r.hi); c++) table[c] = 1;
|
|
12732
|
+
}
|
|
12733
|
+
return table;
|
|
12734
|
+
}
|
|
12563
12735
|
function clearRunEnd(input, cur, ctx, triviaP, plain2) {
|
|
12564
12736
|
const rootKinds = ctx._rootTriviaKindIndex;
|
|
12565
12737
|
const spec = triviaP?._meta.labeledTriviaSpec;
|
|
@@ -12608,6 +12780,9 @@ function clearOf(ranges, input, from, to) {
|
|
|
12608
12780
|
return true;
|
|
12609
12781
|
}
|
|
12610
12782
|
|
|
12783
|
+
// src/table/assemble.ts
|
|
12784
|
+
import { PlainBuf as PlainBuf2, PlainField, PlainLeaf as PlainLeaf9, PlainNode as PlainNode2, PlainSpan as PlainSpan10 } from "../cst/plain.js";
|
|
12785
|
+
|
|
12611
12786
|
// src/table/fail-clean.ts
|
|
12612
12787
|
function passChild(code, ip) {
|
|
12613
12788
|
switch (code[ip]) {
|
|
@@ -12918,7 +13093,7 @@ function assemble(t2, prog, cfg) {
|
|
|
12918
13093
|
const NULLABLE = /* @__PURE__ */ new Map();
|
|
12919
13094
|
const CLEAN = REC ? () => false : failCleanAnalysis(code);
|
|
12920
13095
|
function pushLeaf(ctx, value, s, e) {
|
|
12921
|
-
const lf =
|
|
13096
|
+
const lf = new PlainLeaf9(value, new PlainSpan10(s, e));
|
|
12922
13097
|
pushCstLeaf(ctx, lf);
|
|
12923
13098
|
}
|
|
12924
13099
|
function plainBuildNode(child, build, trailing) {
|
|
@@ -12951,7 +13126,7 @@ function assemble(t2, prog, cfg) {
|
|
|
12951
13126
|
ctx.captureTrivia = sCap;
|
|
12952
13127
|
if (value === FAIL) return FAIL;
|
|
12953
13128
|
const end = EC.e;
|
|
12954
|
-
const span =
|
|
13129
|
+
const span = new PlainSpan10(pos, end);
|
|
12955
13130
|
const node2 = build(kids, void 0, span, rawKids, EMPTY_TL2, void 0);
|
|
12956
13131
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
12957
13132
|
pushCstChild(ctx, node2, rawEntry(node2, input, pos, end));
|
|
@@ -12996,7 +13171,7 @@ function assemble(t2, prog, cfg) {
|
|
|
12996
13171
|
ctx.captureTrivia = sCap;
|
|
12997
13172
|
if (value === FAIL) return FAIL;
|
|
12998
13173
|
const end = EC.e;
|
|
12999
|
-
const node2 = build(captured, void 0,
|
|
13174
|
+
const node2 = build(captured, void 0, new PlainSpan10(pos, end), EMPTY_CH, EMPTY_TL2, void 0);
|
|
13000
13175
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
13001
13176
|
pushCstChild(ctx, node2, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node2, input, pos, end) : void 0);
|
|
13002
13177
|
}
|
|
@@ -13033,7 +13208,7 @@ function assemble(t2, prog, cfg) {
|
|
|
13033
13208
|
ctx.captureTrivia = sCap;
|
|
13034
13209
|
if (value === FAIL) return FAIL;
|
|
13035
13210
|
const end = EC.e;
|
|
13036
|
-
const node2 = build(captured, fieldMap,
|
|
13211
|
+
const node2 = build(captured, fieldMap, new PlainSpan10(pos, end), EMPTY_CH, EMPTY_TL2, void 0);
|
|
13037
13212
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
13038
13213
|
pushCstChild(ctx, node2, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node2, input, pos, end) : void 0);
|
|
13039
13214
|
}
|
|
@@ -13070,7 +13245,7 @@ function assemble(t2, prog, cfg) {
|
|
|
13070
13245
|
ctx.captureTrivia = sCap;
|
|
13071
13246
|
if (value === FAIL) return FAIL;
|
|
13072
13247
|
const end = EC.e;
|
|
13073
|
-
const span =
|
|
13248
|
+
const span = new PlainSpan10(pos, end);
|
|
13074
13249
|
const node2 = kids.length === 1 ? kids[0] : build(kids, void 0, span, rawKids, EMPTY_TL2, void 0);
|
|
13075
13250
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
13076
13251
|
pushCstChild(ctx, node2, rawEntry(node2, input, pos, end));
|
|
@@ -13107,7 +13282,7 @@ function assemble(t2, prog, cfg) {
|
|
|
13107
13282
|
ctx.captureTrivia = sCap;
|
|
13108
13283
|
if (value === FAIL) return FAIL;
|
|
13109
13284
|
const end = EC.e;
|
|
13110
|
-
const node2 = captured.length === 1 ? captured[0] : build(captured, void 0,
|
|
13285
|
+
const node2 = captured.length === 1 ? captured[0] : build(captured, void 0, new PlainSpan10(pos, end), EMPTY_CH, EMPTY_TL2, void 0);
|
|
13111
13286
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
13112
13287
|
pushCstChild(ctx, node2, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node2, input, pos, end) : void 0);
|
|
13113
13288
|
}
|
|
@@ -13216,7 +13391,23 @@ function assemble(t2, prog, cfg) {
|
|
|
13216
13391
|
}
|
|
13217
13392
|
return out;
|
|
13218
13393
|
}
|
|
13394
|
+
const LEAD_TABLES = trivia2.map((tp) => tp === void 0 ? null : triviaLeadTable(tp));
|
|
13395
|
+
let LEAD_OF;
|
|
13396
|
+
let LEAD_TABLE = null;
|
|
13397
|
+
function cannotStartTrivia(input, cur, triviaP) {
|
|
13398
|
+
if (triviaP !== LEAD_OF) {
|
|
13399
|
+
LEAD_OF = triviaP;
|
|
13400
|
+
const slot = trivia2.indexOf(triviaP);
|
|
13401
|
+
LEAD_TABLE = slot >= 0 ? LEAD_TABLES[slot] : triviaLeadTable(triviaP);
|
|
13402
|
+
}
|
|
13403
|
+
const table = LEAD_TABLE;
|
|
13404
|
+
if (table === null) return false;
|
|
13405
|
+
const c = input.charCodeAt(cur);
|
|
13406
|
+
return c < 128 && table[c] === 0;
|
|
13407
|
+
}
|
|
13219
13408
|
function skipTrivia(input, cur, ctx) {
|
|
13409
|
+
const t3 = ctx.trivia;
|
|
13410
|
+
if (t3 !== void 0 && cannotStartTrivia(input, cur, t3)) return cur;
|
|
13220
13411
|
const s = SCAN;
|
|
13221
13412
|
if (s !== null && ctx._triviaLog === void 0 && !(ctx.captureTrivia === true && (ctx._cstBuf !== void 0 || ctx._cstTriviaLog !== void 0))) {
|
|
13222
13413
|
return s(input, cur);
|
|
@@ -13231,7 +13422,8 @@ function assemble(t2, prog, cfg) {
|
|
|
13231
13422
|
const frames = [];
|
|
13232
13423
|
let depth = 0;
|
|
13233
13424
|
function nextTerm(child, input, cur, ctx) {
|
|
13234
|
-
|
|
13425
|
+
const t3 = ctx.trivia;
|
|
13426
|
+
if (t3 === void 0 || cannotStartTrivia(input, cur, t3)) {
|
|
13235
13427
|
const v2 = child(input, cur, ctx);
|
|
13236
13428
|
if (v2 === FAIL) return -1;
|
|
13237
13429
|
TERMV = v2;
|
|
@@ -13260,7 +13452,8 @@ function assemble(t2, prog, cfg) {
|
|
|
13260
13452
|
return cur;
|
|
13261
13453
|
}
|
|
13262
13454
|
function nextTermBuffered(child, input, cur, ctx) {
|
|
13263
|
-
|
|
13455
|
+
const t3 = ctx.trivia;
|
|
13456
|
+
if (t3 === void 0 || cannotStartTrivia(input, cur, t3)) {
|
|
13264
13457
|
const v2 = child(input, cur, ctx);
|
|
13265
13458
|
if (v2 === FAIL) return -1;
|
|
13266
13459
|
TERMV = v2;
|
|
@@ -13522,7 +13715,7 @@ function assemble(t2, prog, cfg) {
|
|
|
13522
13715
|
return (input, pos, selEnd, key, ctx, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot) => {
|
|
13523
13716
|
const savedRouted = ctx._routed;
|
|
13524
13717
|
if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
|
|
13525
|
-
ctx._routed = { value: key, span:
|
|
13718
|
+
ctx._routed = { value: key, span: new PlainSpan10(pos, selEnd) };
|
|
13526
13719
|
let v;
|
|
13527
13720
|
try {
|
|
13528
13721
|
v = child(input, pos, ctx);
|
|
@@ -13955,7 +14148,7 @@ function assemble(t2, prog, cfg) {
|
|
|
13955
14148
|
case OP_EXPECT: {
|
|
13956
14149
|
const child = link(code[ip + 1]);
|
|
13957
14150
|
const xf = fx[code[ip + 2]];
|
|
13958
|
-
const expectSpan = (ctx, pos) => prog.lines === 1 ? spanLines(ctx, pos, pos) :
|
|
14151
|
+
const expectSpan = (ctx, pos) => prog.lines === 1 ? spanLines(ctx, pos, pos) : new PlainSpan10(pos, pos);
|
|
13959
14152
|
if (REC) {
|
|
13960
14153
|
return (input, pos, ctx) => {
|
|
13961
14154
|
const v = child(input, pos, ctx);
|
|
@@ -13987,7 +14180,7 @@ function assemble(t2, prog, cfg) {
|
|
|
13987
14180
|
return (input, pos, ctx) => {
|
|
13988
14181
|
const v = child(input, pos, ctx);
|
|
13989
14182
|
if (v === FAIL) return FAIL;
|
|
13990
|
-
ctx._fields?.push(
|
|
14183
|
+
ctx._fields?.push(new PlainField(name, v, new PlainSpan10(pos, EC.e)));
|
|
13991
14184
|
return v;
|
|
13992
14185
|
};
|
|
13993
14186
|
}
|
|
@@ -14011,7 +14204,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14011
14204
|
return (input, pos, ctx) => {
|
|
14012
14205
|
const v = child(input, pos, ctx);
|
|
14013
14206
|
if (v === FAIL) return FAIL;
|
|
14014
|
-
return fn(v,
|
|
14207
|
+
return fn(v, new PlainSpan10(pos, EC.e));
|
|
14015
14208
|
};
|
|
14016
14209
|
}
|
|
14017
14210
|
case OP_SCAN: {
|
|
@@ -14062,6 +14255,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14062
14255
|
const scopeTrivia = ki < 0 ? void 0 : trivia2[ki];
|
|
14063
14256
|
const scopeLabels = scopeTrivia?._meta.triviaKindLabels;
|
|
14064
14257
|
const scanFor = swapLegal && ki >= 0 && !triviaLabelled[ki] ? triviaScan[ki] : null;
|
|
14258
|
+
const scopeLead = ki < 0 ? null : LEAD_TABLES[ki];
|
|
14065
14259
|
const child = link(code[ip + 2]);
|
|
14066
14260
|
const scopePiece = code[ip] === OP_SCOPE_CAP ? (input, pos, ctx) => {
|
|
14067
14261
|
const saved = ctx.trivia;
|
|
@@ -14069,6 +14263,9 @@ function assemble(t2, prog, cfg) {
|
|
|
14069
14263
|
const savedScan = SCAN;
|
|
14070
14264
|
const savedCap = ctx.captureTrivia;
|
|
14071
14265
|
SCAN = scanFor;
|
|
14266
|
+
const savedLeadOf = LEAD_OF, savedLead = LEAD_TABLE;
|
|
14267
|
+
LEAD_OF = scopeTrivia;
|
|
14268
|
+
LEAD_TABLE = scopeLead;
|
|
14072
14269
|
ctx.trivia = scopeTrivia;
|
|
14073
14270
|
ctx.triviaKindLabels = scopeLabels;
|
|
14074
14271
|
ctx.captureTrivia = true;
|
|
@@ -14077,18 +14274,25 @@ function assemble(t2, prog, cfg) {
|
|
|
14077
14274
|
ctx.trivia = saved;
|
|
14078
14275
|
ctx.triviaKindLabels = savedLabels;
|
|
14079
14276
|
SCAN = savedScan;
|
|
14277
|
+
LEAD_OF = savedLeadOf;
|
|
14278
|
+
LEAD_TABLE = savedLead;
|
|
14080
14279
|
return v;
|
|
14081
14280
|
} : (input, pos, ctx) => {
|
|
14082
14281
|
const saved = ctx.trivia;
|
|
14083
14282
|
const savedLabels = ctx.triviaKindLabels;
|
|
14084
14283
|
const savedScan = SCAN;
|
|
14085
14284
|
SCAN = scanFor;
|
|
14285
|
+
const savedLeadOf = LEAD_OF, savedLead = LEAD_TABLE;
|
|
14286
|
+
LEAD_OF = scopeTrivia;
|
|
14287
|
+
LEAD_TABLE = scopeLead;
|
|
14086
14288
|
ctx.trivia = scopeTrivia;
|
|
14087
14289
|
ctx.triviaKindLabels = scopeLabels;
|
|
14088
14290
|
const v = child(input, pos, ctx);
|
|
14089
14291
|
ctx.trivia = saved;
|
|
14090
14292
|
ctx.triviaKindLabels = savedLabels;
|
|
14091
14293
|
SCAN = savedScan;
|
|
14294
|
+
LEAD_OF = savedLeadOf;
|
|
14295
|
+
LEAD_TABLE = savedLead;
|
|
14092
14296
|
return v;
|
|
14093
14297
|
};
|
|
14094
14298
|
return scopeRootPolicy(scopePiece, code[ip] === OP_SCOPE_PLAIN ? 0 : code[ip + 3]);
|
|
@@ -14104,7 +14308,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14104
14308
|
ctx._fx = ROUTED_FX;
|
|
14105
14309
|
return FAIL;
|
|
14106
14310
|
}
|
|
14107
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
14311
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf9(item.value, item.span));
|
|
14108
14312
|
EC.e = item.span.end;
|
|
14109
14313
|
return item.value;
|
|
14110
14314
|
};
|
|
@@ -14290,7 +14494,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14290
14494
|
if (v === FAIL) return FAIL;
|
|
14291
14495
|
const end = EC.e;
|
|
14292
14496
|
const value = input.slice(pos, end);
|
|
14293
|
-
if (wasCapturing) pushCstLeaf(ctx,
|
|
14497
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
|
|
14294
14498
|
EC.e = end;
|
|
14295
14499
|
return value;
|
|
14296
14500
|
};
|
|
@@ -14324,7 +14528,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14324
14528
|
if (ctx._probe !== void 0) failAt(ctx, suffixExpected, end);
|
|
14325
14529
|
}
|
|
14326
14530
|
const value = input.slice(pos, end);
|
|
14327
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
14531
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
|
|
14328
14532
|
EC.e = end;
|
|
14329
14533
|
return value;
|
|
14330
14534
|
};
|
|
@@ -14367,7 +14571,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14367
14571
|
}
|
|
14368
14572
|
if (end < 0) return FAIL;
|
|
14369
14573
|
const value = input.slice(pos, end);
|
|
14370
|
-
if (wasCapturing) pushCstLeaf(ctx,
|
|
14574
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
|
|
14371
14575
|
EC.e = end;
|
|
14372
14576
|
return value;
|
|
14373
14577
|
};
|
|
@@ -14376,7 +14580,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14376
14580
|
const end = run(input, pos, ctx);
|
|
14377
14581
|
if (end < 0) return FAIL;
|
|
14378
14582
|
const value = input.slice(pos, end);
|
|
14379
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
14583
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
|
|
14380
14584
|
EC.e = end;
|
|
14381
14585
|
return value;
|
|
14382
14586
|
};
|
|
@@ -14409,12 +14613,8 @@ function assemble(t2, prog, cfg) {
|
|
|
14409
14613
|
}
|
|
14410
14614
|
if (v === FAIL) return FAIL;
|
|
14411
14615
|
const end = EC.e;
|
|
14412
|
-
const out = fn(v,
|
|
14413
|
-
if (wasCapturing) pushCstLeaf(ctx,
|
|
14414
|
-
_tag: "leaf",
|
|
14415
|
-
value: op === OP_SOURCE_LEAF && hostCst ? input.slice(pos, end) : out,
|
|
14416
|
-
span: { start: pos, end }
|
|
14417
|
-
});
|
|
14616
|
+
const out = fn(v, new PlainSpan10(pos, end));
|
|
14617
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf9(op === OP_SOURCE_LEAF && hostCst ? input.slice(pos, end) : out, new PlainSpan10(pos, end)));
|
|
14418
14618
|
EC.e = end;
|
|
14419
14619
|
return out;
|
|
14420
14620
|
};
|
|
@@ -14549,7 +14749,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14549
14749
|
const cur = runSyncTerms(input, pos, ctx, values);
|
|
14550
14750
|
if (cur < 0) return FAIL;
|
|
14551
14751
|
EC.e = cur;
|
|
14552
|
-
return projection >= 0 ? values[projection] : fn(values,
|
|
14752
|
+
return projection >= 0 ? values[projection] : fn(values, new PlainSpan10(pos, cur));
|
|
14553
14753
|
};
|
|
14554
14754
|
}
|
|
14555
14755
|
if (wantValues) {
|
|
@@ -14643,7 +14843,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14643
14843
|
const cur = runAdjTerms(input, pos, ctx, values);
|
|
14644
14844
|
if (cur < 0) return FAIL;
|
|
14645
14845
|
EC.e = cur;
|
|
14646
|
-
return projection >= 0 ? values[projection] : fn(values,
|
|
14846
|
+
return projection >= 0 ? values[projection] : fn(values, new PlainSpan10(pos, cur));
|
|
14647
14847
|
};
|
|
14648
14848
|
}
|
|
14649
14849
|
if (wantValues) {
|
|
@@ -14668,7 +14868,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14668
14868
|
return (input, pos, ctx) => {
|
|
14669
14869
|
const v = k0(input, pos, ctx);
|
|
14670
14870
|
if (v === FAIL) return FAIL;
|
|
14671
|
-
return projection === 0 ? v : fn([v],
|
|
14871
|
+
return projection === 0 ? v : fn([v], new PlainSpan10(pos, EC.e));
|
|
14672
14872
|
};
|
|
14673
14873
|
}
|
|
14674
14874
|
if (wantValues) {
|
|
@@ -14693,7 +14893,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14693
14893
|
const cur = step(k1, input, EC.e, ctx);
|
|
14694
14894
|
if (cur < 0) return FAIL;
|
|
14695
14895
|
EC.e = cur;
|
|
14696
|
-
return projection === 0 ? v0 : projection === 1 ? TERMV : fn([v0, TERMV],
|
|
14896
|
+
return projection === 0 ? v0 : projection === 1 ? TERMV : fn([v0, TERMV], new PlainSpan10(pos, cur));
|
|
14697
14897
|
};
|
|
14698
14898
|
}
|
|
14699
14899
|
if (wantValues) {
|
|
@@ -14727,7 +14927,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14727
14927
|
cur = step(k2, input, cur, ctx);
|
|
14728
14928
|
if (cur < 0) return FAIL;
|
|
14729
14929
|
EC.e = cur;
|
|
14730
|
-
return projection === 0 ? v0 : projection === 1 ? v1 : projection === 2 ? TERMV : fn([v0, v1, TERMV],
|
|
14930
|
+
return projection === 0 ? v0 : projection === 1 ? v1 : projection === 2 ? TERMV : fn([v0, v1, TERMV], new PlainSpan10(pos, cur));
|
|
14731
14931
|
};
|
|
14732
14932
|
}
|
|
14733
14933
|
if (wantValues) {
|
|
@@ -14824,7 +15024,7 @@ function assemble(t2, prog, cfg) {
|
|
|
14824
15024
|
const cur = runDirectTerms(input, pos, ctx, values);
|
|
14825
15025
|
if (cur < 0) return FAIL;
|
|
14826
15026
|
EC.e = cur;
|
|
14827
|
-
return projection >= 0 ? values[projection] : fn(values,
|
|
15027
|
+
return projection >= 0 ? values[projection] : fn(values, new PlainSpan10(pos, cur));
|
|
14828
15028
|
};
|
|
14829
15029
|
}
|
|
14830
15030
|
if (wantValues) {
|
|
@@ -15722,10 +15922,10 @@ function assemble(t2, prog, cfg) {
|
|
|
15722
15922
|
return FAIL;
|
|
15723
15923
|
}
|
|
15724
15924
|
const value = regexValue ? input.slice(pos, end) : spec;
|
|
15725
|
-
const leaf2 =
|
|
15925
|
+
const leaf2 = new PlainLeaf9(value, new PlainSpan10(pos, end));
|
|
15726
15926
|
const kids = [leaf2];
|
|
15727
15927
|
const rawKids = [leaf2];
|
|
15728
|
-
const span =
|
|
15928
|
+
const span = new PlainSpan10(pos, end);
|
|
15729
15929
|
EC.e = end;
|
|
15730
15930
|
const nd = build2(kids, void 0, span, rawKids, EMPTY_TL2, void 0);
|
|
15731
15931
|
if (ctx._cstBuf !== void 0 || ctx._cstChildren !== void 0) {
|
|
@@ -15807,7 +16007,7 @@ function assemble(t2, prog, cfg) {
|
|
|
15807
16007
|
const sCh = ctx._cstChildren;
|
|
15808
16008
|
const sCap = ctx.captureTrivia;
|
|
15809
16009
|
const sBuf = ctx._cstBuf;
|
|
15810
|
-
const buf = rawOnly ?
|
|
16010
|
+
const buf = rawOnly ? new PlainBuf2(true, void 0, 0) : omitsRaw ? new PlainBuf2(void 0, true, 0) : new PlainBuf2(void 0, void 0, 0);
|
|
15811
16011
|
ctx._cstBuf = buf;
|
|
15812
16012
|
ctx.captureTrivia = captureWide;
|
|
15813
16013
|
const savedFields = ctx._fields;
|
|
@@ -15829,7 +16029,7 @@ function assemble(t2, prog, cfg) {
|
|
|
15829
16029
|
ctx.captureTrivia = sCap;
|
|
15830
16030
|
if (v === FAIL) return FAIL;
|
|
15831
16031
|
const end = EC.e;
|
|
15832
|
-
const span = tracked ? spanLines(ctx, pos, end) :
|
|
16032
|
+
const span = tracked ? spanLines(ctx, pos, end) : new PlainSpan10(pos, end);
|
|
15833
16033
|
const st = readsState ? ctx.state : void 0;
|
|
15834
16034
|
let nd;
|
|
15835
16035
|
if (unwrap && kids.length === 1) {
|
|
@@ -15853,7 +16053,7 @@ function assemble(t2, prog, cfg) {
|
|
|
15853
16053
|
} else if (host !== void 0) {
|
|
15854
16054
|
nd = host(type, hostKids, fieldMap, span, rawKids, tlog, st, tags);
|
|
15855
16055
|
} else {
|
|
15856
|
-
nd =
|
|
16056
|
+
nd = new PlainNode2(type, span, st ?? null, kids === EMPTY_CH ? kids : [...kids]);
|
|
15857
16057
|
}
|
|
15858
16058
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
15859
16059
|
pushCstChild(ctx, nd, rawEntry(nd, input, pos, end));
|
|
@@ -15879,7 +16079,7 @@ function assemble(t2, prog, cfg) {
|
|
|
15879
16079
|
const at = fe === void 0 || fe < 0 ? pos : fe;
|
|
15880
16080
|
return { ok: false, expected: ctx._fx ?? EMPTY_FX2, span: { start: at, end: at } };
|
|
15881
16081
|
}
|
|
15882
|
-
return { ok: true, value: v, span:
|
|
16082
|
+
return { ok: true, value: v, span: new PlainSpan10(pos, EC.e) };
|
|
15883
16083
|
}
|
|
15884
16084
|
};
|
|
15885
16085
|
}
|
|
@@ -15994,7 +16194,12 @@ function assemble(t2, prog, cfg) {
|
|
|
15994
16194
|
LEAD,
|
|
15995
16195
|
triviaFieldCapture,
|
|
15996
16196
|
skipDeferredTrivia,
|
|
15997
|
-
collapseEmpty
|
|
16197
|
+
collapseEmpty,
|
|
16198
|
+
PlainSpan10,
|
|
16199
|
+
PlainLeaf9,
|
|
16200
|
+
PlainNode2,
|
|
16201
|
+
PlainField,
|
|
16202
|
+
PlainBuf2
|
|
15998
16203
|
);
|
|
15999
16204
|
emitReached = new Set(pre.reached);
|
|
16000
16205
|
if (emitted.ext !== void 0) HYBRID = emitted;
|
|
@@ -16081,7 +16286,12 @@ function assemble(t2, prog, cfg) {
|
|
|
16081
16286
|
LEAD,
|
|
16082
16287
|
triviaFieldCapture,
|
|
16083
16288
|
skipDeferredTrivia,
|
|
16084
|
-
collapseEmpty
|
|
16289
|
+
collapseEmpty,
|
|
16290
|
+
PlainSpan10,
|
|
16291
|
+
PlainLeaf9,
|
|
16292
|
+
PlainNode2,
|
|
16293
|
+
PlainField,
|
|
16294
|
+
PlainBuf2
|
|
16085
16295
|
);
|
|
16086
16296
|
emitReached = em.reached;
|
|
16087
16297
|
} catch (e) {
|
|
@@ -16339,7 +16549,11 @@ function tableRules(source, metadataOrEntry = {}) {
|
|
|
16339
16549
|
return map[entry];
|
|
16340
16550
|
}
|
|
16341
16551
|
|
|
16552
|
+
// src/version.ts
|
|
16553
|
+
var PARSEMAN_VERSION = "0.59.0";
|
|
16554
|
+
|
|
16342
16555
|
// src/table/emit.ts
|
|
16556
|
+
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`)});`;
|
|
16343
16557
|
function jsString(s) {
|
|
16344
16558
|
return JSON.stringify(s);
|
|
16345
16559
|
}
|
|
@@ -16414,7 +16628,7 @@ function emitAssemblies(prog, cfgs) {
|
|
|
16414
16628
|
throw e;
|
|
16415
16629
|
}
|
|
16416
16630
|
const plan = em.plan;
|
|
16417
|
-
out.push(`{key:${key},factory:function(${EMITTED_PARAMS.join(",")}){${em.source}
|
|
16631
|
+
out.push(`{key:${key},factory:function(${EMITTED_PARAMS.join(",")}){${FACTORY_ARITY_GUARD}${em.source}
|
|
16418
16632
|
},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(",")}]}`);
|
|
16419
16633
|
}
|
|
16420
16634
|
return [`a:[${out.join(",")}],`];
|
|
@@ -18037,6 +18251,7 @@ function encodeForRun(ruleMap, opts) {
|
|
|
18037
18251
|
}
|
|
18038
18252
|
|
|
18039
18253
|
// src/compiler/linker.ts
|
|
18254
|
+
import { PlainNode as PlainNode3, PlainTaggedNode } from "../cst/plain.js";
|
|
18040
18255
|
function normalizeCstCollapse(collapse) {
|
|
18041
18256
|
if (collapse === true) return () => true;
|
|
18042
18257
|
if (Array.isArray(collapse)) {
|
|
@@ -18046,7 +18261,7 @@ function normalizeCstCollapse(collapse) {
|
|
|
18046
18261
|
return typeof collapse === "function" ? collapse : void 0;
|
|
18047
18262
|
}
|
|
18048
18263
|
function buildCstNode(type, children2, _fields, span, _rawChildren, _triviaLog, state, tags) {
|
|
18049
|
-
return tags !== void 0 && tags.length > 0 ?
|
|
18264
|
+
return tags !== void 0 && tags.length > 0 ? new PlainTaggedNode(type, tags, copySpan(span), state ?? null, [...children2]) : new PlainNode3(type, copySpan(span), state ?? null, [...children2]);
|
|
18050
18265
|
}
|
|
18051
18266
|
function cstBuildHost(typeOrOptions, children2, _fields, span, rawChildren, triviaLog, state, _tags) {
|
|
18052
18267
|
if (typeof typeOrOptions === "string") {
|