parseman 0.32.0 → 0.33.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAwBA,OAAO,WAAW,MAAM,cAAc,CAAA;AAmBtC,MAAM,MAAM,uBAAuB,GAAG;IACpC,8DAA8D;IAC9D,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;8CAC0C;IAC1C,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAA;;;AAgSD,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAA;IAC3C,kFAAkF;IAClF,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB,CAAA;AA0CD,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,aAAa,cAA6B,EAC1C,kBAAkB,UAAQ,EAC1B,QAAQ,UAAQ,EAChB,eAAe,UAAQ,GACtB,oBAAoB,GAAG,IAAI,CAw+B7B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAwBA,OAAO,WAAW,MAAM,cAAc,CAAA;AAmBtC,MAAM,MAAM,uBAAuB,GAAG;IACpC,8DAA8D;IAC9D,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;8CAC0C;IAC1C,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAA;;;AAgSD,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAA;IAC3C,kFAAkF;IAClF,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB,CAAA;AA0CD,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,aAAa,cAA6B,EAC1C,kBAAkB,UAAQ,EAC1B,QAAQ,UAAQ,EAChB,eAAe,UAAQ,GACtB,oBAAoB,GAAG,IAAI,CAwgC7B"}
@@ -2795,7 +2795,7 @@ function leaf(root, fn) {
2795
2795
  }
2796
2796
 
2797
2797
  // src/version.ts
2798
- var PARSEMAN_VERSION = "0.32.0";
2798
+ var PARSEMAN_VERSION = "0.33.0";
2799
2799
 
2800
2800
  // src/analysis/gating.ts
2801
2801
  var isAny = (fs2) => fs2.kind === "any";
@@ -7554,9 +7554,9 @@ function lazyTarget(c) {
7554
7554
  }
7555
7555
  var Unserializable = class extends Error {
7556
7556
  };
7557
- function serializeRuleMap(ruleMap) {
7557
+ function serializeRuleMap(ruleMap, scanSkip) {
7558
7558
  try {
7559
- return new Serializer(ruleMap).run();
7559
+ return new Serializer(ruleMap, scanSkip ?? []).run();
7560
7560
  } catch (e) {
7561
7561
  if (e instanceof Unserializable) {
7562
7562
  if (process.env.PARSEMAN_IR_DEBUG) console.error(`[ir] fallback: ${e.message}`);
@@ -7717,10 +7717,28 @@ var Serializer = class {
7717
7717
  decls = [];
7718
7718
  ruleValues = /* @__PURE__ */ new Set();
7719
7719
  ruleMap;
7720
- constructor(ruleMap) {
7720
+ scanSkip;
7721
+ constructor(ruleMap, scanSkip = []) {
7721
7722
  this.ruleMap = ruleMap;
7723
+ this.scanSkip = scanSkip;
7722
7724
  for (const [, c] of ruleMap) this.ruleValues.add(this.body(c));
7723
7725
  }
7726
+ /** A grammar-level `scanSkip` unit is an opaque TERMINAL (a string, a balanced
7727
+ * bracket) — it must not reach a grammar-rule ref (`g[name]`), because the
7728
+ * serialized `scanSkip` array sits in the `rules({ scanSkip })` OPTIONS position,
7729
+ * outside the `(g) => …` factory where `g` is bound. A unit that does reference a
7730
+ * rule can't be carried in options; bail to the full-pieces fallback. */
7731
+ assertNoRuleRef(c, seen) {
7732
+ if (seen.has(c)) return;
7733
+ seen.add(c);
7734
+ if (c._def.tag === "lazy") {
7735
+ if (ruleNameOf2(c) !== void 0) throw new Unserializable("scanSkip unit references a grammar rule");
7736
+ const target = lazyTarget(c);
7737
+ if (target) this.assertNoRuleRef(target, seen);
7738
+ return;
7739
+ }
7740
+ for (const child of childrenOf2(c._def)) this.assertNoRuleRef(child, seen);
7741
+ }
7724
7742
  /** A `rules()` map wraps each rule value in a named `lazy` proxy; the real body is
7725
7743
  * its target (compileLinkable unwraps the same way). A ref INSIDE a body stays a
7726
7744
  * `g[name]` ref — only the top-level entry is unwrapped. */
@@ -7729,21 +7747,38 @@ var Serializer = class {
7729
7747
  }
7730
7748
  run() {
7731
7749
  for (const [, c] of this.ruleMap) this.analyze(this.body(c), /* @__PURE__ */ new Set());
7750
+ for (const c of this.scanSkip) {
7751
+ this.assertNoRuleRef(c, /* @__PURE__ */ new Set());
7752
+ this.analyze(c, /* @__PURE__ */ new Set());
7753
+ }
7732
7754
  let n = 0;
7733
7755
  for (const [c, count] of this.counts) {
7734
7756
  if (this.ruleValues.has(c)) continue;
7735
7757
  if (count >= 2 || this.selfRef.has(c)) this.constName.set(c, `_s${n++}`);
7736
7758
  }
7759
+ const outerDecls = [];
7760
+ const innerDecls = [];
7761
+ let optionsArg = "";
7762
+ if (this.scanSkip.length > 0) {
7763
+ this.decls = outerDecls;
7764
+ const units = this.scanSkip.map((c) => this.ref(c, null));
7765
+ optionsArg = `{ scanSkip: [${units.join(", ")}] }, `;
7766
+ }
7767
+ this.decls = innerDecls;
7737
7768
  const body = this.ruleMap.map(([name, c]) => ` ${JSON.stringify(name)}: ${this.wrap(this.body(c))}`).join(",\n");
7738
- if (this.decls.length === 0) return `rules((g) => ({
7769
+ const factory = innerDecls.length === 0 ? `(g) => ({
7739
7770
  ${body}
7740
- }))`;
7741
- return `rules((g) => {
7742
- ${this.decls.map((d) => " " + d).join("\n")}
7771
+ })` : `(g) => {
7772
+ ${innerDecls.map((d) => " " + d).join("\n")}
7743
7773
  return ({
7744
7774
  ${body}
7745
7775
  })
7746
- })`;
7776
+ }`;
7777
+ const call = `rules(${optionsArg}${factory})`;
7778
+ return outerDecls.length === 0 ? call : `(() => {
7779
+ ${outerDecls.map((d) => " " + d).join("\n")}
7780
+ return ${call}
7781
+ })()`;
7747
7782
  }
7748
7783
  /** Count identity references and flag self-referential subtrees. `active` is the
7749
7784
  * set of combinators on the current DFS path (to detect a lazy pointing back). */
@@ -9161,6 +9196,14 @@ function transformMacro(code, id, moduleAliases = /* @__PURE__ */ new Set([PARSE
9161
9196
  const gTrivia = triviaValue ? evaluateExpr(triviaValue, scope, code, []) : void 0;
9162
9197
  const scanSkipValue = optionValue("scanSkip");
9163
9198
  const gScanSkip = scanSkipValue ? evaluateCombinatorArray(scanSkipValue, scope, code) ?? void 0 : void 0;
9199
+ if (gScanSkip) {
9200
+ for (const rule of ruleMap.values()) {
9201
+ if (rule && !rule._meta.isTrivia) {
9202
+ ;
9203
+ rule._meta.grammarScanSkip = gScanSkip;
9204
+ }
9205
+ }
9206
+ }
9164
9207
  return { ruleMap, ...gTrivia ? { trivia: gTrivia } : {}, ...gScanSkip ? { scanSkip: gScanSkip } : {} };
9165
9208
  };
9166
9209
  const compileRulesFactory = (init, label2) => {
@@ -9297,12 +9340,12 @@ function transformMacro(code, id, moduleAliases = /* @__PURE__ */ new Set([PARSE
9297
9340
  }
9298
9341
  return pieces;
9299
9342
  };
9300
- const localCarried = (rm, label2, composing) => {
9343
+ const localCarried = (rm, label2, composing, scanSkip) => {
9301
9344
  const entries = [...rm];
9302
9345
  const ns = nsFor(label2);
9303
- const ir = serializeRuleMap(entries);
9346
+ const ir = serializeRuleMap(entries, scanSkip);
9304
9347
  if (ir) return { carried: [{ ns, ir }] };
9305
- const p = compileLinkable(entries, ns, { ...composing ? { trivia: composing } : {}, recovery });
9348
+ const p = compileLinkable(entries, ns, { ...composing ? { trivia: composing } : {}, ...scanSkip ? { scanSkip } : {}, recovery });
9306
9349
  return p ? { carried: [p] } : null;
9307
9350
  };
9308
9351
  const argPieces = (arg, label2, composing) => {
@@ -9327,18 +9370,13 @@ function transformMacro(code, id, moduleAliases = /* @__PURE__ */ new Set([PARSE
9327
9370
  }
9328
9371
  }
9329
9372
  if (isRulesCall(arg)) {
9330
- const rulesArgs = arg.arguments;
9331
- const a0 = rulesArgs[0];
9332
- const a1 = rulesArgs[1];
9333
- const optionsFirst = a0?.type === "ObjectExpression";
9334
- const factory = optionsFirst ? a1 : a0;
9335
- const rm = factory ? evaluateParserFactory(factory, scope, code, []) : null;
9336
- return rm ? localCarried(rm, label2, composing) : null;
9373
+ const evaluated = evaluateRulesFactory(arg, label2);
9374
+ return evaluated ? localCarried(evaluated.ruleMap, label2, composing, evaluated.scanSkip) : null;
9337
9375
  }
9338
9376
  if (arg.type === "Identifier") {
9339
9377
  const name = arg.name;
9340
9378
  const rm = localRuleMaps.get(name);
9341
- if (rm) return localCarried(rm, label2, composing);
9379
+ if (rm) return localCarried(rm, label2, composing, localGrammarScanSkip.get(name));
9342
9380
  const composed = localComposedCarried.get(name);
9343
9381
  if (composed) return { carried: composed };
9344
9382
  const pieces = importedPieces(name);
@@ -9561,9 +9599,12 @@ function transformMacro(code, id, moduleAliases = /* @__PURE__ */ new Set([PARSE
9561
9599
  );
9562
9600
  if (exportPrefix) {
9563
9601
  const ns = nsFor(varName);
9564
- const pieces = compileLinkable([...compiledRules.ruleMap], ns, { recovery });
9602
+ const pieces = compileLinkable([...compiledRules.ruleMap], ns, {
9603
+ ...compiledRules.scanSkip ? { scanSkip: compiledRules.scanSkip } : {},
9604
+ recovery
9605
+ });
9565
9606
  if (pieces && !pieces.mfFns.length && !pieces.buildFns.length) {
9566
- const ir = serializeRuleMap([...compiledRules.ruleMap]);
9607
+ const ir = serializeRuleMap([...compiledRules.ruleMap], compiledRules.scanSkip);
9567
9608
  replacement = withCarriedPieces(replacement, [ir ? { ns, ir } : pieces]);
9568
9609
  }
9569
9610
  }