parseman 0.50.4 → 0.50.5

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.
@@ -16569,6 +16569,32 @@ var Serializer = class {
16569
16569
  body(c) {
16570
16570
  return c._def.tag === "lazy" && ruleNameOf3(c) !== void 0 ? lazyTarget(c) ?? c : c;
16571
16571
  }
16572
+ /**
16573
+ * The child a rule-entry grammar scope should serialize as its body, when that
16574
+ * scope merely WRAPS the rule's own named `lazy` proxy.
16575
+ *
16576
+ * `rules({ trackLines: true }, …)` wraps every rule VALUE — which is that rule's
16577
+ * own named lazy proxy — in a `grammarParser({ trackLines: true })` scope
16578
+ * (`parser.ts:229-242`). `body()` unwraps a BARE lazy entry to its defined target;
16579
+ * a lazy wrapped one level deep by that scope must be unwrapped INSIDE the scope
16580
+ * too. Left wrapped, the inner proxy serializes as a `g[name]` SELF-reference and
16581
+ * the rule's real body is dropped, so it re-lowers to `Name: parser(opts, g.Name)`
16582
+ * — a bodyless self-cycle the table encoder rejects with `alias cycle — lazy (rule
16583
+ * 'Name') encodes to its own recursion trampoline`. This is why the four
16584
+ * `*PositionsGrammar` exports fell back to a runtime `compose()` under trackLines.
16585
+ *
16586
+ * STRICT: only a scope that IS a rule entry (in `localRuleNames`) AND wraps ITS
16587
+ * OWN name unwraps. A scope wrapping another rule's ref (a genuine cross-rule
16588
+ * alias, `Name: parser(opts, g.Other)`) or a real body is untouched, so the
16589
+ * non-trackLines and non-self-wrap output stays byte-identical.
16590
+ */
16591
+ scopeSelfBody(c) {
16592
+ const name = this.localRuleNames.get(c);
16593
+ if (name === void 0 || c._def.tag !== "grammar") return void 0;
16594
+ const inner = c._def.parser;
16595
+ if (inner._def.tag !== "lazy" || ruleNameOf3(inner) !== name) return void 0;
16596
+ return lazyTarget(inner) ?? void 0;
16597
+ }
16572
16598
  run() {
16573
16599
  for (const [, c] of this.ruleMap) this.analyze(this.body(c), /* @__PURE__ */ new Set());
16574
16600
  for (const c of this.scanSkip) {
@@ -16638,7 +16664,9 @@ ${outerDecls.map((d) => " " + d).join("\n")}
16638
16664
  return;
16639
16665
  }
16640
16666
  active.add(c);
16641
- for (const child of childrenOf3(def)) this.analyze(child, active);
16667
+ const selfBody = def.tag === "grammar" ? this.scopeSelfBody(c) : void 0;
16668
+ const kids = selfBody === void 0 ? childrenOf3(def) : def.tag === "grammar" && def.triviaParser ? [selfBody, def.triviaParser] : [selfBody];
16669
+ for (const child of kids) this.analyze(child, active);
16642
16670
  active.delete(c);
16643
16671
  }
16644
16672
  /** Reference `c`: a const var if it has one (emitting its decl first), else inline.
@@ -16804,7 +16832,7 @@ ${outerDecls.map((d) => " " + d).join("\n")}
16804
16832
  const spec = classified && def.triviaParser ? analyzeLabeledTrivia(def.triviaParser) : null;
16805
16833
  if (classified && !spec) throw new Unserializable("classified trivia without labeled arms");
16806
16834
  const trivia2 = def.clearTrivia ? "null" : spec ? `classifiedTrivia({ ${spec.arms.map((arm) => `${JSON.stringify(arm.label)}: ${kid(arm.parser)}`).join(", ")} })` : def.triviaParser ? kid(def.triviaParser) : "undefined";
16807
- return `parser({ trivia: ${trivia2}${def.captureTrivia ? ", captureTrivia: true" : ""}${def.rootCapture ? `, rootCapture: ${JSON.stringify(def.rootCapture)}` : ""}${def.trackLines ? ", trackLines: true" : ""} }, ${kid(def.parser)})`;
16835
+ return `parser({ trivia: ${trivia2}${def.captureTrivia ? ", captureTrivia: true" : ""}${def.rootCapture ? `, rootCapture: ${JSON.stringify(def.rootCapture)}` : ""}${def.trackLines ? ", trackLines: true" : ""} }, ${kid(this.scopeSelfBody(c) ?? def.parser)})`;
16808
16836
  }
16809
16837
  case "withCtx": {
16810
16838
  if (def.extraSrc === void 0) throw new Unserializable("withCtx without extraSrc");
@@ -16940,7 +16968,7 @@ function compileRuleMap(ruleMap, opts = {}) {
16940
16968
  }
16941
16969
 
16942
16970
  // src/version.ts
16943
- var PARSEMAN_VERSION = "0.50.4";
16971
+ var PARSEMAN_VERSION = "0.50.5";
16944
16972
 
16945
16973
  // src/compiler/compile-linkable-table.ts
16946
16974
  function isLocal(rule) {