parseman 0.41.0 → 0.42.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/combinators/expect.d.ts.map +1 -1
- package/dist/combinators/grammar.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/trivia-skip.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts +3 -0
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/inline-build.d.ts +1 -1
- package/dist/compiler/inline-build.d.ts.map +1 -1
- package/dist/compiler/line-index.d.ts +1 -15
- package/dist/compiler/line-index.d.ts.map +1 -1
- package/dist/cst/capture-buffer.d.ts.map +1 -1
- package/dist/index.cjs +364 -99
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +364 -99
- package/dist/index.js.map +4 -4
- package/dist/language-service/index.cjs +48 -2
- package/dist/language-service/index.cjs.map +3 -3
- package/dist/language-service/index.js +48 -2
- package/dist/language-service/index.js.map +3 -3
- package/dist/line-index.d.ts +41 -0
- package/dist/line-index.d.ts.map +1 -0
- package/dist/plugin/index.cjs +334 -93
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.js +334 -93
- package/dist/plugin/index.js.map +4 -4
- package/dist/recovery/scan.d.ts.map +1 -1
- package/dist/regex/first-set.d.ts.map +1 -1
- package/dist/run/index.cjs +47 -1
- package/dist/run/index.cjs.map +3 -3
- package/dist/run/index.d.ts +3 -2
- package/dist/run/index.d.ts.map +1 -1
- package/dist/run/index.js +47 -1
- package/dist/run/index.js.map +3 -3
- package/dist/spec/index.cjs +170 -50
- package/dist/spec/index.cjs.map +4 -4
- package/dist/spec/index.js +170 -50
- package/dist/spec/index.js.map +4 -4
- package/dist/types.d.ts +12 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ __export(index_exports, {
|
|
|
33
33
|
analyzeGatingRules: () => analyzeGatingRules,
|
|
34
34
|
analyzeGrammarGating: () => analyzeGrammarGating,
|
|
35
35
|
annotateSpan: () => annotateSpan,
|
|
36
|
+
annotateTreeSpans: () => annotateTreeSpans,
|
|
36
37
|
applyEdit: () => applyEdit,
|
|
37
38
|
attempt: () => attempt,
|
|
38
39
|
balanced: () => balanced,
|
|
@@ -54,6 +55,7 @@ __export(index_exports, {
|
|
|
54
55
|
createGrammarCoverageCollector: () => createGrammarCoverageCollector,
|
|
55
56
|
createGrammarInstrumentationContext: () => createGrammarInstrumentationContext,
|
|
56
57
|
createGrammarTraceSink: () => createGrammarTraceSink,
|
|
58
|
+
createLineIndex: () => createLineIndex,
|
|
57
59
|
createVisitor: () => createVisitor,
|
|
58
60
|
cstBuildHost: () => cstBuildHost,
|
|
59
61
|
dispatch: () => dispatch,
|
|
@@ -87,6 +89,7 @@ __export(index_exports, {
|
|
|
87
89
|
matches: () => matches,
|
|
88
90
|
noTrivia: () => noTrivia,
|
|
89
91
|
node: () => node,
|
|
92
|
+
normalizeLineIndex: () => normalizeLineIndex,
|
|
90
93
|
not: () => not,
|
|
91
94
|
offsetToLineCol: () => offsetToLineCol,
|
|
92
95
|
oneOrMore: () => oneOrMore,
|
|
@@ -97,6 +100,7 @@ __export(index_exports, {
|
|
|
97
100
|
parseDoc: () => parseDoc,
|
|
98
101
|
parser: () => parser,
|
|
99
102
|
peek: () => peek,
|
|
103
|
+
recordLineRange: () => recordLineRange,
|
|
100
104
|
ref: () => ref,
|
|
101
105
|
regex: () => regex,
|
|
102
106
|
relativize: () => relativize,
|
|
@@ -363,6 +367,87 @@ function failAt(ctx, expected, pos) {
|
|
|
363
367
|
return r;
|
|
364
368
|
}
|
|
365
369
|
|
|
370
|
+
// src/line-index.ts
|
|
371
|
+
function createLineIndex() {
|
|
372
|
+
return { lineStarts: [0] };
|
|
373
|
+
}
|
|
374
|
+
function buildLineIndex(input) {
|
|
375
|
+
const lineStarts = [0];
|
|
376
|
+
for (let i = 0; i < input.length; i++) {
|
|
377
|
+
if (input.charCodeAt(i) === 10) lineStarts.push(i + 1);
|
|
378
|
+
}
|
|
379
|
+
return { lineStarts };
|
|
380
|
+
}
|
|
381
|
+
function recordLineRange(index, input, start, end) {
|
|
382
|
+
const lineStarts = index.lineStarts;
|
|
383
|
+
for (let i = start; i < end; i++) {
|
|
384
|
+
if (input.charCodeAt(i) === 10) lineStarts.push(i + 1);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function recordLineRangeFromContext(ctx, input, _startHint, end) {
|
|
388
|
+
if (!ctx.trackLines) return;
|
|
389
|
+
const from = ctx._lineScannedTo ?? 0;
|
|
390
|
+
if (end <= from) return;
|
|
391
|
+
const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
|
|
392
|
+
if (!index) return;
|
|
393
|
+
recordLineRange(index, input, from, end);
|
|
394
|
+
ctx._lineScannedTo = end;
|
|
395
|
+
}
|
|
396
|
+
function normalizeLineIndex(index) {
|
|
397
|
+
const starts = index.lineStarts;
|
|
398
|
+
starts.sort((a, b) => a - b);
|
|
399
|
+
let write = 0;
|
|
400
|
+
for (let read = 0; read < starts.length; read++) {
|
|
401
|
+
const value = starts[read];
|
|
402
|
+
if (write === 0 || starts[write - 1] !== value) starts[write++] = value;
|
|
403
|
+
}
|
|
404
|
+
starts.length = write;
|
|
405
|
+
if (starts.length === 0 || starts[0] !== 0) starts.unshift(0);
|
|
406
|
+
return index;
|
|
407
|
+
}
|
|
408
|
+
function offsetToLineCol(index, offset) {
|
|
409
|
+
const { lineStarts } = index;
|
|
410
|
+
let lo = 0;
|
|
411
|
+
let hi = lineStarts.length - 1;
|
|
412
|
+
while (lo < hi) {
|
|
413
|
+
const mid = lo + hi + 1 >> 1;
|
|
414
|
+
if (lineStarts[mid] <= offset) lo = mid;
|
|
415
|
+
else hi = mid - 1;
|
|
416
|
+
}
|
|
417
|
+
return { line: lo + 1, col: offset - lineStarts[lo] + 1 };
|
|
418
|
+
}
|
|
419
|
+
function annotateSpan(span, index) {
|
|
420
|
+
const s = offsetToLineCol(index, span.start);
|
|
421
|
+
const e = offsetToLineCol(index, span.end);
|
|
422
|
+
return {
|
|
423
|
+
...span,
|
|
424
|
+
startLine: s.line,
|
|
425
|
+
startColumn: s.col,
|
|
426
|
+
endLine: e.line,
|
|
427
|
+
endColumn: e.col
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
function annotateSpanFromLineContext(span, ctx) {
|
|
431
|
+
if (!ctx.trackLines) return span;
|
|
432
|
+
const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
|
|
433
|
+
return index ? annotateSpan(span, index) : span;
|
|
434
|
+
}
|
|
435
|
+
function isSpan(value) {
|
|
436
|
+
return !!value && typeof value === "object" && typeof value.start === "number" && typeof value.end === "number";
|
|
437
|
+
}
|
|
438
|
+
function annotateTreeSpans(value, index, seen = /* @__PURE__ */ new WeakSet()) {
|
|
439
|
+
if (!value || typeof value !== "object") return value;
|
|
440
|
+
if (seen.has(value)) return value;
|
|
441
|
+
seen.add(value);
|
|
442
|
+
const obj = value;
|
|
443
|
+
if (isSpan(obj.span)) obj.span = annotateSpan(obj.span, index);
|
|
444
|
+
for (const key of Object.keys(obj)) {
|
|
445
|
+
const child = obj[key];
|
|
446
|
+
if (child && typeof child === "object") annotateTreeSpans(child, index, seen);
|
|
447
|
+
}
|
|
448
|
+
return value;
|
|
449
|
+
}
|
|
450
|
+
|
|
366
451
|
// src/cst/capture-buffer.ts
|
|
367
452
|
var EMPTY = [];
|
|
368
453
|
var EMPTY_TL = [];
|
|
@@ -404,7 +489,12 @@ function endCstNodeCapture(ctx, saved) {
|
|
|
404
489
|
return materialized;
|
|
405
490
|
}
|
|
406
491
|
function pushCstLeaf(ctx, leaf2) {
|
|
407
|
-
|
|
492
|
+
if (!ctx.trackLines) {
|
|
493
|
+
pushCstChild(ctx, leaf2, leaf2);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const annotated = leaf2 && typeof leaf2 === "object" && leaf2.span ? { ...leaf2, span: annotateSpanFromLineContext(leaf2.span, ctx) } : leaf2;
|
|
497
|
+
pushCstChild(ctx, annotated, annotated);
|
|
408
498
|
}
|
|
409
499
|
function pushCstChild(ctx, built, rawEntry) {
|
|
410
500
|
const b = ctx._cstBuf;
|
|
@@ -538,6 +628,7 @@ function literal(value, opts = {}) {
|
|
|
538
628
|
canMatchNewline: value.includes("\n"),
|
|
539
629
|
isTrivia: false
|
|
540
630
|
};
|
|
631
|
+
const canMatchNewline = meta.canMatchNewline;
|
|
541
632
|
if (caseInsensitive) {
|
|
542
633
|
const upper = value.toUpperCase();
|
|
543
634
|
const lower = value.toLowerCase();
|
|
@@ -554,6 +645,7 @@ function literal(value, opts = {}) {
|
|
|
554
645
|
return function parse3(input, pos, ctx) {
|
|
555
646
|
if (input.charCodeAt(pos) === code) {
|
|
556
647
|
const span = { start: pos, end: pos + 1 };
|
|
648
|
+
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, span.end);
|
|
557
649
|
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span });
|
|
558
650
|
return { ok: true, value, span };
|
|
559
651
|
}
|
|
@@ -567,6 +659,7 @@ function literal(value, opts = {}) {
|
|
|
567
659
|
const matchedValue = caseInsensitive ? input.slice(pos, end) : value;
|
|
568
660
|
if (caseInsensitive ? asciiFoldEq(matchedValue, value) : input.startsWith(value, pos)) {
|
|
569
661
|
const span = { start: pos, end };
|
|
662
|
+
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, end);
|
|
570
663
|
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value: matchedValue, span });
|
|
571
664
|
return { ok: true, value: matchedValue, span };
|
|
572
665
|
}
|
|
@@ -734,6 +827,7 @@ function regex(pattern, flags = "") {
|
|
|
734
827
|
if (scanEnd === null) return failAt(ctx, [`/${source}/`], pos);
|
|
735
828
|
const value = input.slice(pos, scanEnd);
|
|
736
829
|
const span2 = { start: pos, end: scanEnd };
|
|
830
|
+
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, scanEnd);
|
|
737
831
|
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span: span2 });
|
|
738
832
|
return { ok: true, value, span: span2 };
|
|
739
833
|
}
|
|
@@ -743,6 +837,7 @@ function regex(pattern, flags = "") {
|
|
|
743
837
|
return failAt(ctx, [`/${source}/`], pos);
|
|
744
838
|
}
|
|
745
839
|
const span = { start: pos, end: pos + m[0].length };
|
|
840
|
+
if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, span.end);
|
|
746
841
|
if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value: m[0], span });
|
|
747
842
|
return { ok: true, value: m[0], span };
|
|
748
843
|
}
|
|
@@ -881,8 +976,8 @@ function parseRegex(src) {
|
|
|
881
976
|
}
|
|
882
977
|
if (src[k] !== "]") throw BAIL;
|
|
883
978
|
i = k + 1;
|
|
884
|
-
if (negated) return charNode(any(), true);
|
|
885
979
|
const ranges = parseClassRanges(body);
|
|
980
|
+
if (negated) return charNode(any(), !ranges || !rangesHaveNewline(ranges));
|
|
886
981
|
if (!ranges) return charNode(any(), true);
|
|
887
982
|
return charNode(rangesToSet(ranges), rangesHaveNewline(ranges));
|
|
888
983
|
};
|
|
@@ -978,7 +1073,7 @@ function firstSet(n) {
|
|
|
978
1073
|
}
|
|
979
1074
|
}
|
|
980
1075
|
}
|
|
981
|
-
function
|
|
1076
|
+
function canConsumeNewline(n) {
|
|
982
1077
|
switch (n.t) {
|
|
983
1078
|
case "char":
|
|
984
1079
|
return n.nl;
|
|
@@ -987,16 +1082,11 @@ function firstCanBeNewline(n) {
|
|
|
987
1082
|
case "empty":
|
|
988
1083
|
return false;
|
|
989
1084
|
case "rep":
|
|
990
|
-
return
|
|
1085
|
+
return canConsumeNewline(n.node);
|
|
991
1086
|
case "alt":
|
|
992
|
-
return n.arms.some(
|
|
993
|
-
case "seq":
|
|
994
|
-
|
|
995
|
-
if (firstCanBeNewline(part)) return true;
|
|
996
|
-
if (!nullable(part)) break;
|
|
997
|
-
}
|
|
998
|
-
return false;
|
|
999
|
-
}
|
|
1087
|
+
return n.arms.some(canConsumeNewline);
|
|
1088
|
+
case "seq":
|
|
1089
|
+
return n.parts.some(canConsumeNewline);
|
|
1000
1090
|
}
|
|
1001
1091
|
}
|
|
1002
1092
|
function firstSetFromRegex(source) {
|
|
@@ -1006,8 +1096,8 @@ function firstSetFromRegex(source) {
|
|
|
1006
1096
|
} catch {
|
|
1007
1097
|
return { firstSet: any(), canMatchNewline: true };
|
|
1008
1098
|
}
|
|
1009
|
-
if (nullable(ast)) return { firstSet: any(), canMatchNewline:
|
|
1010
|
-
return { firstSet: firstSet(ast), canMatchNewline:
|
|
1099
|
+
if (nullable(ast)) return { firstSet: any(), canMatchNewline: canConsumeNewline(ast) };
|
|
1100
|
+
return { firstSet: firstSet(ast), canMatchNewline: canConsumeNewline(ast) };
|
|
1011
1101
|
}
|
|
1012
1102
|
|
|
1013
1103
|
// src/combinators/case-fold.ts
|
|
@@ -1169,7 +1259,9 @@ function firstSetSentinel(fs) {
|
|
|
1169
1259
|
function recoverScan(input, from, ctx, sync, expected) {
|
|
1170
1260
|
let scanPos = from;
|
|
1171
1261
|
while (scanPos < input.length && !probeAt(sync, input, scanPos, ctx)) scanPos++;
|
|
1172
|
-
const
|
|
1262
|
+
const span = { start: from, end: scanPos };
|
|
1263
|
+
if (ctx.trackLines) recordLineRangeFromContext(ctx, input, from, scanPos);
|
|
1264
|
+
const error = { _tag: "parseError", span: ctx.trackLines ? annotateSpanFromLineContext(span, ctx) : span, expected };
|
|
1173
1265
|
ctx._errors?.push(error);
|
|
1174
1266
|
return { error, end: scanPos };
|
|
1175
1267
|
}
|
|
@@ -1272,7 +1364,8 @@ function expect(combinator, label2) {
|
|
|
1272
1364
|
parse(input, pos, ctx) {
|
|
1273
1365
|
const result = combinator.parse(input, pos, ctx);
|
|
1274
1366
|
if (result.ok) return result;
|
|
1275
|
-
const
|
|
1367
|
+
const span = { start: pos, end: pos };
|
|
1368
|
+
const error = { _tag: "parseError", span: ctx.trackLines ? annotateSpanFromLineContext(span, ctx) : span, expected };
|
|
1276
1369
|
ctx._errors?.push(error);
|
|
1277
1370
|
if (ctx._tolerant) captureError(ctx, error);
|
|
1278
1371
|
return { ok: true, value: error, span: { start: pos, end: pos } };
|
|
@@ -1720,6 +1813,18 @@ function rollbackTrivia(ctx, mark) {
|
|
|
1720
1813
|
rollbackCstCapture(ctx, { raw: mark.raw, tlog: mark.tlog, leaves: mark.leaves, fields: mark.fields, errors: mark.errors });
|
|
1721
1814
|
if (ctx._triviaLog && ctx._triviaLog.length !== mark.log) ctx._triviaLog.length = mark.log;
|
|
1722
1815
|
}
|
|
1816
|
+
function parseTriviaNoCapture(triviaP, input, cur, ctx) {
|
|
1817
|
+
const probeCtx = {
|
|
1818
|
+
trackLines: ctx.trackLines,
|
|
1819
|
+
state: ctx.state,
|
|
1820
|
+
...ctx._lineIndex ? { _lineIndex: ctx._lineIndex } : {},
|
|
1821
|
+
...ctx._lineStarts ? { _lineStarts: ctx._lineStarts } : {},
|
|
1822
|
+
...ctx._lineScannedTo !== void 0 ? { _lineScannedTo: ctx._lineScannedTo } : {}
|
|
1823
|
+
};
|
|
1824
|
+
const result = triviaP.parse(input, cur, probeCtx);
|
|
1825
|
+
ctx._lineScannedTo = probeCtx._lineScannedTo;
|
|
1826
|
+
return result;
|
|
1827
|
+
}
|
|
1723
1828
|
function saveLookaheadMark(ctx) {
|
|
1724
1829
|
return { ...saveTriviaMark(ctx), probeBest: ctx._probe ? ctx._probe.best : null };
|
|
1725
1830
|
}
|
|
@@ -1742,13 +1847,29 @@ function scanWithLabels(input, cur, ctx) {
|
|
|
1742
1847
|
function advanceTrivia(input, cur, ctx) {
|
|
1743
1848
|
const triviaP = ctx.trivia;
|
|
1744
1849
|
if (!triviaP) return cur;
|
|
1850
|
+
if (!ctx.trackLines) {
|
|
1851
|
+
const fast2 = fastTriviaScanner(triviaP);
|
|
1852
|
+
if (fast2) return fast2(input, cur);
|
|
1853
|
+
if (ctx.triviaKindLabels) {
|
|
1854
|
+
const scan = scanWithLabels(input, cur, ctx);
|
|
1855
|
+
return scan.end;
|
|
1856
|
+
}
|
|
1857
|
+
const tr2 = triviaP.parse(input, cur, { trackLines: ctx.trackLines, state: ctx.state });
|
|
1858
|
+
return tr2.ok && tr2.span.end > cur ? tr2.span.end : cur;
|
|
1859
|
+
}
|
|
1860
|
+
const trackTriviaLines = ctx.trackLines && triviaP._meta.canMatchNewline;
|
|
1745
1861
|
const fast = fastTriviaScanner(triviaP);
|
|
1746
|
-
if (fast)
|
|
1862
|
+
if (fast) {
|
|
1863
|
+
const end = fast(input, cur);
|
|
1864
|
+
if (trackTriviaLines) recordLineRangeFromContext(ctx, input, cur, end);
|
|
1865
|
+
return end;
|
|
1866
|
+
}
|
|
1747
1867
|
if (ctx.triviaKindLabels) {
|
|
1748
1868
|
const scan = scanWithLabels(input, cur, ctx);
|
|
1869
|
+
if (trackTriviaLines) recordLineRangeFromContext(ctx, input, cur, scan.end);
|
|
1749
1870
|
return scan.end;
|
|
1750
1871
|
}
|
|
1751
|
-
const tr = triviaP
|
|
1872
|
+
const tr = parseTriviaNoCapture(triviaP, input, cur, ctx);
|
|
1752
1873
|
return tr.ok && tr.span.end > cur ? tr.span.end : cur;
|
|
1753
1874
|
}
|
|
1754
1875
|
function scanTrivia(input, cur, ctx) {
|
|
@@ -1756,18 +1877,46 @@ function scanTrivia(input, cur, ctx) {
|
|
|
1756
1877
|
if (!triviaP) return { end: cur, commit: NOOP_COMMIT };
|
|
1757
1878
|
const log = ctx._triviaLog;
|
|
1758
1879
|
const captureTl = ctx.captureTrivia && (ctx._cstBuf !== void 0 || ctx._cstTriviaLog !== void 0);
|
|
1880
|
+
if (!ctx.trackLines) {
|
|
1881
|
+
const fast2 = !ctx.triviaKindLabels ? fastTriviaScanner(triviaP) : null;
|
|
1882
|
+
if (fast2 && log === void 0 && !captureTl) {
|
|
1883
|
+
return { end: fast2(input, cur), commit: NOOP_COMMIT };
|
|
1884
|
+
}
|
|
1885
|
+
if (ctx.triviaKindLabels && (log !== void 0 || captureTl)) {
|
|
1886
|
+
return scanWithLabels(input, cur, ctx);
|
|
1887
|
+
}
|
|
1888
|
+
if (log !== void 0 || captureTl) {
|
|
1889
|
+
const tr3 = triviaP.parse(input, cur, {
|
|
1890
|
+
trackLines: log !== void 0 ? false : ctx.trackLines,
|
|
1891
|
+
state: ctx.state
|
|
1892
|
+
});
|
|
1893
|
+
if (!tr3.ok || tr3.span.end === cur) return { end: cur, commit: NOOP_COMMIT };
|
|
1894
|
+
const end = tr3.span.end;
|
|
1895
|
+
return {
|
|
1896
|
+
end,
|
|
1897
|
+
commit: () => {
|
|
1898
|
+
pushTriviaLogEntry(ctx, cur, end);
|
|
1899
|
+
if (captureTl) pushCstTriviaEntry(ctx, cur, end);
|
|
1900
|
+
}
|
|
1901
|
+
};
|
|
1902
|
+
}
|
|
1903
|
+
const tr2 = triviaP.parse(input, cur, { trackLines: ctx.trackLines, state: ctx.state });
|
|
1904
|
+
return { end: tr2.ok ? tr2.span.end : cur, commit: NOOP_COMMIT };
|
|
1905
|
+
}
|
|
1906
|
+
const trackTriviaLines = ctx.trackLines && triviaP._meta.canMatchNewline;
|
|
1759
1907
|
const fast = !ctx.triviaKindLabels ? fastTriviaScanner(triviaP) : null;
|
|
1760
1908
|
if (fast && log === void 0 && !captureTl) {
|
|
1761
|
-
|
|
1909
|
+
const end = fast(input, cur);
|
|
1910
|
+
if (trackTriviaLines) recordLineRangeFromContext(ctx, input, cur, end);
|
|
1911
|
+
return { end, commit: NOOP_COMMIT };
|
|
1762
1912
|
}
|
|
1763
1913
|
if (ctx.triviaKindLabels && (log !== void 0 || captureTl)) {
|
|
1764
|
-
|
|
1914
|
+
const scan = scanWithLabels(input, cur, ctx);
|
|
1915
|
+
if (trackTriviaLines) recordLineRangeFromContext(ctx, input, cur, scan.end);
|
|
1916
|
+
return scan;
|
|
1765
1917
|
}
|
|
1766
1918
|
if (log !== void 0 || captureTl) {
|
|
1767
|
-
const tr2 = triviaP
|
|
1768
|
-
trackLines: log !== void 0 ? false : ctx.trackLines,
|
|
1769
|
-
state: ctx.state
|
|
1770
|
-
});
|
|
1919
|
+
const tr2 = parseTriviaNoCapture(triviaP, input, cur, ctx);
|
|
1771
1920
|
if (!tr2.ok || tr2.span.end === cur) return { end: cur, commit: NOOP_COMMIT };
|
|
1772
1921
|
const end = tr2.span.end;
|
|
1773
1922
|
return {
|
|
@@ -1778,7 +1927,7 @@ function scanTrivia(input, cur, ctx) {
|
|
|
1778
1927
|
}
|
|
1779
1928
|
};
|
|
1780
1929
|
}
|
|
1781
|
-
const tr = triviaP
|
|
1930
|
+
const tr = parseTriviaNoCapture(triviaP, input, cur, ctx);
|
|
1782
1931
|
return { end: tr.ok ? tr.span.end : cur, commit: NOOP_COMMIT };
|
|
1783
1932
|
}
|
|
1784
1933
|
function consumeTrivia(input, cur, ctx) {
|
|
@@ -3202,13 +3351,14 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
3202
3351
|
const st = clonesState && ctx.state !== void 0 ? Object.assign({}, ctx.state) : void 0;
|
|
3203
3352
|
const nodeType = def.type ?? missingInferredType();
|
|
3204
3353
|
const cstOutput = cstOutputHost(ctx.build);
|
|
3354
|
+
const span = ctx.trackLines ? annotateSpanFromLineContext(r.span, ctx) : r.span;
|
|
3205
3355
|
const hostState = clonesState ? st : ctx.state !== void 0 ? Object.assign({}, ctx.state) : void 0;
|
|
3206
|
-
const built = unwrap && children2.length === 1 ? unwrapChild(children2[0]) : collapse && children2.length === 1 ? children2[0] : !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,
|
|
3207
|
-
const rawEntry = isCstChild(built) ? built : { _tag: "leaf", value: typeof built === "string" ? built : typeof built === "object" && built !== null ? input.slice(r.span.start, r.span.end) : "", span
|
|
3356
|
+
const built = unwrap && children2.length === 1 ? unwrapChild(children2[0]) : collapse && children2.length === 1 ? children2[0] : !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, hostState) : projectChild(children2, project, nodeType) : build ? cstOutput && ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, hostState) : build(children2, fields, span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, st) : { _tag: "node", type: nodeType, span: ctx.trackLines ? { ...span } : { start: r.span.start, end: r.span.end }, state: st ?? null, children: children2 };
|
|
3357
|
+
const rawEntry = isCstChild(built) ? built : { _tag: "leaf", value: typeof built === "string" ? built : typeof built === "object" && built !== null ? input.slice(r.span.start, r.span.end) : "", span };
|
|
3208
3358
|
if (saved.buf !== void 0 || saved.ch !== void 0) {
|
|
3209
3359
|
pushCstChild(ctx, built, rawEntry);
|
|
3210
3360
|
}
|
|
3211
|
-
return { ok: true, value: built, span
|
|
3361
|
+
return { ok: true, value: built, span };
|
|
3212
3362
|
}
|
|
3213
3363
|
};
|
|
3214
3364
|
}
|
|
@@ -3279,38 +3429,24 @@ function field(name, combinator) {
|
|
|
3279
3429
|
};
|
|
3280
3430
|
}
|
|
3281
3431
|
|
|
3282
|
-
// src/
|
|
3283
|
-
function
|
|
3284
|
-
const
|
|
3285
|
-
|
|
3286
|
-
|
|
3432
|
+
// src/combinators/grammar.ts
|
|
3433
|
+
function annotateResultLines(result, index) {
|
|
3434
|
+
const annotated = { ...result, span: annotateSpan(result.span, index) };
|
|
3435
|
+
const errors = annotated.errors;
|
|
3436
|
+
if (errors) {
|
|
3437
|
+
;
|
|
3438
|
+
annotated.errors = errors.map((error) => ({
|
|
3439
|
+
...error,
|
|
3440
|
+
span: annotateSpan(error.span, index)
|
|
3441
|
+
}));
|
|
3287
3442
|
}
|
|
3288
|
-
return
|
|
3443
|
+
return annotated;
|
|
3289
3444
|
}
|
|
3290
|
-
function
|
|
3291
|
-
const
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
while (lo < hi) {
|
|
3295
|
-
const mid = lo + hi + 1 >> 1;
|
|
3296
|
-
if (lineStarts[mid] <= offset) lo = mid;
|
|
3297
|
-
else hi = mid - 1;
|
|
3298
|
-
}
|
|
3299
|
-
return { line: lo + 1, col: offset - lineStarts[lo] + 1 };
|
|
3445
|
+
function createParseLineContext(input, pos) {
|
|
3446
|
+
const lineIndex = createLineIndex();
|
|
3447
|
+
if (pos > 0) recordLineRange(lineIndex, input, 0, pos);
|
|
3448
|
+
return { lineIndex, lineScannedTo: pos };
|
|
3300
3449
|
}
|
|
3301
|
-
function annotateSpan(span, index) {
|
|
3302
|
-
const s = offsetToLineCol(index, span.start);
|
|
3303
|
-
const e = offsetToLineCol(index, span.end);
|
|
3304
|
-
return {
|
|
3305
|
-
...span,
|
|
3306
|
-
startLine: s.line,
|
|
3307
|
-
startColumn: s.col,
|
|
3308
|
-
endLine: e.line,
|
|
3309
|
-
endColumn: e.col
|
|
3310
|
-
};
|
|
3311
|
-
}
|
|
3312
|
-
|
|
3313
|
-
// src/combinators/grammar.ts
|
|
3314
3450
|
function parser(opts, root) {
|
|
3315
3451
|
const clearTrivia = opts.trivia === null;
|
|
3316
3452
|
return {
|
|
@@ -3326,9 +3462,13 @@ function parser(opts, root) {
|
|
|
3326
3462
|
},
|
|
3327
3463
|
parse(input, pos, _ctx) {
|
|
3328
3464
|
const trackLines = opts.trackLines ?? _ctx?.trackLines ?? false;
|
|
3465
|
+
const lineContext = trackLines && _ctx?._lineIndex === void 0 && _ctx?._lineStarts === void 0 ? createParseLineContext(input, pos ?? 0) : void 0;
|
|
3466
|
+
const lineIndex = trackLines ? _ctx?._lineIndex ?? (_ctx?._lineStarts ? { lineStarts: _ctx._lineStarts } : lineContext.lineIndex) : void 0;
|
|
3329
3467
|
const ctx = {
|
|
3330
3468
|
..._ctx,
|
|
3331
3469
|
trackLines,
|
|
3470
|
+
...lineIndex ? { _lineIndex: lineIndex } : {},
|
|
3471
|
+
...lineContext ? { _lineScannedTo: lineContext.lineScannedTo } : {},
|
|
3332
3472
|
// trivia: null clears (contiguous terms); a Combinator sets; undefined inherits.
|
|
3333
3473
|
...clearTrivia ? {
|
|
3334
3474
|
trivia: void 0,
|
|
@@ -3346,11 +3486,10 @@ function parser(opts, root) {
|
|
|
3346
3486
|
...opts.captureTriviaKinds && !clearTrivia ? { _triviaCaptureMask: triviaKindMask(opts.trivia?._meta.triviaKindLabels ?? _ctx?.triviaKindLabels, opts.captureTriviaKinds) } : {}
|
|
3347
3487
|
};
|
|
3348
3488
|
const result = root.parse(input, pos ?? 0, ctx);
|
|
3349
|
-
if (trackLines) {
|
|
3350
|
-
|
|
3351
|
-
return { ...result, span: annotateSpan(result.span, idx) };
|
|
3489
|
+
if (trackLines && _ctx && ctx._lineScannedTo !== void 0) {
|
|
3490
|
+
_ctx._lineScannedTo = Math.max(_ctx._lineScannedTo ?? 0, ctx._lineScannedTo);
|
|
3352
3491
|
}
|
|
3353
|
-
return result;
|
|
3492
|
+
return lineIndex ? annotateResultLines(result, normalizeLineIndex(lineIndex)) : result;
|
|
3354
3493
|
}
|
|
3355
3494
|
};
|
|
3356
3495
|
}
|
|
@@ -3364,25 +3503,25 @@ function parse(combinator, input, opts = {}) {
|
|
|
3364
3503
|
markUnusedValues(combinator);
|
|
3365
3504
|
}
|
|
3366
3505
|
const trackLines = opts.trackLines ?? false;
|
|
3506
|
+
const lineContext = trackLines ? createParseLineContext(input, 0) : void 0;
|
|
3507
|
+
const lineIndex = lineContext?.lineIndex;
|
|
3367
3508
|
const _errors = opts.recover ? [] : void 0;
|
|
3368
3509
|
const _probe = opts.recover ? { offset: input.length, best: null } : void 0;
|
|
3369
3510
|
const grammarTrivia = combinator._meta.grammarTrivia;
|
|
3370
3511
|
const grammarScanSkip = combinator._meta.grammarScanSkip;
|
|
3371
3512
|
const ctx = {
|
|
3372
3513
|
trackLines,
|
|
3514
|
+
...lineIndex ? { _lineIndex: lineIndex } : {},
|
|
3515
|
+
...lineContext ? { _lineScannedTo: lineContext.lineScannedTo } : {},
|
|
3373
3516
|
...grammarTrivia !== void 0 ? { trivia: grammarTrivia, ...grammarTrivia._meta.triviaKindLabels ? { triviaKindLabels: grammarTrivia._meta.triviaKindLabels } : {} } : {},
|
|
3374
3517
|
...grammarScanSkip !== void 0 ? { scanSkip: grammarScanSkip } : {},
|
|
3375
3518
|
..._errors !== void 0 ? { _errors } : {},
|
|
3376
3519
|
..._probe !== void 0 ? { _probe } : {}
|
|
3377
3520
|
};
|
|
3378
3521
|
const result = combinator.parse(input, 0, ctx);
|
|
3379
|
-
if (!result.ok) return result;
|
|
3522
|
+
if (!result.ok) return lineIndex ? annotateResultLines(result, normalizeLineIndex(lineIndex)) : result;
|
|
3380
3523
|
const withErrors = _errors !== void 0 ? { ...result, errors: _errors, furthestFail: _probe?.best ?? null } : result;
|
|
3381
|
-
|
|
3382
|
-
const idx = buildLineIndex(input);
|
|
3383
|
-
return { ...withErrors, span: annotateSpan(withErrors.span, idx) };
|
|
3384
|
-
}
|
|
3385
|
-
return withErrors;
|
|
3524
|
+
return lineIndex ? annotateResultLines(withErrors, normalizeLineIndex(lineIndex)) : withErrors;
|
|
3386
3525
|
}
|
|
3387
3526
|
|
|
3388
3527
|
// src/combinators/token.ts
|
|
@@ -3481,7 +3620,7 @@ function leaf(root, fn) {
|
|
|
3481
3620
|
}
|
|
3482
3621
|
|
|
3483
3622
|
// src/version.ts
|
|
3484
|
-
var PARSEMAN_VERSION = "0.
|
|
3623
|
+
var PARSEMAN_VERSION = "0.42.0";
|
|
3485
3624
|
|
|
3486
3625
|
// src/cst/host-mode.ts
|
|
3487
3626
|
var FUSED_HOST_MODE = /* @__PURE__ */ Symbol.for("parseman.fusedHostMode");
|
|
@@ -5165,7 +5304,7 @@ function scanTo(sentinel, { skip: skip2, raw = false, orEOF = false } = {}) {
|
|
|
5165
5304
|
let cur = pos;
|
|
5166
5305
|
const skip3 = resolveScanSkip(explicitSkip, raw, ctx);
|
|
5167
5306
|
const probeCtx = {
|
|
5168
|
-
trackLines:
|
|
5307
|
+
trackLines: false,
|
|
5169
5308
|
state: ctx.state,
|
|
5170
5309
|
...ctx._errors !== void 0 ? { _errors: ctx._errors } : {}
|
|
5171
5310
|
};
|
|
@@ -5178,6 +5317,7 @@ function scanTo(sentinel, { skip: skip2, raw = false, orEOF = false } = {}) {
|
|
|
5178
5317
|
while (cur < input.length) {
|
|
5179
5318
|
const s = sentinel.parse(input, cur, probeCtx);
|
|
5180
5319
|
if (s.ok) {
|
|
5320
|
+
if (ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, cur);
|
|
5181
5321
|
emit2(cur);
|
|
5182
5322
|
return { ok: true, value: input.slice(pos, cur), span: { start: pos, end: cur } };
|
|
5183
5323
|
}
|
|
@@ -5193,6 +5333,7 @@ function scanTo(sentinel, { skip: skip2, raw = false, orEOF = false } = {}) {
|
|
|
5193
5333
|
if (!advanced) cur++;
|
|
5194
5334
|
}
|
|
5195
5335
|
if (orEOF) {
|
|
5336
|
+
if (ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, cur);
|
|
5196
5337
|
emit2(cur);
|
|
5197
5338
|
return { ok: true, value: input.slice(pos, cur), span: { start: pos, end: cur } };
|
|
5198
5339
|
}
|
|
@@ -6631,8 +6772,8 @@ function analyzeMkInlineBuild(def) {
|
|
|
6631
6772
|
if (looseMkBuildRe(def.type).test(src)) return def.type;
|
|
6632
6773
|
return null;
|
|
6633
6774
|
}
|
|
6634
|
-
function emitInlineMkNodeExpr(type, chV, rawV,
|
|
6635
|
-
return `{ _tag: 'node', type: ${JSON.stringify(type)}, span:
|
|
6775
|
+
function emitInlineMkNodeExpr(type, chV, rawV, spanExpr, tlV) {
|
|
6776
|
+
return `{ _tag: 'node', type: ${JSON.stringify(type)}, span: ${spanExpr}, children: ${chV}, rawCount: ${rawV}.length, localTriviaLen: ${tlV}.length }`;
|
|
6636
6777
|
}
|
|
6637
6778
|
|
|
6638
6779
|
// src/compiler/inline-callback.ts
|
|
@@ -6814,6 +6955,8 @@ function leadingFirstSetRecipe(p, seen = /* @__PURE__ */ new Set()) {
|
|
|
6814
6955
|
}
|
|
6815
6956
|
}
|
|
6816
6957
|
var HOST_READS_DECL = "const _hostReads = (b, n) => { if (b === undefined) return false; let s; try { s = Function.prototype.toString.call(b) } catch (e) { return true } if (/\\barguments\\b/.test(s)) return true; const m = /^[^(]*\\(([\\s\\S]*?)\\)/.exec(s); if (m && /\\.\\.\\.|=/.test(m[1])) return true; return b.length > n }";
|
|
6958
|
+
var LINE_TRACK_DECL = "const _trackLines = (_ctx, input, start, end) => { const from = _ctx._lineScannedTo ?? 0; if (end <= from) return; for (let i = from; i < end; i++) if (input.charCodeAt(i) === 10) _ctx._lineStarts.push(i + 1); _ctx._lineScannedTo = end }";
|
|
6959
|
+
var LINE_SPAN_DECL = "const _lineCol = (_ctx, offset) => { const starts = _ctx._lineStarts; let lo = 0, hi = starts.length - 1; while (lo < hi) { const mid = (lo + hi + 1) >> 1; if (starts[mid] <= offset) lo = mid; else hi = mid - 1 } return [lo + 1, offset - starts[lo] + 1] }\nconst _spanLines = (_ctx, start, end) => { const s = _lineCol(_ctx, start), e = _lineCol(_ctx, end); return { start, end, startLine: s[0], startColumn: s[1], endLine: e[0], endColumn: e[1] } }";
|
|
6817
6960
|
var _loweringSink = null;
|
|
6818
6961
|
function v(ctx, prefix = "_v") {
|
|
6819
6962
|
return `${prefix}${ctx.vars++}`;
|
|
@@ -6954,14 +7097,46 @@ function emitLeafCapture(ctx, valExpr, startExpr, endExpr) {
|
|
|
6954
7097
|
if (ctx.capAsTrivia) return [];
|
|
6955
7098
|
const i = ind(ctx);
|
|
6956
7099
|
const lf = v(ctx, "_lf");
|
|
7100
|
+
const spanExpr = emitSpanExpr(ctx, startExpr, endExpr);
|
|
6957
7101
|
return [
|
|
6958
7102
|
`${i}if (_ctx._cstLeaves || _ctx._cstRawChildren) {`,
|
|
6959
|
-
`${i} const ${lf} = { _tag: 'leaf', value: ${valExpr}, span:
|
|
7103
|
+
`${i} const ${lf} = { _tag: 'leaf', value: ${valExpr}, span: ${spanExpr} }`,
|
|
6960
7104
|
`${i} if (_ctx._cstLeaves) _ctx._cstLeaves.push(${lf})`,
|
|
6961
7105
|
`${i} if (_ctx._cstRawChildren) _ctx._cstRawChildren.push(${lf})`,
|
|
6962
7106
|
`${i}}`
|
|
6963
7107
|
];
|
|
6964
7108
|
}
|
|
7109
|
+
function emitSpanExpr(ctx, startExpr, endExpr) {
|
|
7110
|
+
if (!ctx.lineTracking) return `{ start: ${startExpr}, end: ${endExpr} }`;
|
|
7111
|
+
ctx.needsLineSpan = true;
|
|
7112
|
+
return `_spanLines(_ctx, ${startExpr}, ${endExpr})`;
|
|
7113
|
+
}
|
|
7114
|
+
function emitLineTrack(ctx, startExpr, endExpr) {
|
|
7115
|
+
if (!ctx.lineTracking) return [];
|
|
7116
|
+
ctx.needsLineTrack = true;
|
|
7117
|
+
return [`${ind(ctx)}_trackLines(_ctx, input, ${startExpr}, ${endExpr})`];
|
|
7118
|
+
}
|
|
7119
|
+
function emitLiteralLineTrack(ctx, startExpr, value) {
|
|
7120
|
+
if (!ctx.lineTracking) return [];
|
|
7121
|
+
const lineDeltas = [];
|
|
7122
|
+
for (let i = 0; i < value.length; i++) {
|
|
7123
|
+
if (value.charCodeAt(i) === 10) lineDeltas.push(i + 1);
|
|
7124
|
+
}
|
|
7125
|
+
if (lineDeltas.length === 0) return [];
|
|
7126
|
+
const fromV = v(ctx, "_ltFrom");
|
|
7127
|
+
const endExpr = value.length === 0 ? startExpr : `${startExpr} + ${value.length}`;
|
|
7128
|
+
return [
|
|
7129
|
+
`${ind(ctx)}const ${fromV} = _ctx._lineScannedTo ?? 0`,
|
|
7130
|
+
`${ind(ctx)}if (${endExpr} > ${fromV}) {`,
|
|
7131
|
+
`${ind(ctx)} for (let i = ${fromV}; i < ${startExpr}; i++) if (input.charCodeAt(i) === 10) _ctx._lineStarts.push(i + 1)`,
|
|
7132
|
+
...lineDeltas.map((delta) => {
|
|
7133
|
+
const lineStart = `${startExpr} + ${delta}`;
|
|
7134
|
+
return `${ind(ctx)} if (${lineStart} > ${fromV}) _ctx._lineStarts.push(${lineStart})`;
|
|
7135
|
+
}),
|
|
7136
|
+
`${ind(ctx)} _ctx._lineScannedTo = ${endExpr}`,
|
|
7137
|
+
`${ind(ctx)}}`
|
|
7138
|
+
];
|
|
7139
|
+
}
|
|
6965
7140
|
function ensureRegexDecl(ctx, source, flags) {
|
|
6966
7141
|
const f = "y" + flags.replace(/[gy]/g, "");
|
|
6967
7142
|
const key = `${source}/${f}`;
|
|
@@ -7346,6 +7521,7 @@ function emitLit(def, ctx, pos) {
|
|
|
7346
7521
|
);
|
|
7347
7522
|
}
|
|
7348
7523
|
const endVar = len === 0 ? pos : `${pos} + ${len}`;
|
|
7524
|
+
stmts.push(...emitLiteralLineTrack(ctx, pos, value));
|
|
7349
7525
|
stmts.push(...emitLeafCapture(ctx, vv, pos, endVar));
|
|
7350
7526
|
return { stmts, valueVar: vv, endVar };
|
|
7351
7527
|
}
|
|
@@ -7425,7 +7601,7 @@ function emitKeywords(def, ctx, pos) {
|
|
|
7425
7601
|
stmts.push(...emitLeafCapture(ctx, vv, pos, endVar));
|
|
7426
7602
|
return { stmts, valueVar: vv, endVar };
|
|
7427
7603
|
}
|
|
7428
|
-
function emitRegex(def, ctx, pos) {
|
|
7604
|
+
function emitRegex(def, ctx, pos, canMatchNewline = true) {
|
|
7429
7605
|
const expectedStr = JSON.stringify(`/${def.source}/`);
|
|
7430
7606
|
const shape = scanShapeFromRegex(def.source, def.flags);
|
|
7431
7607
|
if (shape) {
|
|
@@ -7438,7 +7614,11 @@ function emitRegex(def, ctx, pos) {
|
|
|
7438
7614
|
fresh: (prefix) => v(ctx, prefix)
|
|
7439
7615
|
});
|
|
7440
7616
|
if (scanned) {
|
|
7441
|
-
const stmts2 = [
|
|
7617
|
+
const stmts2 = [
|
|
7618
|
+
...scanned.stmts,
|
|
7619
|
+
...canMatchNewline ? emitLineTrack(ctx, pos, scanned.endVar) : [],
|
|
7620
|
+
...emitLeafCapture(ctx, vv2, pos, scanned.endVar)
|
|
7621
|
+
];
|
|
7442
7622
|
return { stmts: stmts2, valueVar: vv2, endVar: scanned.endVar };
|
|
7443
7623
|
}
|
|
7444
7624
|
}
|
|
@@ -7460,6 +7640,7 @@ function emitRegex(def, ctx, pos) {
|
|
|
7460
7640
|
`${ind(ctx)}const ${vv} = ${mv}[0]`
|
|
7461
7641
|
];
|
|
7462
7642
|
const endVar = `${pos} + ${vv}.length`;
|
|
7643
|
+
if (canMatchNewline) stmts.push(...emitLineTrack(ctx, pos, endVar));
|
|
7463
7644
|
stmts.push(...emitLeafCapture(ctx, vv, pos, endVar));
|
|
7464
7645
|
return { stmts, valueVar: vv, endVar };
|
|
7465
7646
|
}
|
|
@@ -7497,7 +7678,8 @@ function emitSeqValues(def, ctx, pos) {
|
|
|
7497
7678
|
`${ind(ctx)}const ${markV} = _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0`,
|
|
7498
7679
|
`${ind(ctx)}const ${markTl} = _ctx._cstTriviaLog ? _ctx._cstTriviaLog.length : 0`,
|
|
7499
7680
|
`${ind(ctx)}const ${markLog} = _ctx._triviaLog ? _ctx._triviaLog.length : 0`,
|
|
7500
|
-
`${ind(ctx)}const ${scanEndV} = ${capFn}(input, ${curV}, _ctx, 1)
|
|
7681
|
+
`${ind(ctx)}const ${scanEndV} = ${capFn}(input, ${curV}, _ctx, 1)`,
|
|
7682
|
+
...emitLineTrack(ctx, curV, scanEndV)
|
|
7501
7683
|
);
|
|
7502
7684
|
const r2 = emit(def.parsers[i], ctx, scanEndV);
|
|
7503
7685
|
stmts.push(...r2.stmts);
|
|
@@ -7515,7 +7697,8 @@ function emitSeqValues(def, ctx, pos) {
|
|
|
7515
7697
|
const capArg = ctx.noHoist ? "0" : "_ctx._triviaLog !== undefined ? 2 : 0";
|
|
7516
7698
|
stmts.push(
|
|
7517
7699
|
`${ind(ctx)}const ${markLog} = _ctx._triviaLog ? _ctx._triviaLog.length : 0`,
|
|
7518
|
-
`${ind(ctx)}const ${scanEndV} = ${trivFn}(input, ${curV}, _ctx, ${capArg})
|
|
7700
|
+
`${ind(ctx)}const ${scanEndV} = ${trivFn}(input, ${curV}, _ctx, ${capArg})`,
|
|
7701
|
+
...emitLineTrack(ctx, curV, scanEndV)
|
|
7519
7702
|
);
|
|
7520
7703
|
const r2 = emit(def.parsers[i], ctx, scanEndV);
|
|
7521
7704
|
stmts.push(...r2.stmts);
|
|
@@ -8215,14 +8398,15 @@ function emitMany(def, ctx, pos) {
|
|
|
8215
8398
|
`${ind(ctx)}const ${markV} = _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0`,
|
|
8216
8399
|
`${ind(ctx)}const ${markTl} = _ctx._cstTriviaLog ? _ctx._cstTriviaLog.length : 0`,
|
|
8217
8400
|
`${ind(ctx)}const ${markLog} = _ctx._triviaLog ? _ctx._triviaLog.length : 0`,
|
|
8218
|
-
`${ind(ctx)}const ${npV} = ${capFn}(input, ${curV}, _ctx, 1)
|
|
8401
|
+
`${ind(ctx)}const ${npV} = ${capFn}(input, ${curV}, _ctx, 1)`,
|
|
8402
|
+
...emitLineTrack(ctx, curV, npV)
|
|
8219
8403
|
);
|
|
8220
8404
|
itemPos = npV;
|
|
8221
8405
|
rollback = `if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${markV}) _ctx._cstRawChildren.length = ${markV}; if (_ctx._cstTriviaLog && _ctx._cstTriviaLog.length !== ${markTl}) _ctx._cstTriviaLog.length = ${markTl}; if (_ctx._triviaLog && _ctx._triviaLog.length !== ${markLog}) _ctx._triviaLog.length = ${markLog}; `;
|
|
8222
8406
|
} else {
|
|
8223
8407
|
const trivFn = ensureTriviaFn(ctx);
|
|
8224
8408
|
const npV = v(ctx, "_np");
|
|
8225
|
-
stmts.push(`${ind(ctx)}const ${npV} = ${trivFn}(input, ${curV}, _ctx)
|
|
8409
|
+
stmts.push(`${ind(ctx)}const ${npV} = ${trivFn}(input, ${curV}, _ctx)`, ...emitLineTrack(ctx, curV, npV));
|
|
8226
8410
|
itemPos = npV;
|
|
8227
8411
|
}
|
|
8228
8412
|
}
|
|
@@ -8399,7 +8583,8 @@ function emitSepBy(_p, def, ctx, pos) {
|
|
|
8399
8583
|
`${ind(ctx)}const ${markLog} = _ctx._triviaLog ? _ctx._triviaLog.length : 0`,
|
|
8400
8584
|
`${ind(ctx)}const ${markLv} = _ctx._cstLeaves ? _ctx._cstLeaves.length : 0`,
|
|
8401
8585
|
`${ind(ctx)}const ${markFld} = _ctx._fields ? _ctx._fields.length : 0`,
|
|
8402
|
-
`${ind(ctx)}const ${spV} = ${capFn}(input, ${curV}, _ctx, 1)
|
|
8586
|
+
`${ind(ctx)}const ${spV} = ${capFn}(input, ${curV}, _ctx, 1)`,
|
|
8587
|
+
...emitLineTrack(ctx, curV, spV)
|
|
8403
8588
|
);
|
|
8404
8589
|
sepAtPos = spV;
|
|
8405
8590
|
const rollbackToSep = `if (_ctx._cstLeaves && _ctx._cstLeaves.length !== ${markLv}) _ctx._cstLeaves.length = ${markLv}; if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${markV}) _ctx._cstRawChildren.length = ${markV}; if (_ctx._cstTriviaLog && _ctx._cstTriviaLog.length !== ${markTl}) _ctx._cstTriviaLog.length = ${markTl}; if (_ctx._triviaLog && _ctx._triviaLog.length !== ${markLog}) _ctx._triviaLog.length = ${markLog}; if (_ctx._fields && _ctx._fields.length !== ${markFld}) _ctx._fields.length = ${markFld}; `;
|
|
@@ -8409,7 +8594,7 @@ function emitSepBy(_p, def, ctx, pos) {
|
|
|
8409
8594
|
const post = postSepMarks();
|
|
8410
8595
|
stmts.push(...post.decl);
|
|
8411
8596
|
const npV = v(ctx, "_np");
|
|
8412
|
-
stmts.push(`${ind(ctx)}const ${npV} = ${capFn}(input, ${sepEnd}, _ctx, 1)
|
|
8597
|
+
stmts.push(`${ind(ctx)}const ${npV} = ${capFn}(input, ${sepEnd}, _ctx, 1)`, ...emitLineTrack(ctx, sepEnd, npV));
|
|
8413
8598
|
const next = emitFallible(def.parser, ctx, npV, true);
|
|
8414
8599
|
const { stmts: nextStmts, okVar: nextOk, valVar: nextVal, endVar: nextEnd } = next;
|
|
8415
8600
|
stmts.push(
|
|
@@ -8421,13 +8606,13 @@ function emitSepBy(_p, def, ctx, pos) {
|
|
|
8421
8606
|
} else {
|
|
8422
8607
|
const trivFn = ensureTriviaFn(ctx);
|
|
8423
8608
|
const spV = v(ctx, "_sp");
|
|
8424
|
-
stmts.push(`${ind(ctx)}const ${spV} = ${trivFn}(input, ${curV}, _ctx)
|
|
8609
|
+
stmts.push(`${ind(ctx)}const ${spV} = ${trivFn}(input, ${curV}, _ctx)`, ...emitLineTrack(ctx, curV, spV));
|
|
8425
8610
|
sepAtPos = spV;
|
|
8426
8611
|
const sep = emitFallible(def.separator, ctx, sepAtPos, true);
|
|
8427
8612
|
const { stmts: sepStmts, okVar: sepOk, endVar: sepEnd } = sep;
|
|
8428
8613
|
stmts.push(...sepStmts, `${ind(ctx)}if (!${sepOk}) { ${sep.mayCommit ? `if (_ctx._fc) ${committedFailBody(ctx)}; ` : ""}break }`);
|
|
8429
8614
|
const npV = v(ctx, "_np");
|
|
8430
|
-
stmts.push(`${ind(ctx)}const ${npV} = ${trivFn}(input, ${sepEnd}, _ctx)
|
|
8615
|
+
stmts.push(`${ind(ctx)}const ${npV} = ${trivFn}(input, ${sepEnd}, _ctx)`, ...emitLineTrack(ctx, sepEnd, npV));
|
|
8431
8616
|
const next = emitFallible(def.parser, ctx, npV, true);
|
|
8432
8617
|
const { stmts: nextStmts, okVar: nextOk, valVar: nextVal, endVar: nextEnd } = next;
|
|
8433
8618
|
stmts.push(
|
|
@@ -8514,6 +8699,7 @@ function emitScanTo(def, ctx, pos) {
|
|
|
8514
8699
|
}
|
|
8515
8700
|
const valV = v(ctx);
|
|
8516
8701
|
stmts.push(`${ind(ctx)}const ${valV} = input.slice(${pos}, ${curV})`);
|
|
8702
|
+
stmts.push(...emitLineTrack(ctx, pos, curV));
|
|
8517
8703
|
if (ctx.capturing) {
|
|
8518
8704
|
const cap = reindentStmts(emitLeafCapture(ctx, valV, pos, curV), ctx.indent + 1);
|
|
8519
8705
|
stmts.push(`${ind(ctx)}if (${curV} > ${pos}) {`, ...cap, `${ind(ctx)}}`);
|
|
@@ -8657,7 +8843,7 @@ function tokenNullableRegex(def) {
|
|
|
8657
8843
|
}
|
|
8658
8844
|
function emitToken(def, ctx, pos) {
|
|
8659
8845
|
const lowered = tokenNullableRegex(def);
|
|
8660
|
-
if (lowered) return emitRegex(lowered, ctx, pos);
|
|
8846
|
+
if (lowered) return emitRegex(lowered, ctx, pos, def.parser._meta.canMatchNewline);
|
|
8661
8847
|
const savedTrivia = ctx.activeTrivia;
|
|
8662
8848
|
const savedKindLabels = ctx.triviaKindLabels;
|
|
8663
8849
|
ctx.activeTrivia = void 0;
|
|
@@ -8807,7 +8993,7 @@ ${i}const ${chV} = ${chAlloc}, ${rawV} = ${profileRecognizer} ? undefined : [],
|
|
|
8807
8993
|
stmts.push(...innerStmts);
|
|
8808
8994
|
if (def.trailingTrivia === true && ctx.activeTrivia) {
|
|
8809
8995
|
const triviaFn = ensureTriviaFn(ctx);
|
|
8810
|
-
stmts.push(`${i}const ${endVar} = ${okVar} ? ${triviaFn}(input, ${innerEndVar}, _ctx, 1) : ${innerEndVar}
|
|
8996
|
+
stmts.push(`${i}const ${endVar} = ${okVar} ? ${triviaFn}(input, ${innerEndVar}, _ctx, 1) : ${innerEndVar}`, ...emitLineTrack(ctx, innerEndVar, endVar));
|
|
8811
8997
|
}
|
|
8812
8998
|
if (sf && fArr) {
|
|
8813
8999
|
stmts.push(`${i}const ${fArr} = _ctx._fields`);
|
|
@@ -8847,8 +9033,11 @@ ${i}const ${chV} = ${chAlloc}, ${rawV} = ${profileRecognizer} ? undefined : [],
|
|
|
8847
9033
|
);
|
|
8848
9034
|
}
|
|
8849
9035
|
const ndV = v(ctx, "_nd");
|
|
8850
|
-
const
|
|
8851
|
-
const
|
|
9036
|
+
const nodeSpanExpr = emitSpanExpr(ctx, pos, endVar);
|
|
9037
|
+
const nodeSpanV = ctx.lineTracking ? v(ctx, "_nspan") : nodeSpanExpr;
|
|
9038
|
+
if (ctx.lineTracking) stmts.push(`${i}const ${nodeSpanV} = ${nodeSpanExpr}`);
|
|
9039
|
+
const buildExpr = structural ? `{ _tag: 'node', type: ${JSON.stringify(def.type)}, span: ${nodeSpanV}, state: ${stV} ?? null, children: ${chV} }` : mkType ? emitInlineMkNodeExpr(mkType, chV, rawV, nodeSpanV, tlV) : def.project !== void 0 ? emitNodeProjectExpr(def.type, def.project, chV) : `${buildRef(ctx)}[${buildIdx}](${chV}, ${fObj}, ${nodeSpanV}, ${rawV}, ${tlV}, ${stV})`;
|
|
9040
|
+
const hostBuildExpr = `_ctx._pmProfile?.phase === 'host' && _ctx._pmProfile.hostCalls++, _ctx.build(${JSON.stringify(def.type)}, ${chV}, ${fObj}, ${nodeSpanV}, ${rawV}, ${tlV}, ${stV})`;
|
|
8852
9041
|
const ndExpr = structural ? `_ctx.build !== undefined ? (${hostBuildExpr}) : (${buildExpr})` : cstOut ? hostBuildExpr : buildExpr;
|
|
8853
9042
|
const hostCollapseExpr = structural ? `_ctx.build !== undefined && _ctx.build._parsemanCstCollapse !== undefined && ${chV}.length === 1 && ${rawV}.length === 1 && _ctx.build._parsemanCstCollapse(${JSON.stringify(def.type)}, ${chV}[0], ${chV}, ${rawV}) ? ${chV}[0] : (${ndExpr})` : ndExpr;
|
|
8854
9043
|
const unwrapExpr = `${chV}.length === 1 ? (${chV}[0] !== null && typeof ${chV}[0] === 'object' && ${chV}[0]._tag === 'leaf' ? ${chV}[0].value : ${chV}[0]) : (${ndExpr})`;
|
|
@@ -8858,7 +9047,7 @@ ${i}const ${chV} = ${chAlloc}, ${rawV} = ${profileRecognizer} ? undefined : [],
|
|
|
8858
9047
|
`${i}const ${ndV} = (${profileRecognizer} || ${profileCapture}) ? undefined : (${finalExpr})`,
|
|
8859
9048
|
`${i}if (!(${profileRecognizer})) {`,
|
|
8860
9049
|
`${i} if (${sc}) ${sc}.push(${ndV})`,
|
|
8861
|
-
`${i} if (${sr}) ${sr}.push((typeof ${ndV} === 'object' && ${ndV} !== null && (${ndV}._tag === 'node' || ${ndV}._tag === 'leaf' || ${ndV}._tag === 'parseError')) ? ${ndV} : { _tag: 'leaf', value: typeof ${ndV} === 'string' ? ${ndV} : (typeof ${ndV} === 'object' && ${ndV} !== null ? input.slice(${pos}, ${endVar}) : ''), span:
|
|
9050
|
+
`${i} if (${sr}) ${sr}.push((typeof ${ndV} === 'object' && ${ndV} !== null && (${ndV}._tag === 'node' || ${ndV}._tag === 'leaf' || ${ndV}._tag === 'parseError')) ? ${ndV} : { _tag: 'leaf', value: typeof ${ndV} === 'string' ? ${ndV} : (typeof ${ndV} === 'object' && ${ndV} !== null ? input.slice(${pos}, ${endVar}) : ''), span: ${nodeSpanV} })`,
|
|
8862
9051
|
`${i}}`
|
|
8863
9052
|
);
|
|
8864
9053
|
return { stmts, valueVar: ndV, endVar };
|
|
@@ -8874,7 +9063,8 @@ function emitRuntimeFallback(parser2, ctx, pos) {
|
|
|
8874
9063
|
`${ind(ctx)}const ${rv} = _rp[${idx}].parse(input, ${pos}, _ctx)`,
|
|
8875
9064
|
...emitIfFail(ctx, `!${rv}.ok`, failStmt),
|
|
8876
9065
|
`${ind(ctx)}const ${vv} = ${rv}.value`,
|
|
8877
|
-
`${ind(ctx)}const ${ev} = ${rv}.span.end
|
|
9066
|
+
`${ind(ctx)}const ${ev} = ${rv}.span.end`,
|
|
9067
|
+
...parser2._meta.canMatchNewline ? emitLineTrack(ctx, pos, ev) : []
|
|
8878
9068
|
];
|
|
8879
9069
|
return { stmts, valueVar: vv, endVar: ev };
|
|
8880
9070
|
}
|
|
@@ -8940,7 +9130,8 @@ function emitRecover(def, ctx, pos) {
|
|
|
8940
9130
|
`${ind0} if (${sentOk}) break`,
|
|
8941
9131
|
`${ind0} ${scanV}++`,
|
|
8942
9132
|
`${ind0} }`,
|
|
8943
|
-
|
|
9133
|
+
...emitLineTrack(ctx, pos, scanV).map((s) => `${ind0} ${s.trim()}`),
|
|
9134
|
+
`${ind0} const ${errV} = { _tag: 'parseError', span: ${emitSpanExpr(ctx, pos, scanV)}, expected: ${JSON.stringify(deriveExpected(def.parser))} }`,
|
|
8944
9135
|
`${ind0} if (_ctx._errors) _ctx._errors.push(${errV})`,
|
|
8945
9136
|
`${ind0} ${valVar} = ${errV}`,
|
|
8946
9137
|
`${ind0} ${endVar} = ${scanV}`,
|
|
@@ -8956,7 +9147,7 @@ function emitExpect(def, ctx, pos) {
|
|
|
8956
9147
|
const stmts = [
|
|
8957
9148
|
...innerStmts,
|
|
8958
9149
|
`${ind0}if (!${okVar}) {`,
|
|
8959
|
-
`${ind0} const ${errV} = { _tag: 'parseError', span: {
|
|
9150
|
+
`${ind0} const ${errV} = { _tag: 'parseError', span: ${emitSpanExpr(ctx, pos, pos)}, expected: ${JSON.stringify(def.expected)} }`,
|
|
8960
9151
|
`${ind0} if (_ctx._errors) _ctx._errors.push(${errV})`,
|
|
8961
9152
|
// Embed the missing-token error as a `parseError` CST child, mirroring the
|
|
8962
9153
|
// interpreter (expect.ts) and the list-recovery emit sites — guarded on
|
|
@@ -9046,7 +9237,7 @@ function emitDispatch(p, ctx, pos) {
|
|
|
9046
9237
|
case "literal":
|
|
9047
9238
|
return emitLit(def, ctx, pos);
|
|
9048
9239
|
case "regex":
|
|
9049
|
-
return emitRegex(def, ctx, pos);
|
|
9240
|
+
return emitRegex(def, ctx, pos, p._meta.canMatchNewline);
|
|
9050
9241
|
case "keywords":
|
|
9051
9242
|
return emitKeywords(def, ctx, pos);
|
|
9052
9243
|
case "sequence":
|
|
@@ -9296,6 +9487,20 @@ function hasNodeDef(p, seen = /* @__PURE__ */ new Set()) {
|
|
|
9296
9487
|
return false;
|
|
9297
9488
|
}
|
|
9298
9489
|
}
|
|
9490
|
+
function hasLineTrackingDef(p, seen = /* @__PURE__ */ new Set()) {
|
|
9491
|
+
if (seen.has(p)) return false;
|
|
9492
|
+
seen.add(p);
|
|
9493
|
+
const d = p._def;
|
|
9494
|
+
if (d.tag === "grammar" && d.trackLines) return true;
|
|
9495
|
+
if (d.tag === "lazy") {
|
|
9496
|
+
try {
|
|
9497
|
+
return hasLineTrackingDef(d.thunk(), seen);
|
|
9498
|
+
} catch {
|
|
9499
|
+
return false;
|
|
9500
|
+
}
|
|
9501
|
+
}
|
|
9502
|
+
return childrenOf2(d).some((child) => hasLineTrackingDef(child, seen));
|
|
9503
|
+
}
|
|
9299
9504
|
function parserUsesRouted2(p, seen = /* @__PURE__ */ new Set()) {
|
|
9300
9505
|
if (seen.has(p)) return false;
|
|
9301
9506
|
seen.add(p);
|
|
@@ -9663,6 +9868,7 @@ function compile(combinator, mapFnSources, opts) {
|
|
|
9663
9868
|
capturing: hasNodeDef(combinator),
|
|
9664
9869
|
recovery: opts?.recovery ?? false,
|
|
9665
9870
|
hostMode: opts?.hostMode ?? grammarHostMode ?? "ast",
|
|
9871
|
+
lineTracking: opts?.trackLines === true || hasLineTrackingDef(combinator),
|
|
9666
9872
|
...opts?.coverage ? { coverage: { plan: buildGrammarPlan(combinator), entry: combinator } } : {},
|
|
9667
9873
|
lazyUsage: analyzeLazyUsage(combinator),
|
|
9668
9874
|
...grammarTrivia ? { activeTrivia: grammarTrivia, triviaKindLabels: grammarTrivia._meta.triviaKindLabels } : {},
|
|
@@ -9686,9 +9892,13 @@ function compile(combinator, mapFnSources, opts) {
|
|
|
9686
9892
|
const namedPrelude = ctx.namedFnDecls.length > 0 ? [...namedFnPrelude(), ""] : [];
|
|
9687
9893
|
const emptyTlDecls = ctx.needsEmptyTl ? ["const _EMPTY_TL = Object.freeze([])"] : [];
|
|
9688
9894
|
const hostReadsDecls = ctx.needsHostReads ? [HOST_READS_DECL] : [];
|
|
9895
|
+
const lineTrackDecls = ctx.needsLineTrack ? [LINE_TRACK_DECL] : [];
|
|
9896
|
+
const lineSpanDecls = ctx.needsLineSpan ? [LINE_SPAN_DECL] : [];
|
|
9689
9897
|
const source = [
|
|
9690
9898
|
...emptyTlDecls,
|
|
9691
9899
|
...hostReadsDecls,
|
|
9900
|
+
...lineTrackDecls,
|
|
9901
|
+
...lineSpanDecls,
|
|
9692
9902
|
...ctx.regexDecls,
|
|
9693
9903
|
...ctx.expectedDecls,
|
|
9694
9904
|
"",
|
|
@@ -9701,6 +9911,8 @@ function compile(combinator, mapFnSources, opts) {
|
|
|
9701
9911
|
const fn = new Function("input", "_pos", "_rp", "_mf", "_build", "_ctx", [
|
|
9702
9912
|
...emptyTlDecls,
|
|
9703
9913
|
...hostReadsDecls,
|
|
9914
|
+
...lineTrackDecls,
|
|
9915
|
+
...lineSpanDecls,
|
|
9704
9916
|
...ctx.regexDecls,
|
|
9705
9917
|
...ctx.expectedDecls,
|
|
9706
9918
|
...namedPrelude,
|
|
@@ -9719,6 +9931,25 @@ function compile(combinator, mapFnSources, opts) {
|
|
|
9719
9931
|
trackLines: false,
|
|
9720
9932
|
...ctx.triviaKindLabels ? { triviaKindLabels: ctx.triviaKindLabels } : {}
|
|
9721
9933
|
};
|
|
9934
|
+
const annotateWithTrackedLines = (result, lineStarts) => {
|
|
9935
|
+
const index = normalizeLineIndex({ lineStarts });
|
|
9936
|
+
const annotated = { ...result, span: annotateSpan(result.span, index) };
|
|
9937
|
+
const errors = annotated.errors;
|
|
9938
|
+
if (errors) {
|
|
9939
|
+
;
|
|
9940
|
+
annotated.errors = errors.map((error) => ({
|
|
9941
|
+
...error,
|
|
9942
|
+
span: annotateSpan(error.span, index)
|
|
9943
|
+
}));
|
|
9944
|
+
}
|
|
9945
|
+
return annotated;
|
|
9946
|
+
};
|
|
9947
|
+
const trackedCtx = (base, input, pos) => {
|
|
9948
|
+
if (!ctx.lineTracking) return base;
|
|
9949
|
+
const lineIndex = { lineStarts: [0] };
|
|
9950
|
+
if (pos > 0) recordLineRange(lineIndex, input, 0, pos);
|
|
9951
|
+
return { ...base, trackLines: true, _lineStarts: lineIndex.lineStarts, _lineScannedTo: pos };
|
|
9952
|
+
};
|
|
9722
9953
|
const derivedSrcs = ctx.mapFnSrcs.length === ctx.mapFns.length && ctx.mapFnSrcs.every((s) => s !== null) ? ctx.mapFnSrcs : void 0;
|
|
9723
9954
|
const effectiveSources = mapFnSources ?? derivedSrcs;
|
|
9724
9955
|
const buildCovered = ctx.buildFns.length === 0 || ctx.buildSrcs.every((s) => s !== null);
|
|
@@ -9726,17 +9957,46 @@ function compile(combinator, mapFnSources, opts) {
|
|
|
9726
9957
|
const mfCovered = ctx.mapFns.length === 0 || effectiveSources !== void 0 && effectiveSources.length === ctx.mapFns.length;
|
|
9727
9958
|
const canInline = ctx.runtimeParsers.length === 0 && mfCovered && buildCovered;
|
|
9728
9959
|
const inlineExpression = canInline ? buildInlineExpression(ctx, r, effectiveSources, buildSources, coverageRootRuleId) : null;
|
|
9729
|
-
|
|
9960
|
+
const compiledMeta = {
|
|
9730
9961
|
source,
|
|
9731
9962
|
inlineExpression,
|
|
9732
9963
|
...ctx.coverage === void 0 ? {} : { coverageDefinitions: ctx.coverage.plan.definitions },
|
|
9733
|
-
...gatingReport === void 0 ? {} : { gating: gatingReport }
|
|
9964
|
+
...gatingReport === void 0 ? {} : { gating: gatingReport }
|
|
9965
|
+
};
|
|
9966
|
+
if (!ctx.lineTracking) {
|
|
9967
|
+
return {
|
|
9968
|
+
...compiledMeta,
|
|
9969
|
+
parse(input, pos = 0) {
|
|
9970
|
+
return fn(input, pos, ctx.runtimeParsers, ctx.mapFns, ctx.buildFns, defaultCtx);
|
|
9971
|
+
},
|
|
9972
|
+
parseWithContext(input, parseCtx, pos = 0) {
|
|
9973
|
+
assertHostModeCompatible(ctx.hostMode ?? "ast", parseCtx.build, !!ctx.hostBranchElided);
|
|
9974
|
+
return fn(input, pos, ctx.runtimeParsers, ctx.mapFns, ctx.buildFns, parseCtx);
|
|
9975
|
+
},
|
|
9976
|
+
// Note: collects expect() errors via _errors. Unlike interpreter
|
|
9977
|
+
// parse({recover:true}) it does NOT populate furthestFail — the compiled path
|
|
9978
|
+
// inlines failures for throughput and deliberately skips _probe bookkeeping.
|
|
9979
|
+
// Callers wanting a furthest-position diagnostic detect unconsumed input
|
|
9980
|
+
// (span.end < input.length) instead, which is mode-agnostic.
|
|
9981
|
+
parseWithErrors(input, pos = 0) {
|
|
9982
|
+
const errors = [];
|
|
9983
|
+
const result = fn(input, pos, ctx.runtimeParsers, ctx.mapFns, ctx.buildFns, { ...defaultCtx, _errors: errors });
|
|
9984
|
+
return { ...result, errors };
|
|
9985
|
+
}
|
|
9986
|
+
};
|
|
9987
|
+
}
|
|
9988
|
+
return {
|
|
9989
|
+
...compiledMeta,
|
|
9734
9990
|
parse(input, pos = 0) {
|
|
9735
|
-
|
|
9991
|
+
const parseCtx = trackedCtx(defaultCtx, input, pos);
|
|
9992
|
+
const result = fn(input, pos, ctx.runtimeParsers, ctx.mapFns, ctx.buildFns, parseCtx);
|
|
9993
|
+
return annotateWithTrackedLines(result, parseCtx._lineStarts);
|
|
9736
9994
|
},
|
|
9737
9995
|
parseWithContext(input, parseCtx, pos = 0) {
|
|
9738
9996
|
assertHostModeCompatible(ctx.hostMode ?? "ast", parseCtx.build, !!ctx.hostBranchElided);
|
|
9739
|
-
|
|
9997
|
+
const activeCtx = trackedCtx(parseCtx, input, pos);
|
|
9998
|
+
const result = fn(input, pos, ctx.runtimeParsers, ctx.mapFns, ctx.buildFns, activeCtx);
|
|
9999
|
+
return activeCtx.trackLines ? annotateWithTrackedLines(result, activeCtx._lineStarts) : result;
|
|
9740
10000
|
},
|
|
9741
10001
|
// Note: collects expect() errors via _errors. Unlike interpreter
|
|
9742
10002
|
// parse({recover:true}) it does NOT populate furthestFail — the compiled path
|
|
@@ -9745,8 +10005,9 @@ function compile(combinator, mapFnSources, opts) {
|
|
|
9745
10005
|
// (span.end < input.length) instead, which is mode-agnostic.
|
|
9746
10006
|
parseWithErrors(input, pos = 0) {
|
|
9747
10007
|
const errors = [];
|
|
9748
|
-
const
|
|
9749
|
-
|
|
10008
|
+
const parseCtx = trackedCtx({ ...defaultCtx, _errors: errors }, input, pos);
|
|
10009
|
+
const result = { ...fn(input, pos, ctx.runtimeParsers, ctx.mapFns, ctx.buildFns, parseCtx), errors };
|
|
10010
|
+
return annotateWithTrackedLines(result, parseCtx._lineStarts);
|
|
9750
10011
|
}
|
|
9751
10012
|
};
|
|
9752
10013
|
}
|
|
@@ -10033,12 +10294,16 @@ function buildInlineExpression(ctx, r, mapFnSources, buildSources, coverageRootR
|
|
|
10033
10294
|
const buildDecl = buildSources?.length ? ` const _build = [${buildSources.join(", ")}]` : "";
|
|
10034
10295
|
const emptyTlDecl = ctx.needsEmptyTl ? ` const _EMPTY_TL = Object.freeze([])` : "";
|
|
10035
10296
|
const hostReadsDecl = ctx.needsHostReads ? ` ${HOST_READS_DECL}` : "";
|
|
10036
|
-
const
|
|
10297
|
+
const lineTrackDecl = ctx.needsLineTrack ? ` ${LINE_TRACK_DECL}` : "";
|
|
10298
|
+
const lineSpanDecl = ctx.needsLineSpan ? ` ${LINE_SPAN_DECL}` : "";
|
|
10299
|
+
const needsWrapper = ctx.regexDecls.length > 0 || ctx.expectedDecls.length > 0 || ctx.namedFnDecls.length > 0 || !!mfDecl || !!buildDecl || !!emptyTlDecl || !!hostReadsDecl || !!lineTrackDecl || !!lineSpanDecl;
|
|
10037
10300
|
if (!needsWrapper) return innerFn;
|
|
10038
10301
|
const namedPrelude = ctx.namedFnDecls.length > 0 ? namedFnPrelude() : [];
|
|
10039
10302
|
const hoistedDecls = [
|
|
10040
10303
|
emptyTlDecl,
|
|
10041
10304
|
hostReadsDecl,
|
|
10305
|
+
lineTrackDecl,
|
|
10306
|
+
lineSpanDecl,
|
|
10042
10307
|
...ctx.regexDecls.map((d) => ` ${d}`),
|
|
10043
10308
|
...ctx.expectedDecls.map((d) => ` ${d}`),
|
|
10044
10309
|
mfDecl,
|
|
@@ -10587,7 +10852,7 @@ function normalizeCstCollapse(collapse) {
|
|
|
10587
10852
|
return typeof collapse === "function" ? collapse : void 0;
|
|
10588
10853
|
}
|
|
10589
10854
|
function buildCstNode(type, children2, _fields, span, _rawChildren, _triviaLog, state) {
|
|
10590
|
-
return { _tag: "node", type, span: {
|
|
10855
|
+
return { _tag: "node", type, span: { ...span }, state: state ?? null, children: [...children2] };
|
|
10591
10856
|
}
|
|
10592
10857
|
function cstBuildHost(typeOrOptions, children2, _fields, span, rawChildren, triviaLog, state) {
|
|
10593
10858
|
if (typeof typeOrOptions === "string") {
|