parseman 0.50.4 → 0.50.6
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.js +31 -3
- package/dist/index.js.map +1 -1
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.js +34 -3
- package/dist/plugin/index.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/compiler/ir-serialize.ts +41 -2
- package/src/plugin/evaluator.ts +13 -0
- package/src/version.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -16986,6 +16986,32 @@ var Serializer = class {
|
|
|
16986
16986
|
body(c) {
|
|
16987
16987
|
return c._def.tag === "lazy" && ruleNameOf4(c) !== void 0 ? lazyTarget(c) ?? c : c;
|
|
16988
16988
|
}
|
|
16989
|
+
/**
|
|
16990
|
+
* The child a rule-entry grammar scope should serialize as its body, when that
|
|
16991
|
+
* scope merely WRAPS the rule's own named `lazy` proxy.
|
|
16992
|
+
*
|
|
16993
|
+
* `rules({ trackLines: true }, …)` wraps every rule VALUE — which is that rule's
|
|
16994
|
+
* own named lazy proxy — in a `grammarParser({ trackLines: true })` scope
|
|
16995
|
+
* (`parser.ts:229-242`). `body()` unwraps a BARE lazy entry to its defined target;
|
|
16996
|
+
* a lazy wrapped one level deep by that scope must be unwrapped INSIDE the scope
|
|
16997
|
+
* too. Left wrapped, the inner proxy serializes as a `g[name]` SELF-reference and
|
|
16998
|
+
* the rule's real body is dropped, so it re-lowers to `Name: parser(opts, g.Name)`
|
|
16999
|
+
* — a bodyless self-cycle the table encoder rejects with `alias cycle — lazy (rule
|
|
17000
|
+
* 'Name') encodes to its own recursion trampoline`. This is why the four
|
|
17001
|
+
* `*PositionsGrammar` exports fell back to a runtime `compose()` under trackLines.
|
|
17002
|
+
*
|
|
17003
|
+
* STRICT: only a scope that IS a rule entry (in `localRuleNames`) AND wraps ITS
|
|
17004
|
+
* OWN name unwraps. A scope wrapping another rule's ref (a genuine cross-rule
|
|
17005
|
+
* alias, `Name: parser(opts, g.Other)`) or a real body is untouched, so the
|
|
17006
|
+
* non-trackLines and non-self-wrap output stays byte-identical.
|
|
17007
|
+
*/
|
|
17008
|
+
scopeSelfBody(c) {
|
|
17009
|
+
const name = this.localRuleNames.get(c);
|
|
17010
|
+
if (name === void 0 || c._def.tag !== "grammar") return void 0;
|
|
17011
|
+
const inner = c._def.parser;
|
|
17012
|
+
if (inner._def.tag !== "lazy" || ruleNameOf4(inner) !== name) return void 0;
|
|
17013
|
+
return lazyTarget(inner) ?? void 0;
|
|
17014
|
+
}
|
|
16989
17015
|
run() {
|
|
16990
17016
|
for (const [, c] of this.ruleMap) this.analyze(this.body(c), /* @__PURE__ */ new Set());
|
|
16991
17017
|
for (const c of this.scanSkip) {
|
|
@@ -17055,7 +17081,9 @@ ${outerDecls.map((d) => " " + d).join("\n")}
|
|
|
17055
17081
|
return;
|
|
17056
17082
|
}
|
|
17057
17083
|
active.add(c);
|
|
17058
|
-
|
|
17084
|
+
const selfBody = def.tag === "grammar" ? this.scopeSelfBody(c) : void 0;
|
|
17085
|
+
const kids = selfBody === void 0 ? childrenOf3(def) : def.tag === "grammar" && def.triviaParser ? [selfBody, def.triviaParser] : [selfBody];
|
|
17086
|
+
for (const child of kids) this.analyze(child, active);
|
|
17059
17087
|
active.delete(c);
|
|
17060
17088
|
}
|
|
17061
17089
|
/** Reference `c`: a const var if it has one (emitting its decl first), else inline.
|
|
@@ -17221,7 +17249,7 @@ ${outerDecls.map((d) => " " + d).join("\n")}
|
|
|
17221
17249
|
const spec = classified && def.triviaParser ? analyzeLabeledTrivia(def.triviaParser) : null;
|
|
17222
17250
|
if (classified && !spec) throw new Unserializable("classified trivia without labeled arms");
|
|
17223
17251
|
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";
|
|
17224
|
-
return `parser({ trivia: ${trivia2}${def.captureTrivia ? ", captureTrivia: true" : ""}${def.rootCapture ? `, rootCapture: ${JSON.stringify(def.rootCapture)}` : ""}${def.trackLines ? ", trackLines: true" : ""} }, ${kid(def.parser)})`;
|
|
17252
|
+
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)})`;
|
|
17225
17253
|
}
|
|
17226
17254
|
case "withCtx": {
|
|
17227
17255
|
if (def.extraSrc === void 0) throw new Unserializable("withCtx without extraSrc");
|
|
@@ -17357,7 +17385,7 @@ function compileRuleMap(ruleMap, opts = {}) {
|
|
|
17357
17385
|
}
|
|
17358
17386
|
|
|
17359
17387
|
// src/version.ts
|
|
17360
|
-
var PARSEMAN_VERSION = "0.50.
|
|
17388
|
+
var PARSEMAN_VERSION = "0.50.6";
|
|
17361
17389
|
|
|
17362
17390
|
// src/compiler/compile-linkable-table.ts
|
|
17363
17391
|
function isLocal(rule) {
|