parseman 0.58.3 → 0.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/analysis/diagnostics.js +141 -93
  2. package/dist/analysis/diagnostics.js.map +3 -3
  3. package/dist/cli/index.js +143 -94
  4. package/dist/cli/index.js.map +3 -3
  5. package/dist/combinators/dispatch.d.ts.map +1 -1
  6. package/dist/combinators/field-trivia.d.ts.map +1 -1
  7. package/dist/combinators/keywords.d.ts.map +1 -1
  8. package/dist/combinators/literal.d.ts.map +1 -1
  9. package/dist/combinators/node.d.ts.map +1 -1
  10. package/dist/combinators/regex.d.ts.map +1 -1
  11. package/dist/combinators/scanTo.d.ts.map +1 -1
  12. package/dist/combinators/token.d.ts.map +1 -1
  13. package/dist/compiler/linker.d.ts.map +1 -1
  14. package/dist/compiler/token-capability.js.map +1 -1
  15. package/dist/cst/capture-buffer.d.ts.map +1 -1
  16. package/dist/cst/plain.js +69 -0
  17. package/dist/cst/plain.js.map +6 -0
  18. package/dist/index.js +144 -98
  19. package/dist/index.js.map +3 -3
  20. package/dist/language-service/index.js +19 -2
  21. package/dist/language-service/index.js.map +2 -2
  22. package/dist/line-index.d.ts +13 -0
  23. package/dist/line-index.d.ts.map +1 -1
  24. package/dist/plugin/entry-supercompiler.d.ts.map +1 -1
  25. package/dist/plugin/index.js +146 -100
  26. package/dist/plugin/index.js.map +3 -3
  27. package/dist/recovery/scan.d.ts.map +1 -1
  28. package/dist/run/index.js +4 -1
  29. package/dist/run/index.js.map +2 -2
  30. package/dist/spec/index.js +18 -1
  31. package/dist/spec/index.js.map +2 -2
  32. package/dist/table/assemble.d.ts.map +1 -1
  33. package/dist/table/emit-assembly.d.ts +1 -1
  34. package/dist/table/emit-assembly.d.ts.map +1 -1
  35. package/dist/table/emit.d.ts +6 -0
  36. package/dist/table/emit.d.ts.map +1 -1
  37. package/dist/table/index.js +124 -89
  38. package/dist/table/index.js.map +3 -3
  39. package/dist/table/run-support.d.ts.map +1 -1
  40. package/dist/version.d.ts +1 -1
  41. package/package.json +2 -1
  42. package/src/combinators/dispatch.ts +2 -1
  43. package/src/combinators/field-trivia.ts +6 -5
  44. package/src/combinators/keywords.ts +3 -2
  45. package/src/combinators/literal.ts +5 -4
  46. package/src/combinators/node.ts +3 -1
  47. package/src/combinators/regex.ts +5 -4
  48. package/src/combinators/scanTo.ts +2 -1
  49. package/src/combinators/token.ts +3 -6
  50. package/src/compiler/linker.ts +4 -2
  51. package/src/cst/capture-buffer.ts +13 -5
  52. package/src/cst/plain.d.ts +35 -0
  53. package/src/cst/plain.js +74 -0
  54. package/src/line-index.ts +37 -0
  55. package/src/plugin/entry-supercompiler.ts +3 -2
  56. package/src/recovery/scan.ts +2 -1
  57. package/src/table/assemble.ts +33 -35
  58. package/src/table/emit-assembly.ts +27 -24
  59. package/src/table/emit.ts +9 -1
  60. package/src/table/run-support.ts +4 -7
  61. package/src/version.ts +1 -1
package/dist/index.js CHANGED
@@ -349,6 +349,7 @@ function failAt(ctx, expected, pos) {
349
349
  }
350
350
 
351
351
  // src/line-index.ts
352
+ import { PlainLineSpan, PlainSpan } from "./cst/plain.js";
352
353
  function createLineIndex() {
353
354
  return { lineStarts: [0] };
354
355
  }
@@ -408,6 +409,27 @@ function annotateSpan(span, index) {
408
409
  endColumn: e.col
409
410
  };
410
411
  }
412
+ var SPAN_KEYS = ["start", "end", "startLine", "startColumn", "endLine", "endColumn"];
413
+ function copySpan(span) {
414
+ let n = 0;
415
+ for (const key in span) {
416
+ if (key !== SPAN_KEYS[n]) return { ...span };
417
+ n++;
418
+ }
419
+ if (n === 2) return new PlainSpan(span.start, span.end);
420
+ if (n === 6 && span.startLine !== void 0 && span.startColumn !== void 0 && span.endLine !== void 0 && span.endColumn !== void 0) {
421
+ return new PlainLineSpan(span.start, span.end, span.startLine, span.startColumn, span.endLine, span.endColumn);
422
+ }
423
+ return { ...span };
424
+ }
425
+ function lineSpanFromContext(span, ctx) {
426
+ if (!ctx.trackLines) return span;
427
+ const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
428
+ if (!index) return span;
429
+ const s = offsetToLineCol(index, span.start);
430
+ const e = offsetToLineCol(index, span.end);
431
+ return new PlainLineSpan(span.start, span.end, s.line, s.col, e.line, e.col);
432
+ }
411
433
  function annotateSpanFromLineContext(span, ctx) {
412
434
  if (!ctx.trackLines) return span;
413
435
  const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
@@ -430,6 +452,7 @@ function annotateTreeSpans(value, index, seen = /* @__PURE__ */ new WeakSet()) {
430
452
  }
431
453
 
432
454
  // src/cst/capture-buffer.ts
455
+ import { PlainBuf, PlainLeaf } from "./cst/plain.js";
433
456
  var EMPTY = [];
434
457
  var EMPTY_TL = [];
435
458
  function cstCaptureActive(ctx) {
@@ -444,7 +467,7 @@ function beginCstNodeCapture(ctx) {
444
467
  cap: ctx.captureTrivia,
445
468
  buf: ctx._cstBuf
446
469
  };
447
- ctx._cstBuf = {};
470
+ ctx._cstBuf = new PlainBuf(void 0, void 0, 0);
448
471
  ctx._cstChildren = void 0;
449
472
  ctx._cstLeaves = void 0;
450
473
  ctx._cstRawChildren = void 0;
@@ -469,12 +492,15 @@ function endCstNodeCapture(ctx, saved) {
469
492
  ctx.captureTrivia = saved.cap;
470
493
  return materialized;
471
494
  }
495
+ function isLeaf(v) {
496
+ return typeof v === "object" && v !== null && v._tag === "leaf";
497
+ }
472
498
  function pushCstLeaf(ctx, leaf2) {
473
499
  if (!ctx.trackLines) {
474
500
  pushCstChild(ctx, leaf2, leaf2);
475
501
  return;
476
502
  }
477
- const annotated = leaf2 && typeof leaf2 === "object" && leaf2.span ? { ...leaf2, span: annotateSpanFromLineContext(leaf2.span, ctx) } : leaf2;
503
+ 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;
478
504
  pushCstChild(ctx, annotated, annotated);
479
505
  }
480
506
  function pushCstChild(ctx, built, rawEntry2) {
@@ -663,6 +689,7 @@ function assertionFailureExpected(positive, childTag) {
663
689
  }
664
690
 
665
691
  // src/combinators/literal.ts
692
+ import { PlainLeaf as PlainLeaf2, PlainSpan as PlainSpan2 } from "./cst/plain.js";
666
693
  function asciiFoldEq(a, b) {
667
694
  if (a.length !== b.length) return false;
668
695
  for (let i = 0; i < a.length; i++) {
@@ -720,9 +747,9 @@ function literal(value, opts = {}) {
720
747
  const code = value.charCodeAt(0);
721
748
  return function parse3(input, pos, ctx) {
722
749
  if (input.charCodeAt(pos) === code) {
723
- const span = { start: pos, end: pos + 1 };
750
+ const span = new PlainSpan2(pos, pos + 1);
724
751
  if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, span.end);
725
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span });
752
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf2(value, span));
726
753
  return { ok: true, value, span };
727
754
  }
728
755
  return failAt(ctx, expected, pos);
@@ -734,9 +761,9 @@ function literal(value, opts = {}) {
734
761
  }
735
762
  const matchedValue = caseInsensitive ? input.slice(pos, end) : value;
736
763
  if (caseInsensitive ? asciiFoldEq(matchedValue, value) : input.startsWith(value, pos)) {
737
- const span = { start: pos, end };
764
+ const span = new PlainSpan2(pos, end);
738
765
  if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, end);
739
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value: matchedValue, span });
766
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf2(matchedValue, span));
740
767
  return { ok: true, value: matchedValue, span };
741
768
  }
742
769
  return failAt(ctx, expected, pos);
@@ -1198,6 +1225,7 @@ function firstSetFromRegex(source, flags = "") {
1198
1225
  }
1199
1226
 
1200
1227
  // src/combinators/regex.ts
1228
+ import { PlainLeaf as PlainLeaf3, PlainSpan as PlainSpan3 } from "./cst/plain.js";
1201
1229
  var SCAN_BAIL_AT = 64;
1202
1230
  function inRanges(cp, ranges) {
1203
1231
  for (let i = 0; i < ranges.length; i++) {
@@ -1310,9 +1338,9 @@ function regex(pattern, flags = "") {
1310
1338
  if (scanEnd !== void 0) {
1311
1339
  if (scanEnd === null) return failAt(ctx, directTerminalFailureExpected(def), pos);
1312
1340
  const value = input.slice(pos, scanEnd);
1313
- const span2 = { start: pos, end: scanEnd };
1341
+ const span2 = new PlainSpan3(pos, scanEnd);
1314
1342
  if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, scanEnd);
1315
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span: span2 });
1343
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf3(value, span2));
1316
1344
  return { ok: true, value, span: span2 };
1317
1345
  }
1318
1346
  anchored.lastIndex = pos;
@@ -1320,9 +1348,9 @@ function regex(pattern, flags = "") {
1320
1348
  if (m === null) {
1321
1349
  return failAt(ctx, directTerminalFailureExpected(def), pos);
1322
1350
  }
1323
- const span = { start: pos, end: pos + m[0].length };
1351
+ const span = new PlainSpan3(pos, pos + m[0].length);
1324
1352
  if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, span.end);
1325
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value: m[0], span });
1353
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf3(m[0], span));
1326
1354
  return { ok: true, value: m[0], span };
1327
1355
  }
1328
1356
  };
@@ -1364,6 +1392,7 @@ function caseFoldVariants(cp) {
1364
1392
  }
1365
1393
 
1366
1394
  // src/combinators/keywords.ts
1395
+ import { PlainLeaf as PlainLeaf4, PlainSpan as PlainSpan4 } from "./cst/plain.js";
1367
1396
  function word(str, boundaryOrOpts, opts) {
1368
1397
  const boundary = typeof boundaryOrOpts === "string" ? boundaryOrOpts : "_0-9A-Za-z";
1369
1398
  const rest = typeof boundaryOrOpts === "object" && boundaryOrOpts !== null ? boundaryOrOpts : opts;
@@ -1422,8 +1451,8 @@ function keywords(words, opts = {}) {
1422
1451
  const m = re.exec(input);
1423
1452
  if (m === null) return failAt(ctx, directTerminalFailureExpected(def), pos);
1424
1453
  const value = m[0];
1425
- const span = { start: pos, end: pos + value.length };
1426
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span });
1454
+ const span = new PlainSpan4(pos, pos + value.length);
1455
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf4(value, span));
1427
1456
  return { ok: true, value, span };
1428
1457
  }
1429
1458
  };
@@ -2711,6 +2740,7 @@ function altStarSource(source) {
2711
2740
  }
2712
2741
 
2713
2742
  // src/recovery/scan.ts
2743
+ import { PlainSpan as PlainSpan5 } from "./cst/plain.js";
2714
2744
  function probeAt(sentinel, input, pos, ctx) {
2715
2745
  const s = {
2716
2746
  _probe: ctx._probe,
@@ -2787,7 +2817,7 @@ function firstSetSentinel(fs) {
2787
2817
  function recoverScan(input, from, ctx, sync, expected) {
2788
2818
  let scanPos = from;
2789
2819
  while (scanPos < input.length && !probeAt(sync, input, scanPos, ctx)) scanPos++;
2790
- const span = { start: from, end: scanPos };
2820
+ const span = new PlainSpan5(from, scanPos);
2791
2821
  if (ctx.trackLines) recordLineRangeFromContext(ctx, input, from, scanPos);
2792
2822
  const error = { _tag: "parseError", span: ctx.trackLines ? annotateSpanFromLineContext(span, ctx) : span, expected };
2793
2823
  ctx._errors?.push(error);
@@ -2889,17 +2919,18 @@ function scalarRootOf(combinator) {
2889
2919
  }
2890
2920
 
2891
2921
  // src/combinators/field-trivia.ts
2922
+ import { PlainSpan as PlainSpan6, PlainTriviaField } from "./cst/plain.js";
2892
2923
  var LEAD = { at: -1 };
2893
2924
  var FIELD_LEADING_TRIVIA = 1;
2894
2925
  var FIELD_TRAILING_TRIVIA = 2;
2895
2926
  function triviaFieldCapture(name, value, input, start, end, leadFrom, trailEnd) {
2896
- return {
2927
+ return new PlainTriviaField(
2897
2928
  name,
2898
2929
  value,
2899
- span: { start, end },
2900
- leading: leadFrom >= 0 && leadFrom < start ? input.slice(leadFrom, start) : "",
2901
- trailing: trailEnd > end ? input.slice(end, trailEnd) : ""
2902
- };
2930
+ new PlainSpan6(start, end),
2931
+ leadFrom >= 0 && leadFrom < start ? input.slice(leadFrom, start) : "",
2932
+ trailEnd > end ? input.slice(end, trailEnd) : ""
2933
+ );
2903
2934
  }
2904
2935
  function leadsTrivia(p) {
2905
2936
  return p._def.tag === "field" && p._def.leadingTrivia === true;
@@ -3481,6 +3512,7 @@ function buildAsciiDispatch(parsers) {
3481
3512
  }
3482
3513
 
3483
3514
  // src/combinators/dispatch.ts
3515
+ import { PlainLeaf as PlainLeaf5 } from "./cst/plain.js";
3484
3516
  function parserUsesRouted(parser2, seen = /* @__PURE__ */ new Set()) {
3485
3517
  if (seen.has(parser2)) return false;
3486
3518
  seen.add(parser2);
@@ -3620,7 +3652,7 @@ function routed(fallback) {
3620
3652
  return { ok: false, expected: ["routed()"], span: { start: pos, end: pos } };
3621
3653
  }
3622
3654
  if (cstCaptureActive(ctx)) {
3623
- pushCstLeaf(ctx, { _tag: "leaf", value: item.value, span: item.span });
3655
+ pushCstLeaf(ctx, new PlainLeaf5(item.value, item.span));
3624
3656
  }
3625
3657
  return { ok: true, value: item.value, span: item.span };
3626
3658
  }
@@ -5132,6 +5164,7 @@ function buildFieldMap(captures) {
5132
5164
  }
5133
5165
 
5134
5166
  // src/combinators/node.ts
5167
+ import { PlainNode, PlainSpan as PlainSpan7 } from "./cst/plain.js";
5135
5168
  function unwrapChild(child) {
5136
5169
  return child !== null && typeof child === "object" && child._tag === "leaf" ? child.value : child;
5137
5170
  }
@@ -5237,7 +5270,7 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
5237
5270
  const nodeType = def.type ?? missingInferredType();
5238
5271
  const cstOutput2 = cstOutputHost(ctx.build);
5239
5272
  const span = ctx.trackLines ? annotateSpanFromLineContext(r.span, ctx) : r.span;
5240
- const built = unwrap && children2.length === 1 ? unwrapChild(children2[0]) : collapse && children2.length === 1 ? children2[0] : (cstOutput2 || !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 ? cstOutput2 && ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, ctx.state, tags) : projectChild(children2, project, nodeType) : build ? cstOutput2 && ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, ctx.state, tags) : build(children2, fields, span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, st, tags) : { _tag: "node", type: nodeType, span: ctx.trackLines ? { ...span } : { start: r.span.start, end: r.span.end }, state: st ?? null, children: children2 };
5273
+ const built = unwrap && children2.length === 1 ? unwrapChild(children2[0]) : collapse && children2.length === 1 ? children2[0] : (cstOutput2 || !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 ? cstOutput2 && ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, ctx.state, tags) : projectChild(children2, project, nodeType) : build ? cstOutput2 && ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, ctx.state, tags) : build(children2, fields, span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, st, tags) : new PlainNode(nodeType, ctx.trackLines ? copySpan(span) : new PlainSpan7(r.span.start, r.span.end), st ?? null, [...children2]);
5241
5274
  const rawEntry2 = isCstChild(built) ? built : { _tag: "leaf", value: typeof built === "string" ? built : typeof built === "object" && built !== null ? input.slice(r.span.start, r.span.end) : "", span };
5242
5275
  if (saved.buf !== void 0 || saved.ch !== void 0) {
5243
5276
  pushCstChild(ctx, built, rawEntry2);
@@ -5393,6 +5426,7 @@ function field(name, combinator, opts) {
5393
5426
  }
5394
5427
 
5395
5428
  // src/combinators/token.ts
5429
+ import { PlainLeaf as PlainLeaf6 } from "./cst/plain.js";
5396
5430
  function semanticLeafValue(_ctx, _input, _start, _end, value) {
5397
5431
  return value;
5398
5432
  }
@@ -5446,7 +5480,7 @@ function token(root) {
5446
5480
  if (!result.ok) return result;
5447
5481
  const span = result.span;
5448
5482
  const value = input.slice(pos, span.end);
5449
- if (wasCapturing) pushCstLeaf(ctx, { _tag: "leaf", value, span });
5483
+ if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf6(value, span));
5450
5484
  return { ok: true, value, span };
5451
5485
  }
5452
5486
  };
@@ -5494,11 +5528,7 @@ function makeLeaf(root, fn, sourceCstValue) {
5494
5528
  }
5495
5529
  if (!result.ok) return result;
5496
5530
  const value = fn(result.value, result.span);
5497
- if (wasCapturing) pushCstLeaf(ctx, {
5498
- _tag: "leaf",
5499
- value: cstValue(ctx, input, pos, result.span.end, value),
5500
- span: result.span
5501
- });
5531
+ if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf6(cstValue(ctx, input, pos, result.span.end, value), result.span));
5502
5532
  return { ok: true, value, span: result.span };
5503
5533
  }
5504
5534
  };
@@ -5531,6 +5561,7 @@ function buildLexBodyRecognizer(spec, constants) {
5531
5561
  }
5532
5562
 
5533
5563
  // src/table/run-support.ts
5564
+ import { PlainLeaf as PlainLeaf7, PlainLineSpan as PlainLineSpan2, PlainSpan as PlainSpan8 } from "./cst/plain.js";
5534
5565
  function lineCol(ctx, offset) {
5535
5566
  const starts = ctx._lineStarts ?? [0];
5536
5567
  let lo = 0, hi = starts.length - 1;
@@ -5543,18 +5574,14 @@ function lineCol(ctx, offset) {
5543
5574
  }
5544
5575
  function spanLines(ctx, start, end) {
5545
5576
  const s = lineCol(ctx, start), e = lineCol(ctx, end);
5546
- return { start, end, startLine: s[0], startColumn: s[1], endLine: e[0], endColumn: e[1] };
5577
+ return new PlainLineSpan2(start, end, s[0], s[1], e[0], e[1]);
5547
5578
  }
5548
5579
  function rawEntry(v, input, s, e) {
5549
5580
  if (typeof v === "object" && v !== null) {
5550
5581
  const tg = v._tag;
5551
5582
  if (tg === "node" || tg === "leaf" || tg === "parseError") return v;
5552
5583
  }
5553
- return {
5554
- _tag: "leaf",
5555
- value: typeof v === "string" ? v : typeof v === "object" && v !== null ? input.slice(s, e) : "",
5556
- span: { start: s, end: e }
5557
- };
5584
+ return new PlainLeaf7(typeof v === "string" ? v : typeof v === "object" && v !== null ? input.slice(s, e) : "", new PlainSpan8(s, e));
5558
5585
  }
5559
5586
  function lead(input, pos) {
5560
5587
  if (pos >= input.length) return -1;
@@ -5568,7 +5595,7 @@ function collapseEmpty(ctx, build, input, pos, end, readsRaw) {
5568
5595
  const collected = ctx._cstBuf !== void 0 || ctx._cstChildren !== void 0;
5569
5596
  if (collected) popCstChild(ctx);
5570
5597
  const raw = readsRaw ? [rawEntry(void 0, input, pos, end)] : EMPTY_KIDS;
5571
- const nd = build(EMPTY_KIDS, void 0, { start: pos, end }, raw, EMPTY_TRIVIA, void 0);
5598
+ const nd = build(EMPTY_KIDS, void 0, new PlainSpan8(pos, end), raw, EMPTY_TRIVIA, void 0);
5572
5599
  if (collected) pushCstChild(ctx, nd, ctx._cstBuf?.noRaw === true ? void 0 : rawEntry(nd, input, pos, end));
5573
5600
  return nd;
5574
5601
  }
@@ -10851,7 +10878,14 @@ var EMITTED_PARAMS = [
10851
10878
  "skipDeferredTrivia",
10852
10879
  // Appended for the pass-through collapse (`run-support.ts`); old factories
10853
10880
  // ignore it.
10854
- "collapseEmpty"
10881
+ "collapseEmpty",
10882
+ // Appended for constructor-built tree objects (`cst/plain.d.ts`): a `new` call has
10883
+ // no allocation site, so V8 cannot pretenure them. Old factories ignore them.
10884
+ "_SP",
10885
+ "_LF",
10886
+ "_ND",
10887
+ "_FC",
10888
+ "_BUF"
10855
10889
  ];
10856
10890
  var RUNTIME_PRELUDE = `
10857
10891
  let _pfScan=null
@@ -10875,9 +10909,9 @@ if(s!==null)return skipTriviaScanned(s,input,cur,ctx)
10875
10909
  if(needsDeferredTriviaCommit(ctx))return skipDeferredTrivia(input,cur,ctx)
10876
10910
  return advanceTrivia(input,cur,ctx)
10877
10911
  }
10878
- function _pushLeaf(ctx,value,s,e){pushCstLeaf(ctx,{_tag:'leaf',value,span:{start:s,end:e}})}
10912
+ function _pushLeaf(ctx,value,s,e){pushCstLeaf(ctx,new _LF(value,new _SP(s,e)))}
10879
10913
  function _pushLeafBuf(ctx,value,s,e){
10880
- const l={_tag:'leaf',value,span:{start:s,end:e}}
10914
+ const l=new _LF(value,new _SP(s,e))
10881
10915
  const b=ctx._cstBuf
10882
10916
  if(b.ch!==undefined)b.ch.push(l)
10883
10917
  else if(b.single!==undefined){b.ch=[b.single,l];b.single=undefined}
@@ -10935,7 +10969,7 @@ if(ctx._rootTriviaLog!==undefined&&ctx._rootTriviaLog.length!==rt)ctx._rootTrivi
10935
10969
  `;
10936
10970
  var NO_RAW_RUNTIME_PRELUDE = `
10937
10971
  function _pushLeafNoRawBuf(ctx,value,s,e){
10938
- const l={_tag:'leaf',value,span:{start:s,end:e}}
10972
+ const l=new _LF(value,new _SP(s,e))
10939
10973
  const b=ctx._cstBuf
10940
10974
  if(b.ch!==undefined)b.ch.push(l)
10941
10975
  else if(b.single!==undefined){b.ch=[b.single,l];b.single=undefined}
@@ -11612,7 +11646,7 @@ try{return ${child}(input,pos,ctx)}finally{ctx.state=saved}
11612
11646
  return `${head}
11613
11647
  const v=${child}(input,pos,ctx)
11614
11648
  if(v===FAIL)return FAIL
11615
- return ${fn}(v,{start:pos,end:EC.e})
11649
+ return ${fn}(v,new _SP(pos,EC.e))
11616
11650
  }`;
11617
11651
  }
11618
11652
  case OP_LABEL: {
@@ -11633,7 +11667,7 @@ return v
11633
11667
  const v=${child}(input,pos,ctx)
11634
11668
  if(v===FAIL)return FAIL
11635
11669
  const f=ctx._fields
11636
- if(f!==undefined)f.push({name:${name},value:v,span:{start:pos,end:EC.e}})
11670
+ if(f!==undefined)f.push(new _FC(${name},v,new _SP(pos,EC.e)))
11637
11671
  return v
11638
11672
  }`;
11639
11673
  }
@@ -11658,7 +11692,7 @@ return v
11658
11692
  return `${head}
11659
11693
  const v=${child}(input,pos,ctx)
11660
11694
  if(v!==FAIL)return v
11661
- const err={_tag:'parseError',span:${prog.lines === 1 ? "spanLines(ctx,pos,pos)" : "{start:pos,end:pos}"},expected:${xf}}
11695
+ const err={_tag:'parseError',span:${prog.lines === 1 ? "spanLines(ctx,pos,pos)" : "new _SP(pos,pos)"},expected:${xf}}
11662
11696
  const es=ctx._errors
11663
11697
  if(es!==undefined)es.push(err)
11664
11698
  ${REC2 ? "if(ctx._tolerant===true)captureError(ctx,err)\n" : ""}ctx._fc=false
@@ -11669,7 +11703,7 @@ return err
11669
11703
  case OP_ROUTED: {
11670
11704
  const fb = code[ip + 1];
11671
11705
  const fallback = fb >= 0 ? link(fb) : void 0;
11672
- const push = `pushCstLeaf(ctx,{_tag:'leaf',value:it.value,span:it.span})`;
11706
+ const push = `pushCstLeaf(ctx,new _LF(it.value,it.span))`;
11673
11707
  return `${head}
11674
11708
  const it=ctx._routed
11675
11709
  if(it===undefined||pos!==it.span.start){
@@ -11750,8 +11784,8 @@ ctx._triviaLog=sOtl
11750
11784
  }
11751
11785
  if(v===FAIL)return FAIL
11752
11786
  const e=EC.e
11753
- const out=${isToken ? "input.slice(pos,e)" : `${fn}(v,{start:pos,end:e})`}
11754
- if(wasCap)pushCstLeaf(ctx,{_tag:'leaf',value:${capturesSource ? "input.slice(pos,e)" : "out"},span:{start:pos,end:e}})
11787
+ const out=${isToken ? "input.slice(pos,e)" : `${fn}(v,new _SP(pos,e))`}
11788
+ if(wasCap)pushCstLeaf(ctx,new _LF(${capturesSource ? "input.slice(pos,e)" : "out"},new _SP(pos,e)))
11755
11789
  EC.e=e
11756
11790
  return out
11757
11791
  }`;
@@ -11775,7 +11809,7 @@ ${hasSuffix && (lineFlags & 2) !== 0 ? "if(sm)_trackLines(ctx,input,e)" : ""}
11775
11809
  ${hasSuffix ? `if(!sm){ctx._fe=e;ctx._fx=${suffixExpected};if(ctx._probe!==undefined)failAt(ctx,${suffixExpected},e)}` : ""}
11776
11810
  const v=${pending ? "tp?_pfTokValue:" : ""}input.slice(pos,e)
11777
11811
  ${pending ? "if(tp){_pfTokBody=-1;_pfTokValue=undefined}" : ""}
11778
- if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,{_tag:'leaf',value:v,span:{start:pos,end:e}})
11812
+ if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
11779
11813
  EC.e=e
11780
11814
  return v
11781
11815
  }`;
@@ -11814,7 +11848,7 @@ ctx._rootTriviaLog=sRtl
11814
11848
  }
11815
11849
  if(e<0)return FAIL
11816
11850
  const v=input.slice(pos,e)
11817
- if(wasCap)pushCstLeaf(ctx,{_tag:'leaf',value:v,span:{start:pos,end:e}})
11851
+ if(wasCap)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
11818
11852
  EC.e=e
11819
11853
  return v
11820
11854
  }`;
@@ -11822,7 +11856,7 @@ return v
11822
11856
  const e=${run3}(input,pos,ctx)
11823
11857
  if(e<0)return FAIL
11824
11858
  const v=input.slice(pos,e)
11825
- if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,{_tag:'leaf',value:v,span:{start:pos,end:e}})
11859
+ if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
11826
11860
  EC.e=e
11827
11861
  return v
11828
11862
  }`;
@@ -11936,7 +11970,7 @@ return v
11936
11970
  }` : `${parts.join("\n")}
11937
11971
  }`;
11938
11972
  if (n === 1) {
11939
- parts.push(fused ? projection === 0 ? "return v0" : `return ${fn}([v0],{start:pos,end:EC.e})` : wantValues ? "return [v0]" : "return undefined");
11973
+ parts.push(fused ? projection === 0 ? "return v0" : `return ${fn}([v0],new _SP(pos,EC.e))` : wantValues ? "return [v0]" : "return undefined");
11940
11974
  return close();
11941
11975
  }
11942
11976
  parts.push("let cur=EC.e");
@@ -11962,7 +11996,7 @@ return v
11962
11996
  names.push(vn);
11963
11997
  }
11964
11998
  parts.push("EC.e=cur");
11965
- parts.push(fused ? projection >= 0 ? `return ${names[projection]}` : `return ${fn}([${names.join(",")}],{start:pos,end:cur})` : wantValues ? `return [${names.join(",")}]` : "return undefined");
11999
+ parts.push(fused ? projection >= 0 ? `return ${names[projection]}` : `return ${fn}([${names.join(",")}],new _SP(pos,cur))` : wantValues ? `return [${names.join(",")}]` : "return undefined");
11966
12000
  return close();
11967
12001
  }
11968
12002
  case OP_CHOICE: {
@@ -12221,7 +12255,7 @@ ${spec.match.map((m, i) => `${i === 0 ? "" : "else "}if(${dispatchClaim(m)})arm=
12221
12255
  const routedCall = (target) => `{const savedRouted=ctx._routed
12222
12256
  ${emitRollback(m1, L.buf, L.raw, sinks)}
12223
12257
  ${emitMark(m2, L.buf, L.raw, sinks, false)}
12224
- ctx._routed={value:key,span:{start:pos,end:selEnd}}
12258
+ ctx._routed={value:key,span:new _SP(pos,selEnd)}
12225
12259
  try{v=${target}(input,pos,ctx)}finally{ctx._routed=savedRouted}
12226
12260
  break}`;
12227
12261
  const plainCall = (target) => `v=${target}(input,selEnd,ctx);break`;
@@ -12416,8 +12450,8 @@ return out
12416
12450
  const end=${recognize}(input,pos)
12417
12451
  if(end<0){ctx._fe=pos;ctx._fx=${xf};return FAIL}
12418
12452
  const value=${value2}
12419
- const leaf={_tag:'leaf',value,span:{start:pos,end}}
12420
- const kids=[leaf],rawKids=[leaf],span={start:pos,end}
12453
+ const leaf=new _LF(value,new _SP(pos,end))
12454
+ const kids=[leaf],rawKids=[leaf],span=new _SP(pos,end)
12421
12455
  EC.e=end
12422
12456
  const nd=${build2}(kids,undefined,span,rawKids,EMPTY_TL,undefined)
12423
12457
  ${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))"}
@@ -12516,7 +12550,7 @@ ctx._cstTriviaLog=sTl
12516
12550
  ctx.captureTrivia=sCap
12517
12551
  if(v===FAIL)return FAIL
12518
12552
  const end=EC.e
12519
- ${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)`}
12553
+ ${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)`}
12520
12554
  ${publish}
12521
12555
  EC.e=end
12522
12556
  return nd
@@ -12539,20 +12573,20 @@ return nd
12539
12573
  const direct = `${build}(kids,fieldMap,span,rawKids,${captureWide ? "tlog" : "EMPTY_TL"},st)`;
12540
12574
  value = hostCst ? `nd=_pfHost!==undefined?${hostCall}:${direct}` : `nd=${direct}`;
12541
12575
  } else {
12542
- value = `nd=_pfHost!==undefined?_pfHost(${ty},hostKids,fieldMap,span,rawKids,tlog,st,${tags}):{_tag:'node',type:${ty},span,state:st??null,children:kids}`;
12576
+ value = `nd=_pfHost!==undefined?_pfHost(${ty},hostKids,fieldMap,span,rawKids,tlog,st,${tags}):new _ND(${ty},span,st??null,kids===EMPTY_CH?kids:[...kids])`;
12543
12577
  }
12544
12578
  const collapsible = keepChildren && (hostCst || build === void 0 && proj < 0);
12545
- const openCapture = omitsRaw ? `const buf={noRaw:true,rawLen:0}
12579
+ const openCapture = omitsRaw ? `const buf=new _BUF(undefined,true,0)
12546
12580
  ctx._cstBuf=buf
12547
12581
  ctx._cstChildren=undefined
12548
12582
  ctx._cstLeaves=undefined
12549
12583
  ctx._cstRawChildren=undefined
12550
- ctx._cstTriviaLog=undefined` : keepChildren ? `const buf={}
12584
+ ctx._cstTriviaLog=undefined` : keepChildren ? `const buf=new _BUF(undefined,undefined,0)
12551
12585
  ctx._cstBuf=buf
12552
12586
  ctx._cstChildren=undefined
12553
12587
  ctx._cstLeaves=undefined
12554
12588
  ctx._cstRawChildren=undefined
12555
- ctx._cstTriviaLog=undefined` : `const buf={rawOnly:true}
12589
+ ctx._cstTriviaLog=undefined` : `const buf=new _BUF(true,undefined,0)
12556
12590
  ctx._cstBuf=buf
12557
12591
  ctx._cstChildren=undefined
12558
12592
  ctx._cstLeaves=undefined
@@ -12590,7 +12624,7 @@ ctx._cstTriviaLog=sTl
12590
12624
  ctx.captureTrivia=sCap
12591
12625
  if(v===FAIL)return FAIL
12592
12626
  const end=EC.e
12593
- const span=${tracked ? "spanLines(ctx,pos,end)" : "{start:pos,end}"}
12627
+ const span=${tracked ? "spanLines(ctx,pos,end)" : "new _SP(pos,end)"}
12594
12628
  const st=${readsState ? "ctx.state" : "undefined"}
12595
12629
  let nd
12596
12630
  ${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]
@@ -12877,6 +12911,7 @@ function rebuildLineScan(s, subtree) {
12877
12911
  }
12878
12912
 
12879
12913
  // src/combinators/scanTo.ts
12914
+ import { PlainLeaf as PlainLeaf8, PlainSpan as PlainSpan9 } from "./cst/plain.js";
12880
12915
  function resolveScanSkip(explicitSkip, raw, ctx) {
12881
12916
  if (raw) return [];
12882
12917
  const trivia2 = ctx.trivia;
@@ -12914,7 +12949,7 @@ function scanTo(sentinel, { skip, raw = false, orEOF = false, recoverAt, stopAt
12914
12949
  probeCtx._errors = ctx._errors;
12915
12950
  const emit = (end) => {
12916
12951
  if (end > pos && cstCaptureActive(ctx)) {
12917
- const leaf2 = { _tag: "leaf", value: input.slice(pos, end), span: { start: pos, end } };
12952
+ const leaf2 = new PlainLeaf8(input.slice(pos, end), new PlainSpan9(pos, end));
12918
12953
  pushCstLeaf(ctx, leaf2);
12919
12954
  }
12920
12955
  };
@@ -13193,6 +13228,9 @@ function clearOf(ranges, input, from, to) {
13193
13228
  return true;
13194
13229
  }
13195
13230
 
13231
+ // src/table/assemble.ts
13232
+ import { PlainBuf as PlainBuf2, PlainField, PlainLeaf as PlainLeaf9, PlainNode as PlainNode2, PlainSpan as PlainSpan10 } from "./cst/plain.js";
13233
+
13196
13234
  // src/table/fail-clean.ts
13197
13235
  function passChild(code, ip) {
13198
13236
  switch (code[ip]) {
@@ -13520,7 +13558,7 @@ function assemble(t, prog, cfg) {
13520
13558
  const NULLABLE = /* @__PURE__ */ new Map();
13521
13559
  const CLEAN = REC2 ? () => false : failCleanAnalysis(code);
13522
13560
  function pushLeaf(ctx, value, s, e) {
13523
- const lf = { _tag: "leaf", value, span: { start: s, end: e } };
13561
+ const lf = new PlainLeaf9(value, new PlainSpan10(s, e));
13524
13562
  pushCstLeaf(ctx, lf);
13525
13563
  }
13526
13564
  function plainBuildNode(child, build, trailing) {
@@ -13553,7 +13591,7 @@ function assemble(t, prog, cfg) {
13553
13591
  ctx.captureTrivia = sCap;
13554
13592
  if (value === FAIL) return FAIL;
13555
13593
  const end = EC.e;
13556
- const span = { start: pos, end };
13594
+ const span = new PlainSpan10(pos, end);
13557
13595
  const node2 = build(kids, void 0, span, rawKids, EMPTY_TL2, void 0);
13558
13596
  if (sBuf !== void 0 || sCh !== void 0) {
13559
13597
  pushCstChild(ctx, node2, rawEntry(node2, input, pos, end));
@@ -13598,7 +13636,7 @@ function assemble(t, prog, cfg) {
13598
13636
  ctx.captureTrivia = sCap;
13599
13637
  if (value === FAIL) return FAIL;
13600
13638
  const end = EC.e;
13601
- const node2 = build(captured, void 0, { start: pos, end }, EMPTY_CH, EMPTY_TL2, void 0);
13639
+ const node2 = build(captured, void 0, new PlainSpan10(pos, end), EMPTY_CH, EMPTY_TL2, void 0);
13602
13640
  if (sBuf !== void 0 || sCh !== void 0) {
13603
13641
  pushCstChild(ctx, node2, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node2, input, pos, end) : void 0);
13604
13642
  }
@@ -13635,7 +13673,7 @@ function assemble(t, prog, cfg) {
13635
13673
  ctx.captureTrivia = sCap;
13636
13674
  if (value === FAIL) return FAIL;
13637
13675
  const end = EC.e;
13638
- const node2 = build(captured, fieldMap, { start: pos, end }, EMPTY_CH, EMPTY_TL2, void 0);
13676
+ const node2 = build(captured, fieldMap, new PlainSpan10(pos, end), EMPTY_CH, EMPTY_TL2, void 0);
13639
13677
  if (sBuf !== void 0 || sCh !== void 0) {
13640
13678
  pushCstChild(ctx, node2, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node2, input, pos, end) : void 0);
13641
13679
  }
@@ -13672,7 +13710,7 @@ function assemble(t, prog, cfg) {
13672
13710
  ctx.captureTrivia = sCap;
13673
13711
  if (value === FAIL) return FAIL;
13674
13712
  const end = EC.e;
13675
- const span = { start: pos, end };
13713
+ const span = new PlainSpan10(pos, end);
13676
13714
  const node2 = kids.length === 1 ? kids[0] : build(kids, void 0, span, rawKids, EMPTY_TL2, void 0);
13677
13715
  if (sBuf !== void 0 || sCh !== void 0) {
13678
13716
  pushCstChild(ctx, node2, rawEntry(node2, input, pos, end));
@@ -13709,7 +13747,7 @@ function assemble(t, prog, cfg) {
13709
13747
  ctx.captureTrivia = sCap;
13710
13748
  if (value === FAIL) return FAIL;
13711
13749
  const end = EC.e;
13712
- const node2 = captured.length === 1 ? captured[0] : build(captured, void 0, { start: pos, end }, EMPTY_CH, EMPTY_TL2, void 0);
13750
+ const node2 = captured.length === 1 ? captured[0] : build(captured, void 0, new PlainSpan10(pos, end), EMPTY_CH, EMPTY_TL2, void 0);
13713
13751
  if (sBuf !== void 0 || sCh !== void 0) {
13714
13752
  pushCstChild(ctx, node2, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node2, input, pos, end) : void 0);
13715
13753
  }
@@ -14142,7 +14180,7 @@ function assemble(t, prog, cfg) {
14142
14180
  return (input, pos, selEnd, key, ctx, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot) => {
14143
14181
  const savedRouted = ctx._routed;
14144
14182
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
14145
- ctx._routed = { value: key, span: { start: pos, end: selEnd } };
14183
+ ctx._routed = { value: key, span: new PlainSpan10(pos, selEnd) };
14146
14184
  let v;
14147
14185
  try {
14148
14186
  v = child(input, pos, ctx);
@@ -14575,7 +14613,7 @@ function assemble(t, prog, cfg) {
14575
14613
  case OP_EXPECT: {
14576
14614
  const child = link(code[ip + 1]);
14577
14615
  const xf = fx[code[ip + 2]];
14578
- const expectSpan = (ctx, pos) => prog.lines === 1 ? spanLines(ctx, pos, pos) : { start: pos, end: pos };
14616
+ const expectSpan = (ctx, pos) => prog.lines === 1 ? spanLines(ctx, pos, pos) : new PlainSpan10(pos, pos);
14579
14617
  if (REC2) {
14580
14618
  return (input, pos, ctx) => {
14581
14619
  const v = child(input, pos, ctx);
@@ -14607,7 +14645,7 @@ function assemble(t, prog, cfg) {
14607
14645
  return (input, pos, ctx) => {
14608
14646
  const v = child(input, pos, ctx);
14609
14647
  if (v === FAIL) return FAIL;
14610
- ctx._fields?.push({ name, value: v, span: { start: pos, end: EC.e } });
14648
+ ctx._fields?.push(new PlainField(name, v, new PlainSpan10(pos, EC.e)));
14611
14649
  return v;
14612
14650
  };
14613
14651
  }
@@ -14631,7 +14669,7 @@ function assemble(t, prog, cfg) {
14631
14669
  return (input, pos, ctx) => {
14632
14670
  const v = child(input, pos, ctx);
14633
14671
  if (v === FAIL) return FAIL;
14634
- return fn(v, { start: pos, end: EC.e });
14672
+ return fn(v, new PlainSpan10(pos, EC.e));
14635
14673
  };
14636
14674
  }
14637
14675
  case OP_SCAN: {
@@ -14735,7 +14773,7 @@ function assemble(t, prog, cfg) {
14735
14773
  ctx._fx = ROUTED_FX;
14736
14774
  return FAIL;
14737
14775
  }
14738
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value: item.value, span: item.span });
14776
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf9(item.value, item.span));
14739
14777
  EC.e = item.span.end;
14740
14778
  return item.value;
14741
14779
  };
@@ -14921,7 +14959,7 @@ function assemble(t, prog, cfg) {
14921
14959
  if (v === FAIL) return FAIL;
14922
14960
  const end = EC.e;
14923
14961
  const value = input.slice(pos, end);
14924
- if (wasCapturing) pushCstLeaf(ctx, { _tag: "leaf", value, span: { start: pos, end } });
14962
+ if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
14925
14963
  EC.e = end;
14926
14964
  return value;
14927
14965
  };
@@ -14955,7 +14993,7 @@ function assemble(t, prog, cfg) {
14955
14993
  if (ctx._probe !== void 0) failAt(ctx, suffixExpected, end);
14956
14994
  }
14957
14995
  const value = input.slice(pos, end);
14958
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span: { start: pos, end } });
14996
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
14959
14997
  EC.e = end;
14960
14998
  return value;
14961
14999
  };
@@ -14998,7 +15036,7 @@ function assemble(t, prog, cfg) {
14998
15036
  }
14999
15037
  if (end < 0) return FAIL;
15000
15038
  const value = input.slice(pos, end);
15001
- if (wasCapturing) pushCstLeaf(ctx, { _tag: "leaf", value, span: { start: pos, end } });
15039
+ if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
15002
15040
  EC.e = end;
15003
15041
  return value;
15004
15042
  };
@@ -15007,7 +15045,7 @@ function assemble(t, prog, cfg) {
15007
15045
  const end = run3(input, pos, ctx);
15008
15046
  if (end < 0) return FAIL;
15009
15047
  const value = input.slice(pos, end);
15010
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span: { start: pos, end } });
15048
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
15011
15049
  EC.e = end;
15012
15050
  return value;
15013
15051
  };
@@ -15040,12 +15078,8 @@ function assemble(t, prog, cfg) {
15040
15078
  }
15041
15079
  if (v === FAIL) return FAIL;
15042
15080
  const end = EC.e;
15043
- const out = fn(v, { start: pos, end });
15044
- if (wasCapturing) pushCstLeaf(ctx, {
15045
- _tag: "leaf",
15046
- value: op === OP_SOURCE_LEAF && hostCst ? input.slice(pos, end) : out,
15047
- span: { start: pos, end }
15048
- });
15081
+ const out = fn(v, new PlainSpan10(pos, end));
15082
+ if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf9(op === OP_SOURCE_LEAF && hostCst ? input.slice(pos, end) : out, new PlainSpan10(pos, end)));
15049
15083
  EC.e = end;
15050
15084
  return out;
15051
15085
  };
@@ -15180,7 +15214,7 @@ function assemble(t, prog, cfg) {
15180
15214
  const cur = runSyncTerms(input, pos, ctx, values);
15181
15215
  if (cur < 0) return FAIL;
15182
15216
  EC.e = cur;
15183
- return projection >= 0 ? values[projection] : fn(values, { start: pos, end: cur });
15217
+ return projection >= 0 ? values[projection] : fn(values, new PlainSpan10(pos, cur));
15184
15218
  };
15185
15219
  }
15186
15220
  if (wantValues) {
@@ -15274,7 +15308,7 @@ function assemble(t, prog, cfg) {
15274
15308
  const cur = runAdjTerms(input, pos, ctx, values);
15275
15309
  if (cur < 0) return FAIL;
15276
15310
  EC.e = cur;
15277
- return projection >= 0 ? values[projection] : fn(values, { start: pos, end: cur });
15311
+ return projection >= 0 ? values[projection] : fn(values, new PlainSpan10(pos, cur));
15278
15312
  };
15279
15313
  }
15280
15314
  if (wantValues) {
@@ -15299,7 +15333,7 @@ function assemble(t, prog, cfg) {
15299
15333
  return (input, pos, ctx) => {
15300
15334
  const v = k0(input, pos, ctx);
15301
15335
  if (v === FAIL) return FAIL;
15302
- return projection === 0 ? v : fn([v], { start: pos, end: EC.e });
15336
+ return projection === 0 ? v : fn([v], new PlainSpan10(pos, EC.e));
15303
15337
  };
15304
15338
  }
15305
15339
  if (wantValues) {
@@ -15324,7 +15358,7 @@ function assemble(t, prog, cfg) {
15324
15358
  const cur = step(k1, input, EC.e, ctx);
15325
15359
  if (cur < 0) return FAIL;
15326
15360
  EC.e = cur;
15327
- return projection === 0 ? v0 : projection === 1 ? TERMV : fn([v0, TERMV], { start: pos, end: cur });
15361
+ return projection === 0 ? v0 : projection === 1 ? TERMV : fn([v0, TERMV], new PlainSpan10(pos, cur));
15328
15362
  };
15329
15363
  }
15330
15364
  if (wantValues) {
@@ -15358,7 +15392,7 @@ function assemble(t, prog, cfg) {
15358
15392
  cur = step(k2, input, cur, ctx);
15359
15393
  if (cur < 0) return FAIL;
15360
15394
  EC.e = cur;
15361
- return projection === 0 ? v0 : projection === 1 ? v1 : projection === 2 ? TERMV : fn([v0, v1, TERMV], { start: pos, end: cur });
15395
+ return projection === 0 ? v0 : projection === 1 ? v1 : projection === 2 ? TERMV : fn([v0, v1, TERMV], new PlainSpan10(pos, cur));
15362
15396
  };
15363
15397
  }
15364
15398
  if (wantValues) {
@@ -15455,7 +15489,7 @@ function assemble(t, prog, cfg) {
15455
15489
  const cur = runDirectTerms(input, pos, ctx, values);
15456
15490
  if (cur < 0) return FAIL;
15457
15491
  EC.e = cur;
15458
- return projection >= 0 ? values[projection] : fn(values, { start: pos, end: cur });
15492
+ return projection >= 0 ? values[projection] : fn(values, new PlainSpan10(pos, cur));
15459
15493
  };
15460
15494
  }
15461
15495
  if (wantValues) {
@@ -16353,10 +16387,10 @@ function assemble(t, prog, cfg) {
16353
16387
  return FAIL;
16354
16388
  }
16355
16389
  const value = regexValue ? input.slice(pos, end) : spec;
16356
- const leaf2 = { _tag: "leaf", value, span: { start: pos, end } };
16390
+ const leaf2 = new PlainLeaf9(value, new PlainSpan10(pos, end));
16357
16391
  const kids = [leaf2];
16358
16392
  const rawKids = [leaf2];
16359
- const span = { start: pos, end };
16393
+ const span = new PlainSpan10(pos, end);
16360
16394
  EC.e = end;
16361
16395
  const nd = build2(kids, void 0, span, rawKids, EMPTY_TL2, void 0);
16362
16396
  if (ctx._cstBuf !== void 0 || ctx._cstChildren !== void 0) {
@@ -16438,7 +16472,7 @@ function assemble(t, prog, cfg) {
16438
16472
  const sCh = ctx._cstChildren;
16439
16473
  const sCap = ctx.captureTrivia;
16440
16474
  const sBuf = ctx._cstBuf;
16441
- const buf = rawOnly ? { rawOnly: true } : omitsRaw ? { noRaw: true, rawLen: 0 } : {};
16475
+ const buf = rawOnly ? new PlainBuf2(true, void 0, 0) : omitsRaw ? new PlainBuf2(void 0, true, 0) : new PlainBuf2(void 0, void 0, 0);
16442
16476
  ctx._cstBuf = buf;
16443
16477
  ctx.captureTrivia = captureWide;
16444
16478
  const savedFields = ctx._fields;
@@ -16460,7 +16494,7 @@ function assemble(t, prog, cfg) {
16460
16494
  ctx.captureTrivia = sCap;
16461
16495
  if (v === FAIL) return FAIL;
16462
16496
  const end = EC.e;
16463
- const span = tracked ? spanLines(ctx, pos, end) : { start: pos, end };
16497
+ const span = tracked ? spanLines(ctx, pos, end) : new PlainSpan10(pos, end);
16464
16498
  const st = readsState ? ctx.state : void 0;
16465
16499
  let nd;
16466
16500
  if (unwrap && kids.length === 1) {
@@ -16484,7 +16518,7 @@ function assemble(t, prog, cfg) {
16484
16518
  } else if (host !== void 0) {
16485
16519
  nd = host(type, hostKids, fieldMap, span, rawKids, tlog, st, tags);
16486
16520
  } else {
16487
- nd = { _tag: "node", type, span, state: st ?? null, children: kids };
16521
+ nd = new PlainNode2(type, span, st ?? null, kids === EMPTY_CH ? kids : [...kids]);
16488
16522
  }
16489
16523
  if (sBuf !== void 0 || sCh !== void 0) {
16490
16524
  pushCstChild(ctx, nd, rawEntry(nd, input, pos, end));
@@ -16510,7 +16544,7 @@ function assemble(t, prog, cfg) {
16510
16544
  const at = fe === void 0 || fe < 0 ? pos : fe;
16511
16545
  return { ok: false, expected: ctx._fx ?? EMPTY_FX2, span: { start: at, end: at } };
16512
16546
  }
16513
- return { ok: true, value: v, span: { start: pos, end: EC.e } };
16547
+ return { ok: true, value: v, span: new PlainSpan10(pos, EC.e) };
16514
16548
  }
16515
16549
  };
16516
16550
  }
@@ -16625,7 +16659,12 @@ function assemble(t, prog, cfg) {
16625
16659
  LEAD,
16626
16660
  triviaFieldCapture,
16627
16661
  skipDeferredTrivia,
16628
- collapseEmpty
16662
+ collapseEmpty,
16663
+ PlainSpan10,
16664
+ PlainLeaf9,
16665
+ PlainNode2,
16666
+ PlainField,
16667
+ PlainBuf2
16629
16668
  );
16630
16669
  emitReached = new Set(pre.reached);
16631
16670
  if (emitted.ext !== void 0) HYBRID = emitted;
@@ -16712,7 +16751,12 @@ function assemble(t, prog, cfg) {
16712
16751
  LEAD,
16713
16752
  triviaFieldCapture,
16714
16753
  skipDeferredTrivia,
16715
- collapseEmpty
16754
+ collapseEmpty,
16755
+ PlainSpan10,
16756
+ PlainLeaf9,
16757
+ PlainNode2,
16758
+ PlainField,
16759
+ PlainBuf2
16716
16760
  );
16717
16761
  emitReached = em.reached;
16718
16762
  } catch (e) {
@@ -16970,7 +17014,11 @@ function tableRules(source, metadataOrEntry = {}) {
16970
17014
  return map[entry];
16971
17015
  }
16972
17016
 
17017
+ // src/version.ts
17018
+ var PARSEMAN_VERSION = "0.59.0";
17019
+
16973
17020
  // src/table/emit.ts
17021
+ 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`)});`;
16974
17022
  function jsString(s) {
16975
17023
  return JSON.stringify(s);
16976
17024
  }
@@ -17056,7 +17104,7 @@ function emitAssemblies(prog, cfgs) {
17056
17104
  throw e;
17057
17105
  }
17058
17106
  const plan = em.plan;
17059
- out.push(`{key:${key},factory:function(${EMITTED_PARAMS.join(",")}){${em.source}
17107
+ out.push(`{key:${key},factory:function(${EMITTED_PARAMS.join(",")}){${FACTORY_ARITY_GUARD}${em.source}
17060
17108
  },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(",")}]}`);
17061
17109
  }
17062
17110
  return [`a:[${out.join(",")}],`];
@@ -19413,9 +19461,6 @@ function fieldOptionsSrc(def) {
19413
19461
  return `, { ${[def.leadingTrivia === true ? "leadingTrivia: true" : "", def.trailingTrivia === true ? "trailingTrivia: true" : ""].filter(Boolean).join(", ")} }`;
19414
19462
  }
19415
19463
 
19416
- // src/version.ts
19417
- var PARSEMAN_VERSION = "0.58.3";
19418
-
19419
19464
  // src/compiler/compile-linkable-table.ts
19420
19465
  function isLocal(rule) {
19421
19466
  const d = rule._def;
@@ -19482,6 +19527,7 @@ function compileLinkableTable(ruleMapArg, ns, opts = {}) {
19482
19527
  }
19483
19528
 
19484
19529
  // src/compiler/linker.ts
19530
+ import { PlainNode as PlainNode3, PlainTaggedNode } from "./cst/plain.js";
19485
19531
  function normalizeCstCollapse(collapse) {
19486
19532
  if (collapse === true) return () => true;
19487
19533
  if (Array.isArray(collapse)) {
@@ -19491,7 +19537,7 @@ function normalizeCstCollapse(collapse) {
19491
19537
  return typeof collapse === "function" ? collapse : void 0;
19492
19538
  }
19493
19539
  function buildCstNode(type, children2, _fields, span, _rawChildren, _triviaLog, state, tags) {
19494
- return tags !== void 0 && tags.length > 0 ? { _tag: "node", type, tags, span: { ...span }, state: state ?? null, children: [...children2] } : { _tag: "node", type, span: { ...span }, state: state ?? null, children: [...children2] };
19540
+ return tags !== void 0 && tags.length > 0 ? new PlainTaggedNode(type, tags, copySpan(span), state ?? null, [...children2]) : new PlainNode3(type, copySpan(span), state ?? null, [...children2]);
19495
19541
  }
19496
19542
  function cstBuildHost(typeOrOptions, children2, _fields, span, rawChildren, triviaLog, state, _tags) {
19497
19543
  if (typeof typeOrOptions === "string") {