parseman 0.26.1 → 0.26.2
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/compiler/ir-serialize.d.ts.map +1 -1
- package/dist/index.cjs +41 -3
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +41 -3
- package/dist/index.js.map +2 -2
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.cjs +84 -4
- package/dist/plugin/index.cjs.map +3 -3
- package/dist/plugin/index.js +84 -4
- package/dist/plugin/index.js.map +3 -3
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/plugin/evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,UAAU,EAAE,IAAI,EAMjB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/plugin/evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,UAAU,EAAE,IAAI,EAMjB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AA2E7C,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;IAC1B,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB,CAAA;AACD,MAAM,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;AAM3C,KAAK,gBAAgB,GAAG;IAAE,GAAG,EAAE,aAAa,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAA;AA4dhE,0EAA0E;AAC1E,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,KAAK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"}
|
package/dist/plugin/index.cjs
CHANGED
|
@@ -6360,6 +6360,34 @@ function evalRuleMapIR(ir) {
|
|
|
6360
6360
|
n._def.buildSrc = src;
|
|
6361
6361
|
return n;
|
|
6362
6362
|
};
|
|
6363
|
+
const _gch = (items) => {
|
|
6364
|
+
const gateSrcs = [];
|
|
6365
|
+
const arms = items.map((it) => {
|
|
6366
|
+
if (Array.isArray(it)) {
|
|
6367
|
+
const [src, comb] = it;
|
|
6368
|
+
gateSrcs.push(src);
|
|
6369
|
+
let gate;
|
|
6370
|
+
try {
|
|
6371
|
+
gate = (0, eval)(`(${src})`);
|
|
6372
|
+
} catch {
|
|
6373
|
+
gate = () => {
|
|
6374
|
+
throw new Error("IR gate fn not materialized");
|
|
6375
|
+
};
|
|
6376
|
+
}
|
|
6377
|
+
return { gate, combinator: comb };
|
|
6378
|
+
}
|
|
6379
|
+
gateSrcs.push(null);
|
|
6380
|
+
return it;
|
|
6381
|
+
});
|
|
6382
|
+
const c = choice(...arms);
|
|
6383
|
+
const gates = c._def.gates;
|
|
6384
|
+
if (gates && gates.length !== gateSrcs.length) {
|
|
6385
|
+
throw new Error(`_gch: gateSrcs length ${gateSrcs.length} != choice gates length ${gates.length}`);
|
|
6386
|
+
}
|
|
6387
|
+
;
|
|
6388
|
+
c._def.gateSrcs = gateSrcs;
|
|
6389
|
+
return c;
|
|
6390
|
+
};
|
|
6363
6391
|
const fn = new Function(
|
|
6364
6392
|
"rules",
|
|
6365
6393
|
"ref",
|
|
@@ -6385,6 +6413,7 @@ function evalRuleMapIR(ir) {
|
|
|
6385
6413
|
"expect",
|
|
6386
6414
|
"_tf",
|
|
6387
6415
|
"_nd",
|
|
6416
|
+
"_gch",
|
|
6388
6417
|
`return (${ir})`
|
|
6389
6418
|
);
|
|
6390
6419
|
const map = fn(
|
|
@@ -6411,7 +6440,8 @@ function evalRuleMapIR(ir) {
|
|
|
6411
6440
|
field,
|
|
6412
6441
|
expect,
|
|
6413
6442
|
_tf,
|
|
6414
|
-
_nd
|
|
6443
|
+
_nd,
|
|
6444
|
+
_gch
|
|
6415
6445
|
);
|
|
6416
6446
|
return Object.entries(map);
|
|
6417
6447
|
}
|
|
@@ -6523,8 +6553,16 @@ ${body}
|
|
|
6523
6553
|
case "sequence":
|
|
6524
6554
|
return `sequence(${def.parsers.map(kid).join(", ")})`;
|
|
6525
6555
|
case "choice": {
|
|
6526
|
-
|
|
6527
|
-
return `choice(${def.parsers.map(kid).join(", ")})`;
|
|
6556
|
+
const gates = def.gates;
|
|
6557
|
+
if (gates.every((g) => g === null)) return `choice(${def.parsers.map(kid).join(", ")})`;
|
|
6558
|
+
const gateSrcs = def.gateSrcs;
|
|
6559
|
+
const items = def.parsers.map((p, i) => {
|
|
6560
|
+
if (gates[i] === null) return kid(p);
|
|
6561
|
+
const src = gateSrcs?.[i];
|
|
6562
|
+
if (src == null) throw new Unserializable("choice gate() has no captured source");
|
|
6563
|
+
return `[${JSON.stringify(src)}, ${kid(p)}]`;
|
|
6564
|
+
});
|
|
6565
|
+
return `_gch([${items.join(", ")}])`;
|
|
6528
6566
|
}
|
|
6529
6567
|
case "many":
|
|
6530
6568
|
return `many(${kid(def.parser)})`;
|
|
@@ -6705,6 +6743,48 @@ var { isFinite } = Number;
|
|
|
6705
6743
|
registerRegexAnalyzer(firstSetFromRegex);
|
|
6706
6744
|
|
|
6707
6745
|
// src/plugin/evaluator.ts
|
|
6746
|
+
function stripTsFromSource(node2, code) {
|
|
6747
|
+
const cuts = [];
|
|
6748
|
+
const walk2 = (n) => {
|
|
6749
|
+
if (!n || typeof n !== "object") return;
|
|
6750
|
+
const rec = n;
|
|
6751
|
+
if (typeof rec.type === "string" && rec.type.startsWith("TS") && typeof rec.start === "number" && typeof rec.end === "number") {
|
|
6752
|
+
const ex = rec.expression;
|
|
6753
|
+
if ((rec.type === "TSAsExpression" || rec.type === "TSSatisfiesExpression" || rec.type === "TSNonNullExpression" || rec.type === "TSInstantiationExpression") && ex && typeof ex.end === "number") {
|
|
6754
|
+
cuts.push([ex.end, rec.end]);
|
|
6755
|
+
walk2(rec.expression);
|
|
6756
|
+
return;
|
|
6757
|
+
}
|
|
6758
|
+
if (rec.type === "TSTypeAssertion" && ex && typeof ex.start === "number") {
|
|
6759
|
+
cuts.push([rec.start, ex.start]);
|
|
6760
|
+
walk2(rec.expression);
|
|
6761
|
+
return;
|
|
6762
|
+
}
|
|
6763
|
+
cuts.push([rec.start, rec.end]);
|
|
6764
|
+
return;
|
|
6765
|
+
}
|
|
6766
|
+
for (const key of Object.keys(rec)) {
|
|
6767
|
+
if (key === "type" || key === "start" || key === "end") continue;
|
|
6768
|
+
const v2 = rec[key];
|
|
6769
|
+
if (Array.isArray(v2)) {
|
|
6770
|
+
for (const item of v2) walk2(item);
|
|
6771
|
+
} else if (v2 && typeof v2 === "object") walk2(v2);
|
|
6772
|
+
}
|
|
6773
|
+
};
|
|
6774
|
+
walk2(node2);
|
|
6775
|
+
const start = node2.start;
|
|
6776
|
+
const end = node2.end;
|
|
6777
|
+
if (cuts.length === 0) return code.slice(start, end);
|
|
6778
|
+
cuts.sort((a, b) => a[0] - b[0]);
|
|
6779
|
+
let out = "";
|
|
6780
|
+
let cur = start;
|
|
6781
|
+
for (const [s, e] of cuts) {
|
|
6782
|
+
if (s < cur) continue;
|
|
6783
|
+
out += code.slice(cur, s);
|
|
6784
|
+
cur = e;
|
|
6785
|
+
}
|
|
6786
|
+
return out + code.slice(cur, end);
|
|
6787
|
+
}
|
|
6708
6788
|
function isWordFactory(v2) {
|
|
6709
6789
|
return !!v2 && typeof v2 === "object" && v2.tag === "wordFactory";
|
|
6710
6790
|
}
|
|
@@ -6980,7 +7060,7 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
6980
7060
|
if (isGatedArmExpr(argNode)) {
|
|
6981
7061
|
const parts = gatedArmParts(argNode);
|
|
6982
7062
|
if (!parts) return null;
|
|
6983
|
-
const gateSrc =
|
|
7063
|
+
const gateSrc = stripTsFromSource(parts.gate, code);
|
|
6984
7064
|
mfs.push(gateSrc);
|
|
6985
7065
|
const combi = anyValue(parts.combinator, scope, code, mfs);
|
|
6986
7066
|
if (!isCombinator(combi)) return null;
|