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/plugin/index.js
CHANGED
|
@@ -6,6 +6,35 @@ import { parseSync as parseSync5 } from "oxc-parser";
|
|
|
6
6
|
import { ResolverFactory } from "oxc-resolver";
|
|
7
7
|
import MagicString from "magic-string";
|
|
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, resolve3, 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 fs3.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 fs3.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(fs3, assertion) {
|
|
195
229
|
return assertion === null ? fs3 : fs3.kind === "empty" ? assertion : narrowBy(fs3, assertion);
|
|
@@ -535,6 +569,7 @@ function markUnusedValues(root) {
|
|
|
535
569
|
}
|
|
536
570
|
|
|
537
571
|
// src/line-index.ts
|
|
572
|
+
import { PlainLineSpan, PlainSpan } from "../cst/plain.js";
|
|
538
573
|
function createLineIndex() {
|
|
539
574
|
return { lineStarts: [0] };
|
|
540
575
|
}
|
|
@@ -587,6 +622,27 @@ function annotateSpan(span, index) {
|
|
|
587
622
|
endColumn: e.col
|
|
588
623
|
};
|
|
589
624
|
}
|
|
625
|
+
var SPAN_KEYS = ["start", "end", "startLine", "startColumn", "endLine", "endColumn"];
|
|
626
|
+
function copySpan(span) {
|
|
627
|
+
let n = 0;
|
|
628
|
+
for (const key in span) {
|
|
629
|
+
if (key !== SPAN_KEYS[n]) return { ...span };
|
|
630
|
+
n++;
|
|
631
|
+
}
|
|
632
|
+
if (n === 2) return new PlainSpan(span.start, span.end);
|
|
633
|
+
if (n === 6 && span.startLine !== void 0 && span.startColumn !== void 0 && span.endLine !== void 0 && span.endColumn !== void 0) {
|
|
634
|
+
return new PlainLineSpan(span.start, span.end, span.startLine, span.startColumn, span.endLine, span.endColumn);
|
|
635
|
+
}
|
|
636
|
+
return { ...span };
|
|
637
|
+
}
|
|
638
|
+
function lineSpanFromContext(span, ctx) {
|
|
639
|
+
if (!ctx.trackLines) return span;
|
|
640
|
+
const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
|
|
641
|
+
if (!index) return span;
|
|
642
|
+
const s = offsetToLineCol(index, span.start);
|
|
643
|
+
const e = offsetToLineCol(index, span.end);
|
|
644
|
+
return new PlainLineSpan(span.start, span.end, s.line, s.col, e.line, e.col);
|
|
645
|
+
}
|
|
590
646
|
function annotateSpanFromLineContext(span, ctx) {
|
|
591
647
|
if (!ctx.trackLines) return span;
|
|
592
648
|
const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
|
|
@@ -594,6 +650,7 @@ function annotateSpanFromLineContext(span, ctx) {
|
|
|
594
650
|
}
|
|
595
651
|
|
|
596
652
|
// src/cst/capture-buffer.ts
|
|
653
|
+
import { PlainBuf, PlainLeaf } from "../cst/plain.js";
|
|
597
654
|
var EMPTY = [];
|
|
598
655
|
var EMPTY_TL = [];
|
|
599
656
|
function cstCaptureActive(ctx) {
|
|
@@ -608,7 +665,7 @@ function beginCstNodeCapture(ctx) {
|
|
|
608
665
|
cap: ctx.captureTrivia,
|
|
609
666
|
buf: ctx._cstBuf
|
|
610
667
|
};
|
|
611
|
-
ctx._cstBuf =
|
|
668
|
+
ctx._cstBuf = new PlainBuf(void 0, void 0, 0);
|
|
612
669
|
ctx._cstChildren = void 0;
|
|
613
670
|
ctx._cstLeaves = void 0;
|
|
614
671
|
ctx._cstRawChildren = void 0;
|
|
@@ -633,12 +690,15 @@ function endCstNodeCapture(ctx, saved) {
|
|
|
633
690
|
ctx.captureTrivia = saved.cap;
|
|
634
691
|
return materialized;
|
|
635
692
|
}
|
|
693
|
+
function isLeaf(v) {
|
|
694
|
+
return typeof v === "object" && v !== null && v._tag === "leaf";
|
|
695
|
+
}
|
|
636
696
|
function pushCstLeaf(ctx, leaf2) {
|
|
637
697
|
if (!ctx.trackLines) {
|
|
638
698
|
pushCstChild(ctx, leaf2, leaf2);
|
|
639
699
|
return;
|
|
640
700
|
}
|
|
641
|
-
const annotated = leaf2 && typeof leaf2 === "object" && leaf2.span ? { ...leaf2, span: annotateSpanFromLineContext(leaf2.span, ctx) } : leaf2;
|
|
701
|
+
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;
|
|
642
702
|
pushCstChild(ctx, annotated, annotated);
|
|
643
703
|
}
|
|
644
704
|
function pushCstChild(ctx, built, rawEntry2) {
|
|
@@ -880,11 +940,17 @@ function shorthandRanges(ch2) {
|
|
|
880
940
|
if (ch2 === "s") return SPACE_RANGES;
|
|
881
941
|
return [[48, 57], [65, 90], [97, 122], [95, 95]];
|
|
882
942
|
}
|
|
883
|
-
function readUnicodeEscape(body, i) {
|
|
943
|
+
function readUnicodeEscape(body, i, unicode = false) {
|
|
884
944
|
if (body[i] !== "\\" || body[i + 1] !== "u") return null;
|
|
885
945
|
const hex = body.slice(i + 2, i + 6);
|
|
886
946
|
if (!/^[0-9a-fA-F]{4}$/.test(hex)) return null;
|
|
887
|
-
|
|
947
|
+
const cp = Number.parseInt(hex, 16);
|
|
948
|
+
if (unicode && cp >= 55296 && cp <= 56319 && body[i + 6] === "\\" && body[i + 7] === "u") {
|
|
949
|
+
const lowHex = body.slice(i + 8, i + 12);
|
|
950
|
+
const low = /^[0-9a-fA-F]{4}$/.test(lowHex) ? Number.parseInt(lowHex, 16) : -1;
|
|
951
|
+
if (low >= 56320 && low <= 57343) return { cp: 65536 + (cp - 55296 << 10) + (low - 56320), next: i + 12 };
|
|
952
|
+
}
|
|
953
|
+
return { cp, next: i + 6 };
|
|
888
954
|
}
|
|
889
955
|
var META = new Set("()[]{}*+?|^$.".split(""));
|
|
890
956
|
function literalCodePoints(frag) {
|
|
@@ -896,6 +962,7 @@ function literalCodePoints(frag) {
|
|
|
896
962
|
const e = frag[i + 1];
|
|
897
963
|
if (e === void 0) return null;
|
|
898
964
|
if (!(e in CLASS_ESCAPES) && /\w/.test(e)) return null;
|
|
965
|
+
if (e === "0" && frag[i + 2] !== void 0 && frag[i + 2] >= "0" && frag[i + 2] <= "9") return null;
|
|
899
966
|
out.push(e in CLASS_ESCAPES ? CLASS_ESCAPES[e] : e.codePointAt(0));
|
|
900
967
|
i += 2;
|
|
901
968
|
continue;
|
|
@@ -936,14 +1003,14 @@ function parseClassOperand(body) {
|
|
|
936
1003
|
if (cps && cps.length === 1) return { ranges: [[cps[0], cps[0]]], negated: false };
|
|
937
1004
|
return null;
|
|
938
1005
|
}
|
|
939
|
-
function parseClassRanges(body) {
|
|
1006
|
+
function parseClassRanges(body, unicode = false) {
|
|
940
1007
|
const ranges = [];
|
|
941
1008
|
let i = 0;
|
|
942
1009
|
const readAtom = () => {
|
|
943
1010
|
const ch2 = body[i];
|
|
944
1011
|
if (ch2 === void 0) return null;
|
|
945
1012
|
if (ch2 === "\\") {
|
|
946
|
-
const uni = readUnicodeEscape(body, i);
|
|
1013
|
+
const uni = readUnicodeEscape(body, i, unicode);
|
|
947
1014
|
if (uni) {
|
|
948
1015
|
i = uni.next;
|
|
949
1016
|
return { cp: uni.cp };
|
|
@@ -951,13 +1018,15 @@ function parseClassRanges(body) {
|
|
|
951
1018
|
const e = body[i + 1];
|
|
952
1019
|
if (e === void 0) return null;
|
|
953
1020
|
i += 2;
|
|
1021
|
+
if (e === "0" && body[i] !== void 0 && body[i] >= "0" && body[i] <= "9" || e >= "1" && e <= "9") return null;
|
|
954
1022
|
if (e in CLASS_ESCAPES) return { cp: CLASS_ESCAPES[e] };
|
|
955
1023
|
if (e === "d" || e === "w" || e === "s") return { set: shorthandRanges(e) };
|
|
956
1024
|
if (e >= "a" && e <= "z" || e >= "A" && e <= "Z") return null;
|
|
957
1025
|
return { cp: e.codePointAt(0) };
|
|
958
1026
|
}
|
|
959
|
-
i
|
|
960
|
-
|
|
1027
|
+
const cp = unicode ? body.codePointAt(i) : body.charCodeAt(i);
|
|
1028
|
+
i += cp > 65535 ? 2 : 1;
|
|
1029
|
+
return { cp };
|
|
961
1030
|
};
|
|
962
1031
|
while (i < body.length) {
|
|
963
1032
|
const lo = readAtom();
|
|
@@ -1981,6 +2050,7 @@ function assertionFailureExpected(positive, childTag) {
|
|
|
1981
2050
|
}
|
|
1982
2051
|
|
|
1983
2052
|
// src/combinators/literal.ts
|
|
2053
|
+
import { PlainLeaf as PlainLeaf2, PlainSpan as PlainSpan2 } from "../cst/plain.js";
|
|
1984
2054
|
function asciiFoldEq(a, b) {
|
|
1985
2055
|
if (a.length !== b.length) return false;
|
|
1986
2056
|
for (let i = 0; i < a.length; i++) {
|
|
@@ -2038,9 +2108,9 @@ function literal(value, opts = {}) {
|
|
|
2038
2108
|
const code = value.charCodeAt(0);
|
|
2039
2109
|
return function parse3(input, pos, ctx) {
|
|
2040
2110
|
if (input.charCodeAt(pos) === code) {
|
|
2041
|
-
const span =
|
|
2111
|
+
const span = new PlainSpan2(pos, pos + 1);
|
|
2042
2112
|
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, span.end);
|
|
2043
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
2113
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf2(value, span));
|
|
2044
2114
|
return { ok: true, value, span };
|
|
2045
2115
|
}
|
|
2046
2116
|
return failAt(ctx, expected, pos);
|
|
@@ -2052,9 +2122,9 @@ function literal(value, opts = {}) {
|
|
|
2052
2122
|
}
|
|
2053
2123
|
const matchedValue = caseInsensitive ? input.slice(pos, end) : value;
|
|
2054
2124
|
if (caseInsensitive ? asciiFoldEq(matchedValue, value) : input.startsWith(value, pos)) {
|
|
2055
|
-
const span =
|
|
2125
|
+
const span = new PlainSpan2(pos, end);
|
|
2056
2126
|
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, end);
|
|
2057
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
2127
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf2(matchedValue, span));
|
|
2058
2128
|
return { ok: true, value: matchedValue, span };
|
|
2059
2129
|
}
|
|
2060
2130
|
return failAt(ctx, expected, pos);
|
|
@@ -2083,7 +2153,7 @@ function rangesHaveNewline(ranges) {
|
|
|
2083
2153
|
return ranges.some(([lo, hi]) => lo <= 10 && 10 <= hi);
|
|
2084
2154
|
}
|
|
2085
2155
|
var BAIL = /* @__PURE__ */ Symbol("regex-bail");
|
|
2086
|
-
function parseRegex(src) {
|
|
2156
|
+
function parseRegex(src, unicode = false, sets = false) {
|
|
2087
2157
|
let i = 0;
|
|
2088
2158
|
const parseAlt = () => {
|
|
2089
2159
|
const arms = [parseSeq()];
|
|
@@ -2153,9 +2223,11 @@ function parseRegex(src) {
|
|
|
2153
2223
|
i++;
|
|
2154
2224
|
return charNode(fromRange(123, 123), false);
|
|
2155
2225
|
// a `{` with nothing to quantify is a literal brace
|
|
2156
|
-
default:
|
|
2157
|
-
i
|
|
2158
|
-
|
|
2226
|
+
default: {
|
|
2227
|
+
const cp = unicode ? src.codePointAt(i) : src.charCodeAt(i);
|
|
2228
|
+
i += cp > 65535 ? 2 : 1;
|
|
2229
|
+
return charNode(fromRange(cp, cp), ch2 === "\n");
|
|
2230
|
+
}
|
|
2159
2231
|
}
|
|
2160
2232
|
};
|
|
2161
2233
|
const parseGroup = () => {
|
|
@@ -2188,6 +2260,32 @@ function parseRegex(src) {
|
|
|
2188
2260
|
let k = i + 1;
|
|
2189
2261
|
const negated = src[k] === "^";
|
|
2190
2262
|
if (negated) k++;
|
|
2263
|
+
if (sets) {
|
|
2264
|
+
let depth = 1;
|
|
2265
|
+
let nested = false;
|
|
2266
|
+
while (k < src.length && depth > 0) {
|
|
2267
|
+
const c = src[k];
|
|
2268
|
+
if (c === "\\") {
|
|
2269
|
+
if (src[k + 1] === "q") nested = true;
|
|
2270
|
+
k += 2;
|
|
2271
|
+
continue;
|
|
2272
|
+
}
|
|
2273
|
+
if (c === "[") {
|
|
2274
|
+
depth++;
|
|
2275
|
+
nested = true;
|
|
2276
|
+
} else if (c === "]") {
|
|
2277
|
+
depth--;
|
|
2278
|
+
if (depth === 0) break;
|
|
2279
|
+
} else if ((c === "-" || c === "&") && src[k + 1] === c) nested = true;
|
|
2280
|
+
k++;
|
|
2281
|
+
}
|
|
2282
|
+
if (src[k] !== "]") throw BAIL;
|
|
2283
|
+
if (nested) {
|
|
2284
|
+
i = k + 1;
|
|
2285
|
+
return charNode(any(), true);
|
|
2286
|
+
}
|
|
2287
|
+
k = i + 1 + (negated ? 1 : 0);
|
|
2288
|
+
}
|
|
2191
2289
|
let body = "";
|
|
2192
2290
|
while (k < src.length && src[k] !== "]") {
|
|
2193
2291
|
if (src[k] === "\\") {
|
|
@@ -2200,7 +2298,7 @@ function parseRegex(src) {
|
|
|
2200
2298
|
}
|
|
2201
2299
|
if (src[k] !== "]") throw BAIL;
|
|
2202
2300
|
i = k + 1;
|
|
2203
|
-
const ranges = parseClassRanges(body);
|
|
2301
|
+
const ranges = parseClassRanges(body, unicode);
|
|
2204
2302
|
if (negated) return charNode(any(), !ranges || !rangesHaveNewline(ranges));
|
|
2205
2303
|
if (!ranges) return charNode(any(), true);
|
|
2206
2304
|
return charNode(rangesToSet(ranges), rangesHaveNewline(ranges));
|
|
@@ -2208,9 +2306,20 @@ function parseRegex(src) {
|
|
|
2208
2306
|
const parseEscape = () => {
|
|
2209
2307
|
const e = src[i + 1];
|
|
2210
2308
|
if (e === void 0) throw BAIL;
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
i
|
|
2309
|
+
const uni = readUnicodeEscape(src, i, unicode);
|
|
2310
|
+
if (uni !== null) {
|
|
2311
|
+
i = uni.next;
|
|
2312
|
+
return charNode(fromRange(uni.cp, uni.cp), uni.cp === 10);
|
|
2313
|
+
}
|
|
2314
|
+
if (e === "u" && src[i + 2] === "{") {
|
|
2315
|
+
const close = src.indexOf("}", i + 3);
|
|
2316
|
+
const hex = close < 0 ? "" : src.slice(i + 3, close);
|
|
2317
|
+
if (!unicode || !/^[0-9a-fA-F]{1,6}$/.test(hex)) {
|
|
2318
|
+
i += 2;
|
|
2319
|
+
return ANY;
|
|
2320
|
+
}
|
|
2321
|
+
const cp = Number.parseInt(hex, 16);
|
|
2322
|
+
i = close + 1;
|
|
2214
2323
|
return charNode(fromRange(cp, cp), cp === 10);
|
|
2215
2324
|
}
|
|
2216
2325
|
if (e === "x" && /^[0-9a-fA-F]{2}$/.test(src.slice(i + 2, i + 4))) {
|
|
@@ -2218,6 +2327,16 @@ function parseRegex(src) {
|
|
|
2218
2327
|
i += 4;
|
|
2219
2328
|
return charNode(fromRange(cp, cp), cp === 10);
|
|
2220
2329
|
}
|
|
2330
|
+
if (e === "c") {
|
|
2331
|
+
const x = src[i + 2];
|
|
2332
|
+
if (x !== void 0 && /^[A-Za-z]$/.test(x)) {
|
|
2333
|
+
const cp = x.charCodeAt(0) % 32;
|
|
2334
|
+
i += 3;
|
|
2335
|
+
return charNode(fromRange(cp, cp), cp === 10);
|
|
2336
|
+
}
|
|
2337
|
+
i += 2;
|
|
2338
|
+
return ANY;
|
|
2339
|
+
}
|
|
2221
2340
|
i += 2;
|
|
2222
2341
|
switch (e) {
|
|
2223
2342
|
case "d":
|
|
@@ -2245,8 +2364,16 @@ function parseRegex(src) {
|
|
|
2245
2364
|
return charNode(fromRange(12, 12), false);
|
|
2246
2365
|
case "v":
|
|
2247
2366
|
return charNode(fromRange(11, 11), false);
|
|
2367
|
+
// `\0` then a digit is a legacy octal escape (`\012` is a newline), not NUL.
|
|
2248
2368
|
case "0":
|
|
2249
|
-
return charNode(fromRange(0, 0), false);
|
|
2369
|
+
return src[i] !== void 0 && src[i] >= "0" && src[i] <= "9" ? ANY : charNode(fromRange(0, 0), false);
|
|
2370
|
+
// A property escape (`\p{…}`/`\P{…}`) matches one character of a class this
|
|
2371
|
+
// analyzer does not enumerate; `\k<name>` is a backreference, which may match empty.
|
|
2372
|
+
case "p":
|
|
2373
|
+
case "P":
|
|
2374
|
+
return charNode(any(), true);
|
|
2375
|
+
case "k":
|
|
2376
|
+
return ANY;
|
|
2250
2377
|
default:
|
|
2251
2378
|
if (e >= "1" && e <= "9") return ANY;
|
|
2252
2379
|
return charNode(fromRange(e.codePointAt(0), e.codePointAt(0)), e === "\n");
|
|
@@ -2320,10 +2447,10 @@ function regexCanMatchEmpty(source) {
|
|
|
2320
2447
|
return true;
|
|
2321
2448
|
}
|
|
2322
2449
|
}
|
|
2323
|
-
function firstSetFromRegex(source) {
|
|
2450
|
+
function firstSetFromRegex(source, flags = "") {
|
|
2324
2451
|
let ast2;
|
|
2325
2452
|
try {
|
|
2326
|
-
ast2 = parseRegex(source);
|
|
2453
|
+
ast2 = parseRegex(source, flags.includes("u") || flags.includes("v"), flags.includes("v"));
|
|
2327
2454
|
} catch {
|
|
2328
2455
|
return { firstSet: any(), canMatchNewline: true };
|
|
2329
2456
|
}
|
|
@@ -2332,6 +2459,7 @@ function firstSetFromRegex(source) {
|
|
|
2332
2459
|
}
|
|
2333
2460
|
|
|
2334
2461
|
// src/combinators/regex.ts
|
|
2462
|
+
import { PlainLeaf as PlainLeaf3, PlainSpan as PlainSpan3 } from "../cst/plain.js";
|
|
2335
2463
|
var SCAN_BAIL_AT = 64;
|
|
2336
2464
|
function inRanges2(cp, ranges) {
|
|
2337
2465
|
for (let i = 0; i < ranges.length; i++) {
|
|
@@ -2372,8 +2500,18 @@ function shortScanner(source, flags) {
|
|
|
2372
2500
|
return minOne && end === pos ? null : end;
|
|
2373
2501
|
};
|
|
2374
2502
|
}
|
|
2503
|
+
function coversNonAscii(ranges) {
|
|
2504
|
+
let next = 128;
|
|
2505
|
+
for (const r of [...ranges].sort((a, b) => a.lo - b.lo)) {
|
|
2506
|
+
if (r.lo > next) return false;
|
|
2507
|
+
if (r.hi >= next) next = r.hi + 1;
|
|
2508
|
+
if (next > 65535) return true;
|
|
2509
|
+
}
|
|
2510
|
+
return false;
|
|
2511
|
+
}
|
|
2375
2512
|
function asciiCaseFold(fs3) {
|
|
2376
2513
|
if (fs3.kind !== "ranges") return fs3;
|
|
2514
|
+
if (fs3.ranges.some((r) => r.hi >= 128) && !coversNonAscii(fs3.ranges)) return any();
|
|
2377
2515
|
const ranges = fs3.ranges.map((r) => ({ lo: r.lo, hi: r.hi }));
|
|
2378
2516
|
const add = (lo, hi) => {
|
|
2379
2517
|
if (lo <= hi) ranges.push({ lo, hi });
|
|
@@ -2398,7 +2536,7 @@ function regex(pattern, flags = "") {
|
|
|
2398
2536
|
const resolvedFlags = typeof pattern === "string" ? flags : pattern.flags;
|
|
2399
2537
|
const anchored = new RegExp(source, "y" + resolvedFlags.replace(/[gy]/g, ""));
|
|
2400
2538
|
const scan = shortScanner(source, resolvedFlags);
|
|
2401
|
-
const raw = firstSetFromRegex(source);
|
|
2539
|
+
const raw = firstSetFromRegex(source, resolvedFlags);
|
|
2402
2540
|
const firstSet2 = !resolvedFlags.includes("i") ? raw.firstSet : resolvedFlags.includes("u") || resolvedFlags.includes("v") ? any() : asciiCaseFold(raw.firstSet);
|
|
2403
2541
|
const canMatchNewline = raw.canMatchNewline;
|
|
2404
2542
|
const meta = { firstSet: firstSet2, canMatchNewline, isTrivia: false };
|
|
@@ -2434,9 +2572,9 @@ function regex(pattern, flags = "") {
|
|
|
2434
2572
|
if (scanEnd !== void 0) {
|
|
2435
2573
|
if (scanEnd === null) return failAt(ctx, directTerminalFailureExpected(def), pos);
|
|
2436
2574
|
const value = input.slice(pos, scanEnd);
|
|
2437
|
-
const span2 =
|
|
2575
|
+
const span2 = new PlainSpan3(pos, scanEnd);
|
|
2438
2576
|
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, scanEnd);
|
|
2439
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
2577
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf3(value, span2));
|
|
2440
2578
|
return { ok: true, value, span: span2 };
|
|
2441
2579
|
}
|
|
2442
2580
|
anchored.lastIndex = pos;
|
|
@@ -2444,9 +2582,9 @@ function regex(pattern, flags = "") {
|
|
|
2444
2582
|
if (m === null) {
|
|
2445
2583
|
return failAt(ctx, directTerminalFailureExpected(def), pos);
|
|
2446
2584
|
}
|
|
2447
|
-
const span =
|
|
2585
|
+
const span = new PlainSpan3(pos, pos + m[0].length);
|
|
2448
2586
|
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, span.end);
|
|
2449
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
2587
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf3(m[0], span));
|
|
2450
2588
|
return { ok: true, value: m[0], span };
|
|
2451
2589
|
}
|
|
2452
2590
|
};
|
|
@@ -2488,6 +2626,7 @@ function caseFoldVariants(cp) {
|
|
|
2488
2626
|
}
|
|
2489
2627
|
|
|
2490
2628
|
// src/combinators/keywords.ts
|
|
2629
|
+
import { PlainLeaf as PlainLeaf4, PlainSpan as PlainSpan4 } from "../cst/plain.js";
|
|
2491
2630
|
function word(str, boundaryOrOpts, opts) {
|
|
2492
2631
|
const boundary = typeof boundaryOrOpts === "string" ? boundaryOrOpts : "_0-9A-Za-z";
|
|
2493
2632
|
const rest = typeof boundaryOrOpts === "object" && boundaryOrOpts !== null ? boundaryOrOpts : opts;
|
|
@@ -2541,8 +2680,8 @@ function keywords(words, opts = {}) {
|
|
|
2541
2680
|
const m = re.exec(input);
|
|
2542
2681
|
if (m === null) return failAt(ctx, directTerminalFailureExpected(def), pos);
|
|
2543
2682
|
const value = m[0];
|
|
2544
|
-
const span =
|
|
2545
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
2683
|
+
const span = new PlainSpan4(pos, pos + value.length);
|
|
2684
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf4(value, span));
|
|
2546
2685
|
return { ok: true, value, span };
|
|
2547
2686
|
}
|
|
2548
2687
|
};
|
|
@@ -3167,6 +3306,7 @@ function altStarSource(source) {
|
|
|
3167
3306
|
}
|
|
3168
3307
|
|
|
3169
3308
|
// src/recovery/scan.ts
|
|
3309
|
+
import { PlainSpan as PlainSpan5 } from "../cst/plain.js";
|
|
3170
3310
|
function probeAt(sentinel, input, pos, ctx) {
|
|
3171
3311
|
const s = {
|
|
3172
3312
|
_probe: ctx._probe,
|
|
@@ -3234,9 +3374,7 @@ function firstSetSentinel(fs3) {
|
|
|
3234
3374
|
parse(input, pos) {
|
|
3235
3375
|
const code = pos < input.length ? input.codePointAt(pos) : void 0;
|
|
3236
3376
|
if (code !== void 0) {
|
|
3237
|
-
|
|
3238
|
-
if (code >= r.lo && code <= r.hi) return { ok: true, value: null, span: { start: pos, end: pos } };
|
|
3239
|
-
}
|
|
3377
|
+
if (rangesHaveLead(ranges, code)) return { ok: true, value: null, span: { start: pos, end: pos } };
|
|
3240
3378
|
}
|
|
3241
3379
|
return { ok: false, expected: [], span: { start: pos, end: pos } };
|
|
3242
3380
|
}
|
|
@@ -3245,7 +3383,7 @@ function firstSetSentinel(fs3) {
|
|
|
3245
3383
|
function recoverScan(input, from, ctx, sync, expected) {
|
|
3246
3384
|
let scanPos = from;
|
|
3247
3385
|
while (scanPos < input.length && !probeAt(sync, input, scanPos, ctx)) scanPos++;
|
|
3248
|
-
const span =
|
|
3386
|
+
const span = new PlainSpan5(from, scanPos);
|
|
3249
3387
|
if (ctx.trackLines) recordLineRangeFromContext(ctx, input, from, scanPos);
|
|
3250
3388
|
const error = { _tag: "parseError", span: ctx.trackLines ? annotateSpanFromLineContext(span, ctx) : span, expected };
|
|
3251
3389
|
ctx._errors?.push(error);
|
|
@@ -3325,17 +3463,18 @@ function notAdjacent(options) {
|
|
|
3325
3463
|
}
|
|
3326
3464
|
|
|
3327
3465
|
// src/combinators/field-trivia.ts
|
|
3466
|
+
import { PlainSpan as PlainSpan6, PlainTriviaField } from "../cst/plain.js";
|
|
3328
3467
|
var LEAD = { at: -1 };
|
|
3329
3468
|
var FIELD_LEADING_TRIVIA = 1;
|
|
3330
3469
|
var FIELD_TRAILING_TRIVIA = 2;
|
|
3331
3470
|
function triviaFieldCapture(name, value, input, start, end, leadFrom, trailEnd) {
|
|
3332
|
-
return
|
|
3471
|
+
return new PlainTriviaField(
|
|
3333
3472
|
name,
|
|
3334
3473
|
value,
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3474
|
+
new PlainSpan6(start, end),
|
|
3475
|
+
leadFrom >= 0 && leadFrom < start ? input.slice(leadFrom, start) : "",
|
|
3476
|
+
trailEnd > end ? input.slice(end, trailEnd) : ""
|
|
3477
|
+
);
|
|
3339
3478
|
}
|
|
3340
3479
|
function leadsTrivia(p) {
|
|
3341
3480
|
return p._def.tag === "field" && p._def.leadingTrivia === true;
|
|
@@ -3887,6 +4026,9 @@ function inFirstSet(code, fs3) {
|
|
|
3887
4026
|
if (fs3.kind === "any") return true;
|
|
3888
4027
|
if (fs3.kind === "empty") return false;
|
|
3889
4028
|
for (const r of fs3.ranges) if (code >= r.lo && code <= r.hi) return true;
|
|
4029
|
+
if (code <= 65535) return false;
|
|
4030
|
+
const high = 55296 + (code - 65536 >> 10);
|
|
4031
|
+
for (const r of fs3.ranges) if (high >= r.lo && high <= r.hi) return true;
|
|
3890
4032
|
return false;
|
|
3891
4033
|
}
|
|
3892
4034
|
function areDisjoint(sets) {
|
|
@@ -3911,6 +4053,7 @@ function buildAsciiDispatch(parsers) {
|
|
|
3911
4053
|
}
|
|
3912
4054
|
|
|
3913
4055
|
// src/combinators/dispatch.ts
|
|
4056
|
+
import { PlainLeaf as PlainLeaf5 } from "../cst/plain.js";
|
|
3914
4057
|
function parserUsesRouted(parser2, seen = /* @__PURE__ */ new Set()) {
|
|
3915
4058
|
if (seen.has(parser2)) return false;
|
|
3916
4059
|
seen.add(parser2);
|
|
@@ -4047,7 +4190,7 @@ function routed(fallback2) {
|
|
|
4047
4190
|
return { ok: false, expected: ["routed()"], span: { start: pos, end: pos } };
|
|
4048
4191
|
}
|
|
4049
4192
|
if (cstCaptureActive(ctx)) {
|
|
4050
|
-
pushCstLeaf(ctx,
|
|
4193
|
+
pushCstLeaf(ctx, new PlainLeaf5(item.value, item.span));
|
|
4051
4194
|
}
|
|
4052
4195
|
return { ok: true, value: item.value, span: item.span };
|
|
4053
4196
|
}
|
|
@@ -4997,6 +5140,7 @@ function buildFieldMap(captures) {
|
|
|
4997
5140
|
}
|
|
4998
5141
|
|
|
4999
5142
|
// src/combinators/node.ts
|
|
5143
|
+
import { PlainNode, PlainSpan as PlainSpan7 } from "../cst/plain.js";
|
|
5000
5144
|
function unwrapChild(child) {
|
|
5001
5145
|
return child !== null && typeof child === "object" && child._tag === "leaf" ? child.value : child;
|
|
5002
5146
|
}
|
|
@@ -5102,7 +5246,7 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
5102
5246
|
const nodeType = def.type ?? missingInferredType();
|
|
5103
5247
|
const cstOutput = cstOutputHost(ctx.build);
|
|
5104
5248
|
const span = ctx.trackLines ? annotateSpanFromLineContext(r.span, ctx) : r.span;
|
|
5105
|
-
const built = unwrap && children3.length === 1 ? unwrapChild(children3[0]) : collapse && children3.length === 1 ? children3[0] : (cstOutput || !build && project === void 0) && ctx.build?._parsemanCstCollapse && children3.length === 1 && rawChildren.length === 1 && ctx.build._parsemanCstCollapse(nodeType, children3[0], children3, rawChildren) ? children3[0] : project !== void 0 ? cstOutput && ctx.build ? ctx.build(nodeType, children3, fields, span, rawChildren, triviaLog, ctx.state, tags) : projectChild(children3, project, nodeType) : build ? cstOutput && ctx.build ? ctx.build(nodeType, children3, fields, span, rawChildren, triviaLog, ctx.state, tags) : build(children3, fields, span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children3, fields, span, rawChildren, triviaLog, st, tags) :
|
|
5249
|
+
const built = unwrap && children3.length === 1 ? unwrapChild(children3[0]) : collapse && children3.length === 1 ? children3[0] : (cstOutput || !build && project === void 0) && ctx.build?._parsemanCstCollapse && children3.length === 1 && rawChildren.length === 1 && ctx.build._parsemanCstCollapse(nodeType, children3[0], children3, rawChildren) ? children3[0] : project !== void 0 ? cstOutput && ctx.build ? ctx.build(nodeType, children3, fields, span, rawChildren, triviaLog, ctx.state, tags) : projectChild(children3, project, nodeType) : build ? cstOutput && ctx.build ? ctx.build(nodeType, children3, fields, span, rawChildren, triviaLog, ctx.state, tags) : build(children3, fields, span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children3, fields, span, rawChildren, triviaLog, st, tags) : new PlainNode(nodeType, ctx.trackLines ? copySpan(span) : new PlainSpan7(r.span.start, r.span.end), st ?? null, [...children3]);
|
|
5106
5250
|
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 };
|
|
5107
5251
|
if (saved.buf !== void 0 || saved.ch !== void 0) {
|
|
5108
5252
|
pushCstChild(ctx, built, rawEntry2);
|
|
@@ -5258,6 +5402,7 @@ function field(name, combinator, opts) {
|
|
|
5258
5402
|
}
|
|
5259
5403
|
|
|
5260
5404
|
// src/combinators/token.ts
|
|
5405
|
+
import { PlainLeaf as PlainLeaf6 } from "../cst/plain.js";
|
|
5261
5406
|
function semanticLeafValue(_ctx, _input, _start, _end, value) {
|
|
5262
5407
|
return value;
|
|
5263
5408
|
}
|
|
@@ -5311,7 +5456,7 @@ function token(root) {
|
|
|
5311
5456
|
if (!result.ok) return result;
|
|
5312
5457
|
const span = result.span;
|
|
5313
5458
|
const value = input.slice(pos, span.end);
|
|
5314
|
-
if (wasCapturing) pushCstLeaf(ctx,
|
|
5459
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf6(value, span));
|
|
5315
5460
|
return { ok: true, value, span };
|
|
5316
5461
|
}
|
|
5317
5462
|
};
|
|
@@ -5359,11 +5504,7 @@ function makeLeaf(root, fn, sourceCstValue) {
|
|
|
5359
5504
|
}
|
|
5360
5505
|
if (!result.ok) return result;
|
|
5361
5506
|
const value = fn(result.value, result.span);
|
|
5362
|
-
if (wasCapturing) pushCstLeaf(ctx,
|
|
5363
|
-
_tag: "leaf",
|
|
5364
|
-
value: cstValue(ctx, input, pos, result.span.end, value),
|
|
5365
|
-
span: result.span
|
|
5366
|
-
});
|
|
5507
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf6(cstValue(ctx, input, pos, result.span.end, value), result.span));
|
|
5367
5508
|
return { ok: true, value, span: result.span };
|
|
5368
5509
|
}
|
|
5369
5510
|
};
|
|
@@ -5396,6 +5537,7 @@ function buildLexBodyRecognizer(spec, constants) {
|
|
|
5396
5537
|
}
|
|
5397
5538
|
|
|
5398
5539
|
// src/table/run-support.ts
|
|
5540
|
+
import { PlainLeaf as PlainLeaf7, PlainLineSpan as PlainLineSpan2, PlainSpan as PlainSpan8 } from "../cst/plain.js";
|
|
5399
5541
|
function lineCol(ctx, offset) {
|
|
5400
5542
|
const starts = ctx._lineStarts ?? [0];
|
|
5401
5543
|
let lo = 0, hi = starts.length - 1;
|
|
@@ -5408,18 +5550,14 @@ function lineCol(ctx, offset) {
|
|
|
5408
5550
|
}
|
|
5409
5551
|
function spanLines(ctx, start, end) {
|
|
5410
5552
|
const s = lineCol(ctx, start), e = lineCol(ctx, end);
|
|
5411
|
-
return
|
|
5553
|
+
return new PlainLineSpan2(start, end, s[0], s[1], e[0], e[1]);
|
|
5412
5554
|
}
|
|
5413
5555
|
function rawEntry(v, input, s, e) {
|
|
5414
5556
|
if (typeof v === "object" && v !== null) {
|
|
5415
5557
|
const tg = v._tag;
|
|
5416
5558
|
if (tg === "node" || tg === "leaf" || tg === "parseError") return v;
|
|
5417
5559
|
}
|
|
5418
|
-
return
|
|
5419
|
-
_tag: "leaf",
|
|
5420
|
-
value: typeof v === "string" ? v : typeof v === "object" && v !== null ? input.slice(s, e) : "",
|
|
5421
|
-
span: { start: s, end: e }
|
|
5422
|
-
};
|
|
5560
|
+
return new PlainLeaf7(typeof v === "string" ? v : typeof v === "object" && v !== null ? input.slice(s, e) : "", new PlainSpan8(s, e));
|
|
5423
5561
|
}
|
|
5424
5562
|
function lead(input, pos) {
|
|
5425
5563
|
if (pos >= input.length) return -1;
|
|
@@ -5433,7 +5571,7 @@ function collapseEmpty(ctx, build, input, pos, end, readsRaw) {
|
|
|
5433
5571
|
const collected = ctx._cstBuf !== void 0 || ctx._cstChildren !== void 0;
|
|
5434
5572
|
if (collected) popCstChild(ctx);
|
|
5435
5573
|
const raw = readsRaw ? [rawEntry(void 0, input, pos, end)] : EMPTY_KIDS;
|
|
5436
|
-
const nd = build(EMPTY_KIDS, void 0,
|
|
5574
|
+
const nd = build(EMPTY_KIDS, void 0, new PlainSpan8(pos, end), raw, EMPTY_TRIVIA, void 0);
|
|
5437
5575
|
if (collected) pushCstChild(ctx, nd, ctx._cstBuf?.noRaw === true ? void 0 : rawEntry(nd, input, pos, end));
|
|
5438
5576
|
return nd;
|
|
5439
5577
|
}
|
|
@@ -6103,7 +6241,7 @@ function decodeClassSpec(spec) {
|
|
|
6103
6241
|
function resolveClass(spec) {
|
|
6104
6242
|
const ascii = new Uint8Array(128);
|
|
6105
6243
|
const hi = [];
|
|
6106
|
-
for (const { lo, hi: up } of decodeClassSpec(spec)) {
|
|
6244
|
+
for (const { lo, hi: up } of leadRanges(decodeClassSpec(spec))) {
|
|
6107
6245
|
if (lo < 128) for (let c = lo; c <= Math.min(up, 127); c++) ascii[c] = 1;
|
|
6108
6246
|
if (up >= 128) hi.push(Math.max(lo, 128), up);
|
|
6109
6247
|
}
|
|
@@ -8821,6 +8959,7 @@ function parseSeqParts(source) {
|
|
|
8821
8959
|
cp2 = uni.cp;
|
|
8822
8960
|
i = uni.next;
|
|
8823
8961
|
} else if (e === void 0) return null;
|
|
8962
|
+
else if (e >= "0" && e <= "9" && (e !== "0" || source[i + 2] !== void 0 && source[i + 2] >= "0" && source[i + 2] <= "9")) return null;
|
|
8824
8963
|
else if (e in CLASS_ESCAPES) {
|
|
8825
8964
|
cp2 = CLASS_ESCAPES[e];
|
|
8826
8965
|
i += 2;
|
|
@@ -9370,7 +9509,7 @@ function parseScanShapeCore(source) {
|
|
|
9370
9509
|
return null;
|
|
9371
9510
|
}
|
|
9372
9511
|
function scanShapeFromRegex(source, flags) {
|
|
9373
|
-
if (/[
|
|
9512
|
+
if (/[msuv]/.test(flags)) return null;
|
|
9374
9513
|
if (/i/.test(flags)) return caseFoldShape(source);
|
|
9375
9514
|
return parseScanShape(source);
|
|
9376
9515
|
}
|
|
@@ -9975,7 +10114,7 @@ function triviaLeadRanges(tri, trivia2) {
|
|
|
9975
10114
|
const fs3 = trivia2[tri]?._meta.firstSet;
|
|
9976
10115
|
if (fs3 === void 0) return void 0;
|
|
9977
10116
|
if (fs3.kind === "empty") return [];
|
|
9978
|
-
return fs3.kind === "ranges" && fs3.ranges !== void 0 ? fs3.ranges : void 0;
|
|
10117
|
+
return fs3.kind === "ranges" && fs3.ranges !== void 0 ? leadRanges(fs3.ranges) : void 0;
|
|
9979
10118
|
}
|
|
9980
10119
|
|
|
9981
10120
|
// src/table/scalar-terminal.ts
|
|
@@ -10333,7 +10472,14 @@ var EMITTED_PARAMS = [
|
|
|
10333
10472
|
"skipDeferredTrivia",
|
|
10334
10473
|
// Appended for the pass-through collapse (`run-support.ts`); old factories
|
|
10335
10474
|
// ignore it.
|
|
10336
|
-
"collapseEmpty"
|
|
10475
|
+
"collapseEmpty",
|
|
10476
|
+
// Appended for constructor-built tree objects (`cst/plain.d.ts`): a `new` call has
|
|
10477
|
+
// no allocation site, so V8 cannot pretenure them. Old factories ignore them.
|
|
10478
|
+
"_SP",
|
|
10479
|
+
"_LF",
|
|
10480
|
+
"_ND",
|
|
10481
|
+
"_FC",
|
|
10482
|
+
"_BUF"
|
|
10337
10483
|
];
|
|
10338
10484
|
var RUNTIME_PRELUDE = `
|
|
10339
10485
|
let _pfScan=null
|
|
@@ -10357,9 +10503,9 @@ if(s!==null)return skipTriviaScanned(s,input,cur,ctx)
|
|
|
10357
10503
|
if(needsDeferredTriviaCommit(ctx))return skipDeferredTrivia(input,cur,ctx)
|
|
10358
10504
|
return advanceTrivia(input,cur,ctx)
|
|
10359
10505
|
}
|
|
10360
|
-
function _pushLeaf(ctx,value,s,e){pushCstLeaf(ctx,
|
|
10506
|
+
function _pushLeaf(ctx,value,s,e){pushCstLeaf(ctx,new _LF(value,new _SP(s,e)))}
|
|
10361
10507
|
function _pushLeafBuf(ctx,value,s,e){
|
|
10362
|
-
const l=
|
|
10508
|
+
const l=new _LF(value,new _SP(s,e))
|
|
10363
10509
|
const b=ctx._cstBuf
|
|
10364
10510
|
if(b.ch!==undefined)b.ch.push(l)
|
|
10365
10511
|
else if(b.single!==undefined){b.ch=[b.single,l];b.single=undefined}
|
|
@@ -10417,7 +10563,7 @@ if(ctx._rootTriviaLog!==undefined&&ctx._rootTriviaLog.length!==rt)ctx._rootTrivi
|
|
|
10417
10563
|
`;
|
|
10418
10564
|
var NO_RAW_RUNTIME_PRELUDE = `
|
|
10419
10565
|
function _pushLeafNoRawBuf(ctx,value,s,e){
|
|
10420
|
-
const l=
|
|
10566
|
+
const l=new _LF(value,new _SP(s,e))
|
|
10421
10567
|
const b=ctx._cstBuf
|
|
10422
10568
|
if(b.ch!==undefined)b.ch.push(l)
|
|
10423
10569
|
else if(b.single!==undefined){b.ch=[b.single,l];b.single=undefined}
|
|
@@ -10505,7 +10651,7 @@ if(ctx._errors!==undefined&&ctx._errors.length!==${t}er)ctx._errors.length=${t}e
|
|
|
10505
10651
|
if (!s.fd && !s.er) return `if(${t}n)rollbackTriviaAt(ctx,${t}raw,${t}tl,${t}lv,undefined,undefined,${t}lg,${t}rt)`;
|
|
10506
10652
|
return `if(${t}n){rollbackTriviaAt(ctx,${t}raw,${t}tl,${t}lv,${s.fd ? `${t}fd` : "undefined"},${s.er ? `${t}er` : "undefined"},${t}lg,${t}rt)}`;
|
|
10507
10653
|
}
|
|
10508
|
-
function emitTerm(callee, dst, t, l, skip) {
|
|
10654
|
+
function emitTerm(callee, dst, t, l, skip, miss) {
|
|
10509
10655
|
const fast = `const ${t}v=${callee}(input,cur,ctx)
|
|
10510
10656
|
if(${t}v===FAIL)return FAIL
|
|
10511
10657
|
${dst}=${t}v
|
|
@@ -10523,7 +10669,12 @@ if(${t}v===FAIL)return FAIL
|
|
|
10523
10669
|
${dst}=${t}v
|
|
10524
10670
|
if(EC.e>${t}s)cur=EC.e
|
|
10525
10671
|
else{rollbackScannedTriviaAt(ctx,${t}tl,${t}stl,${t}lg,${t}slg,${t}rt,${t}srt)}`;
|
|
10526
|
-
if (l.tri !== TRI_UNKNOWN) return scanned
|
|
10672
|
+
if (l.tri !== TRI_UNKNOWN) return miss === void 0 ? scanned : `const ${t}c=input.charCodeAt(cur)
|
|
10673
|
+
if(${miss(`${t}c`)}){
|
|
10674
|
+
${fast}
|
|
10675
|
+
}else{
|
|
10676
|
+
${scanned}
|
|
10677
|
+
}`;
|
|
10527
10678
|
return `if(ctx.trivia===undefined){
|
|
10528
10679
|
${fast}
|
|
10529
10680
|
}else{
|
|
@@ -10579,7 +10730,7 @@ function rebuildPools(cc, fx, disp, plan) {
|
|
|
10579
10730
|
})
|
|
10580
10731
|
};
|
|
10581
10732
|
}
|
|
10582
|
-
function emitAssemblySource(t, prog, cfg, extraIps = [], staticBuild = false, select) {
|
|
10733
|
+
function emitAssemblySource(t, prog, cfg, extraIps = [], staticBuild = false, select, scanSinkNeutral = false) {
|
|
10583
10734
|
const { code, k, fx, disp, dsp, triviaLabelled } = t;
|
|
10584
10735
|
const swapLegal = !cfg.trackLines;
|
|
10585
10736
|
const hostCst = cfg.hostCst;
|
|
@@ -10655,7 +10806,7 @@ function emitAssemblySource(t, prog, cfg, extraIps = [], staticBuild = false, se
|
|
|
10655
10806
|
const op = code[ip];
|
|
10656
10807
|
sinkBits.set(
|
|
10657
10808
|
ip,
|
|
10658
|
-
op === OP_SCAN ? 3 : (op === OP_FIELD ? 1 : 0) | (op === OP_EXPECT || REC2 && (op === OP_REP || op === OP_REPV) ? 2 : 0)
|
|
10809
|
+
op === OP_SCAN || !scanSinkNeutral && op === OP_LEX_PROGRAM && t.lexPrograms[code[ip + 1]].scan !== void 0 ? 3 : (op === OP_FIELD ? 1 : 0) | (op === OP_EXPECT || REC2 && (op === OP_REP || op === OP_REPV) ? 2 : 0)
|
|
10659
10810
|
);
|
|
10660
10811
|
}
|
|
10661
10812
|
const sinkKids = [];
|
|
@@ -10828,6 +10979,12 @@ return 1
|
|
|
10828
10979
|
return `if(${gateMissTest(child)}){${miss}}
|
|
10829
10980
|
`;
|
|
10830
10981
|
}
|
|
10982
|
+
function triviaMiss(ki) {
|
|
10983
|
+
const leads = triviaLeadRanges(ki, t.trivia);
|
|
10984
|
+
if (leads === void 0 || leads.length > 16) return void 0;
|
|
10985
|
+
if (leads.length === 0) return (c) => `${c}<55296`;
|
|
10986
|
+
return (c) => `${c}<55296&&!(${leads.map((r) => r.lo === r.hi ? `${c}===${r.lo}` : `(${c}>=${r.lo}&&${c}<=${r.hi})`).join("||")})`;
|
|
10987
|
+
}
|
|
10831
10988
|
function skipFor(l) {
|
|
10832
10989
|
if (l.tri < 0) return "_skipTrivia";
|
|
10833
10990
|
const ki = l.tri;
|
|
@@ -10838,8 +10995,13 @@ return 1
|
|
|
10838
10995
|
const nm = `_sk${skipPool.size}`;
|
|
10839
10996
|
skipPool.set(key, nm);
|
|
10840
10997
|
if (!hasScan) {
|
|
10841
|
-
|
|
10842
|
-
|
|
10998
|
+
const miss = triviaMiss(ki);
|
|
10999
|
+
const pre = miss === void 0 ? "" : `const c=input.charCodeAt(cur)
|
|
11000
|
+
if(${miss("c")})return cur
|
|
11001
|
+
`;
|
|
11002
|
+
skipDefs.push(l.buf ? `function ${nm}(input,cur,ctx){${pre === "" ? "" : `
|
|
11003
|
+
${pre}`}return skipDeferredTrivia(input,cur,ctx)}` : `function ${nm}(input,cur,ctx){
|
|
11004
|
+
${pre}if(needsDeferredTriviaCommit(ctx))return skipDeferredTrivia(input,cur,ctx)
|
|
10843
11005
|
return advanceTrivia(input,cur,ctx)}`);
|
|
10844
11006
|
return nm;
|
|
10845
11007
|
}
|
|
@@ -11078,7 +11240,7 @@ try{return ${child}(input,pos,ctx)}finally{ctx.state=saved}
|
|
|
11078
11240
|
return `${head}
|
|
11079
11241
|
const v=${child}(input,pos,ctx)
|
|
11080
11242
|
if(v===FAIL)return FAIL
|
|
11081
|
-
return ${fn}(v,
|
|
11243
|
+
return ${fn}(v,new _SP(pos,EC.e))
|
|
11082
11244
|
}`;
|
|
11083
11245
|
}
|
|
11084
11246
|
case OP_LABEL: {
|
|
@@ -11099,7 +11261,7 @@ return v
|
|
|
11099
11261
|
const v=${child}(input,pos,ctx)
|
|
11100
11262
|
if(v===FAIL)return FAIL
|
|
11101
11263
|
const f=ctx._fields
|
|
11102
|
-
if(f!==undefined)f.push({name
|
|
11264
|
+
if(f!==undefined)f.push(new _FC(${name},v,new _SP(pos,EC.e)))
|
|
11103
11265
|
return v
|
|
11104
11266
|
}`;
|
|
11105
11267
|
}
|
|
@@ -11124,7 +11286,7 @@ return v
|
|
|
11124
11286
|
return `${head}
|
|
11125
11287
|
const v=${child}(input,pos,ctx)
|
|
11126
11288
|
if(v!==FAIL)return v
|
|
11127
|
-
const err={_tag:'parseError',span:${prog.lines === 1 ? "spanLines(ctx,pos,pos)" : "
|
|
11289
|
+
const err={_tag:'parseError',span:${prog.lines === 1 ? "spanLines(ctx,pos,pos)" : "new _SP(pos,pos)"},expected:${xf}}
|
|
11128
11290
|
const es=ctx._errors
|
|
11129
11291
|
if(es!==undefined)es.push(err)
|
|
11130
11292
|
${REC2 ? "if(ctx._tolerant===true)captureError(ctx,err)\n" : ""}ctx._fc=false
|
|
@@ -11135,7 +11297,7 @@ return err
|
|
|
11135
11297
|
case OP_ROUTED: {
|
|
11136
11298
|
const fb = code[ip + 1];
|
|
11137
11299
|
const fallback2 = fb >= 0 ? link(fb) : void 0;
|
|
11138
|
-
const push = `pushCstLeaf(ctx,
|
|
11300
|
+
const push = `pushCstLeaf(ctx,new _LF(it.value,it.span))`;
|
|
11139
11301
|
return `${head}
|
|
11140
11302
|
const it=ctx._routed
|
|
11141
11303
|
if(it===undefined||pos!==it.span.start){
|
|
@@ -11216,8 +11378,8 @@ ctx._triviaLog=sOtl
|
|
|
11216
11378
|
}
|
|
11217
11379
|
if(v===FAIL)return FAIL
|
|
11218
11380
|
const e=EC.e
|
|
11219
|
-
const out=${isToken ? "input.slice(pos,e)" : `${fn}(v,
|
|
11220
|
-
if(wasCap)pushCstLeaf(ctx,{
|
|
11381
|
+
const out=${isToken ? "input.slice(pos,e)" : `${fn}(v,new _SP(pos,e))`}
|
|
11382
|
+
if(wasCap)pushCstLeaf(ctx,new _LF(${capturesSource ? "input.slice(pos,e)" : "out"},new _SP(pos,e)))
|
|
11221
11383
|
EC.e=e
|
|
11222
11384
|
return out
|
|
11223
11385
|
}`;
|
|
@@ -11241,7 +11403,7 @@ ${hasSuffix && (lineFlags & 2) !== 0 ? "if(sm)_trackLines(ctx,input,e)" : ""}
|
|
|
11241
11403
|
${hasSuffix ? `if(!sm){ctx._fe=e;ctx._fx=${suffixExpected};if(ctx._probe!==undefined)failAt(ctx,${suffixExpected},e)}` : ""}
|
|
11242
11404
|
const v=${pending ? "tp?_pfTokValue:" : ""}input.slice(pos,e)
|
|
11243
11405
|
${pending ? "if(tp){_pfTokBody=-1;_pfTokValue=undefined}" : ""}
|
|
11244
|
-
if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,
|
|
11406
|
+
if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
|
|
11245
11407
|
EC.e=e
|
|
11246
11408
|
return v
|
|
11247
11409
|
}`;
|
|
@@ -11280,7 +11442,7 @@ ctx._rootTriviaLog=sRtl
|
|
|
11280
11442
|
}
|
|
11281
11443
|
if(e<0)return FAIL
|
|
11282
11444
|
const v=input.slice(pos,e)
|
|
11283
|
-
if(wasCap)pushCstLeaf(ctx,
|
|
11445
|
+
if(wasCap)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
|
|
11284
11446
|
EC.e=e
|
|
11285
11447
|
return v
|
|
11286
11448
|
}`;
|
|
@@ -11288,7 +11450,7 @@ return v
|
|
|
11288
11450
|
const e=${run2}(input,pos,ctx)
|
|
11289
11451
|
if(e<0)return FAIL
|
|
11290
11452
|
const v=input.slice(pos,e)
|
|
11291
|
-
if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,
|
|
11453
|
+
if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
|
|
11292
11454
|
EC.e=e
|
|
11293
11455
|
return v
|
|
11294
11456
|
}`;
|
|
@@ -11402,7 +11564,7 @@ return v
|
|
|
11402
11564
|
}` : `${parts.join("\n")}
|
|
11403
11565
|
}`;
|
|
11404
11566
|
if (n === 1) {
|
|
11405
|
-
parts.push(fused ? projection === 0 ? "return v0" : `return ${fn}([v0],
|
|
11567
|
+
parts.push(fused ? projection === 0 ? "return v0" : `return ${fn}([v0],new _SP(pos,EC.e))` : wantValues ? "return [v0]" : "return undefined");
|
|
11406
11568
|
return close();
|
|
11407
11569
|
}
|
|
11408
11570
|
parts.push("let cur=EC.e");
|
|
@@ -11423,12 +11585,12 @@ return v
|
|
|
11423
11585
|
);
|
|
11424
11586
|
} else {
|
|
11425
11587
|
const callee = leadingTriviaFieldAt(code, k, childIp) ? `(LEAD.at=cur,${kids[i]})` : kids[i];
|
|
11426
|
-
parts.push(holdsGap(code, k, base, n, i, nullable2) ? emitHoldTerm(callee, vn, tmp(), L, skipFor(L)) : emitTerm(callee, vn, tmp(), L, skipFor(L)));
|
|
11588
|
+
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));
|
|
11427
11589
|
}
|
|
11428
11590
|
names.push(vn);
|
|
11429
11591
|
}
|
|
11430
11592
|
parts.push("EC.e=cur");
|
|
11431
|
-
parts.push(fused ? projection >= 0 ? `return ${names[projection]}` : `return ${fn}([${names.join(",")}],
|
|
11593
|
+
parts.push(fused ? projection >= 0 ? `return ${names[projection]}` : `return ${fn}([${names.join(",")}],new _SP(pos,cur))` : wantValues ? `return [${names.join(",")}]` : "return undefined");
|
|
11432
11594
|
return close();
|
|
11433
11595
|
}
|
|
11434
11596
|
case OP_CHOICE: {
|
|
@@ -11687,7 +11849,7 @@ ${spec.match.map((m, i) => `${i === 0 ? "" : "else "}if(${dispatchClaim(m)})arm=
|
|
|
11687
11849
|
const routedCall = (target) => `{const savedRouted=ctx._routed
|
|
11688
11850
|
${emitRollback(m1, L.buf, L.raw, sinks)}
|
|
11689
11851
|
${emitMark(m2, L.buf, L.raw, sinks, false)}
|
|
11690
|
-
ctx._routed={value:key,span:
|
|
11852
|
+
ctx._routed={value:key,span:new _SP(pos,selEnd)}
|
|
11691
11853
|
try{v=${target}(input,pos,ctx)}finally{ctx._routed=savedRouted}
|
|
11692
11854
|
break}`;
|
|
11693
11855
|
const plainCall = (target) => `v=${target}(input,selEnd,ctx);break`;
|
|
@@ -11882,8 +12044,8 @@ return out
|
|
|
11882
12044
|
const end=${recognize}(input,pos)
|
|
11883
12045
|
if(end<0){ctx._fe=pos;ctx._fx=${xf};return FAIL}
|
|
11884
12046
|
const value=${value2}
|
|
11885
|
-
const leaf=
|
|
11886
|
-
const kids=[leaf],rawKids=[leaf],span=
|
|
12047
|
+
const leaf=new _LF(value,new _SP(pos,end))
|
|
12048
|
+
const kids=[leaf],rawKids=[leaf],span=new _SP(pos,end)
|
|
11887
12049
|
EC.e=end
|
|
11888
12050
|
const nd=${build2}(kids,undefined,span,rawKids,EMPTY_TL,undefined)
|
|
11889
12051
|
${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))"}
|
|
@@ -11982,7 +12144,7 @@ ctx._cstTriviaLog=sTl
|
|
|
11982
12144
|
ctx.captureTrivia=sCap
|
|
11983
12145
|
if(v===FAIL)return FAIL
|
|
11984
12146
|
const end=EC.e
|
|
11985
|
-
${collapseChildren ? `const nd=captured.length===1?captured[0]:${build}(captured,undefined,
|
|
12147
|
+
${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)`}
|
|
11986
12148
|
${publish}
|
|
11987
12149
|
EC.e=end
|
|
11988
12150
|
return nd
|
|
@@ -12005,20 +12167,20 @@ return nd
|
|
|
12005
12167
|
const direct = `${build}(kids,fieldMap,span,rawKids,${captureWide ? "tlog" : "EMPTY_TL"},st)`;
|
|
12006
12168
|
value = hostCst ? `nd=_pfHost!==undefined?${hostCall}:${direct}` : `nd=${direct}`;
|
|
12007
12169
|
} else {
|
|
12008
|
-
value = `nd=_pfHost!==undefined?_pfHost(${ty},hostKids,fieldMap,span,rawKids,tlog,st,${tags}):{
|
|
12170
|
+
value = `nd=_pfHost!==undefined?_pfHost(${ty},hostKids,fieldMap,span,rawKids,tlog,st,${tags}):new _ND(${ty},span,st??null,kids===EMPTY_CH?kids:[...kids])`;
|
|
12009
12171
|
}
|
|
12010
12172
|
const collapsible = keepChildren && (hostCst || build === void 0 && proj < 0);
|
|
12011
|
-
const openCapture = omitsRaw ? `const buf=
|
|
12173
|
+
const openCapture = omitsRaw ? `const buf=new _BUF(undefined,true,0)
|
|
12012
12174
|
ctx._cstBuf=buf
|
|
12013
12175
|
ctx._cstChildren=undefined
|
|
12014
12176
|
ctx._cstLeaves=undefined
|
|
12015
12177
|
ctx._cstRawChildren=undefined
|
|
12016
|
-
ctx._cstTriviaLog=undefined` : keepChildren ? `const buf=
|
|
12178
|
+
ctx._cstTriviaLog=undefined` : keepChildren ? `const buf=new _BUF(undefined,undefined,0)
|
|
12017
12179
|
ctx._cstBuf=buf
|
|
12018
12180
|
ctx._cstChildren=undefined
|
|
12019
12181
|
ctx._cstLeaves=undefined
|
|
12020
12182
|
ctx._cstRawChildren=undefined
|
|
12021
|
-
ctx._cstTriviaLog=undefined` : `const buf=
|
|
12183
|
+
ctx._cstTriviaLog=undefined` : `const buf=new _BUF(true,undefined,0)
|
|
12022
12184
|
ctx._cstBuf=buf
|
|
12023
12185
|
ctx._cstChildren=undefined
|
|
12024
12186
|
ctx._cstLeaves=undefined
|
|
@@ -12056,7 +12218,7 @@ ctx._cstTriviaLog=sTl
|
|
|
12056
12218
|
ctx.captureTrivia=sCap
|
|
12057
12219
|
if(v===FAIL)return FAIL
|
|
12058
12220
|
const end=EC.e
|
|
12059
|
-
const span=${tracked ? "spanLines(ctx,pos,end)" : "
|
|
12221
|
+
const span=${tracked ? "spanLines(ctx,pos,end)" : "new _SP(pos,end)"}
|
|
12060
12222
|
const st=${readsState ? "ctx.state" : "undefined"}
|
|
12061
12223
|
let nd
|
|
12062
12224
|
${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]
|
|
@@ -12343,6 +12505,7 @@ function rebuildLineScan(s, subtree) {
|
|
|
12343
12505
|
}
|
|
12344
12506
|
|
|
12345
12507
|
// src/combinators/scanTo.ts
|
|
12508
|
+
import { PlainLeaf as PlainLeaf8, PlainSpan as PlainSpan9 } from "../cst/plain.js";
|
|
12346
12509
|
function resolveScanSkip(explicitSkip, raw, ctx) {
|
|
12347
12510
|
if (raw) return [];
|
|
12348
12511
|
const trivia2 = ctx.trivia;
|
|
@@ -12380,7 +12543,7 @@ function scanTo(sentinel, { skip, raw = false, orEOF = false, recoverAt, stopAt
|
|
|
12380
12543
|
probeCtx._errors = ctx._errors;
|
|
12381
12544
|
const emit = (end) => {
|
|
12382
12545
|
if (end > pos && cstCaptureActive(ctx)) {
|
|
12383
|
-
const leaf2 =
|
|
12546
|
+
const leaf2 = new PlainLeaf8(input.slice(pos, end), new PlainSpan9(pos, end));
|
|
12384
12547
|
pushCstLeaf(ctx, leaf2);
|
|
12385
12548
|
}
|
|
12386
12549
|
};
|
|
@@ -12602,6 +12765,15 @@ function skipDeferredTrivia(input, cur, ctx) {
|
|
|
12602
12765
|
if (plain) remember(cur, scan, ctx, input, triviaP);
|
|
12603
12766
|
return scan;
|
|
12604
12767
|
}
|
|
12768
|
+
function triviaLeadTable(triviaP) {
|
|
12769
|
+
const fs3 = triviaP._meta.firstSet;
|
|
12770
|
+
if (fs3.kind === "any") return null;
|
|
12771
|
+
const table = new Uint8Array(128);
|
|
12772
|
+
if (fs3.kind === "ranges") {
|
|
12773
|
+
for (const r of fs3.ranges) for (let c = Math.max(0, r.lo); c <= Math.min(127, r.hi); c++) table[c] = 1;
|
|
12774
|
+
}
|
|
12775
|
+
return table;
|
|
12776
|
+
}
|
|
12605
12777
|
function clearRunEnd(input, cur, ctx, triviaP, plain) {
|
|
12606
12778
|
const rootKinds = ctx._rootTriviaKindIndex;
|
|
12607
12779
|
const spec = triviaP?._meta.labeledTriviaSpec;
|
|
@@ -12650,6 +12822,9 @@ function clearOf(ranges, input, from, to) {
|
|
|
12650
12822
|
return true;
|
|
12651
12823
|
}
|
|
12652
12824
|
|
|
12825
|
+
// src/table/assemble.ts
|
|
12826
|
+
import { PlainBuf as PlainBuf2, PlainField, PlainLeaf as PlainLeaf9, PlainNode as PlainNode2, PlainSpan as PlainSpan10 } from "../cst/plain.js";
|
|
12827
|
+
|
|
12653
12828
|
// src/table/fail-clean.ts
|
|
12654
12829
|
function passChild(code, ip) {
|
|
12655
12830
|
switch (code[ip]) {
|
|
@@ -12977,7 +13152,7 @@ function assemble(t, prog, cfg) {
|
|
|
12977
13152
|
const NULLABLE = /* @__PURE__ */ new Map();
|
|
12978
13153
|
const CLEAN = REC2 ? () => false : failCleanAnalysis(code);
|
|
12979
13154
|
function pushLeaf(ctx, value, s, e) {
|
|
12980
|
-
const lf =
|
|
13155
|
+
const lf = new PlainLeaf9(value, new PlainSpan10(s, e));
|
|
12981
13156
|
pushCstLeaf(ctx, lf);
|
|
12982
13157
|
}
|
|
12983
13158
|
function plainBuildNode(child, build, trailing) {
|
|
@@ -13010,7 +13185,7 @@ function assemble(t, prog, cfg) {
|
|
|
13010
13185
|
ctx.captureTrivia = sCap;
|
|
13011
13186
|
if (value === FAIL) return FAIL;
|
|
13012
13187
|
const end = EC.e;
|
|
13013
|
-
const span =
|
|
13188
|
+
const span = new PlainSpan10(pos, end);
|
|
13014
13189
|
const node2 = build(kids, void 0, span, rawKids, EMPTY_TL2, void 0);
|
|
13015
13190
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
13016
13191
|
pushCstChild(ctx, node2, rawEntry(node2, input, pos, end));
|
|
@@ -13055,7 +13230,7 @@ function assemble(t, prog, cfg) {
|
|
|
13055
13230
|
ctx.captureTrivia = sCap;
|
|
13056
13231
|
if (value === FAIL) return FAIL;
|
|
13057
13232
|
const end = EC.e;
|
|
13058
|
-
const node2 = build(captured, void 0,
|
|
13233
|
+
const node2 = build(captured, void 0, new PlainSpan10(pos, end), EMPTY_CH, EMPTY_TL2, void 0);
|
|
13059
13234
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
13060
13235
|
pushCstChild(ctx, node2, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node2, input, pos, end) : void 0);
|
|
13061
13236
|
}
|
|
@@ -13092,7 +13267,7 @@ function assemble(t, prog, cfg) {
|
|
|
13092
13267
|
ctx.captureTrivia = sCap;
|
|
13093
13268
|
if (value === FAIL) return FAIL;
|
|
13094
13269
|
const end = EC.e;
|
|
13095
|
-
const node2 = build(captured, fieldMap,
|
|
13270
|
+
const node2 = build(captured, fieldMap, new PlainSpan10(pos, end), EMPTY_CH, EMPTY_TL2, void 0);
|
|
13096
13271
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
13097
13272
|
pushCstChild(ctx, node2, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node2, input, pos, end) : void 0);
|
|
13098
13273
|
}
|
|
@@ -13129,7 +13304,7 @@ function assemble(t, prog, cfg) {
|
|
|
13129
13304
|
ctx.captureTrivia = sCap;
|
|
13130
13305
|
if (value === FAIL) return FAIL;
|
|
13131
13306
|
const end = EC.e;
|
|
13132
|
-
const span =
|
|
13307
|
+
const span = new PlainSpan10(pos, end);
|
|
13133
13308
|
const node2 = kids.length === 1 ? kids[0] : build(kids, void 0, span, rawKids, EMPTY_TL2, void 0);
|
|
13134
13309
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
13135
13310
|
pushCstChild(ctx, node2, rawEntry(node2, input, pos, end));
|
|
@@ -13166,7 +13341,7 @@ function assemble(t, prog, cfg) {
|
|
|
13166
13341
|
ctx.captureTrivia = sCap;
|
|
13167
13342
|
if (value === FAIL) return FAIL;
|
|
13168
13343
|
const end = EC.e;
|
|
13169
|
-
const node2 = captured.length === 1 ? captured[0] : build(captured, void 0,
|
|
13344
|
+
const node2 = captured.length === 1 ? captured[0] : build(captured, void 0, new PlainSpan10(pos, end), EMPTY_CH, EMPTY_TL2, void 0);
|
|
13170
13345
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
13171
13346
|
pushCstChild(ctx, node2, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node2, input, pos, end) : void 0);
|
|
13172
13347
|
}
|
|
@@ -13275,7 +13450,23 @@ function assemble(t, prog, cfg) {
|
|
|
13275
13450
|
}
|
|
13276
13451
|
return out;
|
|
13277
13452
|
}
|
|
13453
|
+
const LEAD_TABLES = trivia2.map((tp) => tp === void 0 ? null : triviaLeadTable(tp));
|
|
13454
|
+
let LEAD_OF;
|
|
13455
|
+
let LEAD_TABLE = null;
|
|
13456
|
+
function cannotStartTrivia(input, cur, triviaP) {
|
|
13457
|
+
if (triviaP !== LEAD_OF) {
|
|
13458
|
+
LEAD_OF = triviaP;
|
|
13459
|
+
const slot = trivia2.indexOf(triviaP);
|
|
13460
|
+
LEAD_TABLE = slot >= 0 ? LEAD_TABLES[slot] : triviaLeadTable(triviaP);
|
|
13461
|
+
}
|
|
13462
|
+
const table = LEAD_TABLE;
|
|
13463
|
+
if (table === null) return false;
|
|
13464
|
+
const c = input.charCodeAt(cur);
|
|
13465
|
+
return c < 128 && table[c] === 0;
|
|
13466
|
+
}
|
|
13278
13467
|
function skipTrivia(input, cur, ctx) {
|
|
13468
|
+
const t2 = ctx.trivia;
|
|
13469
|
+
if (t2 !== void 0 && cannotStartTrivia(input, cur, t2)) return cur;
|
|
13279
13470
|
const s = SCAN;
|
|
13280
13471
|
if (s !== null && ctx._triviaLog === void 0 && !(ctx.captureTrivia === true && (ctx._cstBuf !== void 0 || ctx._cstTriviaLog !== void 0))) {
|
|
13281
13472
|
return s(input, cur);
|
|
@@ -13290,7 +13481,8 @@ function assemble(t, prog, cfg) {
|
|
|
13290
13481
|
const frames = [];
|
|
13291
13482
|
let depth = 0;
|
|
13292
13483
|
function nextTerm(child, input, cur, ctx) {
|
|
13293
|
-
|
|
13484
|
+
const t2 = ctx.trivia;
|
|
13485
|
+
if (t2 === void 0 || cannotStartTrivia(input, cur, t2)) {
|
|
13294
13486
|
const v2 = child(input, cur, ctx);
|
|
13295
13487
|
if (v2 === FAIL) return -1;
|
|
13296
13488
|
TERMV = v2;
|
|
@@ -13319,7 +13511,8 @@ function assemble(t, prog, cfg) {
|
|
|
13319
13511
|
return cur;
|
|
13320
13512
|
}
|
|
13321
13513
|
function nextTermBuffered(child, input, cur, ctx) {
|
|
13322
|
-
|
|
13514
|
+
const t2 = ctx.trivia;
|
|
13515
|
+
if (t2 === void 0 || cannotStartTrivia(input, cur, t2)) {
|
|
13323
13516
|
const v2 = child(input, cur, ctx);
|
|
13324
13517
|
if (v2 === FAIL) return -1;
|
|
13325
13518
|
TERMV = v2;
|
|
@@ -13581,7 +13774,7 @@ function assemble(t, prog, cfg) {
|
|
|
13581
13774
|
return (input, pos, selEnd, key, ctx, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot) => {
|
|
13582
13775
|
const savedRouted = ctx._routed;
|
|
13583
13776
|
if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
|
|
13584
|
-
ctx._routed = { value: key, span:
|
|
13777
|
+
ctx._routed = { value: key, span: new PlainSpan10(pos, selEnd) };
|
|
13585
13778
|
let v;
|
|
13586
13779
|
try {
|
|
13587
13780
|
v = child(input, pos, ctx);
|
|
@@ -14014,7 +14207,7 @@ function assemble(t, prog, cfg) {
|
|
|
14014
14207
|
case OP_EXPECT: {
|
|
14015
14208
|
const child = link(code[ip + 1]);
|
|
14016
14209
|
const xf = fx[code[ip + 2]];
|
|
14017
|
-
const expectSpan = (ctx, pos) => prog.lines === 1 ? spanLines(ctx, pos, pos) :
|
|
14210
|
+
const expectSpan = (ctx, pos) => prog.lines === 1 ? spanLines(ctx, pos, pos) : new PlainSpan10(pos, pos);
|
|
14018
14211
|
if (REC2) {
|
|
14019
14212
|
return (input, pos, ctx) => {
|
|
14020
14213
|
const v = child(input, pos, ctx);
|
|
@@ -14046,7 +14239,7 @@ function assemble(t, prog, cfg) {
|
|
|
14046
14239
|
return (input, pos, ctx) => {
|
|
14047
14240
|
const v = child(input, pos, ctx);
|
|
14048
14241
|
if (v === FAIL) return FAIL;
|
|
14049
|
-
ctx._fields?.push(
|
|
14242
|
+
ctx._fields?.push(new PlainField(name, v, new PlainSpan10(pos, EC.e)));
|
|
14050
14243
|
return v;
|
|
14051
14244
|
};
|
|
14052
14245
|
}
|
|
@@ -14070,7 +14263,7 @@ function assemble(t, prog, cfg) {
|
|
|
14070
14263
|
return (input, pos, ctx) => {
|
|
14071
14264
|
const v = child(input, pos, ctx);
|
|
14072
14265
|
if (v === FAIL) return FAIL;
|
|
14073
|
-
return fn(v,
|
|
14266
|
+
return fn(v, new PlainSpan10(pos, EC.e));
|
|
14074
14267
|
};
|
|
14075
14268
|
}
|
|
14076
14269
|
case OP_SCAN: {
|
|
@@ -14121,6 +14314,7 @@ function assemble(t, prog, cfg) {
|
|
|
14121
14314
|
const scopeTrivia = ki < 0 ? void 0 : trivia2[ki];
|
|
14122
14315
|
const scopeLabels = scopeTrivia?._meta.triviaKindLabels;
|
|
14123
14316
|
const scanFor = swapLegal && ki >= 0 && !triviaLabelled[ki] ? triviaScan[ki] : null;
|
|
14317
|
+
const scopeLead = ki < 0 ? null : LEAD_TABLES[ki];
|
|
14124
14318
|
const child = link(code[ip + 2]);
|
|
14125
14319
|
const scopePiece = code[ip] === OP_SCOPE_CAP ? (input, pos, ctx) => {
|
|
14126
14320
|
const saved = ctx.trivia;
|
|
@@ -14128,6 +14322,9 @@ function assemble(t, prog, cfg) {
|
|
|
14128
14322
|
const savedScan = SCAN;
|
|
14129
14323
|
const savedCap = ctx.captureTrivia;
|
|
14130
14324
|
SCAN = scanFor;
|
|
14325
|
+
const savedLeadOf = LEAD_OF, savedLead = LEAD_TABLE;
|
|
14326
|
+
LEAD_OF = scopeTrivia;
|
|
14327
|
+
LEAD_TABLE = scopeLead;
|
|
14131
14328
|
ctx.trivia = scopeTrivia;
|
|
14132
14329
|
ctx.triviaKindLabels = scopeLabels;
|
|
14133
14330
|
ctx.captureTrivia = true;
|
|
@@ -14136,18 +14333,25 @@ function assemble(t, prog, cfg) {
|
|
|
14136
14333
|
ctx.trivia = saved;
|
|
14137
14334
|
ctx.triviaKindLabels = savedLabels;
|
|
14138
14335
|
SCAN = savedScan;
|
|
14336
|
+
LEAD_OF = savedLeadOf;
|
|
14337
|
+
LEAD_TABLE = savedLead;
|
|
14139
14338
|
return v;
|
|
14140
14339
|
} : (input, pos, ctx) => {
|
|
14141
14340
|
const saved = ctx.trivia;
|
|
14142
14341
|
const savedLabels = ctx.triviaKindLabels;
|
|
14143
14342
|
const savedScan = SCAN;
|
|
14144
14343
|
SCAN = scanFor;
|
|
14344
|
+
const savedLeadOf = LEAD_OF, savedLead = LEAD_TABLE;
|
|
14345
|
+
LEAD_OF = scopeTrivia;
|
|
14346
|
+
LEAD_TABLE = scopeLead;
|
|
14145
14347
|
ctx.trivia = scopeTrivia;
|
|
14146
14348
|
ctx.triviaKindLabels = scopeLabels;
|
|
14147
14349
|
const v = child(input, pos, ctx);
|
|
14148
14350
|
ctx.trivia = saved;
|
|
14149
14351
|
ctx.triviaKindLabels = savedLabels;
|
|
14150
14352
|
SCAN = savedScan;
|
|
14353
|
+
LEAD_OF = savedLeadOf;
|
|
14354
|
+
LEAD_TABLE = savedLead;
|
|
14151
14355
|
return v;
|
|
14152
14356
|
};
|
|
14153
14357
|
return scopeRootPolicy(scopePiece, code[ip] === OP_SCOPE_PLAIN ? 0 : code[ip + 3]);
|
|
@@ -14163,7 +14367,7 @@ function assemble(t, prog, cfg) {
|
|
|
14163
14367
|
ctx._fx = ROUTED_FX;
|
|
14164
14368
|
return FAIL;
|
|
14165
14369
|
}
|
|
14166
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
14370
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf9(item.value, item.span));
|
|
14167
14371
|
EC.e = item.span.end;
|
|
14168
14372
|
return item.value;
|
|
14169
14373
|
};
|
|
@@ -14349,7 +14553,7 @@ function assemble(t, prog, cfg) {
|
|
|
14349
14553
|
if (v === FAIL) return FAIL;
|
|
14350
14554
|
const end = EC.e;
|
|
14351
14555
|
const value = input.slice(pos, end);
|
|
14352
|
-
if (wasCapturing) pushCstLeaf(ctx,
|
|
14556
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
|
|
14353
14557
|
EC.e = end;
|
|
14354
14558
|
return value;
|
|
14355
14559
|
};
|
|
@@ -14383,7 +14587,7 @@ function assemble(t, prog, cfg) {
|
|
|
14383
14587
|
if (ctx._probe !== void 0) failAt(ctx, suffixExpected, end);
|
|
14384
14588
|
}
|
|
14385
14589
|
const value = input.slice(pos, end);
|
|
14386
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
14590
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
|
|
14387
14591
|
EC.e = end;
|
|
14388
14592
|
return value;
|
|
14389
14593
|
};
|
|
@@ -14426,7 +14630,7 @@ function assemble(t, prog, cfg) {
|
|
|
14426
14630
|
}
|
|
14427
14631
|
if (end < 0) return FAIL;
|
|
14428
14632
|
const value = input.slice(pos, end);
|
|
14429
|
-
if (wasCapturing) pushCstLeaf(ctx,
|
|
14633
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
|
|
14430
14634
|
EC.e = end;
|
|
14431
14635
|
return value;
|
|
14432
14636
|
};
|
|
@@ -14435,7 +14639,7 @@ function assemble(t, prog, cfg) {
|
|
|
14435
14639
|
const end = run2(input, pos, ctx);
|
|
14436
14640
|
if (end < 0) return FAIL;
|
|
14437
14641
|
const value = input.slice(pos, end);
|
|
14438
|
-
if (cstCaptureActive(ctx)) pushCstLeaf(ctx,
|
|
14642
|
+
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
|
|
14439
14643
|
EC.e = end;
|
|
14440
14644
|
return value;
|
|
14441
14645
|
};
|
|
@@ -14468,12 +14672,8 @@ function assemble(t, prog, cfg) {
|
|
|
14468
14672
|
}
|
|
14469
14673
|
if (v === FAIL) return FAIL;
|
|
14470
14674
|
const end = EC.e;
|
|
14471
|
-
const out = fn(v,
|
|
14472
|
-
if (wasCapturing) pushCstLeaf(ctx,
|
|
14473
|
-
_tag: "leaf",
|
|
14474
|
-
value: op === OP_SOURCE_LEAF && hostCst ? input.slice(pos, end) : out,
|
|
14475
|
-
span: { start: pos, end }
|
|
14476
|
-
});
|
|
14675
|
+
const out = fn(v, new PlainSpan10(pos, end));
|
|
14676
|
+
if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf9(op === OP_SOURCE_LEAF && hostCst ? input.slice(pos, end) : out, new PlainSpan10(pos, end)));
|
|
14477
14677
|
EC.e = end;
|
|
14478
14678
|
return out;
|
|
14479
14679
|
};
|
|
@@ -14608,7 +14808,7 @@ function assemble(t, prog, cfg) {
|
|
|
14608
14808
|
const cur = runSyncTerms(input, pos, ctx, values);
|
|
14609
14809
|
if (cur < 0) return FAIL;
|
|
14610
14810
|
EC.e = cur;
|
|
14611
|
-
return projection >= 0 ? values[projection] : fn(values,
|
|
14811
|
+
return projection >= 0 ? values[projection] : fn(values, new PlainSpan10(pos, cur));
|
|
14612
14812
|
};
|
|
14613
14813
|
}
|
|
14614
14814
|
if (wantValues) {
|
|
@@ -14702,7 +14902,7 @@ function assemble(t, prog, cfg) {
|
|
|
14702
14902
|
const cur = runAdjTerms(input, pos, ctx, values);
|
|
14703
14903
|
if (cur < 0) return FAIL;
|
|
14704
14904
|
EC.e = cur;
|
|
14705
|
-
return projection >= 0 ? values[projection] : fn(values,
|
|
14905
|
+
return projection >= 0 ? values[projection] : fn(values, new PlainSpan10(pos, cur));
|
|
14706
14906
|
};
|
|
14707
14907
|
}
|
|
14708
14908
|
if (wantValues) {
|
|
@@ -14727,7 +14927,7 @@ function assemble(t, prog, cfg) {
|
|
|
14727
14927
|
return (input, pos, ctx) => {
|
|
14728
14928
|
const v = k0(input, pos, ctx);
|
|
14729
14929
|
if (v === FAIL) return FAIL;
|
|
14730
|
-
return projection === 0 ? v : fn([v],
|
|
14930
|
+
return projection === 0 ? v : fn([v], new PlainSpan10(pos, EC.e));
|
|
14731
14931
|
};
|
|
14732
14932
|
}
|
|
14733
14933
|
if (wantValues) {
|
|
@@ -14752,7 +14952,7 @@ function assemble(t, prog, cfg) {
|
|
|
14752
14952
|
const cur = step(k1, input, EC.e, ctx);
|
|
14753
14953
|
if (cur < 0) return FAIL;
|
|
14754
14954
|
EC.e = cur;
|
|
14755
|
-
return projection === 0 ? v0 : projection === 1 ? TERMV : fn([v0, TERMV],
|
|
14955
|
+
return projection === 0 ? v0 : projection === 1 ? TERMV : fn([v0, TERMV], new PlainSpan10(pos, cur));
|
|
14756
14956
|
};
|
|
14757
14957
|
}
|
|
14758
14958
|
if (wantValues) {
|
|
@@ -14786,7 +14986,7 @@ function assemble(t, prog, cfg) {
|
|
|
14786
14986
|
cur = step(k2, input, cur, ctx);
|
|
14787
14987
|
if (cur < 0) return FAIL;
|
|
14788
14988
|
EC.e = cur;
|
|
14789
|
-
return projection === 0 ? v0 : projection === 1 ? v1 : projection === 2 ? TERMV : fn([v0, v1, TERMV],
|
|
14989
|
+
return projection === 0 ? v0 : projection === 1 ? v1 : projection === 2 ? TERMV : fn([v0, v1, TERMV], new PlainSpan10(pos, cur));
|
|
14790
14990
|
};
|
|
14791
14991
|
}
|
|
14792
14992
|
if (wantValues) {
|
|
@@ -14883,7 +15083,7 @@ function assemble(t, prog, cfg) {
|
|
|
14883
15083
|
const cur = runDirectTerms(input, pos, ctx, values);
|
|
14884
15084
|
if (cur < 0) return FAIL;
|
|
14885
15085
|
EC.e = cur;
|
|
14886
|
-
return projection >= 0 ? values[projection] : fn(values,
|
|
15086
|
+
return projection >= 0 ? values[projection] : fn(values, new PlainSpan10(pos, cur));
|
|
14887
15087
|
};
|
|
14888
15088
|
}
|
|
14889
15089
|
if (wantValues) {
|
|
@@ -15781,10 +15981,10 @@ function assemble(t, prog, cfg) {
|
|
|
15781
15981
|
return FAIL;
|
|
15782
15982
|
}
|
|
15783
15983
|
const value = regexValue ? input.slice(pos, end) : spec;
|
|
15784
|
-
const leaf2 =
|
|
15984
|
+
const leaf2 = new PlainLeaf9(value, new PlainSpan10(pos, end));
|
|
15785
15985
|
const kids = [leaf2];
|
|
15786
15986
|
const rawKids = [leaf2];
|
|
15787
|
-
const span =
|
|
15987
|
+
const span = new PlainSpan10(pos, end);
|
|
15788
15988
|
EC.e = end;
|
|
15789
15989
|
const nd = build2(kids, void 0, span, rawKids, EMPTY_TL2, void 0);
|
|
15790
15990
|
if (ctx._cstBuf !== void 0 || ctx._cstChildren !== void 0) {
|
|
@@ -15866,7 +16066,7 @@ function assemble(t, prog, cfg) {
|
|
|
15866
16066
|
const sCh = ctx._cstChildren;
|
|
15867
16067
|
const sCap = ctx.captureTrivia;
|
|
15868
16068
|
const sBuf = ctx._cstBuf;
|
|
15869
|
-
const buf = rawOnly ?
|
|
16069
|
+
const buf = rawOnly ? new PlainBuf2(true, void 0, 0) : omitsRaw ? new PlainBuf2(void 0, true, 0) : new PlainBuf2(void 0, void 0, 0);
|
|
15870
16070
|
ctx._cstBuf = buf;
|
|
15871
16071
|
ctx.captureTrivia = captureWide;
|
|
15872
16072
|
const savedFields = ctx._fields;
|
|
@@ -15888,7 +16088,7 @@ function assemble(t, prog, cfg) {
|
|
|
15888
16088
|
ctx.captureTrivia = sCap;
|
|
15889
16089
|
if (v === FAIL) return FAIL;
|
|
15890
16090
|
const end = EC.e;
|
|
15891
|
-
const span = tracked ? spanLines(ctx, pos, end) :
|
|
16091
|
+
const span = tracked ? spanLines(ctx, pos, end) : new PlainSpan10(pos, end);
|
|
15892
16092
|
const st = readsState ? ctx.state : void 0;
|
|
15893
16093
|
let nd;
|
|
15894
16094
|
if (unwrap && kids.length === 1) {
|
|
@@ -15912,7 +16112,7 @@ function assemble(t, prog, cfg) {
|
|
|
15912
16112
|
} else if (host !== void 0) {
|
|
15913
16113
|
nd = host(type, hostKids, fieldMap, span, rawKids, tlog, st, tags);
|
|
15914
16114
|
} else {
|
|
15915
|
-
nd =
|
|
16115
|
+
nd = new PlainNode2(type, span, st ?? null, kids === EMPTY_CH ? kids : [...kids]);
|
|
15916
16116
|
}
|
|
15917
16117
|
if (sBuf !== void 0 || sCh !== void 0) {
|
|
15918
16118
|
pushCstChild(ctx, nd, rawEntry(nd, input, pos, end));
|
|
@@ -15938,7 +16138,7 @@ function assemble(t, prog, cfg) {
|
|
|
15938
16138
|
const at = fe === void 0 || fe < 0 ? pos : fe;
|
|
15939
16139
|
return { ok: false, expected: ctx._fx ?? EMPTY_FX2, span: { start: at, end: at } };
|
|
15940
16140
|
}
|
|
15941
|
-
return { ok: true, value: v, span:
|
|
16141
|
+
return { ok: true, value: v, span: new PlainSpan10(pos, EC.e) };
|
|
15942
16142
|
}
|
|
15943
16143
|
};
|
|
15944
16144
|
}
|
|
@@ -16053,7 +16253,12 @@ function assemble(t, prog, cfg) {
|
|
|
16053
16253
|
LEAD,
|
|
16054
16254
|
triviaFieldCapture,
|
|
16055
16255
|
skipDeferredTrivia,
|
|
16056
|
-
collapseEmpty
|
|
16256
|
+
collapseEmpty,
|
|
16257
|
+
PlainSpan10,
|
|
16258
|
+
PlainLeaf9,
|
|
16259
|
+
PlainNode2,
|
|
16260
|
+
PlainField,
|
|
16261
|
+
PlainBuf2
|
|
16057
16262
|
);
|
|
16058
16263
|
emitReached = new Set(pre.reached);
|
|
16059
16264
|
if (emitted.ext !== void 0) HYBRID = emitted;
|
|
@@ -16140,7 +16345,12 @@ function assemble(t, prog, cfg) {
|
|
|
16140
16345
|
LEAD,
|
|
16141
16346
|
triviaFieldCapture,
|
|
16142
16347
|
skipDeferredTrivia,
|
|
16143
|
-
collapseEmpty
|
|
16348
|
+
collapseEmpty,
|
|
16349
|
+
PlainSpan10,
|
|
16350
|
+
PlainLeaf9,
|
|
16351
|
+
PlainNode2,
|
|
16352
|
+
PlainField,
|
|
16353
|
+
PlainBuf2
|
|
16144
16354
|
);
|
|
16145
16355
|
emitReached = em.reached;
|
|
16146
16356
|
} catch (e) {
|
|
@@ -16409,7 +16619,11 @@ function tableRules(source, metadataOrEntry = {}) {
|
|
|
16409
16619
|
return map[entry];
|
|
16410
16620
|
}
|
|
16411
16621
|
|
|
16622
|
+
// src/version.ts
|
|
16623
|
+
var PARSEMAN_VERSION = "0.59.0";
|
|
16624
|
+
|
|
16412
16625
|
// src/table/emit.ts
|
|
16626
|
+
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`)});`;
|
|
16413
16627
|
function jsString(s) {
|
|
16414
16628
|
return JSON.stringify(s);
|
|
16415
16629
|
}
|
|
@@ -16495,7 +16709,7 @@ function emitAssemblies(prog, cfgs) {
|
|
|
16495
16709
|
throw e;
|
|
16496
16710
|
}
|
|
16497
16711
|
const plan = em.plan;
|
|
16498
|
-
out.push(`{key:${key},factory:function(${EMITTED_PARAMS.join(",")}){${em.source}
|
|
16712
|
+
out.push(`{key:${key},factory:function(${EMITTED_PARAMS.join(",")}){${FACTORY_ARITY_GUARD}${em.source}
|
|
16499
16713
|
},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(",")}]}`);
|
|
16500
16714
|
}
|
|
16501
16715
|
return [`a:[${out.join(",")}],`];
|
|
@@ -18194,8 +18408,8 @@ function compileRuleMap(ruleMap, opts = {}) {
|
|
|
18194
18408
|
const roots = assemblyExtraIps(artifact);
|
|
18195
18409
|
let siteBytes, fixed;
|
|
18196
18410
|
try {
|
|
18197
|
-
siteBytes = emitAssemblySource(table, artifact, cfg, roots, true).siteBytes;
|
|
18198
|
-
fixed = emitAssemblySource(table, artifact, cfg, roots, true, /* @__PURE__ */ new Set()).source.length;
|
|
18411
|
+
siteBytes = emitAssemblySource(table, artifact, cfg, roots, true, void 0, true).siteBytes;
|
|
18412
|
+
fixed = emitAssemblySource(table, artifact, cfg, roots, true, /* @__PURE__ */ new Set(), true).source.length;
|
|
18199
18413
|
} catch (e) {
|
|
18200
18414
|
if (e instanceof Unemittable) return { ...none, refusal: e.construct };
|
|
18201
18415
|
throw e;
|
|
@@ -18211,7 +18425,7 @@ function compileRuleMap(ruleMap, opts = {}) {
|
|
|
18211
18425
|
refusal: `a site within its ${Math.floor(ceiling)} B selection ceiling (the prelude alone is ${fixed} B)`
|
|
18212
18426
|
};
|
|
18213
18427
|
}
|
|
18214
|
-
const bytes = emitAssemblySource(table, artifact, cfg, roots, true, sites).source.length;
|
|
18428
|
+
const bytes = emitAssemblySource(table, artifact, cfg, roots, true, sites, true).source.length;
|
|
18215
18429
|
if (bytes <= ceiling) return { sites, bytes: Math.ceil(bytes * SUPERCOMPILE_GROWTH) };
|
|
18216
18430
|
target *= Math.min(ceiling / bytes, 0.99);
|
|
18217
18431
|
}
|
|
@@ -18855,9 +19069,6 @@ function fieldOptionsSrc(def) {
|
|
|
18855
19069
|
return `, { ${[def.leadingTrivia === true ? "leadingTrivia: true" : "", def.trailingTrivia === true ? "trailingTrivia: true" : ""].filter(Boolean).join(", ")} }`;
|
|
18856
19070
|
}
|
|
18857
19071
|
|
|
18858
|
-
// src/version.ts
|
|
18859
|
-
var PARSEMAN_VERSION = "0.58.2";
|
|
18860
|
-
|
|
18861
19072
|
// src/compiler/compile-linkable-table.ts
|
|
18862
19073
|
function isLocal(rule) {
|
|
18863
19074
|
const d = rule._def;
|
|
@@ -18924,6 +19135,7 @@ function compileLinkableTable(ruleMapArg, ns, opts = {}) {
|
|
|
18924
19135
|
}
|
|
18925
19136
|
|
|
18926
19137
|
// src/compiler/linker.ts
|
|
19138
|
+
import { PlainNode as PlainNode3, PlainTaggedNode } from "../cst/plain.js";
|
|
18927
19139
|
function normalizeCstCollapse(collapse) {
|
|
18928
19140
|
if (collapse === true) return () => true;
|
|
18929
19141
|
if (Array.isArray(collapse)) {
|
|
@@ -18933,7 +19145,7 @@ function normalizeCstCollapse(collapse) {
|
|
|
18933
19145
|
return typeof collapse === "function" ? collapse : void 0;
|
|
18934
19146
|
}
|
|
18935
19147
|
function buildCstNode(type, children3, _fields, span, _rawChildren, _triviaLog, state, tags) {
|
|
18936
|
-
return tags !== void 0 && tags.length > 0 ?
|
|
19148
|
+
return tags !== void 0 && tags.length > 0 ? new PlainTaggedNode(type, tags, copySpan(span), state ?? null, [...children3]) : new PlainNode3(type, copySpan(span), state ?? null, [...children3]);
|
|
18937
19149
|
}
|
|
18938
19150
|
function cstBuildHost(typeOrOptions, children3, _fields, span, rawChildren, triviaLog, state, _tags) {
|
|
18939
19151
|
if (typeof typeOrOptions === "string") {
|
|
@@ -21388,8 +21600,8 @@ function supercompileRuleMapReplacement(prog, replacement, select) {
|
|
|
21388
21600
|
if (typeof body.start !== "number" || typeof body.end !== "number") return replacement;
|
|
21389
21601
|
const start = body.start - prefix.length + 1;
|
|
21390
21602
|
const end = body.end - prefix.length - 1;
|
|
21391
|
-
if (replacement.slice(start, end) !== canonical2.source + "\n") return replacement;
|
|
21392
|
-
const transformed = replacement.slice(0, start) + candidate.source + "\n" + replacement.slice(end);
|
|
21603
|
+
if (replacement.slice(start, end) !== FACTORY_ARITY_GUARD + canonical2.source + "\n") return replacement;
|
|
21604
|
+
const transformed = replacement.slice(0, start) + FACTORY_ARITY_GUARD + candidate.source + "\n" + replacement.slice(end);
|
|
21393
21605
|
const checked = parseSync4("parseman-entry-supercompile-replacement-result.js", prefix + transformed);
|
|
21394
21606
|
return checked.errors.length === 0 ? transformed : replacement;
|
|
21395
21607
|
}
|