parseman 0.40.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -53,8 +53,8 @@ export { buildTriviaIndex } from './cst/trivia-index.ts';
53
53
  export type { TriviaIndex, TriviaToken, TriviaIndexOptions } from './cst/trivia-index.ts';
54
54
  export { walk, createVisitor } from './cst/walk.ts';
55
55
  export type { Walkable, WalkVisitor, VisitApi, VisitorHandlers } from './cst/walk.ts';
56
- export { triviaEntries } from './cst/trivia-entries.ts';
57
- export type { TriviaEntriesView } from './cst/trivia-entries.ts';
56
+ export { buildRootTriviaIndex, triviaEntries } from './cst/trivia-entries.ts';
57
+ export type { RootTriviaGap, RootTriviaIndex, TriviaEntriesView } from './cst/trivia-entries.ts';
58
58
  export { triviaKindMask } from './cst/trivia-kinds.ts';
59
59
  export { OffsetIndex, buildOffsetIndex, collectLeafSlots, gapText, lineBreaksIn, blankLinesIn, lineStartWithin, indentWidth, indentMixed, commentsIn, gapIsSignificant, } from './cst/offset-model.ts';
60
60
  export type { Slot, Gap } from './cst/offset-model.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,oBAAoB,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE7R,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAClD,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAE9D,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AA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,9 +2586,11 @@ function markUnusedValues(root) {
2586
2586
  visit(def.parser, consumed);
2587
2587
  visit(def.sentinel, false);
2588
2588
  return;
2589
+ case "token":
2590
+ visit(def.parser, false);
2591
+ return;
2589
2592
  case "label":
2590
2593
  case "trivia":
2591
- case "token":
2592
2594
  case "attempt":
2593
2595
  case "withCtx":
2594
2596
  case "expect":
@@ -3353,7 +3355,7 @@ function leaf(root, fn) {
3353
3355
  }
3354
3356
 
3355
3357
  // src/version.ts
3356
- var PARSEMAN_VERSION = "0.40.0";
3358
+ var PARSEMAN_VERSION = "0.41.0";
3357
3359
 
3358
3360
  // src/cst/host-mode.ts
3359
3361
  var FUSED_HOST_MODE = /* @__PURE__ */ Symbol.for("parseman.fusedHostMode");
@@ -6297,7 +6299,7 @@ function scanBranchLabeled(shape, kindIndex, mint) {
6297
6299
  ` if (${m.end} > _e) {`,
6298
6300
  ` if (_cap) {`,
6299
6301
  ` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_e, ${m.end}, ${kindIndex})`,
6300
- ` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << kindIndex}))) _ctx._cstTriviaLog.push(_e, ${m.end}, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${kindIndex})`,
6302
+ ` if (_cap === 1 && _ctx._cstTriviaLog !== undefined && _ctx.captureTrivia && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << kindIndex}))) _ctx._cstTriviaLog.push(_e, ${m.end}, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${kindIndex})`,
6301
6303
  ` }`,
6302
6304
  ` _e = ${m.end}`,
6303
6305
  ` continue`,
@@ -6353,7 +6355,7 @@ function analyzeTriviaFastPath(trivia2) {
6353
6355
  var CAP_RECORD = [
6354
6356
  ` if (_cap && _e > _pos) {`,
6355
6357
  ` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_pos, _e)`,
6356
- ` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
6358
+ ` if (_cap === 1 && _ctx._cstTriviaLog !== undefined && _ctx.captureTrivia) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
6357
6359
  ` }`
6358
6360
  ].join("\n");
6359
6361
  function composeFastLoop(shapes) {
@@ -6413,7 +6415,7 @@ function buildLabeledRegexTriviaFnDecl(fnName, spec, reNames) {
6413
6415
  ` const _ce = _e + _m${i}[0].length`,
6414
6416
  ` if (_cap) {`,
6415
6417
  ` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_e, _ce, ${k})`,
6416
- ` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << k}))) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
6418
+ ` if (_cap === 1 && _ctx._cstTriviaLog !== undefined && _ctx.captureTrivia && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << k}))) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
6417
6419
  ` }`,
6418
6420
  ` _e = _ce`,
6419
6421
  ` _matched = true`,
@@ -6451,7 +6453,7 @@ function buildLabeledRuntimeTriviaFnDecl(fnName, spec, rpStartIndex) {
6451
6453
  ` const _ce = _r${i}.span.end`,
6452
6454
  ` if (_cap) {`,
6453
6455
  ` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_e, _ce, ${k})`,
6454
- ` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << k}))) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
6456
+ ` if (_cap === 1 && _ctx._cstTriviaLog !== undefined && _ctx.captureTrivia && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << k}))) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
6455
6457
  ` }`,
6456
6458
  ` _e = _ce`,
6457
6459
  ` _matched = true`,
@@ -6537,6 +6539,9 @@ function transformFnSource(fn, fnSrc) {
6537
6539
  function replaceParam(body, param, valueVar) {
6538
6540
  return body.replace(new RegExp(`\\b${escapeRegExp2(param)}\\b`, "g"), valueVar);
6539
6541
  }
6542
+ function hasExplicitObjectKey(body, param) {
6543
+ return new RegExp(`\\b${escapeRegExp2(param)}\\b\\s*:`).test(body);
6544
+ }
6540
6545
  function stripForIdCheck(body) {
6541
6546
  return body.replace(/'[^'\\]*(?:\\.[^'\\]*)*'|"[^"\\]*(?:\\.[^"\\]*)*"/g, '""').replace(/\bas\s+const\b/g, "").replace(/\b[A-Za-z_$][\w$]*\s*:/g, ":");
6542
6547
  }
@@ -6579,10 +6584,19 @@ function tryInlineDestructureTransform(src, valueVars) {
6579
6584
  const allowed = new Set(valueVars);
6580
6585
  for (let i = 0; i < slots.length; i++) {
6581
6586
  const name = slots[i];
6582
- if (name) body = replaceParam(body, name, valueVars[i]);
6587
+ if (!name) continue;
6588
+ if (hasExplicitObjectKey(body, name)) return null;
6589
+ body = replaceParam(body, name, valueVars[i]);
6583
6590
  }
6584
6591
  return hasFreeIdentifiers(body, allowed) ? null : body;
6585
6592
  }
6593
+ function isDispatchTailOnlyTransform(src) {
6594
+ const m = src.match(/^\(\s*\[([^\]]*)\]\s*\)\s*=>\s*(.+)$/s);
6595
+ if (!m) return false;
6596
+ const slots = parseArrayDestructure(m[1], 2);
6597
+ const tail = slots[1];
6598
+ return tail !== null && m[2].trim() === tail;
6599
+ }
6586
6600
 
6587
6601
  // src/compiler/codegen.ts
6588
6602
  function leadingFirstSetRecipe(p, seen = /* @__PURE__ */ new Set()) {
@@ -6833,6 +6847,17 @@ function ensureRegexDecl(ctx, source, flags) {
6833
6847
  }
6834
6848
  return rName;
6835
6849
  }
6850
+ function ensurePlainRegexDecl(ctx, source, flags) {
6851
+ const f = flags.replace(/[gy]/g, "");
6852
+ const key = `${source}/${f}`;
6853
+ let rName = ctx.regexMap.get(key);
6854
+ if (rName === void 0) {
6855
+ rName = `${nsp(ctx)}_re${ctx.regexDecls.length}`;
6856
+ ctx.regexDecls.push(`const ${rName} = ${new RegExp(source, f).toString()}`);
6857
+ ctx.regexMap.set(key, rName);
6858
+ }
6859
+ return rName;
6860
+ }
6836
6861
  function ensureTriviaFn(ctx) {
6837
6862
  const trivia2 = ctx.activeTrivia;
6838
6863
  const existing = ctx.triviaFnNames.get(trivia2);
@@ -6898,7 +6923,7 @@ function ensureTriviaFn(ctx) {
6898
6923
  ` }`,
6899
6924
  ` if (_cap && _e > _pos) {`,
6900
6925
  ` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_pos, _e)`,
6901
- ` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
6926
+ ` if (_cap === 1 && _ctx._cstTriviaLog !== undefined && _ctx.captureTrivia) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
6902
6927
  ` }`,
6903
6928
  ` return _e`,
6904
6929
  `}`
@@ -7359,14 +7384,19 @@ function emitSeqValues(def, ctx, pos) {
7359
7384
  continue;
7360
7385
  } else {
7361
7386
  const trivFn = ensureTriviaFn(ctx);
7387
+ const markLog = v(ctx, "_mklg");
7362
7388
  const scanEndV = v(ctx, "_sne");
7363
- stmts.push(`${ind(ctx)}const ${scanEndV} = ${trivFn}(input, ${curV}, _ctx)`);
7389
+ const capArg = ctx.noHoist ? "0" : "_ctx._triviaLog !== undefined ? 2 : 0";
7390
+ stmts.push(
7391
+ `${ind(ctx)}const ${markLog} = _ctx._triviaLog ? _ctx._triviaLog.length : 0`,
7392
+ `${ind(ctx)}const ${scanEndV} = ${trivFn}(input, ${curV}, _ctx, ${capArg})`
7393
+ );
7364
7394
  const r2 = emit(def.parsers[i], ctx, scanEndV);
7365
7395
  stmts.push(...r2.stmts);
7366
7396
  const endAfterV = v(ctx, "_sea");
7367
7397
  stmts.push(
7368
7398
  `${ind(ctx)}const ${endAfterV} = ${r2.endVar}`,
7369
- `${ind(ctx)}if (${endAfterV} > ${scanEndV}) ${curV} = ${endAfterV}`
7399
+ `${ind(ctx)}if (${endAfterV} > ${scanEndV}) ${curV} = ${endAfterV}; else if (_ctx._triviaLog && _ctx._triviaLog.length !== ${markLog}) _ctx._triviaLog.length = ${markLog}`
7370
7400
  );
7371
7401
  valueVars.push(r2.valueVar);
7372
7402
  continue;
@@ -7596,19 +7626,20 @@ function mayRecordRecoveryError(p, recovery, seen = /* @__PURE__ */ new Set()) {
7596
7626
  return false;
7597
7627
  }
7598
7628
  }
7599
- function emitDispatchCombinator(parser2, def, ctx, pos) {
7629
+ function emitDispatchCombinator(parser2, def, ctx, pos, valueMode = "pair") {
7600
7630
  if (parserUsesRouted2(def.selector)) {
7601
7631
  throw new Error("parseman: routed() can only appear inside a dispatch() branch");
7602
7632
  }
7603
7633
  const coverageIds = ctx.coverage?.plan.dispatches.get(parser2) ?? [];
7604
7634
  const branchUsesRouted2 = (entry) => entry.usesRouted === true || parserUsesRouted2(entry.parser);
7605
7635
  const hasRoutedBranch = def.cases.some(branchUsesRouted2) || (def.matchers ? def.matchers.some(branchUsesRouted2) : false) || (def.otherwise ? def.otherwiseUsesRouted === true || parserUsesRouted2(def.otherwise) : false);
7606
- const selectorLeafMark = hasRoutedBranch ? v(ctx, "_dsl") : null;
7607
- const selectorRawMark = hasRoutedBranch ? v(ctx, "_dsr") : null;
7608
- const selectorTriviaMark = hasRoutedBranch ? v(ctx, "_dst") : null;
7609
- const selectorLogMark = hasRoutedBranch ? v(ctx, "_dsg") : null;
7610
- const selectorFieldMark = hasRoutedBranch ? v(ctx, "_dsf") : null;
7611
- const selectorErrorMark = hasRoutedBranch ? v(ctx, "_dse") : null;
7636
+ const selectorNeedsRollback = hasRoutedBranch && (ctx.capturing === true && capturesLeaf(def.selector) || ctx.activeTrivia !== void 0 && parserHasTriviaSite(def.selector) || parserEnablesTriviaCapture(def.selector) || parserHasOwnFields(def.selector) || mayRecordRecoveryError(def.selector, !!ctx.recovery));
7637
+ const selectorLeafMark = selectorNeedsRollback ? v(ctx, "_dsl") : null;
7638
+ const selectorRawMark = selectorNeedsRollback ? v(ctx, "_dsr") : null;
7639
+ const selectorTriviaMark = selectorNeedsRollback ? v(ctx, "_dst") : null;
7640
+ const selectorLogMark = selectorNeedsRollback ? v(ctx, "_dsg") : null;
7641
+ const selectorFieldMark = selectorNeedsRollback ? v(ctx, "_dsf") : null;
7642
+ const selectorErrorMark = selectorNeedsRollback ? v(ctx, "_dse") : null;
7612
7643
  const selector = emit(def.selector, ctx, pos);
7613
7644
  const outV = v(ctx, "_dval");
7614
7645
  const outE = v(ctx, "_dend");
@@ -7633,13 +7664,14 @@ function emitDispatchCombinator(parser2, def, ctx, pos) {
7633
7664
  stmts.push(head);
7634
7665
  ctx.indent++;
7635
7666
  const usesRouted = branchUsesRouted2(entry);
7636
- const routedV = usesRouted ? v(ctx, "_drt") : null;
7667
+ const needsRoutedContext = usesRouted && routedNeedsContextBridge(parser3, ctx);
7668
+ const routedV = needsRoutedContext ? v(ctx, "_drt") : null;
7637
7669
  const mayError = mayRecordRecoveryError(parser3, !!ctx.recovery);
7638
7670
  const errMark = mayError ? v(ctx, "_derr") : null;
7639
7671
  const logMark = ctx.activeTrivia ? v(ctx, "_dlog") : null;
7640
- if (routedV) {
7672
+ if (usesRouted) {
7641
7673
  stmts.push(
7642
- `${ind(ctx)}const ${routedV} = _ctx._routed; _ctx._routed = { value: ${selector.valueVar}, span: { start: ${pos}, end: ${selector.endVar} } }`,
7674
+ ...routedV ? [`${ind(ctx)}const ${routedV} = _ctx._routed; _ctx._routed = { value: ${selector.valueVar}, span: { start: ${pos}, end: ${selector.endVar} } }`] : [],
7643
7675
  ...selectorLeafMark ? [
7644
7676
  `${ind(ctx)}if (_ctx._cstLeaves && _ctx._cstLeaves.length !== ${selectorLeafMark}) _ctx._cstLeaves.length = ${selectorLeafMark}; if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${selectorRawMark}) _ctx._cstRawChildren.length = ${selectorRawMark}; if (_ctx._cstTriviaLog && _ctx._cstTriviaLog.length !== ${selectorTriviaMark}) _ctx._cstTriviaLog.length = ${selectorTriviaMark}; if (_ctx._triviaLog && _ctx._triviaLog.length !== ${selectorLogMark}) _ctx._triviaLog.length = ${selectorLogMark}; if (_ctx._fields && _ctx._fields.length !== ${selectorFieldMark}) _ctx._fields.length = ${selectorFieldMark}; if (_ctx._errors && _ctx._errors.length !== ${selectorErrorMark}) _ctx._errors.length = ${selectorErrorMark}`
7645
7677
  ] : []
@@ -7647,7 +7679,17 @@ function emitDispatchCombinator(parser2, def, ctx, pos) {
7647
7679
  }
7648
7680
  if (errMark) stmts.push(`${ind(ctx)}const ${errMark} = _ctx._errors?.length ?? 0`);
7649
7681
  if (logMark) stmts.push(`${ind(ctx)}const ${logMark} = _ctx._triviaLog?.length ?? 0`);
7682
+ const savedRoutedLocal = ctx.routedLocal;
7683
+ const savedNoHoist = ctx.noHoist;
7684
+ if (usesRouted && !needsRoutedContext) {
7685
+ ctx.routedLocal = { valueVar: selector.valueVar, startVar: pos, endVar: selector.endVar };
7686
+ ctx.noHoist = true;
7687
+ } else if (usesRouted) {
7688
+ ctx.routedLocal = void 0;
7689
+ }
7650
7690
  const tail = emitTailFallible(parser3, ctx, usesRouted ? pos : selector.endVar);
7691
+ ctx.routedLocal = savedRoutedLocal;
7692
+ ctx.noHoist = savedNoHoist;
7651
7693
  stmts.push(...coverageAttempt(ctx, coverageId, pos));
7652
7694
  const errorRollback = errMark ? `if (_ctx._errors && _ctx._errors.length !== ${errMark}) _ctx._errors.length = ${errMark}; ` : "";
7653
7695
  const logRollback = logMark ? `if (_ctx._triviaLog && _ctx._triviaLog.length !== ${logMark}) _ctx._triviaLog.length = ${logMark}; ` : "";
@@ -7657,7 +7699,7 @@ function emitDispatchCombinator(parser2, def, ctx, pos) {
7657
7699
  ...tail.stmts,
7658
7700
  `${ind(ctx)}if (!${tail.okVar}) { ${routedRollback}${errorRollback}${logRollback}${coverageFailure}${committedFailBody(ctx)} }`,
7659
7701
  ...routedV ? [`${ind(ctx)}_ctx._routed = ${routedV}`] : [],
7660
- `${ind(ctx)}${outV} = [${selector.valueVar}, ${tail.valVar}]`,
7702
+ `${ind(ctx)}${outV} = ${valueMode === "tail" ? tail.valVar : `[${selector.valueVar}, ${tail.valVar}]`}`,
7661
7703
  `${ind(ctx)}${outE} = ${tail.endVar}`,
7662
7704
  ...coverageHit(ctx, coverageId, pos, tail.endVar)
7663
7705
  );
@@ -7672,7 +7714,7 @@ function emitDispatchCombinator(parser2, def, ctx, pos) {
7672
7714
  }
7673
7715
  const emitMatcherTails = () => {
7674
7716
  for (const matcher of def.matchers ?? []) {
7675
- emitSelectedTail(matcher, wroteBranch ? "else if" : "if", emitDispatchMatcherCondition(keyV, matcher), coverageIds[coverageIndex++]);
7717
+ emitSelectedTail(matcher, wroteBranch ? "else if" : "if", emitDispatchMatcherCondition(ctx, keyV, matcher), coverageIds[coverageIndex++]);
7676
7718
  wroteBranch = true;
7677
7719
  }
7678
7720
  };
@@ -7697,10 +7739,10 @@ function emitDispatchKeyCondition(valueVar, key, caseInsensitive) {
7697
7739
  }
7698
7740
  return parts.join(" && ");
7699
7741
  }
7700
- function emitDispatchMatcherCondition(valueVar, matcher) {
7742
+ function emitDispatchMatcherCondition(ctx, valueVar, matcher) {
7701
7743
  if (matcher.kind === "matches") {
7702
7744
  const flags = matcher.caseInsensitive && !matcher.flags?.includes("i") ? `${matcher.flags ?? ""}i` : matcher.flags ?? "";
7703
- return `${new RegExp(matcher.value, flags).toString()}.test(${valueVar})`;
7745
+ return `${ensurePlainRegexDecl(ctx, matcher.value, flags)}.test(${valueVar})`;
7704
7746
  }
7705
7747
  const text = matcher.value;
7706
7748
  const parts = [`${valueVar}.length >= ${text.length}`];
@@ -7903,6 +7945,28 @@ function emitsAsNamedFn(p, ctx) {
7903
7945
  const usage = ctx.lazyUsage;
7904
7946
  return !!usage && !ctx.noHoist && !ctx.capAsTrivia && isHoistableTag(p._def.tag) && (usage.counts.get(p) ?? 0) > 1 && (usage.sizes.get(p) ?? 0) >= HOIST_MIN_SUBTREE;
7905
7947
  }
7948
+ function routedNeedsContextBridge(p, ctx, seen = /* @__PURE__ */ new Set()) {
7949
+ if (seen.has(p)) return false;
7950
+ seen.add(p);
7951
+ if (p._def.tag === "lazy") {
7952
+ if (ctx.ruleNames?.has(p) || ctx.namedParsers.has(p)) return parserUsesRouted2(p);
7953
+ const usage = ctx.lazyUsage;
7954
+ if (usage && (usage.counts.get(p) ?? 0) <= 1 && !usage.recursive.has(p)) {
7955
+ try {
7956
+ return routedNeedsContextBridge(p._def.thunk(), ctx, seen);
7957
+ } catch {
7958
+ return parserUsesRouted2(p);
7959
+ }
7960
+ }
7961
+ return parserUsesRouted2(p);
7962
+ }
7963
+ if (ctx.ruleNames?.has(p)) return parserUsesRouted2(p);
7964
+ if (ctx.namedParsers.has(p)) return parserUsesRouted2(p);
7965
+ const d = p._def;
7966
+ if (d.tag === "dispatch") return false;
7967
+ if (d.tag === "withCtx") return parserUsesRouted2(d.parser);
7968
+ return childrenOf2(d).some((child) => routedNeedsContextBridge(child, ctx, seen));
7969
+ }
7906
7970
  function armReplayInScope(arm, ctx) {
7907
7971
  let p = arm;
7908
7972
  for (; ; ) {
@@ -8153,15 +8217,16 @@ function emitSepBy(_p, def, ctx, pos) {
8153
8217
  const itemFailBreak = (sepEndVar, sepRb, postSepRb) => def.trailing === void 0 ? `${sepRb}break` : `${postSepRb}${curV} = ${sepEndVar}; break`;
8154
8218
  const postSepMarks = () => {
8155
8219
  if (def.trailing === void 0 || !ctx.capturing) return { decl: [], rb: "" };
8156
- const lv = v(ctx, "_tlv"), rw = v(ctx, "_trw"), tl = v(ctx, "_ttl"), lg = v(ctx, "_tlg");
8220
+ const lv = v(ctx, "_tlv"), rw = v(ctx, "_trw"), tl = v(ctx, "_ttl"), lg = v(ctx, "_tlg"), fl = v(ctx, "_tlf");
8157
8221
  return {
8158
8222
  decl: [
8159
8223
  `${ind(ctx)}const ${lv} = _ctx._cstLeaves ? _ctx._cstLeaves.length : 0`,
8160
8224
  `${ind(ctx)}const ${rw} = _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0`,
8161
8225
  `${ind(ctx)}const ${tl} = _ctx._cstTriviaLog ? _ctx._cstTriviaLog.length : 0`,
8162
- `${ind(ctx)}const ${lg} = _ctx._triviaLog ? _ctx._triviaLog.length : 0`
8226
+ `${ind(ctx)}const ${lg} = _ctx._triviaLog ? _ctx._triviaLog.length : 0`,
8227
+ `${ind(ctx)}const ${fl} = _ctx._fields ? _ctx._fields.length : 0`
8163
8228
  ],
8164
- rb: `if (_ctx._cstLeaves && _ctx._cstLeaves.length !== ${lv}) _ctx._cstLeaves.length = ${lv}; if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${rw}) _ctx._cstRawChildren.length = ${rw}; if (_ctx._cstTriviaLog && _ctx._cstTriviaLog.length !== ${tl}) _ctx._cstTriviaLog.length = ${tl}; if (_ctx._triviaLog && _ctx._triviaLog.length !== ${lg}) _ctx._triviaLog.length = ${lg}; `
8229
+ rb: `if (_ctx._cstLeaves && _ctx._cstLeaves.length !== ${lv}) _ctx._cstLeaves.length = ${lv}; if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${rw}) _ctx._cstRawChildren.length = ${rw}; if (_ctx._cstTriviaLog && _ctx._cstTriviaLog.length !== ${tl}) _ctx._cstTriviaLog.length = ${tl}; if (_ctx._triviaLog && _ctx._triviaLog.length !== ${lg}) _ctx._triviaLog.length = ${lg}; if (_ctx._fields && _ctx._fields.length !== ${fl}) _ctx._fields.length = ${fl}; `
8165
8230
  };
8166
8231
  };
8167
8232
  if (rec) {
@@ -8200,16 +8265,18 @@ function emitSepBy(_p, def, ctx, pos) {
8200
8265
  const markTl = v(ctx, "_mktl");
8201
8266
  const markLog = v(ctx, "_mklg");
8202
8267
  const markLv = v(ctx, "_mklv");
8268
+ const markFld = v(ctx, "_mkf");
8203
8269
  const spV = v(ctx, "_sp");
8204
8270
  stmts.push(
8205
8271
  `${ind(ctx)}const ${markV} = _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0`,
8206
8272
  `${ind(ctx)}const ${markTl} = _ctx._cstTriviaLog ? _ctx._cstTriviaLog.length : 0`,
8207
8273
  `${ind(ctx)}const ${markLog} = _ctx._triviaLog ? _ctx._triviaLog.length : 0`,
8208
8274
  `${ind(ctx)}const ${markLv} = _ctx._cstLeaves ? _ctx._cstLeaves.length : 0`,
8275
+ `${ind(ctx)}const ${markFld} = _ctx._fields ? _ctx._fields.length : 0`,
8209
8276
  `${ind(ctx)}const ${spV} = ${capFn}(input, ${curV}, _ctx, 1)`
8210
8277
  );
8211
8278
  sepAtPos = spV;
8212
- const rollbackToSep = `if (_ctx._cstLeaves && _ctx._cstLeaves.length !== ${markLv}) _ctx._cstLeaves.length = ${markLv}; if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${markV}) _ctx._cstRawChildren.length = ${markV}; if (_ctx._cstTriviaLog && _ctx._cstTriviaLog.length !== ${markTl}) _ctx._cstTriviaLog.length = ${markTl}; if (_ctx._triviaLog && _ctx._triviaLog.length !== ${markLog}) _ctx._triviaLog.length = ${markLog}; `;
8279
+ const rollbackToSep = `if (_ctx._cstLeaves && _ctx._cstLeaves.length !== ${markLv}) _ctx._cstLeaves.length = ${markLv}; if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${markV}) _ctx._cstRawChildren.length = ${markV}; if (_ctx._cstTriviaLog && _ctx._cstTriviaLog.length !== ${markTl}) _ctx._cstTriviaLog.length = ${markTl}; if (_ctx._triviaLog && _ctx._triviaLog.length !== ${markLog}) _ctx._triviaLog.length = ${markLog}; if (_ctx._fields && _ctx._fields.length !== ${markFld}) _ctx._fields.length = ${markFld}; `;
8213
8280
  const sep = emitFallible(def.separator, ctx, sepAtPos, true);
8214
8281
  const { stmts: sepStmts, okVar: sepOk, endVar: sepEnd } = sep;
8215
8282
  stmts.push(...sepStmts, `${ind(ctx)}if (!${sepOk}) { ${rollbackToSep}${sep.mayCommit ? `if (_ctx._fc) ${committedFailBody(ctx)}; ` : ""}break }`);
@@ -8247,16 +8314,18 @@ function emitSepBy(_p, def, ctx, pos) {
8247
8314
  } else {
8248
8315
  const markLv = ctx.capturing ? v(ctx, "_mklv") : null;
8249
8316
  const markRw = ctx.capturing ? v(ctx, "_mkrw") : null;
8317
+ const markFld = ctx.capturing ? v(ctx, "_mkf") : null;
8250
8318
  if (markLv) {
8251
8319
  stmts.push(
8252
8320
  `${ind(ctx)}const ${markLv} = _ctx._cstLeaves ? _ctx._cstLeaves.length : 0`,
8253
- `${ind(ctx)}const ${markRw} = _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0`
8321
+ `${ind(ctx)}const ${markRw} = _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0`,
8322
+ `${ind(ctx)}const ${markFld} = _ctx._fields ? _ctx._fields.length : 0`
8254
8323
  );
8255
8324
  }
8256
8325
  const sep = emitFallible(def.separator, ctx, sepAtPos, true);
8257
8326
  const { stmts: sepStmts, okVar: sepOk, endVar: sepEnd } = sep;
8258
8327
  stmts.push(...sepStmts, `${ind(ctx)}if (!${sepOk}) { ${sep.mayCommit ? `if (_ctx._fc) ${committedFailBody(ctx)}; ` : ""}break }`);
8259
- const nextRb = markLv ? `if (_ctx._cstLeaves && _ctx._cstLeaves.length !== ${markLv}) _ctx._cstLeaves.length = ${markLv}; if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${markRw}) _ctx._cstRawChildren.length = ${markRw}; ` : "";
8328
+ const nextRb = markLv ? `if (_ctx._cstLeaves && _ctx._cstLeaves.length !== ${markLv}) _ctx._cstLeaves.length = ${markLv}; if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${markRw}) _ctx._cstRawChildren.length = ${markRw}; if (_ctx._fields && _ctx._fields.length !== ${markFld}) _ctx._fields.length = ${markFld}; ` : "";
8260
8329
  const post = postSepMarks();
8261
8330
  stmts.push(...post.decl);
8262
8331
  const next = emitFallible(def.parser, ctx, sepEnd, true);
@@ -8326,7 +8395,7 @@ function emitScanTo(def, ctx, pos) {
8326
8395
  return { stmts, valueVar: valV, endVar: curV };
8327
8396
  }
8328
8397
  function emitNot(def, ctx, pos) {
8329
- const sinksLive = !!ctx.capturing || !!ctx.recovery;
8398
+ const sinksLive = !!ctx.capturing || !!ctx.recovery || !!ctx.activeTrivia;
8330
8399
  const leaves = sinksLive ? v(ctx, "_ntl") : null;
8331
8400
  const raw = sinksLive ? v(ctx, "_ntr") : null;
8332
8401
  const tl = sinksLive ? v(ctx, "_ntt") : null;
@@ -8365,6 +8434,17 @@ function emitPeek(def, ctx, pos) {
8365
8434
  };
8366
8435
  }
8367
8436
  function emitRouted(ctx, pos) {
8437
+ const local = ctx.routedLocal;
8438
+ if (local !== void 0) {
8439
+ return {
8440
+ stmts: [
8441
+ ...emitIfFail(ctx, `${local.startVar} !== ${pos}`, failBody(ctx, '"routed()"', pos)),
8442
+ ...emitLeafCapture(ctx, local.valueVar, local.startVar, local.endVar)
8443
+ ],
8444
+ valueVar: local.valueVar,
8445
+ endVar: local.endVar
8446
+ };
8447
+ }
8368
8448
  const item = v(ctx, "_rt");
8369
8449
  return {
8370
8450
  stmts: [
@@ -8860,6 +8940,9 @@ function emitDispatch(p, ctx, pos) {
8860
8940
  return emitSepBy(p, def, ctx, pos);
8861
8941
  case "transform": {
8862
8942
  const fnSrc = transformFnSource(def.fn, def.fnSrc);
8943
+ if (fnSrc && def.parser._def.tag === "dispatch" && isDispatchTailOnlyTransform(fnSrc)) {
8944
+ return emitDispatchCombinator(def.parser, def.parser._def, ctx, pos, "tail");
8945
+ }
8863
8946
  if (fnSrc && def.parser._def.tag === "sequence") {
8864
8947
  const seqR = emitSeqValues(def.parser._def, ctx, pos);
8865
8948
  const inlined = tryInlineDestructureTransform(fnSrc, seqR.valueVars);
@@ -9549,8 +9632,8 @@ function assertRuleName(name) {
9549
9632
  );
9550
9633
  }
9551
9634
  }
9552
- function publicRuleWrapperSource(rule, fnSource) {
9553
- const labels = rule._meta.triviaKindLabels;
9635
+ function publicRuleWrapperSource(rule, fnSource, ambientTriviaKindLabels) {
9636
+ const labels = rule._meta.triviaKindLabels ?? ambientTriviaKindLabels;
9554
9637
  if (labels === void 0) return fnSource;
9555
9638
  return `Object.assign(${fnSource}, { _meta: { triviaKindLabels: ${JSON.stringify(labels)} } })`;
9556
9639
  }
@@ -9719,7 +9802,7 @@ function compileLinkable(ruleMapArg, ns, opts) {
9719
9802
  ...r.stmts,
9720
9803
  ` return { ok: true, value: ${r.valueVar}, span: { start: _pos, end: ${r.endVar} } }`,
9721
9804
  `}`
9722
- ].join("\n")));
9805
+ ].join("\n"), ctx.triviaKindLabels));
9723
9806
  }
9724
9807
  const firstSets = /* @__PURE__ */ new Map();
9725
9808
  const firstSetRecipes = /* @__PURE__ */ new Map();
@@ -11237,8 +11320,158 @@ function parseDoc(registry, rootRule, input, opts = {}) {
11237
11320
  return new ParseDocImpl(registry, rootRule, opts, { abs: null }, [fail], null, input);
11238
11321
  }
11239
11322
 
11323
+ // src/cst/trivia-entries.ts
11324
+ var EMPTY_INDICES = Object.freeze([]);
11325
+ var EMPTY_GAPS = Object.freeze([]);
11326
+ function entryOffset(i, stride) {
11327
+ return i * stride;
11328
+ }
11329
+ function triviaEntries(log, labels, opts) {
11330
+ const baseStride = opts?.nodeLog ? 3 : 2;
11331
+ const stride = labels ? baseStride + 1 : baseStride;
11332
+ const length = Math.floor(log.length / stride);
11333
+ return {
11334
+ length,
11335
+ labels,
11336
+ stride,
11337
+ start(i) {
11338
+ return log[entryOffset(i, stride)];
11339
+ },
11340
+ end(i) {
11341
+ return log[entryOffset(i, stride) + 1];
11342
+ },
11343
+ insertIndex(i) {
11344
+ return opts?.nodeLog ? log[entryOffset(i, stride) + 2] : void 0;
11345
+ },
11346
+ kindIndex(i) {
11347
+ if (!labels) return void 0;
11348
+ return log[entryOffset(i, stride) + baseStride];
11349
+ },
11350
+ kind(i) {
11351
+ const ki = labels ? log[entryOffset(i, stride) + baseStride] : void 0;
11352
+ return ki !== void 0 ? labels[ki] : void 0;
11353
+ },
11354
+ text(i, input) {
11355
+ const s = log[entryOffset(i, stride)];
11356
+ const e = log[entryOffset(i, stride) + 1];
11357
+ return input.slice(s, e);
11358
+ }
11359
+ };
11360
+ }
11361
+ function appendEntryRange(map, key, first, last) {
11362
+ let indices = map.get(key);
11363
+ if (!indices) {
11364
+ indices = [];
11365
+ map.set(key, indices);
11366
+ }
11367
+ for (let i = first; i <= last; i++) indices.push(i);
11368
+ }
11369
+ function buildGap(entries, start, end, first, last) {
11370
+ const entryIndices = [];
11371
+ for (let i = first; i <= last; i++) entryIndices.push(i);
11372
+ return {
11373
+ start,
11374
+ end,
11375
+ entryIndices,
11376
+ hasKind(kind) {
11377
+ for (const i of entryIndices) {
11378
+ if (entries.kind(i) === kind) return true;
11379
+ }
11380
+ return false;
11381
+ },
11382
+ text(input) {
11383
+ return input.slice(start, end);
11384
+ }
11385
+ };
11386
+ }
11387
+ function buildRootMaps(entries) {
11388
+ const before = /* @__PURE__ */ new Map();
11389
+ const after = /* @__PURE__ */ new Map();
11390
+ const beforeGaps = /* @__PURE__ */ new Map();
11391
+ const afterGaps = /* @__PURE__ */ new Map();
11392
+ const gaps = [];
11393
+ if (entries.length === 0) return { before, after, beforeGaps, afterGaps, gaps };
11394
+ const appendGap = (first2, last, start2, end2) => {
11395
+ const gap = buildGap(entries, start2, end2, first2, last);
11396
+ gaps.push(gap);
11397
+ afterGaps.set(start2, gap);
11398
+ beforeGaps.set(end2, gap);
11399
+ appendEntryRange(after, start2, first2, last);
11400
+ appendEntryRange(before, end2, first2, last);
11401
+ };
11402
+ let first = 0;
11403
+ let start = entries.start(0);
11404
+ let end = entries.end(0);
11405
+ for (let i = 1; i < entries.length; i++) {
11406
+ const nextStart = entries.start(i);
11407
+ const nextEnd = entries.end(i);
11408
+ if (nextStart === end) {
11409
+ end = nextEnd;
11410
+ continue;
11411
+ }
11412
+ appendGap(first, i - 1, start, end);
11413
+ first = i;
11414
+ start = nextStart;
11415
+ end = nextEnd;
11416
+ }
11417
+ appendGap(first, entries.length - 1, start, end);
11418
+ return { before, after, beforeGaps, afterGaps, gaps };
11419
+ }
11420
+ function buildRootTriviaIndex(log, labels) {
11421
+ const entries = triviaEntries(log, labels);
11422
+ let maps;
11423
+ const getMaps = () => {
11424
+ maps ??= buildRootMaps(entries);
11425
+ return maps;
11426
+ };
11427
+ return {
11428
+ entries,
11429
+ labels,
11430
+ get before() {
11431
+ return getMaps().before;
11432
+ },
11433
+ get after() {
11434
+ return getMaps().after;
11435
+ },
11436
+ entryIndicesBefore(offset) {
11437
+ return getMaps().before.get(offset) ?? EMPTY_INDICES;
11438
+ },
11439
+ entryIndicesAfter(offset) {
11440
+ return getMaps().after.get(offset) ?? EMPTY_INDICES;
11441
+ },
11442
+ gapBefore(offset) {
11443
+ return getMaps().beforeGaps.get(offset);
11444
+ },
11445
+ gapAfter(offset) {
11446
+ return getMaps().afterGaps.get(offset);
11447
+ },
11448
+ gaps() {
11449
+ return getMaps().gaps;
11450
+ },
11451
+ gapsWithKind(kind) {
11452
+ const kinds = typeof kind === "string" ? [kind] : kind;
11453
+ const matches2 = [];
11454
+ for (const gap of getMaps().gaps) {
11455
+ for (const k of kinds) {
11456
+ if (gap.hasKind(k)) {
11457
+ matches2.push(gap);
11458
+ break;
11459
+ }
11460
+ }
11461
+ }
11462
+ return matches2.length === 0 ? EMPTY_GAPS : matches2;
11463
+ }
11464
+ };
11465
+ }
11466
+
11240
11467
  // src/functional/run.ts
11241
11468
  var invoke = (r, input, pos, ctx) => typeof r === "function" ? r(input, pos, ctx) : r.parse(input, pos, ctx);
11469
+ function triviaKindLabelsFromRunnable(r) {
11470
+ if (!r) return void 0;
11471
+ if (typeof r === "function") return r._meta?.triviaKindLabels;
11472
+ const grammarTrivia = r._meta.grammarTrivia;
11473
+ return r._meta.triviaKindLabels ?? grammarTrivia?._meta.triviaKindLabels ?? (r._def.tag === "grammar" ? r._def.triviaParser?._meta.triviaKindLabels : void 0);
11474
+ }
11242
11475
  function runOnce(entry, input, options, phase, profileState) {
11243
11476
  if (typeof entry !== "function" && typeof entry?.parse !== "function") {
11244
11477
  throw new TypeError(
@@ -11251,6 +11484,7 @@ function runOnce(entry, input, options, phase, profileState) {
11251
11484
  const skipGlobalSinks = phase === "recognizer" || phase === "capture";
11252
11485
  const grammarTrivia = typeof entry !== "function" ? entry._meta.grammarTrivia : void 0;
11253
11486
  const grammarScanSkip = typeof entry !== "function" ? entry._meta.grammarScanSkip : void 0;
11487
+ const triviaKindLabels = triviaKindLabelsFromRunnable(entry) ?? triviaKindLabelsFromRunnable(options.trivia);
11254
11488
  const stamped = entry;
11255
11489
  assertHostModeCompatible(
11256
11490
  typeof entry === "function" ? stamped[FUSED_HOST_MODE] ?? "ast" : entry._meta.grammarHostMode ?? "ast",
@@ -11262,7 +11496,7 @@ function runOnce(entry, input, options, phase, profileState) {
11262
11496
  ...skipGlobalSinks ? { _pmProfile: profile } : { _triviaLog: triviaLog, _errors: errors, ...profile === void 0 ? {} : { _pmProfile: profile } },
11263
11497
  build: options.build,
11264
11498
  state: options.state,
11265
- ...grammarTrivia !== void 0 ? { trivia: grammarTrivia, ...grammarTrivia._meta.triviaKindLabels ? { triviaKindLabels: grammarTrivia._meta.triviaKindLabels } : {} } : {},
11499
+ ...grammarTrivia !== void 0 ? { trivia: grammarTrivia, ...triviaKindLabels ? { triviaKindLabels } : {} } : triviaKindLabels ? { triviaKindLabels } : {},
11266
11500
  ...grammarScanSkip !== void 0 ? { scanSkip: grammarScanSkip } : {},
11267
11501
  ...options.triviaCaptureMask !== void 0 ? { _triviaCaptureMask: options.triviaCaptureMask } : {},
11268
11502
  ...options.tolerant ? { _tolerant: true, _rec: REC } : {},
@@ -11285,6 +11519,8 @@ function runOnce(entry, input, options, phase, profileState) {
11285
11519
  expected: r.ok ? [] : r.expected ?? [],
11286
11520
  errors,
11287
11521
  triviaLog,
11522
+ ...triviaKindLabels === void 0 ? {} : { triviaKindLabels },
11523
+ triviaMap: buildRootTriviaIndex(triviaLog, triviaKindLabels),
11288
11524
  unconsumedFrom
11289
11525
  };
11290
11526
  }
@@ -11743,43 +11979,6 @@ function createVisitor(handlers) {
11743
11979
  return (node2) => api.visit(node2);
11744
11980
  }
11745
11981
 
11746
- // src/cst/trivia-entries.ts
11747
- function entryOffset(i, stride) {
11748
- return i * stride;
11749
- }
11750
- function triviaEntries(log, labels, opts) {
11751
- const baseStride = opts?.nodeLog ? 3 : 2;
11752
- const stride = labels ? baseStride + 1 : baseStride;
11753
- const length = Math.floor(log.length / stride);
11754
- return {
11755
- length,
11756
- labels,
11757
- stride,
11758
- start(i) {
11759
- return log[entryOffset(i, stride)];
11760
- },
11761
- end(i) {
11762
- return log[entryOffset(i, stride) + 1];
11763
- },
11764
- insertIndex(i) {
11765
- return opts?.nodeLog ? log[entryOffset(i, stride) + 2] : void 0;
11766
- },
11767
- kindIndex(i) {
11768
- if (!labels) return void 0;
11769
- return log[entryOffset(i, stride) + baseStride];
11770
- },
11771
- kind(i) {
11772
- const ki = labels ? log[entryOffset(i, stride) + baseStride] : void 0;
11773
- return ki !== void 0 ? labels[ki] : void 0;
11774
- },
11775
- text(i, input) {
11776
- const s = log[entryOffset(i, stride)];
11777
- const e = log[entryOffset(i, stride) + 1];
11778
- return input.slice(s, e);
11779
- }
11780
- };
11781
- }
11782
-
11783
11982
  // src/cst/offset-model.ts
11784
11983
  var { isFinite } = Number;
11785
11984
  function floorIndex(arr, len, x) {
@@ -11992,6 +12191,7 @@ export {
11992
12191
  blankLinesIn,
11993
12192
  buildLineIndex,
11994
12193
  buildOffsetIndex,
12194
+ buildRootTriviaIndex,
11995
12195
  buildTriviaIndex,
11996
12196
  charClassMembers,
11997
12197
  choice,