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":"ir-serialize.d.ts","sourceRoot":"","sources":["../../src/compiler/ir-serialize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,aAAa,CAAA;AAiBxD,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;AA4C/B,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,GAC9C,MAAM,GAAG,IAAI,CAUf;AAED;;oFAEoF;AACpF,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"ir-serialize.d.ts","sourceRoot":"","sources":["../../src/compiler/ir-serialize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,aAAa,CAAA;AAiBxD,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;AA4C/B,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,GAC9C,MAAM,GAAG,IAAI,CAUf;AAED;;oFAEoF;AACpF,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAgE/D"}
|
package/dist/index.cjs
CHANGED
|
@@ -6345,6 +6345,34 @@ function evalRuleMapIR(ir) {
|
|
|
6345
6345
|
n._def.buildSrc = src;
|
|
6346
6346
|
return n;
|
|
6347
6347
|
};
|
|
6348
|
+
const _gch = (items) => {
|
|
6349
|
+
const gateSrcs = [];
|
|
6350
|
+
const arms = items.map((it) => {
|
|
6351
|
+
if (Array.isArray(it)) {
|
|
6352
|
+
const [src, comb] = it;
|
|
6353
|
+
gateSrcs.push(src);
|
|
6354
|
+
let gate;
|
|
6355
|
+
try {
|
|
6356
|
+
gate = (0, eval)(`(${src})`);
|
|
6357
|
+
} catch {
|
|
6358
|
+
gate = () => {
|
|
6359
|
+
throw new Error("IR gate fn not materialized");
|
|
6360
|
+
};
|
|
6361
|
+
}
|
|
6362
|
+
return { gate, combinator: comb };
|
|
6363
|
+
}
|
|
6364
|
+
gateSrcs.push(null);
|
|
6365
|
+
return it;
|
|
6366
|
+
});
|
|
6367
|
+
const c = choice(...arms);
|
|
6368
|
+
const gates = c._def.gates;
|
|
6369
|
+
if (gates && gates.length !== gateSrcs.length) {
|
|
6370
|
+
throw new Error(`_gch: gateSrcs length ${gateSrcs.length} != choice gates length ${gates.length}`);
|
|
6371
|
+
}
|
|
6372
|
+
;
|
|
6373
|
+
c._def.gateSrcs = gateSrcs;
|
|
6374
|
+
return c;
|
|
6375
|
+
};
|
|
6348
6376
|
const fn = new Function(
|
|
6349
6377
|
"rules",
|
|
6350
6378
|
"ref",
|
|
@@ -6370,6 +6398,7 @@ function evalRuleMapIR(ir) {
|
|
|
6370
6398
|
"expect",
|
|
6371
6399
|
"_tf",
|
|
6372
6400
|
"_nd",
|
|
6401
|
+
"_gch",
|
|
6373
6402
|
`return (${ir})`
|
|
6374
6403
|
);
|
|
6375
6404
|
const map = fn(
|
|
@@ -6396,7 +6425,8 @@ function evalRuleMapIR(ir) {
|
|
|
6396
6425
|
field,
|
|
6397
6426
|
expect,
|
|
6398
6427
|
_tf,
|
|
6399
|
-
_nd
|
|
6428
|
+
_nd,
|
|
6429
|
+
_gch
|
|
6400
6430
|
);
|
|
6401
6431
|
return Object.entries(map);
|
|
6402
6432
|
}
|
|
@@ -6508,8 +6538,16 @@ ${body}
|
|
|
6508
6538
|
case "sequence":
|
|
6509
6539
|
return `sequence(${def.parsers.map(kid).join(", ")})`;
|
|
6510
6540
|
case "choice": {
|
|
6511
|
-
|
|
6512
|
-
return `choice(${def.parsers.map(kid).join(", ")})`;
|
|
6541
|
+
const gates = def.gates;
|
|
6542
|
+
if (gates.every((g) => g === null)) return `choice(${def.parsers.map(kid).join(", ")})`;
|
|
6543
|
+
const gateSrcs = def.gateSrcs;
|
|
6544
|
+
const items = def.parsers.map((p, i) => {
|
|
6545
|
+
if (gates[i] === null) return kid(p);
|
|
6546
|
+
const src = gateSrcs?.[i];
|
|
6547
|
+
if (src == null) throw new Unserializable("choice gate() has no captured source");
|
|
6548
|
+
return `[${JSON.stringify(src)}, ${kid(p)}]`;
|
|
6549
|
+
});
|
|
6550
|
+
return `_gch([${items.join(", ")}])`;
|
|
6513
6551
|
}
|
|
6514
6552
|
case "many":
|
|
6515
6553
|
return `many(${kid(def.parser)})`;
|