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/index.js
CHANGED
|
@@ -5547,7 +5547,7 @@ function emitDispatch(p, ctx, pos) {
|
|
|
5547
5547
|
ctx.indent = 1;
|
|
5548
5548
|
ctx.failLabel = "_pfail";
|
|
5549
5549
|
ctx.recordFail = true;
|
|
5550
|
-
const innerR =
|
|
5550
|
+
const innerR = emitDispatch(innerParser, ctx, "_pos");
|
|
5551
5551
|
ctx.indent = savedIndent;
|
|
5552
5552
|
ctx.failLabel = savedFailLabel;
|
|
5553
5553
|
ctx.recordFail = savedRecord;
|
|
@@ -6179,6 +6179,23 @@ function escapeClassChar(ch) {
|
|
|
6179
6179
|
return ch.replace(/[\\\]^-]/g, "\\$&");
|
|
6180
6180
|
}
|
|
6181
6181
|
|
|
6182
|
+
// src/combinators/withCtx.ts
|
|
6183
|
+
function withCtx(extra, combinator) {
|
|
6184
|
+
const meta = {
|
|
6185
|
+
firstSet: combinator._meta.firstSet,
|
|
6186
|
+
canMatchNewline: combinator._meta.canMatchNewline,
|
|
6187
|
+
isTrivia: false
|
|
6188
|
+
};
|
|
6189
|
+
return {
|
|
6190
|
+
_tag: "withCtx",
|
|
6191
|
+
_meta: meta,
|
|
6192
|
+
_def: { tag: "withCtx", extra, parser: combinator },
|
|
6193
|
+
parse(input, pos, ctx) {
|
|
6194
|
+
return combinator.parse(input, pos, { ...ctx, state: extra });
|
|
6195
|
+
}
|
|
6196
|
+
};
|
|
6197
|
+
}
|
|
6198
|
+
|
|
6182
6199
|
// src/compiler/ir-serialize.ts
|
|
6183
6200
|
function childrenOf2(def) {
|
|
6184
6201
|
switch (def.tag) {
|
|
@@ -6195,6 +6212,7 @@ function childrenOf2(def) {
|
|
|
6195
6212
|
case "field":
|
|
6196
6213
|
case "not":
|
|
6197
6214
|
case "node":
|
|
6215
|
+
case "withCtx":
|
|
6198
6216
|
case "expect":
|
|
6199
6217
|
return [def.parser];
|
|
6200
6218
|
case "grammar":
|
|
@@ -6210,7 +6228,6 @@ function childrenOf2(def) {
|
|
|
6210
6228
|
case "regex":
|
|
6211
6229
|
case "keywords":
|
|
6212
6230
|
case "guard":
|
|
6213
|
-
case "withCtx":
|
|
6214
6231
|
case "recover":
|
|
6215
6232
|
case "unknown":
|
|
6216
6233
|
return [];
|
|
@@ -6285,6 +6302,17 @@ function evalRuleMapIR(ir) {
|
|
|
6285
6302
|
c._def.gateSrcs = gateSrcs;
|
|
6286
6303
|
return c;
|
|
6287
6304
|
};
|
|
6305
|
+
const _wc = (src, inner) => {
|
|
6306
|
+
let extra;
|
|
6307
|
+
try {
|
|
6308
|
+
extra = (0, eval)(`(${src})`);
|
|
6309
|
+
} catch {
|
|
6310
|
+
extra = void 0;
|
|
6311
|
+
}
|
|
6312
|
+
const w = withCtx(extra, inner);
|
|
6313
|
+
w._def.extraSrc = src;
|
|
6314
|
+
return w;
|
|
6315
|
+
};
|
|
6288
6316
|
const fn = new Function(
|
|
6289
6317
|
"rules",
|
|
6290
6318
|
"ref",
|
|
@@ -6311,6 +6339,7 @@ function evalRuleMapIR(ir) {
|
|
|
6311
6339
|
"_tf",
|
|
6312
6340
|
"_nd",
|
|
6313
6341
|
"_gch",
|
|
6342
|
+
"_wc",
|
|
6314
6343
|
`return (${ir})`
|
|
6315
6344
|
);
|
|
6316
6345
|
const map = fn(
|
|
@@ -6338,7 +6367,8 @@ function evalRuleMapIR(ir) {
|
|
|
6338
6367
|
expect,
|
|
6339
6368
|
_tf,
|
|
6340
6369
|
_nd,
|
|
6341
|
-
_gch
|
|
6370
|
+
_gch,
|
|
6371
|
+
_wc
|
|
6342
6372
|
);
|
|
6343
6373
|
return Object.entries(map);
|
|
6344
6374
|
}
|
|
@@ -6394,7 +6424,7 @@ ${body}
|
|
|
6394
6424
|
this.analyze(target, active);
|
|
6395
6425
|
return;
|
|
6396
6426
|
}
|
|
6397
|
-
if (def.tag === "guard" || def.tag === "
|
|
6427
|
+
if (def.tag === "guard" || def.tag === "recover" || def.tag === "unknown") {
|
|
6398
6428
|
throw new Unserializable(`unsupported tag ${def.tag}`);
|
|
6399
6429
|
}
|
|
6400
6430
|
this.counts.set(c, (this.counts.get(c) ?? 0) + 1);
|
|
@@ -6503,8 +6533,11 @@ ${body}
|
|
|
6503
6533
|
const trivia2 = def.clearTrivia ? "null" : def.triviaParser ? kid(def.triviaParser) : "undefined";
|
|
6504
6534
|
return `parser({ trivia: ${trivia2}${def.trackLines ? ", trackLines: true" : ""} }, ${kid(def.parser)})`;
|
|
6505
6535
|
}
|
|
6536
|
+
case "withCtx": {
|
|
6537
|
+
if (def.extraSrc === void 0) throw new Unserializable("withCtx without extraSrc");
|
|
6538
|
+
return `_wc(${JSON.stringify(def.extraSrc)}, ${kid(def.parser)})`;
|
|
6539
|
+
}
|
|
6506
6540
|
case "guard":
|
|
6507
|
-
case "withCtx":
|
|
6508
6541
|
case "recover":
|
|
6509
6542
|
case "unknown":
|
|
6510
6543
|
throw new Unserializable(`unsupported tag ${def.tag}`);
|
|
@@ -6678,23 +6711,6 @@ function guard(predicate) {
|
|
|
6678
6711
|
};
|
|
6679
6712
|
}
|
|
6680
6713
|
|
|
6681
|
-
// src/combinators/withCtx.ts
|
|
6682
|
-
function withCtx(extra, combinator) {
|
|
6683
|
-
const meta = {
|
|
6684
|
-
firstSet: combinator._meta.firstSet,
|
|
6685
|
-
canMatchNewline: combinator._meta.canMatchNewline,
|
|
6686
|
-
isTrivia: false
|
|
6687
|
-
};
|
|
6688
|
-
return {
|
|
6689
|
-
_tag: "withCtx",
|
|
6690
|
-
_meta: meta,
|
|
6691
|
-
_def: { tag: "withCtx", extra, parser: combinator },
|
|
6692
|
-
parse(input, pos, ctx) {
|
|
6693
|
-
return combinator.parse(input, pos, { ...ctx, state: extra });
|
|
6694
|
-
}
|
|
6695
|
-
};
|
|
6696
|
-
}
|
|
6697
|
-
|
|
6698
6714
|
// src/combinators/completions.ts
|
|
6699
6715
|
function completionsAt(target, input, offset, options = {}) {
|
|
6700
6716
|
const probe = { offset, best: null };
|