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.js
CHANGED
|
@@ -5530,7 +5530,7 @@ function emitDispatch(p, ctx, pos) {
|
|
|
5530
5530
|
ctx.indent = 1;
|
|
5531
5531
|
ctx.failLabel = "_pfail";
|
|
5532
5532
|
ctx.recordFail = true;
|
|
5533
|
-
const innerR =
|
|
5533
|
+
const innerR = emitDispatch(innerParser, ctx, "_pos");
|
|
5534
5534
|
ctx.indent = savedIndent;
|
|
5535
5535
|
ctx.failLabel = savedFailLabel;
|
|
5536
5536
|
ctx.recordFail = savedRecord;
|
|
@@ -6247,6 +6247,23 @@ function escapeClassChar(ch) {
|
|
|
6247
6247
|
return ch.replace(/[\\\]^-]/g, "\\$&");
|
|
6248
6248
|
}
|
|
6249
6249
|
|
|
6250
|
+
// src/combinators/withCtx.ts
|
|
6251
|
+
function withCtx(extra, combinator) {
|
|
6252
|
+
const meta = {
|
|
6253
|
+
firstSet: combinator._meta.firstSet,
|
|
6254
|
+
canMatchNewline: combinator._meta.canMatchNewline,
|
|
6255
|
+
isTrivia: false
|
|
6256
|
+
};
|
|
6257
|
+
return {
|
|
6258
|
+
_tag: "withCtx",
|
|
6259
|
+
_meta: meta,
|
|
6260
|
+
_def: { tag: "withCtx", extra, parser: combinator },
|
|
6261
|
+
parse(input, pos, ctx) {
|
|
6262
|
+
return combinator.parse(input, pos, { ...ctx, state: extra });
|
|
6263
|
+
}
|
|
6264
|
+
};
|
|
6265
|
+
}
|
|
6266
|
+
|
|
6250
6267
|
// src/compiler/ir-serialize.ts
|
|
6251
6268
|
function childrenOf2(def) {
|
|
6252
6269
|
switch (def.tag) {
|
|
@@ -6263,6 +6280,7 @@ function childrenOf2(def) {
|
|
|
6263
6280
|
case "field":
|
|
6264
6281
|
case "not":
|
|
6265
6282
|
case "node":
|
|
6283
|
+
case "withCtx":
|
|
6266
6284
|
case "expect":
|
|
6267
6285
|
return [def.parser];
|
|
6268
6286
|
case "grammar":
|
|
@@ -6278,7 +6296,6 @@ function childrenOf2(def) {
|
|
|
6278
6296
|
case "regex":
|
|
6279
6297
|
case "keywords":
|
|
6280
6298
|
case "guard":
|
|
6281
|
-
case "withCtx":
|
|
6282
6299
|
case "recover":
|
|
6283
6300
|
case "unknown":
|
|
6284
6301
|
return [];
|
|
@@ -6353,6 +6370,17 @@ function evalRuleMapIR(ir) {
|
|
|
6353
6370
|
c._def.gateSrcs = gateSrcs;
|
|
6354
6371
|
return c;
|
|
6355
6372
|
};
|
|
6373
|
+
const _wc = (src, inner) => {
|
|
6374
|
+
let extra;
|
|
6375
|
+
try {
|
|
6376
|
+
extra = (0, eval)(`(${src})`);
|
|
6377
|
+
} catch {
|
|
6378
|
+
extra = void 0;
|
|
6379
|
+
}
|
|
6380
|
+
const w = withCtx(extra, inner);
|
|
6381
|
+
w._def.extraSrc = src;
|
|
6382
|
+
return w;
|
|
6383
|
+
};
|
|
6356
6384
|
const fn = new Function(
|
|
6357
6385
|
"rules",
|
|
6358
6386
|
"ref",
|
|
@@ -6379,6 +6407,7 @@ function evalRuleMapIR(ir) {
|
|
|
6379
6407
|
"_tf",
|
|
6380
6408
|
"_nd",
|
|
6381
6409
|
"_gch",
|
|
6410
|
+
"_wc",
|
|
6382
6411
|
`return (${ir})`
|
|
6383
6412
|
);
|
|
6384
6413
|
const map = fn(
|
|
@@ -6406,7 +6435,8 @@ function evalRuleMapIR(ir) {
|
|
|
6406
6435
|
expect,
|
|
6407
6436
|
_tf,
|
|
6408
6437
|
_nd,
|
|
6409
|
-
_gch
|
|
6438
|
+
_gch,
|
|
6439
|
+
_wc
|
|
6410
6440
|
);
|
|
6411
6441
|
return Object.entries(map);
|
|
6412
6442
|
}
|
|
@@ -6462,7 +6492,7 @@ ${body}
|
|
|
6462
6492
|
this.analyze(target, active);
|
|
6463
6493
|
return;
|
|
6464
6494
|
}
|
|
6465
|
-
if (def.tag === "guard" || def.tag === "
|
|
6495
|
+
if (def.tag === "guard" || def.tag === "recover" || def.tag === "unknown") {
|
|
6466
6496
|
throw new Unserializable(`unsupported tag ${def.tag}`);
|
|
6467
6497
|
}
|
|
6468
6498
|
this.counts.set(c, (this.counts.get(c) ?? 0) + 1);
|
|
@@ -6571,8 +6601,11 @@ ${body}
|
|
|
6571
6601
|
const trivia2 = def.clearTrivia ? "null" : def.triviaParser ? kid(def.triviaParser) : "undefined";
|
|
6572
6602
|
return `parser({ trivia: ${trivia2}${def.trackLines ? ", trackLines: true" : ""} }, ${kid(def.parser)})`;
|
|
6573
6603
|
}
|
|
6604
|
+
case "withCtx": {
|
|
6605
|
+
if (def.extraSrc === void 0) throw new Unserializable("withCtx without extraSrc");
|
|
6606
|
+
return `_wc(${JSON.stringify(def.extraSrc)}, ${kid(def.parser)})`;
|
|
6607
|
+
}
|
|
6574
6608
|
case "guard":
|
|
6575
|
-
case "withCtx":
|
|
6576
6609
|
case "recover":
|
|
6577
6610
|
case "unknown":
|
|
6578
6611
|
throw new Unserializable(`unsupported tag ${def.tag}`);
|
|
@@ -6684,23 +6717,6 @@ function guard(predicate) {
|
|
|
6684
6717
|
};
|
|
6685
6718
|
}
|
|
6686
6719
|
|
|
6687
|
-
// src/combinators/withCtx.ts
|
|
6688
|
-
function withCtx(extra, combinator) {
|
|
6689
|
-
const meta = {
|
|
6690
|
-
firstSet: combinator._meta.firstSet,
|
|
6691
|
-
canMatchNewline: combinator._meta.canMatchNewline,
|
|
6692
|
-
isTrivia: false
|
|
6693
|
-
};
|
|
6694
|
-
return {
|
|
6695
|
-
_tag: "withCtx",
|
|
6696
|
-
_meta: meta,
|
|
6697
|
-
_def: { tag: "withCtx", extra, parser: combinator },
|
|
6698
|
-
parse(input, pos, ctx) {
|
|
6699
|
-
return combinator.parse(input, pos, { ...ctx, state: extra });
|
|
6700
|
-
}
|
|
6701
|
-
};
|
|
6702
|
-
}
|
|
6703
|
-
|
|
6704
6720
|
// src/cst/offset-model.ts
|
|
6705
6721
|
var { isFinite } = Number;
|
|
6706
6722
|
|