parseman 0.26.2 → 0.26.3
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/codegen.d.ts.map +1 -1
- package/dist/compiler/ir-serialize.d.ts.map +1 -1
- package/dist/index.cjs +38 -22
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +38 -22
- package/dist/index.js.map +3 -3
- package/dist/plugin/index.cjs +38 -22
- package/dist/plugin/index.cjs.map +3 -3
- package/dist/plugin/index.js +38 -22
- package/dist/plugin/index.js.map +3 -3
- package/package.json +1 -1
package/dist/plugin/index.cjs
CHANGED
|
@@ -5565,7 +5565,7 @@ function emitDispatch(p, ctx, pos) {
|
|
|
5565
5565
|
ctx.indent = 1;
|
|
5566
5566
|
ctx.failLabel = "_pfail";
|
|
5567
5567
|
ctx.recordFail = true;
|
|
5568
|
-
const innerR =
|
|
5568
|
+
const innerR = emitDispatch(innerParser, ctx, "_pos");
|
|
5569
5569
|
ctx.indent = savedIndent;
|
|
5570
5570
|
ctx.failLabel = savedFailLabel;
|
|
5571
5571
|
ctx.recordFail = savedRecord;
|
|
@@ -6282,6 +6282,23 @@ function escapeClassChar(ch) {
|
|
|
6282
6282
|
return ch.replace(/[\\\]^-]/g, "\\$&");
|
|
6283
6283
|
}
|
|
6284
6284
|
|
|
6285
|
+
// src/combinators/withCtx.ts
|
|
6286
|
+
function withCtx(extra, combinator) {
|
|
6287
|
+
const meta = {
|
|
6288
|
+
firstSet: combinator._meta.firstSet,
|
|
6289
|
+
canMatchNewline: combinator._meta.canMatchNewline,
|
|
6290
|
+
isTrivia: false
|
|
6291
|
+
};
|
|
6292
|
+
return {
|
|
6293
|
+
_tag: "withCtx",
|
|
6294
|
+
_meta: meta,
|
|
6295
|
+
_def: { tag: "withCtx", extra, parser: combinator },
|
|
6296
|
+
parse(input, pos, ctx) {
|
|
6297
|
+
return combinator.parse(input, pos, { ...ctx, state: extra });
|
|
6298
|
+
}
|
|
6299
|
+
};
|
|
6300
|
+
}
|
|
6301
|
+
|
|
6285
6302
|
// src/compiler/ir-serialize.ts
|
|
6286
6303
|
function childrenOf2(def) {
|
|
6287
6304
|
switch (def.tag) {
|
|
@@ -6298,6 +6315,7 @@ function childrenOf2(def) {
|
|
|
6298
6315
|
case "field":
|
|
6299
6316
|
case "not":
|
|
6300
6317
|
case "node":
|
|
6318
|
+
case "withCtx":
|
|
6301
6319
|
case "expect":
|
|
6302
6320
|
return [def.parser];
|
|
6303
6321
|
case "grammar":
|
|
@@ -6313,7 +6331,6 @@ function childrenOf2(def) {
|
|
|
6313
6331
|
case "regex":
|
|
6314
6332
|
case "keywords":
|
|
6315
6333
|
case "guard":
|
|
6316
|
-
case "withCtx":
|
|
6317
6334
|
case "recover":
|
|
6318
6335
|
case "unknown":
|
|
6319
6336
|
return [];
|
|
@@ -6388,6 +6405,17 @@ function evalRuleMapIR(ir) {
|
|
|
6388
6405
|
c._def.gateSrcs = gateSrcs;
|
|
6389
6406
|
return c;
|
|
6390
6407
|
};
|
|
6408
|
+
const _wc = (src, inner) => {
|
|
6409
|
+
let extra;
|
|
6410
|
+
try {
|
|
6411
|
+
extra = (0, eval)(`(${src})`);
|
|
6412
|
+
} catch {
|
|
6413
|
+
extra = void 0;
|
|
6414
|
+
}
|
|
6415
|
+
const w = withCtx(extra, inner);
|
|
6416
|
+
w._def.extraSrc = src;
|
|
6417
|
+
return w;
|
|
6418
|
+
};
|
|
6391
6419
|
const fn = new Function(
|
|
6392
6420
|
"rules",
|
|
6393
6421
|
"ref",
|
|
@@ -6414,6 +6442,7 @@ function evalRuleMapIR(ir) {
|
|
|
6414
6442
|
"_tf",
|
|
6415
6443
|
"_nd",
|
|
6416
6444
|
"_gch",
|
|
6445
|
+
"_wc",
|
|
6417
6446
|
`return (${ir})`
|
|
6418
6447
|
);
|
|
6419
6448
|
const map = fn(
|
|
@@ -6441,7 +6470,8 @@ function evalRuleMapIR(ir) {
|
|
|
6441
6470
|
expect,
|
|
6442
6471
|
_tf,
|
|
6443
6472
|
_nd,
|
|
6444
|
-
_gch
|
|
6473
|
+
_gch,
|
|
6474
|
+
_wc
|
|
6445
6475
|
);
|
|
6446
6476
|
return Object.entries(map);
|
|
6447
6477
|
}
|
|
@@ -6497,7 +6527,7 @@ ${body}
|
|
|
6497
6527
|
this.analyze(target, active);
|
|
6498
6528
|
return;
|
|
6499
6529
|
}
|
|
6500
|
-
if (def.tag === "guard" || def.tag === "
|
|
6530
|
+
if (def.tag === "guard" || def.tag === "recover" || def.tag === "unknown") {
|
|
6501
6531
|
throw new Unserializable(`unsupported tag ${def.tag}`);
|
|
6502
6532
|
}
|
|
6503
6533
|
this.counts.set(c, (this.counts.get(c) ?? 0) + 1);
|
|
@@ -6606,8 +6636,11 @@ ${body}
|
|
|
6606
6636
|
const trivia2 = def.clearTrivia ? "null" : def.triviaParser ? kid(def.triviaParser) : "undefined";
|
|
6607
6637
|
return `parser({ trivia: ${trivia2}${def.trackLines ? ", trackLines: true" : ""} }, ${kid(def.parser)})`;
|
|
6608
6638
|
}
|
|
6639
|
+
case "withCtx": {
|
|
6640
|
+
if (def.extraSrc === void 0) throw new Unserializable("withCtx without extraSrc");
|
|
6641
|
+
return `_wc(${JSON.stringify(def.extraSrc)}, ${kid(def.parser)})`;
|
|
6642
|
+
}
|
|
6609
6643
|
case "guard":
|
|
6610
|
-
case "withCtx":
|
|
6611
6644
|
case "recover":
|
|
6612
6645
|
case "unknown":
|
|
6613
6646
|
throw new Unserializable(`unsupported tag ${def.tag}`);
|
|
@@ -6719,23 +6752,6 @@ function guard(predicate) {
|
|
|
6719
6752
|
};
|
|
6720
6753
|
}
|
|
6721
6754
|
|
|
6722
|
-
// src/combinators/withCtx.ts
|
|
6723
|
-
function withCtx(extra, combinator) {
|
|
6724
|
-
const meta = {
|
|
6725
|
-
firstSet: combinator._meta.firstSet,
|
|
6726
|
-
canMatchNewline: combinator._meta.canMatchNewline,
|
|
6727
|
-
isTrivia: false
|
|
6728
|
-
};
|
|
6729
|
-
return {
|
|
6730
|
-
_tag: "withCtx",
|
|
6731
|
-
_meta: meta,
|
|
6732
|
-
_def: { tag: "withCtx", extra, parser: combinator },
|
|
6733
|
-
parse(input, pos, ctx) {
|
|
6734
|
-
return combinator.parse(input, pos, { ...ctx, state: extra });
|
|
6735
|
-
}
|
|
6736
|
-
};
|
|
6737
|
-
}
|
|
6738
|
-
|
|
6739
6755
|
// src/cst/offset-model.ts
|
|
6740
6756
|
var { isFinite } = Number;
|
|
6741
6757
|
|