parseman 0.58.3 → 0.59.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/analysis/diagnostics.js +159 -137
  2. package/dist/analysis/diagnostics.js.map +3 -3
  3. package/dist/cli/index.js +161 -138
  4. package/dist/cli/index.js.map +3 -3
  5. package/dist/combinators/choice.d.ts +0 -5
  6. package/dist/combinators/choice.d.ts.map +1 -1
  7. package/dist/combinators/dispatch.d.ts.map +1 -1
  8. package/dist/combinators/field-trivia.d.ts.map +1 -1
  9. package/dist/combinators/keywords.d.ts.map +1 -1
  10. package/dist/combinators/literal.d.ts.map +1 -1
  11. package/dist/combinators/node.d.ts.map +1 -1
  12. package/dist/combinators/regex.d.ts.map +1 -1
  13. package/dist/combinators/scanTo.d.ts +1 -16
  14. package/dist/combinators/scanTo.d.ts.map +1 -1
  15. package/dist/combinators/token.d.ts.map +1 -1
  16. package/dist/compiler/ir-serialize.d.ts.map +1 -1
  17. package/dist/compiler/linker.d.ts +0 -3
  18. package/dist/compiler/linker.d.ts.map +1 -1
  19. package/dist/compiler/token-alphabet.d.ts +5 -25
  20. package/dist/compiler/token-alphabet.d.ts.map +1 -1
  21. package/dist/compiler/token-capability.js.map +1 -1
  22. package/dist/compiler/token-dispatch.d.ts +8 -79
  23. package/dist/compiler/token-dispatch.d.ts.map +1 -1
  24. package/dist/cst/capture-buffer.d.ts.map +1 -1
  25. package/dist/cst/plain.js +69 -0
  26. package/dist/cst/plain.js.map +6 -0
  27. package/dist/cst/root-trivia-scope.d.ts +0 -3
  28. package/dist/cst/root-trivia-scope.d.ts.map +1 -1
  29. package/dist/cst/trivia-entries.d.ts +0 -2
  30. package/dist/cst/trivia-entries.d.ts.map +1 -1
  31. package/dist/cst/trivia-kinds.d.ts +0 -5
  32. package/dist/cst/trivia-kinds.d.ts.map +1 -1
  33. package/dist/index.js +163 -143
  34. package/dist/index.js.map +3 -3
  35. package/dist/language-service/index.js +19 -2
  36. package/dist/language-service/index.js.map +2 -2
  37. package/dist/line-index.d.ts +13 -0
  38. package/dist/line-index.d.ts.map +1 -1
  39. package/dist/plugin/entry-supercompiler.d.ts.map +1 -1
  40. package/dist/plugin/index.js +165 -145
  41. package/dist/plugin/index.js.map +3 -3
  42. package/dist/recovery/scan.d.ts.map +1 -1
  43. package/dist/run/index.js +4 -1
  44. package/dist/run/index.js.map +2 -2
  45. package/dist/spec/index.js +18 -1
  46. package/dist/spec/index.js.map +2 -2
  47. package/dist/spec/model.d.ts +0 -8
  48. package/dist/spec/model.d.ts.map +1 -1
  49. package/dist/table/assemble.d.ts.map +1 -1
  50. package/dist/table/emit-assembly.d.ts +1 -1
  51. package/dist/table/emit-assembly.d.ts.map +1 -1
  52. package/dist/table/emit.d.ts +6 -0
  53. package/dist/table/emit.d.ts.map +1 -1
  54. package/dist/table/encode.d.ts.map +1 -1
  55. package/dist/table/index.js +142 -133
  56. package/dist/table/index.js.map +3 -3
  57. package/dist/table/program.d.ts +0 -1
  58. package/dist/table/program.d.ts.map +1 -1
  59. package/dist/table/run-support.d.ts.map +1 -1
  60. package/dist/table/scalar-terminal.d.ts +0 -7
  61. package/dist/table/scalar-terminal.d.ts.map +1 -1
  62. package/dist/table/scan-shapes.d.ts +0 -8
  63. package/dist/table/scan-shapes.d.ts.map +1 -1
  64. package/dist/table/site-labels.d.ts +0 -2
  65. package/dist/table/site-labels.d.ts.map +1 -1
  66. package/dist/version.d.ts +1 -1
  67. package/package.json +2 -1
  68. package/src/combinators/choice.ts +1 -1
  69. package/src/combinators/dispatch.ts +2 -1
  70. package/src/combinators/field-trivia.ts +6 -5
  71. package/src/combinators/keywords.ts +3 -2
  72. package/src/combinators/literal.ts +5 -4
  73. package/src/combinators/node.ts +3 -1
  74. package/src/combinators/regex.ts +5 -4
  75. package/src/combinators/scanTo.ts +3 -2
  76. package/src/combinators/token.ts +3 -6
  77. package/src/compiler/ir-serialize.ts +2 -1
  78. package/src/compiler/linker.ts +5 -3
  79. package/src/compiler/token-alphabet.ts +14 -10
  80. package/src/compiler/token-dispatch.ts +10 -313
  81. package/src/compiler/token-scanner.ts +2 -2
  82. package/src/cst/capture-buffer.ts +13 -5
  83. package/src/cst/plain.d.ts +35 -0
  84. package/src/cst/plain.js +74 -0
  85. package/src/cst/root-trivia-scope.ts +1 -1
  86. package/src/cst/trivia-entries.ts +1 -1
  87. package/src/cst/trivia-kinds.ts +1 -1
  88. package/src/line-index.ts +37 -0
  89. package/src/plugin/entry-supercompiler.ts +3 -2
  90. package/src/recovery/scan.ts +2 -1
  91. package/src/spec/model.ts +1 -1
  92. package/src/table/assemble.ts +33 -35
  93. package/src/table/emit-assembly.ts +27 -24
  94. package/src/table/emit.ts +9 -1
  95. package/src/table/encode.ts +16 -39
  96. package/src/table/program.ts +1 -1
  97. package/src/table/run-support.ts +4 -7
  98. package/src/table/scalar-terminal.ts +1 -1
  99. package/src/table/scan-shapes.ts +15 -46
  100. package/src/table/site-labels.ts +1 -1
  101. package/src/version.ts +1 -1
@@ -383,6 +383,7 @@ function createDetachedParseContext(trackLines, state) {
383
383
  }
384
384
 
385
385
  // src/line-index.ts
386
+ import { PlainLineSpan, PlainSpan } from "../cst/plain.js";
386
387
  function createLineIndex() {
387
388
  return { lineStarts: [0] };
388
389
  }
@@ -435,6 +436,14 @@ function annotateSpan(span, index) {
435
436
  endColumn: e.col
436
437
  };
437
438
  }
439
+ function lineSpanFromContext(span, ctx) {
440
+ if (!ctx.trackLines) return span;
441
+ const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
442
+ if (!index) return span;
443
+ const s = offsetToLineCol(index, span.start);
444
+ const e = offsetToLineCol(index, span.end);
445
+ return new PlainLineSpan(span.start, span.end, s.line, s.col, e.line, e.col);
446
+ }
438
447
  function annotateSpanFromLineContext(span, ctx) {
439
448
  if (!ctx.trackLines) return span;
440
449
  const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
@@ -639,15 +648,19 @@ function rebuildLineScan(s, subtree) {
639
648
  }
640
649
 
641
650
  // src/cst/capture-buffer.ts
651
+ import { PlainBuf, PlainLeaf } from "../cst/plain.js";
642
652
  function cstCaptureActive(ctx) {
643
653
  return ctx._cstBuf !== void 0 || ctx._cstLeaves !== void 0;
644
654
  }
655
+ function isLeaf(v) {
656
+ return typeof v === "object" && v !== null && v._tag === "leaf";
657
+ }
645
658
  function pushCstLeaf(ctx, leaf2) {
646
659
  if (!ctx.trackLines) {
647
660
  pushCstChild(ctx, leaf2, leaf2);
648
661
  return;
649
662
  }
650
- const annotated = leaf2 && typeof leaf2 === "object" && leaf2.span ? { ...leaf2, span: annotateSpanFromLineContext(leaf2.span, ctx) } : leaf2;
663
+ 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;
651
664
  pushCstChild(ctx, annotated, annotated);
652
665
  }
653
666
  function pushCstChild(ctx, built, rawEntry2) {
@@ -1562,6 +1575,7 @@ function triviaKindMask(labels, keep) {
1562
1575
  }
1563
1576
 
1564
1577
  // src/recovery/scan.ts
1578
+ import { PlainSpan as PlainSpan2 } from "../cst/plain.js";
1565
1579
  function probeAt(sentinel, input, pos, ctx) {
1566
1580
  const s = {
1567
1581
  _probe: ctx._probe,
@@ -1638,7 +1652,7 @@ function firstSetSentinel(fs) {
1638
1652
  function recoverScan(input, from, ctx, sync, expected) {
1639
1653
  let scanPos = from;
1640
1654
  while (scanPos < input.length && !probeAt(sync, input, scanPos, ctx)) scanPos++;
1641
- const span = { start: from, end: scanPos };
1655
+ const span = new PlainSpan2(from, scanPos);
1642
1656
  if (ctx.trackLines) recordLineRangeFromContext(ctx, input, from, scanPos);
1643
1657
  const error = { _tag: "parseError", span: ctx.trackLines ? annotateSpanFromLineContext(span, ctx) : span, expected };
1644
1658
  ctx._errors?.push(error);
@@ -2741,17 +2755,18 @@ function buildAsciiDispatch(parsers) {
2741
2755
  }
2742
2756
 
2743
2757
  // src/combinators/field-trivia.ts
2758
+ import { PlainSpan as PlainSpan3, PlainTriviaField } from "../cst/plain.js";
2744
2759
  var LEAD = { at: -1 };
2745
2760
  var FIELD_LEADING_TRIVIA = 1;
2746
2761
  var FIELD_TRAILING_TRIVIA = 2;
2747
2762
  function triviaFieldCapture(name, value, input, start, end, leadFrom, trailEnd) {
2748
- return {
2763
+ return new PlainTriviaField(
2749
2764
  name,
2750
2765
  value,
2751
- span: { start, end },
2752
- leading: leadFrom >= 0 && leadFrom < start ? input.slice(leadFrom, start) : "",
2753
- trailing: trailEnd > end ? input.slice(end, trailEnd) : ""
2754
- };
2766
+ new PlainSpan3(start, end),
2767
+ leadFrom >= 0 && leadFrom < start ? input.slice(leadFrom, start) : "",
2768
+ trailEnd > end ? input.slice(end, trailEnd) : ""
2769
+ );
2755
2770
  }
2756
2771
  function leadsTrivia(p) {
2757
2772
  return p._def.tag === "field" && p._def.leadingTrivia === true;
@@ -3366,6 +3381,7 @@ function firstSetFromRegex(source, flags = "") {
3366
3381
  }
3367
3382
 
3368
3383
  // src/combinators/regex.ts
3384
+ import { PlainLeaf as PlainLeaf2, PlainSpan as PlainSpan4 } from "../cst/plain.js";
3369
3385
  var SCAN_BAIL_AT = 64;
3370
3386
  function inRanges3(cp, ranges) {
3371
3387
  for (let i = 0; i < ranges.length; i++) {
@@ -3478,9 +3494,9 @@ function regex(pattern, flags = "") {
3478
3494
  if (scanEnd !== void 0) {
3479
3495
  if (scanEnd === null) return failAt(ctx, directTerminalFailureExpected(def), pos);
3480
3496
  const value = input.slice(pos, scanEnd);
3481
- const span2 = { start: pos, end: scanEnd };
3497
+ const span2 = new PlainSpan4(pos, scanEnd);
3482
3498
  if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, scanEnd);
3483
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span: span2 });
3499
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf2(value, span2));
3484
3500
  return { ok: true, value, span: span2 };
3485
3501
  }
3486
3502
  anchored.lastIndex = pos;
@@ -3488,9 +3504,9 @@ function regex(pattern, flags = "") {
3488
3504
  if (m === null) {
3489
3505
  return failAt(ctx, directTerminalFailureExpected(def), pos);
3490
3506
  }
3491
- const span = { start: pos, end: pos + m[0].length };
3507
+ const span = new PlainSpan4(pos, pos + m[0].length);
3492
3508
  if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, span.end);
3493
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value: m[0], span });
3509
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf2(m[0], span));
3494
3510
  return { ok: true, value: m[0], span };
3495
3511
  }
3496
3512
  };
@@ -3517,6 +3533,7 @@ function buildLexBodyRecognizer(spec, constants) {
3517
3533
  }
3518
3534
 
3519
3535
  // src/table/run-support.ts
3536
+ import { PlainLeaf as PlainLeaf3, PlainLineSpan as PlainLineSpan2, PlainSpan as PlainSpan5 } from "../cst/plain.js";
3520
3537
  function lineCol(ctx, offset) {
3521
3538
  const starts = ctx._lineStarts ?? [0];
3522
3539
  let lo = 0, hi = starts.length - 1;
@@ -3529,18 +3546,14 @@ function lineCol(ctx, offset) {
3529
3546
  }
3530
3547
  function spanLines(ctx, start, end) {
3531
3548
  const s = lineCol(ctx, start), e = lineCol(ctx, end);
3532
- return { start, end, startLine: s[0], startColumn: s[1], endLine: e[0], endColumn: e[1] };
3549
+ return new PlainLineSpan2(start, end, s[0], s[1], e[0], e[1]);
3533
3550
  }
3534
3551
  function rawEntry(v, input, s, e) {
3535
3552
  if (typeof v === "object" && v !== null) {
3536
3553
  const tg = v._tag;
3537
3554
  if (tg === "node" || tg === "leaf" || tg === "parseError") return v;
3538
3555
  }
3539
- return {
3540
- _tag: "leaf",
3541
- value: typeof v === "string" ? v : typeof v === "object" && v !== null ? input.slice(s, e) : "",
3542
- span: { start: s, end: e }
3543
- };
3556
+ return new PlainLeaf3(typeof v === "string" ? v : typeof v === "object" && v !== null ? input.slice(s, e) : "", new PlainSpan5(s, e));
3544
3557
  }
3545
3558
  function lead(input, pos) {
3546
3559
  if (pos >= input.length) return -1;
@@ -3554,7 +3567,7 @@ function collapseEmpty(ctx, build, input, pos, end, readsRaw) {
3554
3567
  const collected = ctx._cstBuf !== void 0 || ctx._cstChildren !== void 0;
3555
3568
  if (collected) popCstChild(ctx);
3556
3569
  const raw = readsRaw ? [rawEntry(void 0, input, pos, end)] : EMPTY_KIDS;
3557
- const nd = build(EMPTY_KIDS, void 0, { start: pos, end }, raw, EMPTY_TRIVIA, void 0);
3570
+ const nd = build(EMPTY_KIDS, void 0, new PlainSpan5(pos, end), raw, EMPTY_TRIVIA, void 0);
3558
3571
  if (collected) pushCstChild(ctx, nd, ctx._cstBuf?.noRaw === true ? void 0 : rawEntry(nd, input, pos, end));
3559
3572
  return nd;
3560
3573
  }
@@ -4435,6 +4448,7 @@ function expandCompactFolded(f) {
4435
4448
  }
4436
4449
 
4437
4450
  // src/combinators/literal.ts
4451
+ import { PlainLeaf as PlainLeaf4, PlainSpan as PlainSpan6 } from "../cst/plain.js";
4438
4452
  function asciiFoldEq(a, b) {
4439
4453
  if (a.length !== b.length) return false;
4440
4454
  for (let i = 0; i < a.length; i++) {
@@ -4492,9 +4506,9 @@ function literal(value, opts = {}) {
4492
4506
  const code = value.charCodeAt(0);
4493
4507
  return function parse2(input, pos, ctx) {
4494
4508
  if (input.charCodeAt(pos) === code) {
4495
- const span = { start: pos, end: pos + 1 };
4509
+ const span = new PlainSpan6(pos, pos + 1);
4496
4510
  if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, span.end);
4497
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span });
4511
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf4(value, span));
4498
4512
  return { ok: true, value, span };
4499
4513
  }
4500
4514
  return failAt(ctx, expected, pos);
@@ -4506,9 +4520,9 @@ function literal(value, opts = {}) {
4506
4520
  }
4507
4521
  const matchedValue = caseInsensitive ? input.slice(pos, end) : value;
4508
4522
  if (caseInsensitive ? asciiFoldEq(matchedValue, value) : input.startsWith(value, pos)) {
4509
- const span = { start: pos, end };
4523
+ const span = new PlainSpan6(pos, end);
4510
4524
  if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, end);
4511
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value: matchedValue, span });
4525
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf4(matchedValue, span));
4512
4526
  return { ok: true, value: matchedValue, span };
4513
4527
  }
4514
4528
  return failAt(ctx, expected, pos);
@@ -5049,6 +5063,7 @@ function buildReadsState(def) {
5049
5063
  }
5050
5064
 
5051
5065
  // src/combinators/token.ts
5066
+ import { PlainLeaf as PlainLeaf5 } from "../cst/plain.js";
5052
5067
  function semanticLeafValue(_ctx, _input, _start, _end, value) {
5053
5068
  return value;
5054
5069
  }
@@ -5102,7 +5117,7 @@ function token(root) {
5102
5117
  if (!result.ok) return result;
5103
5118
  const span = result.span;
5104
5119
  const value = input.slice(pos, span.end);
5105
- if (wasCapturing) pushCstLeaf(ctx, { _tag: "leaf", value, span });
5120
+ if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf5(value, span));
5106
5121
  return { ok: true, value, span };
5107
5122
  }
5108
5123
  };
@@ -5150,11 +5165,7 @@ function makeLeaf(root, fn, sourceCstValue) {
5150
5165
  }
5151
5166
  if (!result.ok) return result;
5152
5167
  const value = fn(result.value, result.span);
5153
- if (wasCapturing) pushCstLeaf(ctx, {
5154
- _tag: "leaf",
5155
- value: cstValue(ctx, input, pos, result.span.end, value),
5156
- span: result.span
5157
- });
5168
+ if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf5(cstValue(ctx, input, pos, result.span.end, value), result.span));
5158
5169
  return { ok: true, value, span: result.span };
5159
5170
  }
5160
5171
  };
@@ -5167,6 +5178,7 @@ function sourceLeaf(root, fn) {
5167
5178
  }
5168
5179
 
5169
5180
  // src/combinators/scanTo.ts
5181
+ import { PlainLeaf as PlainLeaf6, PlainSpan as PlainSpan7 } from "../cst/plain.js";
5170
5182
  function resolveScanSkip(explicitSkip, raw, ctx) {
5171
5183
  if (raw) return [];
5172
5184
  const trivia2 = ctx.trivia;
@@ -5204,7 +5216,7 @@ function scanTo(sentinel, { skip, raw = false, orEOF = false, recoverAt, stopAt
5204
5216
  probeCtx._errors = ctx._errors;
5205
5217
  const emit = (end) => {
5206
5218
  if (end > pos && cstCaptureActive(ctx)) {
5207
- const leaf2 = { _tag: "leaf", value: input.slice(pos, end), span: { start: pos, end } };
5219
+ const leaf2 = new PlainLeaf6(input.slice(pos, end), new PlainSpan7(pos, end));
5208
5220
  pushCstLeaf(ctx, leaf2);
5209
5221
  }
5210
5222
  };
@@ -5555,6 +5567,7 @@ function clearOf(ranges, input, from, to) {
5555
5567
  }
5556
5568
 
5557
5569
  // src/combinators/dispatch.ts
5570
+ import { PlainLeaf as PlainLeaf7 } from "../cst/plain.js";
5558
5571
  function parserUsesRouted(parser2, seen = /* @__PURE__ */ new Set()) {
5559
5572
  if (seen.has(parser2)) return false;
5560
5573
  seen.add(parser2);
@@ -5623,6 +5636,7 @@ function asciiFoldKey(key) {
5623
5636
  }
5624
5637
 
5625
5638
  // src/combinators/node.ts
5639
+ import { PlainNode, PlainSpan as PlainSpan8 } from "../cst/plain.js";
5626
5640
  function unwrapChild(child) {
5627
5641
  return child !== null && typeof child === "object" && child._tag === "leaf" ? child.value : child;
5628
5642
  }
@@ -5636,6 +5650,9 @@ function projectChild(children2, project, type) {
5636
5650
  return unwrapChild(children2[project]);
5637
5651
  }
5638
5652
 
5653
+ // src/table/assemble.ts
5654
+ import { PlainBuf as PlainBuf2, PlainField, PlainLeaf as PlainLeaf8, PlainNode as PlainNode2, PlainSpan as PlainSpan9 } from "../cst/plain.js";
5655
+
5639
5656
  // src/table/ops.ts
5640
5657
  var OP_LIT = 1;
5641
5658
  var OP_RX = 2;
@@ -6436,7 +6453,6 @@ function caseFoldLiteralOrAlt(source) {
6436
6453
  }
6437
6454
  return { kind: "alt", arms: litArms, disjoint: false, firsts: litArms.map(() => null) };
6438
6455
  }
6439
- var scanToIndexOfEnabled = () => process.env.PARSEMAN_SCANTO === "indexof";
6440
6456
  var classCond = (cVar, ranges) => ranges.map(([lo, hi]) => lo === hi ? `${cVar} === ${lo}` : `(${cVar} >= ${lo} && ${cVar} <= ${hi})`).join(" || ");
6441
6457
  var litCond = (base, cps, firstVar) => cps.map(
6442
6458
  (cp, k) => k === 0 && firstVar ? `${firstVar} === ${cp}` : `input.charCodeAt(${base}${k ? ` + ${k}` : ""}) === ${cp}`
@@ -6666,13 +6682,7 @@ function emitShapeMatch(shape, start, mint, ind, firstChar) {
6666
6682
  const j2 = mint("_j");
6667
6683
  const openLen2 = shape.open.length;
6668
6684
  const openChk2 = openLen2 === 1 ? `${codeAt(start, firstChar)} === ${shape.open[0]}` : litCond(start, shape.open, firstChar);
6669
- const stopCp = shape.stop.length === 1 && shape.stop[0][0] === shape.stop[0][1] ? shape.stop[0][0] : null;
6670
- const scanLine = stopCp !== null && stopCp <= 65535 && scanToIndexOfEnabled() ? (
6671
- // No temp is minted: a temp would renumber every later variable in the
6672
- // function and show up as an artifact-size delta that is counter
6673
- // renumbering rather than this change (the §9.1.4 / §9.2 effect).
6674
- `${ind} ${j2} = input.indexOf(${JSON.stringify(String.fromCharCode(stopCp))}, ${j2}); if (${j2} < 0) ${j2} = input.length`
6675
- ) : `${ind} while (${j2} < input.length && !(${classCond(`input.charCodeAt(${j2})`, shape.stop)})) ${j2}++`;
6685
+ const scanLine = `${ind} while (${j2} < input.length && !(${classCond(`input.charCodeAt(${j2})`, shape.stop)})) ${j2}++`;
6676
6686
  return {
6677
6687
  setup: [
6678
6688
  `${ind}let ${j2} = ${start}`,
@@ -6730,11 +6740,7 @@ function emitShapeMatch(shape, start, mint, ind, firstChar) {
6730
6740
  const closeLen = shape.close.length;
6731
6741
  const openChk = openLen === 1 ? `${codeAt(start, firstChar)} === ${shape.open[0]}` : litCond(start, shape.open, firstChar);
6732
6742
  const closeChk = litCond(j, shape.close);
6733
- const closeStr = String.fromCharCode(...shape.close);
6734
- const scanLines = scanToIndexOfEnabled() ? [
6735
- `${ind} ${j} = input.indexOf(${JSON.stringify(closeStr)}, ${j}); if (${j} < 0) ${j} = input.length`,
6736
- `${ind} if (${j} + ${closeLen} <= input.length) ${endV} = ${j} + ${closeLen}`
6737
- ] : [
6743
+ const scanLines = [
6738
6744
  `${ind} while (${j} + ${closeLen - 1} < input.length && !(${closeChk})) ${j}++`,
6739
6745
  `${ind} if (${j} + ${closeLen} <= input.length && (${closeChk})) ${endV} = ${j} + ${closeLen}`
6740
6746
  ];
@@ -7370,7 +7376,14 @@ var EMITTED_PARAMS = [
7370
7376
  "skipDeferredTrivia",
7371
7377
  // Appended for the pass-through collapse (`run-support.ts`); old factories
7372
7378
  // ignore it.
7373
- "collapseEmpty"
7379
+ "collapseEmpty",
7380
+ // Appended for constructor-built tree objects (`cst/plain.d.ts`): a `new` call has
7381
+ // no allocation site, so V8 cannot pretenure them. Old factories ignore them.
7382
+ "_SP",
7383
+ "_LF",
7384
+ "_ND",
7385
+ "_FC",
7386
+ "_BUF"
7374
7387
  ];
7375
7388
  var RUNTIME_PRELUDE = `
7376
7389
  let _pfScan=null
@@ -7394,9 +7407,9 @@ if(s!==null)return skipTriviaScanned(s,input,cur,ctx)
7394
7407
  if(needsDeferredTriviaCommit(ctx))return skipDeferredTrivia(input,cur,ctx)
7395
7408
  return advanceTrivia(input,cur,ctx)
7396
7409
  }
7397
- function _pushLeaf(ctx,value,s,e){pushCstLeaf(ctx,{_tag:'leaf',value,span:{start:s,end:e}})}
7410
+ function _pushLeaf(ctx,value,s,e){pushCstLeaf(ctx,new _LF(value,new _SP(s,e)))}
7398
7411
  function _pushLeafBuf(ctx,value,s,e){
7399
- const l={_tag:'leaf',value,span:{start:s,end:e}}
7412
+ const l=new _LF(value,new _SP(s,e))
7400
7413
  const b=ctx._cstBuf
7401
7414
  if(b.ch!==undefined)b.ch.push(l)
7402
7415
  else if(b.single!==undefined){b.ch=[b.single,l];b.single=undefined}
@@ -7454,7 +7467,7 @@ if(ctx._rootTriviaLog!==undefined&&ctx._rootTriviaLog.length!==rt)ctx._rootTrivi
7454
7467
  `;
7455
7468
  var NO_RAW_RUNTIME_PRELUDE = `
7456
7469
  function _pushLeafNoRawBuf(ctx,value,s,e){
7457
- const l={_tag:'leaf',value,span:{start:s,end:e}}
7470
+ const l=new _LF(value,new _SP(s,e))
7458
7471
  const b=ctx._cstBuf
7459
7472
  if(b.ch!==undefined)b.ch.push(l)
7460
7473
  else if(b.single!==undefined){b.ch=[b.single,l];b.single=undefined}
@@ -8131,7 +8144,7 @@ try{return ${child}(input,pos,ctx)}finally{ctx.state=saved}
8131
8144
  return `${head}
8132
8145
  const v=${child}(input,pos,ctx)
8133
8146
  if(v===FAIL)return FAIL
8134
- return ${fn}(v,{start:pos,end:EC.e})
8147
+ return ${fn}(v,new _SP(pos,EC.e))
8135
8148
  }`;
8136
8149
  }
8137
8150
  case OP_LABEL: {
@@ -8152,7 +8165,7 @@ return v
8152
8165
  const v=${child}(input,pos,ctx)
8153
8166
  if(v===FAIL)return FAIL
8154
8167
  const f=ctx._fields
8155
- if(f!==undefined)f.push({name:${name},value:v,span:{start:pos,end:EC.e}})
8168
+ if(f!==undefined)f.push(new _FC(${name},v,new _SP(pos,EC.e)))
8156
8169
  return v
8157
8170
  }`;
8158
8171
  }
@@ -8177,7 +8190,7 @@ return v
8177
8190
  return `${head}
8178
8191
  const v=${child}(input,pos,ctx)
8179
8192
  if(v!==FAIL)return v
8180
- const err={_tag:'parseError',span:${prog.lines === 1 ? "spanLines(ctx,pos,pos)" : "{start:pos,end:pos}"},expected:${xf}}
8193
+ const err={_tag:'parseError',span:${prog.lines === 1 ? "spanLines(ctx,pos,pos)" : "new _SP(pos,pos)"},expected:${xf}}
8181
8194
  const es=ctx._errors
8182
8195
  if(es!==undefined)es.push(err)
8183
8196
  ${REC ? "if(ctx._tolerant===true)captureError(ctx,err)\n" : ""}ctx._fc=false
@@ -8188,7 +8201,7 @@ return err
8188
8201
  case OP_ROUTED: {
8189
8202
  const fb = code[ip + 1];
8190
8203
  const fallback = fb >= 0 ? link(fb) : void 0;
8191
- const push = `pushCstLeaf(ctx,{_tag:'leaf',value:it.value,span:it.span})`;
8204
+ const push = `pushCstLeaf(ctx,new _LF(it.value,it.span))`;
8192
8205
  return `${head}
8193
8206
  const it=ctx._routed
8194
8207
  if(it===undefined||pos!==it.span.start){
@@ -8269,8 +8282,8 @@ ctx._triviaLog=sOtl
8269
8282
  }
8270
8283
  if(v===FAIL)return FAIL
8271
8284
  const e=EC.e
8272
- const out=${isToken ? "input.slice(pos,e)" : `${fn}(v,{start:pos,end:e})`}
8273
- if(wasCap)pushCstLeaf(ctx,{_tag:'leaf',value:${capturesSource ? "input.slice(pos,e)" : "out"},span:{start:pos,end:e}})
8285
+ const out=${isToken ? "input.slice(pos,e)" : `${fn}(v,new _SP(pos,e))`}
8286
+ if(wasCap)pushCstLeaf(ctx,new _LF(${capturesSource ? "input.slice(pos,e)" : "out"},new _SP(pos,e)))
8274
8287
  EC.e=e
8275
8288
  return out
8276
8289
  }`;
@@ -8294,7 +8307,7 @@ ${hasSuffix && (lineFlags & 2) !== 0 ? "if(sm)_trackLines(ctx,input,e)" : ""}
8294
8307
  ${hasSuffix ? `if(!sm){ctx._fe=e;ctx._fx=${suffixExpected};if(ctx._probe!==undefined)failAt(ctx,${suffixExpected},e)}` : ""}
8295
8308
  const v=${pending ? "tp?_pfTokValue:" : ""}input.slice(pos,e)
8296
8309
  ${pending ? "if(tp){_pfTokBody=-1;_pfTokValue=undefined}" : ""}
8297
- if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,{_tag:'leaf',value:v,span:{start:pos,end:e}})
8310
+ if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
8298
8311
  EC.e=e
8299
8312
  return v
8300
8313
  }`;
@@ -8333,7 +8346,7 @@ ctx._rootTriviaLog=sRtl
8333
8346
  }
8334
8347
  if(e<0)return FAIL
8335
8348
  const v=input.slice(pos,e)
8336
- if(wasCap)pushCstLeaf(ctx,{_tag:'leaf',value:v,span:{start:pos,end:e}})
8349
+ if(wasCap)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
8337
8350
  EC.e=e
8338
8351
  return v
8339
8352
  }`;
@@ -8341,7 +8354,7 @@ return v
8341
8354
  const e=${run}(input,pos,ctx)
8342
8355
  if(e<0)return FAIL
8343
8356
  const v=input.slice(pos,e)
8344
- if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,{_tag:'leaf',value:v,span:{start:pos,end:e}})
8357
+ if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
8345
8358
  EC.e=e
8346
8359
  return v
8347
8360
  }`;
@@ -8455,7 +8468,7 @@ return v
8455
8468
  }` : `${parts.join("\n")}
8456
8469
  }`;
8457
8470
  if (n === 1) {
8458
- parts.push(fused ? projection === 0 ? "return v0" : `return ${fn}([v0],{start:pos,end:EC.e})` : wantValues ? "return [v0]" : "return undefined");
8471
+ parts.push(fused ? projection === 0 ? "return v0" : `return ${fn}([v0],new _SP(pos,EC.e))` : wantValues ? "return [v0]" : "return undefined");
8459
8472
  return close();
8460
8473
  }
8461
8474
  parts.push("let cur=EC.e");
@@ -8481,7 +8494,7 @@ return v
8481
8494
  names.push(vn);
8482
8495
  }
8483
8496
  parts.push("EC.e=cur");
8484
- parts.push(fused ? projection >= 0 ? `return ${names[projection]}` : `return ${fn}([${names.join(",")}],{start:pos,end:cur})` : wantValues ? `return [${names.join(",")}]` : "return undefined");
8497
+ parts.push(fused ? projection >= 0 ? `return ${names[projection]}` : `return ${fn}([${names.join(",")}],new _SP(pos,cur))` : wantValues ? `return [${names.join(",")}]` : "return undefined");
8485
8498
  return close();
8486
8499
  }
8487
8500
  case OP_CHOICE: {
@@ -8740,7 +8753,7 @@ ${spec.match.map((m, i) => `${i === 0 ? "" : "else "}if(${dispatchClaim(m)})arm=
8740
8753
  const routedCall = (target) => `{const savedRouted=ctx._routed
8741
8754
  ${emitRollback(m1, L.buf, L.raw, sinks)}
8742
8755
  ${emitMark(m2, L.buf, L.raw, sinks, false)}
8743
- ctx._routed={value:key,span:{start:pos,end:selEnd}}
8756
+ ctx._routed={value:key,span:new _SP(pos,selEnd)}
8744
8757
  try{v=${target}(input,pos,ctx)}finally{ctx._routed=savedRouted}
8745
8758
  break}`;
8746
8759
  const plainCall = (target) => `v=${target}(input,selEnd,ctx);break`;
@@ -8935,8 +8948,8 @@ return out
8935
8948
  const end=${recognize}(input,pos)
8936
8949
  if(end<0){ctx._fe=pos;ctx._fx=${xf};return FAIL}
8937
8950
  const value=${value2}
8938
- const leaf={_tag:'leaf',value,span:{start:pos,end}}
8939
- const kids=[leaf],rawKids=[leaf],span={start:pos,end}
8951
+ const leaf=new _LF(value,new _SP(pos,end))
8952
+ const kids=[leaf],rawKids=[leaf],span=new _SP(pos,end)
8940
8953
  EC.e=end
8941
8954
  const nd=${build2}(kids,undefined,span,rawKids,EMPTY_TL,undefined)
8942
8955
  ${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))"}
@@ -9035,7 +9048,7 @@ ctx._cstTriviaLog=sTl
9035
9048
  ctx.captureTrivia=sCap
9036
9049
  if(v===FAIL)return FAIL
9037
9050
  const end=EC.e
9038
- ${collapseChildren ? `const nd=captured.length===1?captured[0]:${build}(captured,undefined,{start:pos,end},EMPTY_CH,EMPTY_TL,undefined)` : `const nd=${build}(captured,${fields ? "fieldMap" : "undefined"},{start:pos,end},EMPTY_CH,EMPTY_TL,undefined)`}
9051
+ ${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)`}
9039
9052
  ${publish}
9040
9053
  EC.e=end
9041
9054
  return nd
@@ -9058,20 +9071,20 @@ return nd
9058
9071
  const direct = `${build}(kids,fieldMap,span,rawKids,${captureWide ? "tlog" : "EMPTY_TL"},st)`;
9059
9072
  value = hostCst ? `nd=_pfHost!==undefined?${hostCall}:${direct}` : `nd=${direct}`;
9060
9073
  } else {
9061
- value = `nd=_pfHost!==undefined?_pfHost(${ty},hostKids,fieldMap,span,rawKids,tlog,st,${tags}):{_tag:'node',type:${ty},span,state:st??null,children:kids}`;
9074
+ value = `nd=_pfHost!==undefined?_pfHost(${ty},hostKids,fieldMap,span,rawKids,tlog,st,${tags}):new _ND(${ty},span,st??null,kids===EMPTY_CH?kids:[...kids])`;
9062
9075
  }
9063
9076
  const collapsible = keepChildren && (hostCst || build === void 0 && proj < 0);
9064
- const openCapture = omitsRaw ? `const buf={noRaw:true,rawLen:0}
9077
+ const openCapture = omitsRaw ? `const buf=new _BUF(undefined,true,0)
9065
9078
  ctx._cstBuf=buf
9066
9079
  ctx._cstChildren=undefined
9067
9080
  ctx._cstLeaves=undefined
9068
9081
  ctx._cstRawChildren=undefined
9069
- ctx._cstTriviaLog=undefined` : keepChildren ? `const buf={}
9082
+ ctx._cstTriviaLog=undefined` : keepChildren ? `const buf=new _BUF(undefined,undefined,0)
9070
9083
  ctx._cstBuf=buf
9071
9084
  ctx._cstChildren=undefined
9072
9085
  ctx._cstLeaves=undefined
9073
9086
  ctx._cstRawChildren=undefined
9074
- ctx._cstTriviaLog=undefined` : `const buf={rawOnly:true}
9087
+ ctx._cstTriviaLog=undefined` : `const buf=new _BUF(true,undefined,0)
9075
9088
  ctx._cstBuf=buf
9076
9089
  ctx._cstChildren=undefined
9077
9090
  ctx._cstLeaves=undefined
@@ -9109,7 +9122,7 @@ ctx._cstTriviaLog=sTl
9109
9122
  ctx.captureTrivia=sCap
9110
9123
  if(v===FAIL)return FAIL
9111
9124
  const end=EC.e
9112
- const span=${tracked ? "spanLines(ctx,pos,end)" : "{start:pos,end}"}
9125
+ const span=${tracked ? "spanLines(ctx,pos,end)" : "new _SP(pos,end)"}
9113
9126
  const st=${readsState ? "ctx.state" : "undefined"}
9114
9127
  let nd
9115
9128
  ${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]
@@ -9547,7 +9560,7 @@ function assemble(t, prog, cfg) {
9547
9560
  const NULLABLE = /* @__PURE__ */ new Map();
9548
9561
  const CLEAN = REC ? () => false : failCleanAnalysis(code);
9549
9562
  function pushLeaf(ctx, value, s, e) {
9550
- const lf = { _tag: "leaf", value, span: { start: s, end: e } };
9563
+ const lf = new PlainLeaf8(value, new PlainSpan9(s, e));
9551
9564
  pushCstLeaf(ctx, lf);
9552
9565
  }
9553
9566
  function plainBuildNode(child, build, trailing) {
@@ -9580,7 +9593,7 @@ function assemble(t, prog, cfg) {
9580
9593
  ctx.captureTrivia = sCap;
9581
9594
  if (value === FAIL) return FAIL;
9582
9595
  const end = EC.e;
9583
- const span = { start: pos, end };
9596
+ const span = new PlainSpan9(pos, end);
9584
9597
  const node = build(kids, void 0, span, rawKids, EMPTY_TL, void 0);
9585
9598
  if (sBuf !== void 0 || sCh !== void 0) {
9586
9599
  pushCstChild(ctx, node, rawEntry(node, input, pos, end));
@@ -9625,7 +9638,7 @@ function assemble(t, prog, cfg) {
9625
9638
  ctx.captureTrivia = sCap;
9626
9639
  if (value === FAIL) return FAIL;
9627
9640
  const end = EC.e;
9628
- const node = build(captured, void 0, { start: pos, end }, EMPTY_CH, EMPTY_TL, void 0);
9641
+ const node = build(captured, void 0, new PlainSpan9(pos, end), EMPTY_CH, EMPTY_TL, void 0);
9629
9642
  if (sBuf !== void 0 || sCh !== void 0) {
9630
9643
  pushCstChild(ctx, node, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node, input, pos, end) : void 0);
9631
9644
  }
@@ -9662,7 +9675,7 @@ function assemble(t, prog, cfg) {
9662
9675
  ctx.captureTrivia = sCap;
9663
9676
  if (value === FAIL) return FAIL;
9664
9677
  const end = EC.e;
9665
- const node = build(captured, fieldMap, { start: pos, end }, EMPTY_CH, EMPTY_TL, void 0);
9678
+ const node = build(captured, fieldMap, new PlainSpan9(pos, end), EMPTY_CH, EMPTY_TL, void 0);
9666
9679
  if (sBuf !== void 0 || sCh !== void 0) {
9667
9680
  pushCstChild(ctx, node, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node, input, pos, end) : void 0);
9668
9681
  }
@@ -9699,7 +9712,7 @@ function assemble(t, prog, cfg) {
9699
9712
  ctx.captureTrivia = sCap;
9700
9713
  if (value === FAIL) return FAIL;
9701
9714
  const end = EC.e;
9702
- const span = { start: pos, end };
9715
+ const span = new PlainSpan9(pos, end);
9703
9716
  const node = kids.length === 1 ? kids[0] : build(kids, void 0, span, rawKids, EMPTY_TL, void 0);
9704
9717
  if (sBuf !== void 0 || sCh !== void 0) {
9705
9718
  pushCstChild(ctx, node, rawEntry(node, input, pos, end));
@@ -9736,7 +9749,7 @@ function assemble(t, prog, cfg) {
9736
9749
  ctx.captureTrivia = sCap;
9737
9750
  if (value === FAIL) return FAIL;
9738
9751
  const end = EC.e;
9739
- const node = captured.length === 1 ? captured[0] : build(captured, void 0, { start: pos, end }, EMPTY_CH, EMPTY_TL, void 0);
9752
+ const node = captured.length === 1 ? captured[0] : build(captured, void 0, new PlainSpan9(pos, end), EMPTY_CH, EMPTY_TL, void 0);
9740
9753
  if (sBuf !== void 0 || sCh !== void 0) {
9741
9754
  pushCstChild(ctx, node, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node, input, pos, end) : void 0);
9742
9755
  }
@@ -10169,7 +10182,7 @@ function assemble(t, prog, cfg) {
10169
10182
  return (input, pos, selEnd, key, ctx, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot) => {
10170
10183
  const savedRouted = ctx._routed;
10171
10184
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
10172
- ctx._routed = { value: key, span: { start: pos, end: selEnd } };
10185
+ ctx._routed = { value: key, span: new PlainSpan9(pos, selEnd) };
10173
10186
  let v;
10174
10187
  try {
10175
10188
  v = child(input, pos, ctx);
@@ -10602,7 +10615,7 @@ function assemble(t, prog, cfg) {
10602
10615
  case OP_EXPECT: {
10603
10616
  const child = link(code[ip + 1]);
10604
10617
  const xf = fx[code[ip + 2]];
10605
- const expectSpan = (ctx, pos) => prog.lines === 1 ? spanLines(ctx, pos, pos) : { start: pos, end: pos };
10618
+ const expectSpan = (ctx, pos) => prog.lines === 1 ? spanLines(ctx, pos, pos) : new PlainSpan9(pos, pos);
10606
10619
  if (REC) {
10607
10620
  return (input, pos, ctx) => {
10608
10621
  const v = child(input, pos, ctx);
@@ -10634,7 +10647,7 @@ function assemble(t, prog, cfg) {
10634
10647
  return (input, pos, ctx) => {
10635
10648
  const v = child(input, pos, ctx);
10636
10649
  if (v === FAIL) return FAIL;
10637
- ctx._fields?.push({ name, value: v, span: { start: pos, end: EC.e } });
10650
+ ctx._fields?.push(new PlainField(name, v, new PlainSpan9(pos, EC.e)));
10638
10651
  return v;
10639
10652
  };
10640
10653
  }
@@ -10658,7 +10671,7 @@ function assemble(t, prog, cfg) {
10658
10671
  return (input, pos, ctx) => {
10659
10672
  const v = child(input, pos, ctx);
10660
10673
  if (v === FAIL) return FAIL;
10661
- return fn(v, { start: pos, end: EC.e });
10674
+ return fn(v, new PlainSpan9(pos, EC.e));
10662
10675
  };
10663
10676
  }
10664
10677
  case OP_SCAN: {
@@ -10762,7 +10775,7 @@ function assemble(t, prog, cfg) {
10762
10775
  ctx._fx = ROUTED_FX;
10763
10776
  return FAIL;
10764
10777
  }
10765
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value: item.value, span: item.span });
10778
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf8(item.value, item.span));
10766
10779
  EC.e = item.span.end;
10767
10780
  return item.value;
10768
10781
  };
@@ -10948,7 +10961,7 @@ function assemble(t, prog, cfg) {
10948
10961
  if (v === FAIL) return FAIL;
10949
10962
  const end = EC.e;
10950
10963
  const value = input.slice(pos, end);
10951
- if (wasCapturing) pushCstLeaf(ctx, { _tag: "leaf", value, span: { start: pos, end } });
10964
+ if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf8(value, new PlainSpan9(pos, end)));
10952
10965
  EC.e = end;
10953
10966
  return value;
10954
10967
  };
@@ -10982,7 +10995,7 @@ function assemble(t, prog, cfg) {
10982
10995
  if (ctx._probe !== void 0) failAt(ctx, suffixExpected, end);
10983
10996
  }
10984
10997
  const value = input.slice(pos, end);
10985
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span: { start: pos, end } });
10998
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf8(value, new PlainSpan9(pos, end)));
10986
10999
  EC.e = end;
10987
11000
  return value;
10988
11001
  };
@@ -11025,7 +11038,7 @@ function assemble(t, prog, cfg) {
11025
11038
  }
11026
11039
  if (end < 0) return FAIL;
11027
11040
  const value = input.slice(pos, end);
11028
- if (wasCapturing) pushCstLeaf(ctx, { _tag: "leaf", value, span: { start: pos, end } });
11041
+ if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf8(value, new PlainSpan9(pos, end)));
11029
11042
  EC.e = end;
11030
11043
  return value;
11031
11044
  };
@@ -11034,7 +11047,7 @@ function assemble(t, prog, cfg) {
11034
11047
  const end = run(input, pos, ctx);
11035
11048
  if (end < 0) return FAIL;
11036
11049
  const value = input.slice(pos, end);
11037
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span: { start: pos, end } });
11050
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf8(value, new PlainSpan9(pos, end)));
11038
11051
  EC.e = end;
11039
11052
  return value;
11040
11053
  };
@@ -11067,12 +11080,8 @@ function assemble(t, prog, cfg) {
11067
11080
  }
11068
11081
  if (v === FAIL) return FAIL;
11069
11082
  const end = EC.e;
11070
- const out = fn(v, { start: pos, end });
11071
- if (wasCapturing) pushCstLeaf(ctx, {
11072
- _tag: "leaf",
11073
- value: op === OP_SOURCE_LEAF && hostCst ? input.slice(pos, end) : out,
11074
- span: { start: pos, end }
11075
- });
11083
+ const out = fn(v, new PlainSpan9(pos, end));
11084
+ if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf8(op === OP_SOURCE_LEAF && hostCst ? input.slice(pos, end) : out, new PlainSpan9(pos, end)));
11076
11085
  EC.e = end;
11077
11086
  return out;
11078
11087
  };
@@ -11207,7 +11216,7 @@ function assemble(t, prog, cfg) {
11207
11216
  const cur = runSyncTerms(input, pos, ctx, values);
11208
11217
  if (cur < 0) return FAIL;
11209
11218
  EC.e = cur;
11210
- return projection >= 0 ? values[projection] : fn(values, { start: pos, end: cur });
11219
+ return projection >= 0 ? values[projection] : fn(values, new PlainSpan9(pos, cur));
11211
11220
  };
11212
11221
  }
11213
11222
  if (wantValues) {
@@ -11301,7 +11310,7 @@ function assemble(t, prog, cfg) {
11301
11310
  const cur = runAdjTerms(input, pos, ctx, values);
11302
11311
  if (cur < 0) return FAIL;
11303
11312
  EC.e = cur;
11304
- return projection >= 0 ? values[projection] : fn(values, { start: pos, end: cur });
11313
+ return projection >= 0 ? values[projection] : fn(values, new PlainSpan9(pos, cur));
11305
11314
  };
11306
11315
  }
11307
11316
  if (wantValues) {
@@ -11326,7 +11335,7 @@ function assemble(t, prog, cfg) {
11326
11335
  return (input, pos, ctx) => {
11327
11336
  const v = k0(input, pos, ctx);
11328
11337
  if (v === FAIL) return FAIL;
11329
- return projection === 0 ? v : fn([v], { start: pos, end: EC.e });
11338
+ return projection === 0 ? v : fn([v], new PlainSpan9(pos, EC.e));
11330
11339
  };
11331
11340
  }
11332
11341
  if (wantValues) {
@@ -11351,7 +11360,7 @@ function assemble(t, prog, cfg) {
11351
11360
  const cur = step(k1, input, EC.e, ctx);
11352
11361
  if (cur < 0) return FAIL;
11353
11362
  EC.e = cur;
11354
- return projection === 0 ? v0 : projection === 1 ? TERMV : fn([v0, TERMV], { start: pos, end: cur });
11363
+ return projection === 0 ? v0 : projection === 1 ? TERMV : fn([v0, TERMV], new PlainSpan9(pos, cur));
11355
11364
  };
11356
11365
  }
11357
11366
  if (wantValues) {
@@ -11385,7 +11394,7 @@ function assemble(t, prog, cfg) {
11385
11394
  cur = step(k2, input, cur, ctx);
11386
11395
  if (cur < 0) return FAIL;
11387
11396
  EC.e = cur;
11388
- return projection === 0 ? v0 : projection === 1 ? v1 : projection === 2 ? TERMV : fn([v0, v1, TERMV], { start: pos, end: cur });
11397
+ return projection === 0 ? v0 : projection === 1 ? v1 : projection === 2 ? TERMV : fn([v0, v1, TERMV], new PlainSpan9(pos, cur));
11389
11398
  };
11390
11399
  }
11391
11400
  if (wantValues) {
@@ -11482,7 +11491,7 @@ function assemble(t, prog, cfg) {
11482
11491
  const cur = runDirectTerms(input, pos, ctx, values);
11483
11492
  if (cur < 0) return FAIL;
11484
11493
  EC.e = cur;
11485
- return projection >= 0 ? values[projection] : fn(values, { start: pos, end: cur });
11494
+ return projection >= 0 ? values[projection] : fn(values, new PlainSpan9(pos, cur));
11486
11495
  };
11487
11496
  }
11488
11497
  if (wantValues) {
@@ -12380,10 +12389,10 @@ function assemble(t, prog, cfg) {
12380
12389
  return FAIL;
12381
12390
  }
12382
12391
  const value = regexValue ? input.slice(pos, end) : spec;
12383
- const leaf2 = { _tag: "leaf", value, span: { start: pos, end } };
12392
+ const leaf2 = new PlainLeaf8(value, new PlainSpan9(pos, end));
12384
12393
  const kids = [leaf2];
12385
12394
  const rawKids = [leaf2];
12386
- const span = { start: pos, end };
12395
+ const span = new PlainSpan9(pos, end);
12387
12396
  EC.e = end;
12388
12397
  const nd = build2(kids, void 0, span, rawKids, EMPTY_TL, void 0);
12389
12398
  if (ctx._cstBuf !== void 0 || ctx._cstChildren !== void 0) {
@@ -12465,7 +12474,7 @@ function assemble(t, prog, cfg) {
12465
12474
  const sCh = ctx._cstChildren;
12466
12475
  const sCap = ctx.captureTrivia;
12467
12476
  const sBuf = ctx._cstBuf;
12468
- const buf = rawOnly ? { rawOnly: true } : omitsRaw ? { noRaw: true, rawLen: 0 } : {};
12477
+ const buf = rawOnly ? new PlainBuf2(true, void 0, 0) : omitsRaw ? new PlainBuf2(void 0, true, 0) : new PlainBuf2(void 0, void 0, 0);
12469
12478
  ctx._cstBuf = buf;
12470
12479
  ctx.captureTrivia = captureWide;
12471
12480
  const savedFields = ctx._fields;
@@ -12487,7 +12496,7 @@ function assemble(t, prog, cfg) {
12487
12496
  ctx.captureTrivia = sCap;
12488
12497
  if (v === FAIL) return FAIL;
12489
12498
  const end = EC.e;
12490
- const span = tracked ? spanLines(ctx, pos, end) : { start: pos, end };
12499
+ const span = tracked ? spanLines(ctx, pos, end) : new PlainSpan9(pos, end);
12491
12500
  const st = readsState ? ctx.state : void 0;
12492
12501
  let nd;
12493
12502
  if (unwrap && kids.length === 1) {
@@ -12511,7 +12520,7 @@ function assemble(t, prog, cfg) {
12511
12520
  } else if (host !== void 0) {
12512
12521
  nd = host(type, hostKids, fieldMap, span, rawKids, tlog, st, tags);
12513
12522
  } else {
12514
- nd = { _tag: "node", type, span, state: st ?? null, children: kids };
12523
+ nd = new PlainNode2(type, span, st ?? null, kids === EMPTY_CH ? kids : [...kids]);
12515
12524
  }
12516
12525
  if (sBuf !== void 0 || sCh !== void 0) {
12517
12526
  pushCstChild(ctx, nd, rawEntry(nd, input, pos, end));
@@ -12537,7 +12546,7 @@ function assemble(t, prog, cfg) {
12537
12546
  const at = fe === void 0 || fe < 0 ? pos : fe;
12538
12547
  return { ok: false, expected: ctx._fx ?? EMPTY_FX2, span: { start: at, end: at } };
12539
12548
  }
12540
- return { ok: true, value: v, span: { start: pos, end: EC.e } };
12549
+ return { ok: true, value: v, span: new PlainSpan9(pos, EC.e) };
12541
12550
  }
12542
12551
  };
12543
12552
  }
@@ -12652,7 +12661,12 @@ function assemble(t, prog, cfg) {
12652
12661
  LEAD,
12653
12662
  triviaFieldCapture,
12654
12663
  skipDeferredTrivia,
12655
- collapseEmpty
12664
+ collapseEmpty,
12665
+ PlainSpan9,
12666
+ PlainLeaf8,
12667
+ PlainNode2,
12668
+ PlainField,
12669
+ PlainBuf2
12656
12670
  );
12657
12671
  emitReached = new Set(pre.reached);
12658
12672
  if (emitted.ext !== void 0) HYBRID = emitted;
@@ -12739,7 +12753,12 @@ function assemble(t, prog, cfg) {
12739
12753
  LEAD,
12740
12754
  triviaFieldCapture,
12741
12755
  skipDeferredTrivia,
12742
- collapseEmpty
12756
+ collapseEmpty,
12757
+ PlainSpan9,
12758
+ PlainLeaf8,
12759
+ PlainNode2,
12760
+ PlainField,
12761
+ PlainBuf2
12743
12762
  );
12744
12763
  emitReached = em.reached;
12745
12764
  } catch (e) {
@@ -13767,6 +13786,7 @@ import {
13767
13786
  } from "../compiler/token-capability.js";
13768
13787
 
13769
13788
  // src/combinators/keywords.ts
13789
+ import { PlainLeaf as PlainLeaf9, PlainSpan as PlainSpan10 } from "../cst/plain.js";
13770
13790
  function escapeRe(s) {
13771
13791
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
13772
13792
  }
@@ -14491,18 +14511,10 @@ var Encoder = class {
14491
14511
  /** TOKEN bodies are an all-program decision. A complete occurrence inside an
14492
14512
  * otherwise incomplete final graph stays on CHARACTER with every sibling. */
14493
14513
  selectLexicalBodies;
14494
- /**
14495
- * Decides the extra operands laid down below. ALWAYS TRUE — see
14496
- * `TableSettings.recovery`. Kept as a field rather than folded away because it
14497
- * is what every emit site reads, and the emit sites are where the shape of the
14498
- * row is stated.
14499
- */
14500
- rec;
14501
14514
  constructor(settings, selectLexicalBodies) {
14502
14515
  this.settings = settings;
14503
14516
  this.track = settings.trackLines === true;
14504
14517
  this.selectLexicalBodies = selectLexicalBodies;
14505
- this.rec = true;
14506
14518
  this.plan = settings.coverage;
14507
14519
  this.cov = settings.coverage === void 0 ? void 0 : settings.coverage.definitions.map((d) => [d.id, covKindCode(d.kind)]);
14508
14520
  this.covIndex = new Map((this.cov ?? []).map((d, i) => [d[0], i]));
@@ -15004,12 +15016,10 @@ var Encoder = class {
15004
15016
  }
15005
15017
  case "sequence": {
15006
15018
  const kids = d.parsers.map((c) => this.node(c).ip);
15007
- const head = this.emitHead(d.valueUnused ? OP_SEQV : OP_SEQ, 1 + kids.length + (this.rec ? kids.length : 0));
15019
+ const head = this.emitHead(d.valueUnused ? OP_SEQV : OP_SEQ, 1 + 2 * kids.length);
15008
15020
  this.code[head + 1] = kids.length;
15009
15021
  for (let i = 0; i < kids.length; i++) this.code[head + 2 + i] = kids[i];
15010
- if (this.rec) {
15011
- for (let i = 0; i < kids.length; i++) this.code[head + 2 + kids.length + i] = this.followClass(d.parsers, i);
15012
- }
15022
+ for (let i = 0; i < kids.length; i++) this.code[head + 2 + kids.length + i] = this.followClass(d.parsers, i);
15013
15023
  return head;
15014
15024
  }
15015
15025
  case "choice": {
@@ -15111,25 +15121,22 @@ var Encoder = class {
15111
15121
  const itemClass = matchesEmpty(d.parser, /* @__PURE__ */ new Set(), rr) ? -1 : this.charClass(firstSetOf(d.parser, /* @__PURE__ */ new Set(), rr, this.activeTrivia));
15112
15122
  const op = d.valueUnused ? OP_REPV : OP_REP;
15113
15123
  const min = d.tag === "many" ? 0 : d.min;
15114
- return this.rec ? this.emit(op, child, min, d.max ?? -1, -1, 0, this.expected(deriveExpected(d.parser)), itemClass) : this.emit(op, child, min, d.max ?? -1, -1, 0);
15124
+ return this.emit(op, child, min, d.max ?? -1, -1, 0, this.expected(deriveExpected(d.parser)), itemClass);
15115
15125
  }
15116
15126
  case "sepBy": {
15117
15127
  const child = this.node(d.parser).ip;
15118
15128
  const sep = this.node(d.separator).ip;
15119
15129
  const flags = (d.trailing === "allow" ? 1 : 0) | (d.keepSeparators === true ? 2 : 0) | (d.min >= 2 ? 4 : 0);
15120
- if (this.rec) {
15121
- return this.emit(
15122
- OP_REP,
15123
- child,
15124
- d.min,
15125
- d.max ?? -1,
15126
- sep,
15127
- flags,
15128
- this.expected(deriveExpected(d.parser)),
15129
- this.charClass(firstSetOf(d.separator, /* @__PURE__ */ new Set(), this.refResolver(), this.activeTrivia))
15130
- );
15131
- }
15132
- return d.min >= 2 ? this.emit(OP_REP, child, d.min, d.max ?? -1, sep, flags, this.expected(deriveExpected(d.parser))) : this.emit(OP_REP, child, d.min, d.max ?? -1, sep, flags);
15130
+ return this.emit(
15131
+ OP_REP,
15132
+ child,
15133
+ d.min,
15134
+ d.max ?? -1,
15135
+ sep,
15136
+ flags,
15137
+ this.expected(deriveExpected(d.parser)),
15138
+ this.charClass(firstSetOf(d.separator, /* @__PURE__ */ new Set(), this.refResolver(), this.activeTrivia))
15139
+ );
15133
15140
  }
15134
15141
  case "optional": {
15135
15142
  const head = this.emit(OP_OPT, this.lookaheadGate(d.parser, this.node(d.parser).ip));
@@ -15140,14 +15147,12 @@ var Encoder = class {
15140
15147
  const inner = d.parser._def;
15141
15148
  if (inner.tag === "sequence" && !this.memo.has(d.parser) && !this.pending.has(d.parser)) {
15142
15149
  const kids = inner.parsers.map((c) => this.node(c).ip);
15143
- const head = this.emitHead(OP_SEQX, 2 + kids.length + (this.rec ? kids.length : 0));
15150
+ const head = this.emitHead(OP_SEQX, 2 + 2 * kids.length);
15144
15151
  const projection = directArrayProjection(d.fn, d.fnSrc, kids.length);
15145
15152
  this.code[head + 1] = projection === null ? this.fn(d.fn, d.fnSrc ?? null) : ~projection;
15146
15153
  this.code[head + 2] = kids.length;
15147
15154
  for (let i = 0; i < kids.length; i++) this.code[head + 3 + i] = kids[i];
15148
- if (this.rec) {
15149
- for (let i = 0; i < kids.length; i++) this.code[head + 3 + kids.length + i] = this.followClass(inner.parsers, i);
15150
- }
15155
+ for (let i = 0; i < kids.length; i++) this.code[head + 3 + kids.length + i] = this.followClass(inner.parsers, i);
15151
15156
  return head;
15152
15157
  }
15153
15158
  const child = this.node(d.parser).ip;
@@ -15470,7 +15475,7 @@ var Encoder = class {
15470
15475
  ...this.settings.hostMode === void 0 ? {} : { hostMode: this.settings.hostMode },
15471
15476
  ...this.runtimeOnly.size === 0 ? {} : { runtimeOnly: [...this.runtimeOnly].sort() },
15472
15477
  ...this.triviaSpecs.length === 0 ? {} : { triviaSpecs: this.triviaSpecs },
15473
- ...this.rec ? { rec: 1 } : {},
15478
+ rec: 1,
15474
15479
  ...this.cov === void 0 ? {} : { cov: this.cov },
15475
15480
  lines: this.track ? 1 : 0
15476
15481
  }, void 0, {
@@ -15531,7 +15536,11 @@ function encodeTableProgram(ruleMap, settings = {}) {
15531
15536
  return { prog, fnSrcs: enc.fnSrcs };
15532
15537
  }
15533
15538
 
15539
+ // src/version.ts
15540
+ var PARSEMAN_VERSION = "0.59.1";
15541
+
15534
15542
  // src/table/emit.ts
15543
+ 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`)});`;
15535
15544
  function jsString(s) {
15536
15545
  return JSON.stringify(s);
15537
15546
  }
@@ -15617,7 +15626,7 @@ function emitAssemblies(prog, cfgs) {
15617
15626
  throw e;
15618
15627
  }
15619
15628
  const plan = em.plan;
15620
- out.push(`{key:${key},factory:function(${EMITTED_PARAMS.join(",")}){${em.source}
15629
+ out.push(`{key:${key},factory:function(${EMITTED_PARAMS.join(",")}){${FACTORY_ARITY_GUARD}${em.source}
15621
15630
  },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(",")}]}`);
15622
15631
  }
15623
15632
  return [`a:[${out.join(",")}],`];