parseman 0.60.6 → 0.61.1
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/analysis/backtrack.d.ts +50 -0
- package/dist/analysis/backtrack.d.ts.map +1 -0
- package/dist/analysis/diagnostics.d.ts +3 -0
- package/dist/analysis/diagnostics.d.ts.map +1 -1
- package/dist/analysis/diagnostics.js +1162 -158
- package/dist/analysis/diagnostics.js.map +3 -3
- package/dist/analysis/rebuild.d.ts +17 -1
- package/dist/analysis/rebuild.d.ts.map +1 -1
- package/dist/cli/index.js +353 -69
- package/dist/cli/index.js.map +3 -3
- package/dist/combinators/choice.d.ts.map +1 -1
- package/dist/combinators/dispatch.d.ts +2 -0
- package/dist/combinators/dispatch.d.ts.map +1 -1
- package/dist/combinators/expect.d.ts.map +1 -1
- package/dist/combinators/link-scope.d.ts +7 -0
- package/dist/combinators/link-scope.d.ts.map +1 -0
- package/dist/combinators/node.d.ts.map +1 -1
- package/dist/combinators/parser.d.ts.map +1 -1
- package/dist/compiler/token-capability.js +1 -0
- package/dist/compiler/token-capability.js.map +1 -1
- package/dist/compiler/value-usage.d.ts.map +1 -1
- package/dist/coverage.d.ts.map +1 -1
- package/dist/functional/run.d.ts.map +1 -1
- package/dist/index.js +121 -90
- package/dist/index.js.map +3 -3
- package/dist/language-service/index.js +1 -1
- package/dist/language-service/index.js.map +1 -1
- package/dist/plugin/index.js +274 -243
- package/dist/plugin/index.js.map +3 -3
- package/dist/run/index.js +1 -1
- package/dist/run/index.js.map +1 -1
- package/dist/spec/index.js.map +1 -1
- package/dist/table/backtrack-probe.d.ts +41 -0
- package/dist/table/backtrack-probe.d.ts.map +1 -0
- package/dist/table/child-slots.d.ts +10 -0
- package/dist/table/child-slots.d.ts.map +1 -1
- package/dist/table/emit.d.ts.map +1 -1
- package/dist/table/index.js +31 -20
- package/dist/table/index.js.map +3 -3
- package/dist/table/program.d.ts +3 -1
- package/dist/table/program.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +5 -1
- package/src/analysis/backtrack.ts +249 -0
- package/src/analysis/diagnostics.ts +4 -0
- package/src/analysis/rebuild.ts +63 -11
- package/src/combinators/choice.ts +3 -1
- package/src/combinators/dispatch.ts +9 -0
- package/src/combinators/expect.ts +1 -0
- package/src/combinators/link-scope.ts +19 -0
- package/src/combinators/node.ts +11 -2
- package/src/combinators/parser.ts +37 -31
- package/src/compiler/value-usage.ts +16 -29
- package/src/coverage.ts +2 -14
- package/src/functional/run.ts +3 -1
- package/src/table/backtrack-probe.ts +326 -0
- package/src/table/child-slots.ts +30 -14
- package/src/table/emit.ts +5 -1
- package/src/table/program.ts +8 -2
- package/src/version.ts +1 -1
package/dist/plugin/index.js
CHANGED
|
@@ -500,15 +500,20 @@ function markUnusedValues(root) {
|
|
|
500
500
|
case "many":
|
|
501
501
|
case "oneOrMore":
|
|
502
502
|
mark(def, consumed);
|
|
503
|
-
visit(def.parser, consumed);
|
|
504
|
-
return;
|
|
505
503
|
case "optional":
|
|
504
|
+
// `optional` returns `inner | null` — no aggregate array/tuple to elide, so
|
|
505
|
+
// it carries no valueUnused flag. Still descend so an inner many/sequence
|
|
506
|
+
// under a node() is analyzed (it benefits even when its optional wrapper
|
|
507
|
+
// doesn't).
|
|
508
|
+
case "label":
|
|
509
|
+
case "trivia":
|
|
510
|
+
case "attempt":
|
|
511
|
+
case "withCtx":
|
|
512
|
+
case "expect":
|
|
506
513
|
visit(def.parser, consumed);
|
|
507
514
|
return;
|
|
508
515
|
case "sequence":
|
|
509
516
|
mark(def, consumed);
|
|
510
|
-
for (const p of def.parsers) visit(p, consumed);
|
|
511
|
-
return;
|
|
512
517
|
case "choice":
|
|
513
518
|
for (const p of def.parsers) visit(p, consumed);
|
|
514
519
|
return;
|
|
@@ -519,22 +524,24 @@ function markUnusedValues(root) {
|
|
|
519
524
|
if (def.otherwise) visit(def.otherwise, consumed);
|
|
520
525
|
return;
|
|
521
526
|
case "node":
|
|
527
|
+
// builds from captured children, NOT the inner parser value.
|
|
528
|
+
case "not":
|
|
529
|
+
case "peek":
|
|
530
|
+
// lookahead — value never observed
|
|
531
|
+
case "token":
|
|
522
532
|
visit(def.parser, false);
|
|
523
533
|
return;
|
|
524
534
|
case "transform":
|
|
525
|
-
|
|
526
|
-
return;
|
|
535
|
+
// the map fn reads the value → always consumed.
|
|
527
536
|
case "field":
|
|
537
|
+
// the field capture records the parsed value → always consumed.
|
|
538
|
+
case "leaf":
|
|
528
539
|
visit(def.parser, true);
|
|
529
540
|
return;
|
|
530
541
|
case "sepBy":
|
|
531
542
|
visit(def.parser, true);
|
|
532
543
|
visit(def.separator, false);
|
|
533
544
|
return;
|
|
534
|
-
case "not":
|
|
535
|
-
case "peek":
|
|
536
|
-
visit(def.parser, false);
|
|
537
|
-
return;
|
|
538
545
|
case "grammar":
|
|
539
546
|
visit(def.parser, consumed);
|
|
540
547
|
if (def.triviaParser) visit(def.triviaParser, false);
|
|
@@ -543,19 +550,6 @@ function markUnusedValues(root) {
|
|
|
543
550
|
visit(def.parser, consumed);
|
|
544
551
|
visit(def.sentinel, false);
|
|
545
552
|
return;
|
|
546
|
-
case "token":
|
|
547
|
-
visit(def.parser, false);
|
|
548
|
-
return;
|
|
549
|
-
case "label":
|
|
550
|
-
case "trivia":
|
|
551
|
-
case "attempt":
|
|
552
|
-
case "withCtx":
|
|
553
|
-
case "expect":
|
|
554
|
-
visit(def.parser, consumed);
|
|
555
|
-
return;
|
|
556
|
-
case "leaf":
|
|
557
|
-
visit(def.parser, true);
|
|
558
|
-
return;
|
|
559
553
|
case "lazy":
|
|
560
554
|
return;
|
|
561
555
|
default:
|
|
@@ -585,6 +579,21 @@ function markUnusedValues(root) {
|
|
|
585
579
|
visit(resolveRoot(root), true);
|
|
586
580
|
}
|
|
587
581
|
|
|
582
|
+
// src/combinators/link-scope.ts
|
|
583
|
+
var scope;
|
|
584
|
+
function afterLink(settle) {
|
|
585
|
+
scope?.push(settle);
|
|
586
|
+
}
|
|
587
|
+
function collectAfterLink(pending, build) {
|
|
588
|
+
const outer = scope;
|
|
589
|
+
scope = outer ?? pending;
|
|
590
|
+
try {
|
|
591
|
+
return build();
|
|
592
|
+
} finally {
|
|
593
|
+
scope = outer;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
588
597
|
// src/line-index.ts
|
|
589
598
|
import { PlainLineSpan, PlainSpan } from "../cst/plain.js";
|
|
590
599
|
function createLineIndex() {
|
|
@@ -1992,6 +2001,7 @@ function linkRules(recipes, link) {
|
|
|
1992
2001
|
}
|
|
1993
2002
|
});
|
|
1994
2003
|
const winners = /* @__PURE__ */ new Map();
|
|
2004
|
+
const afterLink2 = [];
|
|
1995
2005
|
const priorHoles = /* @__PURE__ */ new Map();
|
|
1996
2006
|
const prior = new Proxy({}, {
|
|
1997
2007
|
get(_target, key) {
|
|
@@ -2004,38 +2014,42 @@ function linkRules(recipes, link) {
|
|
|
2004
2014
|
return hole;
|
|
2005
2015
|
}
|
|
2006
2016
|
});
|
|
2007
|
-
for (const recipe of recipes) {
|
|
2008
|
-
const definitions = recipe.factory(proxy, prior);
|
|
2009
|
-
for (const key of Object.keys(definitions)) {
|
|
2010
|
-
winners.set(key, { parser: definitions[key], options: recipe.options });
|
|
2011
|
-
}
|
|
2012
|
-
}
|
|
2013
|
-
const keys = [...winners.keys()];
|
|
2014
2017
|
const copies = /* @__PURE__ */ new Map();
|
|
2015
|
-
|
|
2016
|
-
const
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
placeholder
|
|
2024
|
-
|
|
2025
|
-
placeholder
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2018
|
+
try {
|
|
2019
|
+
for (const recipe of recipes) {
|
|
2020
|
+
const definitions = collectAfterLink(afterLink2, () => recipe.factory(proxy, prior));
|
|
2021
|
+
for (const key of Object.keys(definitions)) {
|
|
2022
|
+
winners.set(key, { parser: definitions[key], options: recipe.options });
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
for (const [key, { parser: defined }] of winners) {
|
|
2026
|
+
const placeholder = cache[key];
|
|
2027
|
+
const parser2 = ownRule(defined, copies);
|
|
2028
|
+
if (placeholder === parser2) {
|
|
2029
|
+
throw new Error(`rules(): rule "${key}" cannot be a direct alias to itself`);
|
|
2030
|
+
}
|
|
2031
|
+
if (isDefinableRef(placeholder)) {
|
|
2032
|
+
if (!isNamedRuleRefForAnotherRule(parser2, key)) tagRule(parser2, key);
|
|
2033
|
+
placeholder.define(parser2);
|
|
2034
|
+
placeholder._meta.firstSet = parser2._meta.firstSet;
|
|
2035
|
+
placeholder._meta.canMatchNewline = parser2._meta.canMatchNewline;
|
|
2036
|
+
} else if (isNamedRuleRefForAnotherRule(parser2, key) || link !== void 0) {
|
|
2037
|
+
if (!isNamedRuleRefForAnotherRule(parser2, key)) tagRule(parser2, key);
|
|
2038
|
+
const alias = ref();
|
|
2039
|
+
tagRule(alias, key);
|
|
2040
|
+
alias.define(parser2);
|
|
2041
|
+
alias._meta.firstSet = parser2._meta.firstSet;
|
|
2042
|
+
alias._meta.canMatchNewline = parser2._meta.canMatchNewline;
|
|
2043
|
+
cache[key] = alias;
|
|
2044
|
+
} else {
|
|
2045
|
+
tagRule(parser2, key);
|
|
2046
|
+
cache[key] = parser2;
|
|
2047
|
+
}
|
|
2037
2048
|
}
|
|
2049
|
+
} finally {
|
|
2050
|
+
for (const settle of afterLink2) settle();
|
|
2038
2051
|
}
|
|
2052
|
+
const keys = [...winners.keys()];
|
|
2039
2053
|
for (const key of keys) {
|
|
2040
2054
|
const options = winners.get(key).options;
|
|
2041
2055
|
let rule = cache[key];
|
|
@@ -3742,6 +3756,7 @@ function derive(c, seen) {
|
|
|
3742
3756
|
case "optional":
|
|
3743
3757
|
case "many":
|
|
3744
3758
|
case "oneOrMore":
|
|
3759
|
+
case "sepBy":
|
|
3745
3760
|
case "transform":
|
|
3746
3761
|
case "not":
|
|
3747
3762
|
case "peek":
|
|
@@ -3889,7 +3904,7 @@ function choice(...args) {
|
|
|
3889
3904
|
const result = parsers[idx].parse(input, pos, ctx);
|
|
3890
3905
|
if (result.ok) return result;
|
|
3891
3906
|
expected.push(...result.expected);
|
|
3892
|
-
if (result.committed) return { ok: false, expected, span:
|
|
3907
|
+
if (result.committed) return { ok: false, expected, span: result.span, committed: true };
|
|
3893
3908
|
return { ok: false, expected, span: { start: pos, end: pos } };
|
|
3894
3909
|
}
|
|
3895
3910
|
if (ctx._probe !== void 0 || ctx._tolerant) for (const p of parsers) p.parse(input, pos, ctx);
|
|
@@ -5283,8 +5298,14 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
5283
5298
|
const def = unwrap || collapse || project !== void 0 || captureTrivia || trailingTrivia || buildArity !== void 0 || tags !== void 0 && tags.length > 0 ? { ...baseDef, ...unwrap ? { unwrap: true } : {}, ...collapse ? { collapse: true } : {}, ...project !== void 0 ? { project } : {}, ...captureTrivia ? { captureTrivia: true } : {}, ...trailingTrivia ? { trailingTrivia: true } : {}, ...buildArity !== void 0 ? { buildArity } : {}, ...tags !== void 0 && tags.length > 0 ? { tags } : {} } : baseDef;
|
|
5284
5299
|
const capturesTrivia = captureTrivia || (build ? buildReadsTrivia(def) : project === void 0);
|
|
5285
5300
|
const readsState = build ? buildReadsState(def) : project === void 0;
|
|
5286
|
-
|
|
5287
|
-
|
|
5301
|
+
let hasOwnFields = parserHasOwnFields(combinator);
|
|
5302
|
+
let capturesFields = hasOwnFields && (build ? buildReadsFields(def) : project === void 0);
|
|
5303
|
+
if (!hasOwnFields) {
|
|
5304
|
+
afterLink(() => {
|
|
5305
|
+
hasOwnFields = parserHasOwnFields(combinator);
|
|
5306
|
+
capturesFields = hasOwnFields && (build ? buildReadsFields(def) : project === void 0);
|
|
5307
|
+
});
|
|
5308
|
+
}
|
|
5288
5309
|
const guardable = combinator._meta.firstSet.kind !== "any" && !matchesEmpty(combinator);
|
|
5289
5310
|
let failExpected;
|
|
5290
5311
|
return {
|
|
@@ -5597,6 +5618,9 @@ function sourceLeaf(root, fn) {
|
|
|
5597
5618
|
return makeLeaf(root, fn, true);
|
|
5598
5619
|
}
|
|
5599
5620
|
|
|
5621
|
+
// src/version.ts
|
|
5622
|
+
var PARSEMAN_VERSION = "0.61.1";
|
|
5623
|
+
|
|
5600
5624
|
// src/table/lex-body.ts
|
|
5601
5625
|
function buildLexBodyRecognizer(spec, constants) {
|
|
5602
5626
|
const raw = constants[spec[0]];
|
|
@@ -6212,11 +6236,12 @@ function assemblyExtraIps(prog) {
|
|
|
6212
6236
|
}
|
|
6213
6237
|
function expandCompact(p) {
|
|
6214
6238
|
if ("code" in p) return p;
|
|
6239
|
+
if (p.es === void 0) throw new Error(`parseman: this parser was printed by an earlier parseman; reprint it with parseman ${PARSEMAN_VERSION}`);
|
|
6215
6240
|
return ownTableProgram({
|
|
6216
6241
|
code: p.c,
|
|
6217
6242
|
k: p.k,
|
|
6218
6243
|
cc: p.x,
|
|
6219
|
-
fx: p.e,
|
|
6244
|
+
fx: p.e.map((set) => set.map((i) => p.es[i])),
|
|
6220
6245
|
disp: p.d,
|
|
6221
6246
|
rules: p.r,
|
|
6222
6247
|
fns: p.f,
|
|
@@ -7279,7 +7304,7 @@ function selectOptionalSuffixLexBody(ir) {
|
|
|
7279
7304
|
function reinstallsRuleTrivia(reference, target) {
|
|
7280
7305
|
return (reference._meta.grammarTrivia ?? target._meta.grammarTrivia) !== void 0 && hasOwnTriviaBoundary(target);
|
|
7281
7306
|
}
|
|
7282
|
-
function directTokenBodyParser(parser2, resolve3,
|
|
7307
|
+
function directTokenBodyParser(parser2, resolve3, scope2) {
|
|
7283
7308
|
const outer = parser2._def;
|
|
7284
7309
|
if (outer.tag !== "token") return void 0;
|
|
7285
7310
|
let body = outer.parser;
|
|
@@ -7289,7 +7314,7 @@ function directTokenBodyParser(parser2, resolve3, scope) {
|
|
|
7289
7314
|
const wrapper = body._def;
|
|
7290
7315
|
if (wrapper.tag === "grammar") {
|
|
7291
7316
|
if (wrapper.clearTrivia !== true || wrapper.triviaParser !== void 0 || wrapper.captureTrivia === true || wrapper.rootCapture === "opaque" || wrapper.constructionTrackLines !== "inherit" || wrapper.constructionCaptureTriviaKinds !== void 0) return void 0;
|
|
7292
|
-
if (
|
|
7317
|
+
if (scope2 !== void 0) scope2.cleared = true;
|
|
7293
7318
|
body = wrapper.parser;
|
|
7294
7319
|
continue;
|
|
7295
7320
|
}
|
|
@@ -7546,10 +7571,10 @@ function directFixedLexNode(parser2, resolve3, active, pureOnly = false, cleared
|
|
|
7546
7571
|
}
|
|
7547
7572
|
}
|
|
7548
7573
|
function directFixedTokenBody(parser2, resolve3) {
|
|
7549
|
-
const
|
|
7550
|
-
const body = directTokenBodyParser(parser2, resolve3,
|
|
7574
|
+
const scope2 = { cleared: false };
|
|
7575
|
+
const body = directTokenBodyParser(parser2, resolve3, scope2);
|
|
7551
7576
|
if (body === void 0) return void 0;
|
|
7552
|
-
const root = directFixedLexNode(body, resolve3, /* @__PURE__ */ new Set(), false,
|
|
7577
|
+
const root = directFixedLexNode(body, resolve3, /* @__PURE__ */ new Set(), false, scope2.cleared);
|
|
7553
7578
|
return root === void 0 ? void 0 : { kind: "fixed-tree", root };
|
|
7554
7579
|
}
|
|
7555
7580
|
function directBalancedTokenBody(parser2, resolve3) {
|
|
@@ -10403,6 +10428,12 @@ function emitShapeMatch(shape, start, mint, ind, firstChar) {
|
|
|
10403
10428
|
|
|
10404
10429
|
// src/table/child-slots.ts
|
|
10405
10430
|
function childSlots(code, ip, out) {
|
|
10431
|
+
const from = out.length;
|
|
10432
|
+
if (!childSlotOffsets(code, ip, out)) return false;
|
|
10433
|
+
for (let i = from; i < out.length; i++) out[i] = code[out[i]];
|
|
10434
|
+
return true;
|
|
10435
|
+
}
|
|
10436
|
+
function childSlotOffsets(code, ip, out) {
|
|
10406
10437
|
switch (code[ip]) {
|
|
10407
10438
|
// ZERO-WIDTH / TERMINAL ROWS — no successor. `OP_GUARD` and `OP_ADJ` are both
|
|
10408
10439
|
// childless tests. `OP_LIVE` holds a hand-written combinator in `prog.fns`; its
|
|
@@ -10435,7 +10466,7 @@ function childSlots(code, ip, out) {
|
|
|
10435
10466
|
case OP_COV:
|
|
10436
10467
|
case OP_REJECT:
|
|
10437
10468
|
case OP_GAPGATE:
|
|
10438
|
-
out.push(
|
|
10469
|
+
out.push(ip + 1);
|
|
10439
10470
|
return true;
|
|
10440
10471
|
// Single child at `ip + 2`.
|
|
10441
10472
|
case OP_GATE:
|
|
@@ -10452,55 +10483,55 @@ function childSlots(code, ip, out) {
|
|
|
10452
10483
|
case OP_ARMGATE:
|
|
10453
10484
|
case OP_RGATE:
|
|
10454
10485
|
case OP_RGATE2:
|
|
10455
|
-
out.push(
|
|
10486
|
+
out.push(ip + 2);
|
|
10456
10487
|
return true;
|
|
10457
10488
|
// `STRICT strict tolerant` — both encodings are reachable; an assembly keeps one.
|
|
10458
10489
|
case OP_STRICT:
|
|
10459
|
-
out.push(
|
|
10490
|
+
out.push(ip + 1, ip + 2);
|
|
10460
10491
|
return true;
|
|
10461
10492
|
// `ROUTED fallback` — the operand is an offset or −1. The routed token itself is
|
|
10462
10493
|
// data the enclosing `dispatch()` already consumed, so the only edge is the
|
|
10463
10494
|
// fallback.
|
|
10464
10495
|
case OP_ROUTED:
|
|
10465
|
-
if (code[ip + 1] >= 0) out.push(
|
|
10496
|
+
if (code[ip + 1] >= 0) out.push(ip + 1);
|
|
10466
10497
|
return true;
|
|
10467
10498
|
// `DISPATCH sel d other otherRouted n a1 … an` — the SELECTOR is a child on
|
|
10468
10499
|
// exactly the same footing as the arms: it runs inside whatever node and scope
|
|
10469
10500
|
// this site sits in.
|
|
10470
10501
|
case OP_DISPATCH: {
|
|
10471
|
-
out.push(
|
|
10472
|
-
if (code[ip + 3] >= 0) out.push(
|
|
10502
|
+
out.push(ip + 1);
|
|
10503
|
+
if (code[ip + 3] >= 0) out.push(ip + 3);
|
|
10473
10504
|
const n = code[ip + 5];
|
|
10474
|
-
for (let i = 0; i < n; i++) out.push(
|
|
10505
|
+
for (let i = 0; i < n; i++) out.push(ip + 6 + i);
|
|
10475
10506
|
return true;
|
|
10476
10507
|
}
|
|
10477
10508
|
case OP_SEQ:
|
|
10478
10509
|
case OP_SEQV: {
|
|
10479
10510
|
const n = code[ip + 1];
|
|
10480
|
-
for (let i = 0; i < n; i++) out.push(
|
|
10511
|
+
for (let i = 0; i < n; i++) out.push(ip + 2 + i);
|
|
10481
10512
|
return true;
|
|
10482
10513
|
}
|
|
10483
10514
|
case OP_SEQX: {
|
|
10484
10515
|
const n = code[ip + 2];
|
|
10485
|
-
for (let i = 0; i < n; i++) out.push(
|
|
10516
|
+
for (let i = 0; i < n; i++) out.push(ip + 3 + i);
|
|
10486
10517
|
return true;
|
|
10487
10518
|
}
|
|
10488
10519
|
case OP_CHOICE: {
|
|
10489
10520
|
const n = code[ip + 2];
|
|
10490
|
-
for (let i = 0; i < n; i++) out.push(
|
|
10521
|
+
for (let i = 0; i < n; i++) out.push(ip + 4 + i);
|
|
10491
10522
|
return true;
|
|
10492
10523
|
}
|
|
10493
10524
|
// Arms are stride-2 from `ip + 4` — the gate word sits beside each arm offset.
|
|
10494
10525
|
case OP_GREEDY: {
|
|
10495
|
-
out.push(
|
|
10526
|
+
out.push(ip + 1);
|
|
10496
10527
|
const n = code[ip + 2];
|
|
10497
|
-
for (let i = 0; i < n; i++) out.push(
|
|
10528
|
+
for (let i = 0; i < n; i++) out.push(ip + 4 + 2 * i);
|
|
10498
10529
|
return true;
|
|
10499
10530
|
}
|
|
10500
10531
|
case OP_REP:
|
|
10501
10532
|
case OP_REPV:
|
|
10502
|
-
out.push(
|
|
10503
|
-
if (code[ip + 4] >= 0) out.push(
|
|
10533
|
+
out.push(ip + 1);
|
|
10534
|
+
if (code[ip + 4] >= 0) out.push(ip + 4);
|
|
10504
10535
|
return true;
|
|
10505
10536
|
default:
|
|
10506
10537
|
return false;
|
|
@@ -13545,9 +13576,6 @@ function clearOf(ranges, input, from, to) {
|
|
|
13545
13576
|
return true;
|
|
13546
13577
|
}
|
|
13547
13578
|
|
|
13548
|
-
// src/version.ts
|
|
13549
|
-
var PARSEMAN_VERSION = "0.60.6";
|
|
13550
|
-
|
|
13551
13579
|
// src/table/assemble.ts
|
|
13552
13580
|
import { PlainBuf as PlainBuf2, PlainField, PlainLeaf as PlainLeaf9, PlainNode as PlainNode2, PlainSpan as PlainSpan10 } from "../cst/plain.js";
|
|
13553
13581
|
|
|
@@ -17566,12 +17594,15 @@ function assertPrintable(prog, who) {
|
|
|
17566
17594
|
}
|
|
17567
17595
|
}
|
|
17568
17596
|
function programFields(prog, fns, opts = {}) {
|
|
17597
|
+
const tokens = [...new Set(prog.fx.flat())];
|
|
17598
|
+
const tokenAt = new Map(tokens.map((token2, i) => [token2, i]));
|
|
17569
17599
|
return [
|
|
17570
17600
|
...emitAssemblies(prog, opts.assemblies ?? []),
|
|
17571
17601
|
`c:[${prog.code.join(",")}],`,
|
|
17572
17602
|
`k:[${prog.k.map(emitConst).join(",")}],`,
|
|
17573
17603
|
`x:${emitClassPool(prog.cc)},`,
|
|
17574
|
-
`e:[${prog.fx.map((f) => `[${f.map(
|
|
17604
|
+
`e:[${prog.fx.map((f) => `[${f.map((token2) => tokenAt.get(token2)).join(",")}]`).join(",")}],`,
|
|
17605
|
+
`es:[${tokens.map(jsString).join(",")}],`,
|
|
17575
17606
|
`d:[${prog.disp.map((a) => `[${a.join(",")}]`).join(",")}],`,
|
|
17576
17607
|
`r:${JSON.stringify(prog.rules)},`,
|
|
17577
17608
|
...prog.lines === 1 ? ["l:1,"] : [],
|
|
@@ -20344,7 +20375,7 @@ function runOnce(entry, input, options) {
|
|
|
20344
20375
|
const r = invoke(entry, input, 0, ctx);
|
|
20345
20376
|
const value = r.ok ? r.value : void 0;
|
|
20346
20377
|
let span = r.span ?? { start: 0, end: 0 };
|
|
20347
|
-
const expected = r.ok ? [] : r.expected ?? [];
|
|
20378
|
+
const expected = r.ok ? [] : [...new Set(r.expected ?? [])];
|
|
20348
20379
|
let unconsumedFrom = null;
|
|
20349
20380
|
if (r.ok) {
|
|
20350
20381
|
let pos = span.end;
|
|
@@ -20757,12 +20788,12 @@ function isWhenFactory(v) {
|
|
|
20757
20788
|
function isStaticValueEntry(v) {
|
|
20758
20789
|
return !!v && typeof v === "object" && "value" in v && "mfSrcs" in v;
|
|
20759
20790
|
}
|
|
20760
|
-
function wordFactoryFromArgs(args,
|
|
20791
|
+
function wordFactoryFromArgs(args, scope2, code, mfs) {
|
|
20761
20792
|
const [boundaryOrOptsArg, optsArg] = args;
|
|
20762
20793
|
if (boundaryOrOptsArg?.type === "SpreadElement" || optsArg?.type === "SpreadElement") return null;
|
|
20763
|
-
const rawBoundaryOrOpts = boundaryOrOptsArg === void 0 ? void 0 : anyValue(boundaryOrOptsArg,
|
|
20794
|
+
const rawBoundaryOrOpts = boundaryOrOptsArg === void 0 ? void 0 : anyValue(boundaryOrOptsArg, scope2, code, mfs);
|
|
20764
20795
|
const boundaryOrOpts = rawBoundaryOrOpts === void 0 ? "_0-9A-Za-z" : rawBoundaryOrOpts;
|
|
20765
|
-
const opts = optsArg === void 0 ? void 0 : anyValue(optsArg,
|
|
20796
|
+
const opts = optsArg === void 0 ? void 0 : anyValue(optsArg, scope2, code, mfs);
|
|
20766
20797
|
if (typeof boundaryOrOpts === "string") {
|
|
20767
20798
|
if (opts !== void 0 && (typeof opts !== "object" || opts === null || Array.isArray(opts))) return null;
|
|
20768
20799
|
const caseInsensitive2 = typeof opts === "object" && opts !== null && "caseInsensitive" in opts ? opts.caseInsensitive : false;
|
|
@@ -20786,10 +20817,10 @@ function dispatchWhenOptions(v) {
|
|
|
20786
20817
|
if (typeof caseInsensitive !== "boolean") return null;
|
|
20787
20818
|
return { caseInsensitive };
|
|
20788
20819
|
}
|
|
20789
|
-
function whenFactoryFromArgs(args,
|
|
20820
|
+
function whenFactoryFromArgs(args, scope2, code, mfs) {
|
|
20790
20821
|
const [optsArg, extra] = args;
|
|
20791
20822
|
if (optsArg?.type === "SpreadElement" || extra !== void 0) return null;
|
|
20792
|
-
const rawOpts = optsArg === void 0 ? void 0 : anyValue(optsArg,
|
|
20823
|
+
const rawOpts = optsArg === void 0 ? void 0 : anyValue(optsArg, scope2, code, mfs);
|
|
20793
20824
|
const opts = dispatchWhenOptions(rawOpts);
|
|
20794
20825
|
return opts === null ? null : { tag: "whenFactory", caseInsensitive: opts.caseInsensitive ?? false };
|
|
20795
20826
|
}
|
|
@@ -20861,20 +20892,20 @@ function gatedArmParts(e) {
|
|
|
20861
20892
|
}
|
|
20862
20893
|
return gate2 && combinator ? { gate: gate2, combinator } : null;
|
|
20863
20894
|
}
|
|
20864
|
-
function dispatchArmValue(node2,
|
|
20895
|
+
function dispatchArmValue(node2, scope2, code, mfs) {
|
|
20865
20896
|
if (node2.type === "Identifier") {
|
|
20866
|
-
const value = anyValue(node2,
|
|
20897
|
+
const value = anyValue(node2, scope2, code, mfs);
|
|
20867
20898
|
return isDispatchArm(value) ? value : null;
|
|
20868
20899
|
}
|
|
20869
20900
|
if (node2.type !== "CallExpression") return null;
|
|
20870
20901
|
const callee = node2.callee;
|
|
20871
20902
|
if (callee.type !== "Identifier") return null;
|
|
20872
|
-
const factory =
|
|
20903
|
+
const factory = scope2.get(callee.name);
|
|
20873
20904
|
if (isWhenFactory(factory)) {
|
|
20874
20905
|
const [keyArg, parserArg, extraArg] = node2.arguments;
|
|
20875
20906
|
if (!keyArg || !parserArg || extraArg !== void 0 || keyArg.type === "SpreadElement" || parserArg.type === "SpreadElement") return null;
|
|
20876
|
-
const key = anyValue(keyArg,
|
|
20877
|
-
const parserValue = anyValue(parserArg,
|
|
20907
|
+
const key = anyValue(keyArg, scope2, code, mfs);
|
|
20908
|
+
const parserValue = anyValue(parserArg, scope2, code, mfs);
|
|
20878
20909
|
if (!isCombinator3(parserValue)) return null;
|
|
20879
20910
|
const opts = { caseInsensitive: factory.caseInsensitive };
|
|
20880
20911
|
if (typeof key === "string") return when(key, parserValue, opts);
|
|
@@ -20885,10 +20916,10 @@ function dispatchArmValue(node2, scope, code, mfs) {
|
|
|
20885
20916
|
if (callee.name === "otherwise") {
|
|
20886
20917
|
const [parserArg, optsArg] = node2.arguments;
|
|
20887
20918
|
if (!parserArg || parserArg.type === "SpreadElement" || optsArg?.type === "SpreadElement") return null;
|
|
20888
|
-
const parserValue = anyValue(parserArg,
|
|
20919
|
+
const parserValue = anyValue(parserArg, scope2, code, mfs);
|
|
20889
20920
|
if (!isCombinator3(parserValue)) return null;
|
|
20890
20921
|
if (optsArg === void 0) return otherwise(parserValue);
|
|
20891
|
-
const opts = anyValue(optsArg,
|
|
20922
|
+
const opts = anyValue(optsArg, scope2, code, mfs);
|
|
20892
20923
|
if (typeof opts !== "object" || opts === null) return null;
|
|
20893
20924
|
const commit = opts.commit;
|
|
20894
20925
|
if (commit !== void 0 && typeof commit !== "boolean") return null;
|
|
@@ -20897,9 +20928,9 @@ function dispatchArmValue(node2, scope, code, mfs) {
|
|
|
20897
20928
|
if (callee.name === "when") {
|
|
20898
20929
|
const [keyArg, parserArg, optsArg] = node2.arguments;
|
|
20899
20930
|
if (!keyArg || !parserArg || keyArg.type === "SpreadElement" || parserArg.type === "SpreadElement" || optsArg?.type === "SpreadElement") return null;
|
|
20900
|
-
const key = anyValue(keyArg,
|
|
20901
|
-
const parserValue = anyValue(parserArg,
|
|
20902
|
-
const opts = dispatchWhenOptions(optsArg === void 0 ? void 0 : anyValue(optsArg,
|
|
20931
|
+
const key = anyValue(keyArg, scope2, code, mfs);
|
|
20932
|
+
const parserValue = anyValue(parserArg, scope2, code, mfs);
|
|
20933
|
+
const opts = dispatchWhenOptions(optsArg === void 0 ? void 0 : anyValue(optsArg, scope2, code, mfs));
|
|
20903
20934
|
if (opts === null) return null;
|
|
20904
20935
|
if (!isCombinator3(parserValue)) return null;
|
|
20905
20936
|
if (typeof key === "string") return when(key, parserValue, opts);
|
|
@@ -20926,8 +20957,8 @@ function isDispatchMatcher(v) {
|
|
|
20926
20957
|
if ((rec.kind === "startsWith" || rec.kind === "endsWith") && typeof rec.value === "string") return true;
|
|
20927
20958
|
return rec.kind === "matches" && typeof rec.value === "string" && typeof rec.flags === "string";
|
|
20928
20959
|
}
|
|
20929
|
-
function scopeGet(
|
|
20930
|
-
const entry =
|
|
20960
|
+
function scopeGet(scope2, name, mfs) {
|
|
20961
|
+
const entry = scope2.get(name);
|
|
20931
20962
|
if (!entry) return null;
|
|
20932
20963
|
if (isScopeEntry(entry)) {
|
|
20933
20964
|
if (mfs && entry.mfSrcs.length > 0) mfs.push(...entry.mfSrcs);
|
|
@@ -20948,10 +20979,10 @@ function staticLiteralValue(expr) {
|
|
|
20948
20979
|
const val = unwrapStaticExpr(expr);
|
|
20949
20980
|
return val.type === "Literal" || val.type === "BooleanLiteral" || val.type === "NumericLiteral" ? val.value : void 0;
|
|
20950
20981
|
}
|
|
20951
|
-
function staticStringArray(expr,
|
|
20982
|
+
function staticStringArray(expr, scope2) {
|
|
20952
20983
|
const id = unwrapStaticExpr(expr);
|
|
20953
|
-
if (id.type === "Identifier" &&
|
|
20954
|
-
const scoped =
|
|
20984
|
+
if (id.type === "Identifier" && scope2 !== void 0 && id.name !== void 0) {
|
|
20985
|
+
const scoped = scope2.get(id.name);
|
|
20955
20986
|
const value = isStaticValueEntry(scoped) ? scoped.value : scoped;
|
|
20956
20987
|
return Array.isArray(value) && value.every((v) => typeof v === "string") ? value : void 0;
|
|
20957
20988
|
}
|
|
@@ -20976,11 +21007,11 @@ function staticNodeProject(expr) {
|
|
|
20976
21007
|
if (typeof literalValue === "number" || literalValue !== void 0) return { ok: false };
|
|
20977
21008
|
return { ok: false };
|
|
20978
21009
|
}
|
|
20979
|
-
function scopedStaticValue(expr,
|
|
21010
|
+
function scopedStaticValue(expr, scope2) {
|
|
20980
21011
|
const unwrapped = unwrapStaticExpr(expr);
|
|
20981
21012
|
if (unwrapped.type !== "Identifier" || unwrapped.name === "undefined") return { found: false };
|
|
20982
|
-
if (!
|
|
20983
|
-
const scoped =
|
|
21013
|
+
if (!scope2.has(unwrapped.name)) return { found: false };
|
|
21014
|
+
const scoped = scope2.get(unwrapped.name);
|
|
20984
21015
|
const value = isStaticValueEntry(scoped) ? scoped.value : scoped;
|
|
20985
21016
|
return { found: true, value };
|
|
20986
21017
|
}
|
|
@@ -21006,9 +21037,9 @@ function staticNodeOptionsFromValue(value) {
|
|
|
21006
21037
|
}
|
|
21007
21038
|
return opts.unwrap || opts.collapse || opts.project !== void 0 || opts.captureTrivia || opts.trailingTrivia || opts.tags !== void 0 || opts.buildArity !== void 0 ? opts : void 0;
|
|
21008
21039
|
}
|
|
21009
|
-
function staticNodeOptions(expr,
|
|
21040
|
+
function staticNodeOptions(expr, scope2) {
|
|
21010
21041
|
const unwrapped = unwrapStaticExpr(expr);
|
|
21011
|
-
const scoped = scopedStaticValue(unwrapped,
|
|
21042
|
+
const scoped = scopedStaticValue(unwrapped, scope2);
|
|
21012
21043
|
if (scoped.found) return staticNodeOptionsFromValue(scoped.value);
|
|
21013
21044
|
if (unwrapped.type !== "ObjectExpression") return STATIC_NODE_OPTIONS_NOT_OPTIONS;
|
|
21014
21045
|
const opts = {};
|
|
@@ -21026,7 +21057,7 @@ function staticNodeOptions(expr, scope) {
|
|
|
21026
21057
|
if (project?.ok === false) return STATIC_NODE_OPTIONS_FAILED;
|
|
21027
21058
|
if (project !== void 0) opts.project = project.value;
|
|
21028
21059
|
} else if (name === "tags") {
|
|
21029
|
-
const tags = staticStringArray(p.value,
|
|
21060
|
+
const tags = staticStringArray(p.value, scope2);
|
|
21030
21061
|
if (tags === void 0) return STATIC_NODE_OPTIONS_FAILED;
|
|
21031
21062
|
opts.tags = tags;
|
|
21032
21063
|
} else if (name === "buildArity") {
|
|
@@ -21038,21 +21069,21 @@ function staticNodeOptions(expr, scope) {
|
|
|
21038
21069
|
return opts.unwrap || opts.collapse || opts.project !== void 0 || opts.captureTrivia || opts.trailingTrivia || opts.tags !== void 0 || opts.buildArity !== void 0 ? opts : void 0;
|
|
21039
21070
|
}
|
|
21040
21071
|
var UNKNOWN_OPTIONS = /* @__PURE__ */ Symbol("parseman.unknownOptions");
|
|
21041
|
-
function scanOptions(optsArg,
|
|
21072
|
+
function scanOptions(optsArg, scope2, code) {
|
|
21042
21073
|
if (optsArg === void 0) return void 0;
|
|
21043
21074
|
if (optsArg.type === "SpreadElement") return UNKNOWN_OPTIONS;
|
|
21044
|
-
const opts = anyValue(optsArg,
|
|
21045
|
-
return isHole(optsArg, opts,
|
|
21075
|
+
const opts = anyValue(optsArg, scope2, code, []);
|
|
21076
|
+
return isHole(optsArg, opts, scope2) ? UNKNOWN_OPTIONS : opts;
|
|
21046
21077
|
}
|
|
21047
|
-
function exprToCombi(node2,
|
|
21048
|
-
if (node2.type === "Identifier") return scopeGet(
|
|
21078
|
+
function exprToCombi(node2, scope2, code, mfs) {
|
|
21079
|
+
if (node2.type === "Identifier") return scopeGet(scope2, node2.name, mfs);
|
|
21049
21080
|
if (node2.type !== "CallExpression") return null;
|
|
21050
21081
|
const callee = node2.callee;
|
|
21051
21082
|
if (callee.type === "CallExpression" && callee.callee.type === "Identifier" && callee.callee.name === "makeWord") {
|
|
21052
21083
|
const strArg = node2.arguments[0];
|
|
21053
21084
|
if (!strArg || strArg.type === "SpreadElement") return null;
|
|
21054
|
-
const factory2 = wordFactoryFromArgs(callee.arguments,
|
|
21055
|
-
const str = anyValue(strArg,
|
|
21085
|
+
const factory2 = wordFactoryFromArgs(callee.arguments, scope2, code, mfs);
|
|
21086
|
+
const str = anyValue(strArg, scope2, code, mfs);
|
|
21056
21087
|
if (factory2 === null || typeof str !== "string") return null;
|
|
21057
21088
|
try {
|
|
21058
21089
|
return word(str, factory2.boundary, { caseInsensitive: factory2.caseInsensitive });
|
|
@@ -21061,11 +21092,11 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21061
21092
|
}
|
|
21062
21093
|
}
|
|
21063
21094
|
if (callee.type === "Identifier") {
|
|
21064
|
-
const factory2 =
|
|
21095
|
+
const factory2 = scope2.get(callee.name);
|
|
21065
21096
|
if (isWordFactory(factory2)) {
|
|
21066
21097
|
const [strArg] = node2.arguments;
|
|
21067
21098
|
if (!strArg || strArg.type === "SpreadElement") return null;
|
|
21068
|
-
const str = anyValue(strArg,
|
|
21099
|
+
const str = anyValue(strArg, scope2, code, mfs);
|
|
21069
21100
|
if (typeof str !== "string") return null;
|
|
21070
21101
|
try {
|
|
21071
21102
|
return word(str, factory2.boundary, { caseInsensitive: factory2.caseInsensitive });
|
|
@@ -21078,7 +21109,7 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21078
21109
|
if (callee.name === "transform" && code !== void 0 && mfs !== void 0) {
|
|
21079
21110
|
const [parserArg, fnArg] = node2.arguments;
|
|
21080
21111
|
if (!parserArg || !fnArg || parserArg.type === "SpreadElement" || fnArg.type === "SpreadElement") return null;
|
|
21081
|
-
const inner = anyValue(parserArg,
|
|
21112
|
+
const inner = anyValue(parserArg, scope2, code, mfs);
|
|
21082
21113
|
if (!isCombinator3(inner)) return null;
|
|
21083
21114
|
const fnSrc = stripTsFromSource(fnArg, code);
|
|
21084
21115
|
mfs.push(fnSrc);
|
|
@@ -21093,7 +21124,7 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21093
21124
|
if ((callee.name === "leaf" || callee.name === "sourceLeaf") && code !== void 0 && mfs !== void 0) {
|
|
21094
21125
|
const [parserArg, fnArg] = node2.arguments;
|
|
21095
21126
|
if (!parserArg || !fnArg || parserArg.type === "SpreadElement" || fnArg.type === "SpreadElement") return null;
|
|
21096
|
-
const inner = anyValue(parserArg,
|
|
21127
|
+
const inner = anyValue(parserArg, scope2, code, mfs);
|
|
21097
21128
|
if (!isCombinator3(inner)) return null;
|
|
21098
21129
|
const fnSrc = stripTsFromSource(fnArg, code);
|
|
21099
21130
|
mfs.push(fnSrc);
|
|
@@ -21108,20 +21139,20 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21108
21139
|
if (callee.name === "node" && code !== void 0) {
|
|
21109
21140
|
const [firstArg, secondArg, thirdArg, fourthArg] = node2.arguments;
|
|
21110
21141
|
if (!firstArg || firstArg.type === "SpreadElement") return null;
|
|
21111
|
-
const firstVal = anyValue(firstArg,
|
|
21142
|
+
const firstVal = anyValue(firstArg, scope2, code, mfs);
|
|
21112
21143
|
const explicitType = typeof firstVal === "string" ? firstVal : void 0;
|
|
21113
21144
|
const parserArg = explicitType !== void 0 ? secondArg : firstArg;
|
|
21114
21145
|
const buildArg = explicitType !== void 0 ? thirdArg : secondArg;
|
|
21115
21146
|
const optsArg = explicitType !== void 0 ? fourthArg : thirdArg;
|
|
21116
21147
|
if (!parserArg || parserArg.type === "SpreadElement") return null;
|
|
21117
|
-
const inner = anyValue(parserArg,
|
|
21148
|
+
const inner = anyValue(parserArg, scope2, code, mfs);
|
|
21118
21149
|
if (!isCombinator3(inner)) return null;
|
|
21119
21150
|
const be = buildArg;
|
|
21120
21151
|
const buildExpr = be === void 0 || be.type === "SpreadElement" ? void 0 : unwrapStaticExpr(be);
|
|
21121
|
-
const buildArgOptions = be !== void 0 && be.type !== "SpreadElement" ? staticNodeOptions(buildArg,
|
|
21152
|
+
const buildArgOptions = be !== void 0 && be.type !== "SpreadElement" ? staticNodeOptions(buildArg, scope2) : STATIC_NODE_OPTIONS_NOT_OPTIONS;
|
|
21122
21153
|
if (buildArgOptions === STATIC_NODE_OPTIONS_FAILED) return null;
|
|
21123
21154
|
const buildArgIsOptions = buildArgOptions !== STATIC_NODE_OPTIONS_NOT_OPTIONS;
|
|
21124
|
-
const scopedBuild = buildExpr === void 0 ? { found: false } : scopedStaticValue(buildExpr,
|
|
21155
|
+
const scopedBuild = buildExpr === void 0 ? { found: false } : scopedStaticValue(buildExpr, scope2);
|
|
21125
21156
|
const absentBuild = buildExpr?.type === "Identifier" && buildExpr.name === "undefined" || buildExpr !== void 0 && staticLiteralValue(buildExpr) === null || scopedBuild.found && (scopedBuild.value === void 0 || scopedBuild.value === null);
|
|
21126
21157
|
const hasBuild = be !== void 0 && be.type !== "SpreadElement" && !buildArgIsOptions && !absentBuild;
|
|
21127
21158
|
const buildSrc = hasBuild ? stripTsFromSource(be, code) : void 0;
|
|
@@ -21130,7 +21161,7 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21130
21161
|
opts = buildArgOptions;
|
|
21131
21162
|
} else if (optsArg !== void 0) {
|
|
21132
21163
|
if (optsArg.type === "SpreadElement") return null;
|
|
21133
|
-
const optsResult = staticNodeOptions(optsArg,
|
|
21164
|
+
const optsResult = staticNodeOptions(optsArg, scope2);
|
|
21134
21165
|
if (optsResult === STATIC_NODE_OPTIONS_FAILED || optsResult === STATIC_NODE_OPTIONS_NOT_OPTIONS) return null;
|
|
21135
21166
|
opts = optsResult;
|
|
21136
21167
|
}
|
|
@@ -21186,9 +21217,9 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21186
21217
|
if (callee.name === "parser") {
|
|
21187
21218
|
const [optsArg, rootArg] = node2.arguments;
|
|
21188
21219
|
if (!optsArg || !rootArg || optsArg.type === "SpreadElement" || rootArg.type === "SpreadElement") return null;
|
|
21189
|
-
const opts = anyValue(optsArg,
|
|
21220
|
+
const opts = anyValue(optsArg, scope2, code, []);
|
|
21190
21221
|
if (!opts || typeof opts !== "object") return null;
|
|
21191
|
-
const root = anyValue(rootArg,
|
|
21222
|
+
const root = anyValue(rootArg, scope2, code, mfs);
|
|
21192
21223
|
if (!isCombinator3(root)) return null;
|
|
21193
21224
|
try {
|
|
21194
21225
|
return parser(opts, root);
|
|
@@ -21200,15 +21231,15 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21200
21231
|
const [itemArg, sepArg, optsArg] = node2.arguments;
|
|
21201
21232
|
if (!itemArg || !sepArg || itemArg.type === "SpreadElement" || sepArg.type === "SpreadElement") return null;
|
|
21202
21233
|
const itemMfs = [];
|
|
21203
|
-
const itemCombi = anyValue(itemArg,
|
|
21234
|
+
const itemCombi = anyValue(itemArg, scope2, code, itemMfs);
|
|
21204
21235
|
if (!isCombinator3(itemCombi)) return null;
|
|
21205
21236
|
const sepMfs = [];
|
|
21206
|
-
const sepCombi = anyValue(sepArg,
|
|
21237
|
+
const sepCombi = anyValue(sepArg, scope2, code, sepMfs);
|
|
21207
21238
|
if (!isCombinator3(sepCombi)) return null;
|
|
21208
21239
|
let opts;
|
|
21209
21240
|
if (optsArg) {
|
|
21210
21241
|
if (optsArg.type === "SpreadElement") return null;
|
|
21211
|
-
const v = anyValue(optsArg,
|
|
21242
|
+
const v = anyValue(optsArg, scope2, code, []);
|
|
21212
21243
|
if (!v || typeof v !== "object") return null;
|
|
21213
21244
|
opts = v;
|
|
21214
21245
|
}
|
|
@@ -21223,12 +21254,12 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21223
21254
|
const [itemArg, optsArg] = node2.arguments;
|
|
21224
21255
|
if (!itemArg || itemArg.type === "SpreadElement") return null;
|
|
21225
21256
|
const itemMfs = [];
|
|
21226
|
-
const itemCombi = anyValue(itemArg,
|
|
21257
|
+
const itemCombi = anyValue(itemArg, scope2, code, itemMfs);
|
|
21227
21258
|
if (!isCombinator3(itemCombi)) return null;
|
|
21228
21259
|
let opts;
|
|
21229
21260
|
if (optsArg) {
|
|
21230
21261
|
if (optsArg.type === "SpreadElement") return null;
|
|
21231
|
-
const v = anyValue(optsArg,
|
|
21262
|
+
const v = anyValue(optsArg, scope2, code, []);
|
|
21232
21263
|
if (!v || typeof v !== "object") return null;
|
|
21233
21264
|
opts = v;
|
|
21234
21265
|
}
|
|
@@ -21245,7 +21276,7 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21245
21276
|
if (callee.name === "not") {
|
|
21246
21277
|
const [innerArg] = node2.arguments;
|
|
21247
21278
|
if (!innerArg || innerArg.type === "SpreadElement") return null;
|
|
21248
|
-
const inner = anyValue(innerArg,
|
|
21279
|
+
const inner = anyValue(innerArg, scope2, code, mfs);
|
|
21249
21280
|
if (!isCombinator3(inner)) return null;
|
|
21250
21281
|
try {
|
|
21251
21282
|
return not(inner);
|
|
@@ -21256,7 +21287,7 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21256
21287
|
if (callee.name === "peek") {
|
|
21257
21288
|
const [innerArg] = node2.arguments;
|
|
21258
21289
|
if (!innerArg || innerArg.type === "SpreadElement") return null;
|
|
21259
|
-
const inner = anyValue(innerArg,
|
|
21290
|
+
const inner = anyValue(innerArg, scope2, code, mfs);
|
|
21260
21291
|
if (!isCombinator3(inner)) return null;
|
|
21261
21292
|
try {
|
|
21262
21293
|
return peek(inner);
|
|
@@ -21267,10 +21298,10 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21267
21298
|
if (callee.name === "balanced") {
|
|
21268
21299
|
const [openArg, closeArg, optsArg] = node2.arguments;
|
|
21269
21300
|
if (!openArg || !closeArg || openArg.type === "SpreadElement" || closeArg.type === "SpreadElement") return null;
|
|
21270
|
-
const open = anyValue(openArg,
|
|
21271
|
-
const close = anyValue(closeArg,
|
|
21301
|
+
const open = anyValue(openArg, scope2, code, []);
|
|
21302
|
+
const close = anyValue(closeArg, scope2, code, []);
|
|
21272
21303
|
if (typeof open !== "string" || typeof close !== "string") return null;
|
|
21273
|
-
const opts = scanOptions(optsArg,
|
|
21304
|
+
const opts = scanOptions(optsArg, scope2, code);
|
|
21274
21305
|
if (opts === UNKNOWN_OPTIONS) return null;
|
|
21275
21306
|
try {
|
|
21276
21307
|
return balanced(open, close, opts);
|
|
@@ -21281,9 +21312,9 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21281
21312
|
if (callee.name === "scanTo") {
|
|
21282
21313
|
const [sentinelArg, optsArg] = node2.arguments;
|
|
21283
21314
|
if (!sentinelArg || sentinelArg.type === "SpreadElement") return null;
|
|
21284
|
-
const sentinel = anyValue(sentinelArg,
|
|
21315
|
+
const sentinel = anyValue(sentinelArg, scope2, code, []);
|
|
21285
21316
|
if (!isCombinator3(sentinel)) return null;
|
|
21286
|
-
const opts = scanOptions(optsArg,
|
|
21317
|
+
const opts = scanOptions(optsArg, scope2, code);
|
|
21287
21318
|
if (opts === UNKNOWN_OPTIONS) return null;
|
|
21288
21319
|
try {
|
|
21289
21320
|
return scanTo(sentinel, opts);
|
|
@@ -21312,12 +21343,12 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21312
21343
|
if (!extraArg || !innerArg || extraArg.type === "SpreadElement" || innerArg.type === "SpreadElement") return null;
|
|
21313
21344
|
const extraSrc = stripTsFromSource(extraArg, code);
|
|
21314
21345
|
mfs.push(extraSrc);
|
|
21315
|
-
const inner = anyValue(innerArg,
|
|
21346
|
+
const inner = anyValue(innerArg, scope2, code, mfs);
|
|
21316
21347
|
if (!isCombinator3(inner)) return null;
|
|
21317
21348
|
try {
|
|
21318
21349
|
const extraType = unwrapStaticExpr(extraArg).type;
|
|
21319
21350
|
const derives = extraType === "ArrowFunctionExpression" || extraType === "FunctionExpression";
|
|
21320
|
-
const evaluated = derives ? null : anyValue(extraArg,
|
|
21351
|
+
const evaluated = derives ? null : anyValue(extraArg, scope2, code, []);
|
|
21321
21352
|
const usable = typeof evaluated === "object" && evaluated !== null && !Array.isArray(evaluated) && Object.getPrototypeOf(evaluated) === Object.prototype;
|
|
21322
21353
|
const combi = withCtx(derives ? DERIVE_STAND_IN : usable ? evaluated : UNEVALUATED_EXTRA, inner);
|
|
21323
21354
|
if (combi._def.tag !== "withCtx") return null;
|
|
@@ -21330,12 +21361,12 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21330
21361
|
if (callee.name === "dispatch") {
|
|
21331
21362
|
const [selectorArg, ...armArgs] = node2.arguments;
|
|
21332
21363
|
if (!selectorArg || selectorArg.type === "SpreadElement") return null;
|
|
21333
|
-
const selector = anyValue(selectorArg,
|
|
21364
|
+
const selector = anyValue(selectorArg, scope2, code, mfs);
|
|
21334
21365
|
if (!isCombinator3(selector)) return null;
|
|
21335
21366
|
const arms = [];
|
|
21336
21367
|
for (const arg of armArgs) {
|
|
21337
21368
|
if (arg.type === "SpreadElement") return null;
|
|
21338
|
-
const arm = dispatchArmValue(arg,
|
|
21369
|
+
const arm = dispatchArmValue(arg, scope2, code, mfs);
|
|
21339
21370
|
if (!isDispatchArm(arm)) return null;
|
|
21340
21371
|
arms.push(arm);
|
|
21341
21372
|
}
|
|
@@ -21357,12 +21388,12 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21357
21388
|
if (!parts) return null;
|
|
21358
21389
|
const gateSrc = stripTsFromSource(parts.gate, code);
|
|
21359
21390
|
mfs.push(gateSrc);
|
|
21360
|
-
const combi = anyValue(parts.combinator,
|
|
21391
|
+
const combi = anyValue(parts.combinator, scope2, code, mfs);
|
|
21361
21392
|
if (!isCombinator3(combi)) return null;
|
|
21362
21393
|
arms.push({ gate: () => true, combinator: combi });
|
|
21363
21394
|
gateSrcs.push(gateSrc);
|
|
21364
21395
|
} else {
|
|
21365
|
-
const combi = anyValue(argNode,
|
|
21396
|
+
const combi = anyValue(argNode, scope2, code, mfs);
|
|
21366
21397
|
if (!isCombinator3(combi)) return null;
|
|
21367
21398
|
arms.push(combi);
|
|
21368
21399
|
gateSrcs.push(null);
|
|
@@ -21384,7 +21415,7 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21384
21415
|
if (!factory) return null;
|
|
21385
21416
|
const args = node2.arguments.map((arg) => {
|
|
21386
21417
|
if (arg.type === "SpreadElement") return null;
|
|
21387
|
-
return anyValue(arg,
|
|
21418
|
+
return anyValue(arg, scope2, code, mfs);
|
|
21388
21419
|
});
|
|
21389
21420
|
if (args.some((a) => a === null)) return null;
|
|
21390
21421
|
try {
|
|
@@ -21393,16 +21424,16 @@ function exprToCombi(node2, scope, code, mfs) {
|
|
|
21393
21424
|
return null;
|
|
21394
21425
|
}
|
|
21395
21426
|
}
|
|
21396
|
-
function isHole(node2, value,
|
|
21427
|
+
function isHole(node2, value, scope2) {
|
|
21397
21428
|
if (value !== null) return false;
|
|
21398
21429
|
const n = unwrapStaticExpr(node2);
|
|
21399
|
-
if (n.type === "Identifier") return !
|
|
21430
|
+
if (n.type === "Identifier") return !scope2.has(n.name);
|
|
21400
21431
|
return !(n.type === "Literal" && n.value === null) && n.type !== "ArrowFunctionExpression" && n.type !== "FunctionExpression";
|
|
21401
21432
|
}
|
|
21402
|
-
function anyValue(node2,
|
|
21433
|
+
function anyValue(node2, scope2, code, mfs) {
|
|
21403
21434
|
if (node2.type === "TSAsExpression" || node2.type === "TSSatisfiesExpression" || node2.type === "TSNonNullExpression" || node2.type === "TSTypeAssertion" || node2.type === "TSInstantiationExpression" || node2.type === "ParenthesizedExpression") {
|
|
21404
21435
|
const inner = node2.expression;
|
|
21405
|
-
return inner ? anyValue(inner,
|
|
21436
|
+
return inner ? anyValue(inner, scope2, code, mfs) : null;
|
|
21406
21437
|
}
|
|
21407
21438
|
if (node2.type === "Literal") {
|
|
21408
21439
|
if ("regex" in node2 && node2.regex !== null && node2.regex !== void 0) {
|
|
@@ -21419,8 +21450,8 @@ function anyValue(node2, scope, code, mfs) {
|
|
|
21419
21450
|
continue;
|
|
21420
21451
|
}
|
|
21421
21452
|
if (el.type === "SpreadElement") return null;
|
|
21422
|
-
const v = anyValue(el,
|
|
21423
|
-
if (isHole(el, v,
|
|
21453
|
+
const v = anyValue(el, scope2, code, mfs);
|
|
21454
|
+
if (isHole(el, v, scope2)) return null;
|
|
21424
21455
|
out.push(v);
|
|
21425
21456
|
}
|
|
21426
21457
|
return out;
|
|
@@ -21431,15 +21462,15 @@ function anyValue(node2, scope, code, mfs) {
|
|
|
21431
21462
|
const key = propName(prop);
|
|
21432
21463
|
if (key === null) return null;
|
|
21433
21464
|
const valueNode = prop.value;
|
|
21434
|
-
const v = anyValue(valueNode,
|
|
21435
|
-
if (isHole(valueNode, v,
|
|
21465
|
+
const v = anyValue(valueNode, scope2, code, mfs);
|
|
21466
|
+
if (isHole(valueNode, v, scope2)) return null;
|
|
21436
21467
|
obj[key] = v;
|
|
21437
21468
|
}
|
|
21438
21469
|
return obj;
|
|
21439
21470
|
}
|
|
21440
21471
|
if (node2.type === "Identifier") {
|
|
21441
21472
|
if (node2.name === "undefined") return void 0;
|
|
21442
|
-
const entry =
|
|
21473
|
+
const entry = scope2.get(node2.name) ?? null;
|
|
21443
21474
|
if (isScopeEntry(entry)) {
|
|
21444
21475
|
if (mfs && entry.mfSrcs.length > 0) mfs.push(...entry.mfSrcs);
|
|
21445
21476
|
return entry.combi;
|
|
@@ -21452,10 +21483,10 @@ function anyValue(node2, scope, code, mfs) {
|
|
|
21452
21483
|
}
|
|
21453
21484
|
if (node2.type === "MemberExpression") {
|
|
21454
21485
|
const mem = node2;
|
|
21455
|
-
const obj = anyValue(mem.object,
|
|
21486
|
+
const obj = anyValue(mem.object, scope2, code, mfs);
|
|
21456
21487
|
if (!obj || typeof obj !== "object") return null;
|
|
21457
21488
|
if (node2.computed) {
|
|
21458
|
-
const key = anyValue(node2.property,
|
|
21489
|
+
const key = anyValue(node2.property, scope2, code, mfs);
|
|
21459
21490
|
if (typeof key !== "string" && typeof key !== "number") return null;
|
|
21460
21491
|
return obj[key] ?? null;
|
|
21461
21492
|
}
|
|
@@ -21466,50 +21497,50 @@ function anyValue(node2, scope, code, mfs) {
|
|
|
21466
21497
|
if (node2.type === "CallExpression") {
|
|
21467
21498
|
const callee = node2.callee;
|
|
21468
21499
|
if (callee.type === "Identifier" && callee.name === "makeWord") {
|
|
21469
|
-
return wordFactoryFromArgs(node2.arguments,
|
|
21500
|
+
return wordFactoryFromArgs(node2.arguments, scope2, code, mfs);
|
|
21470
21501
|
}
|
|
21471
21502
|
if (callee.type === "Identifier" && callee.name === "makeWhen") {
|
|
21472
|
-
return whenFactoryFromArgs(node2.arguments,
|
|
21503
|
+
return whenFactoryFromArgs(node2.arguments, scope2, code, mfs);
|
|
21473
21504
|
}
|
|
21474
21505
|
if (callee.type === "Identifier" && (callee.name === "startsWith" || callee.name === "endsWith")) {
|
|
21475
21506
|
if (node2.arguments.length !== 1 || node2.arguments[0]?.type === "SpreadElement") return null;
|
|
21476
|
-
const value = anyValue(node2.arguments[0],
|
|
21507
|
+
const value = anyValue(node2.arguments[0], scope2, code, mfs);
|
|
21477
21508
|
if (typeof value !== "string") return null;
|
|
21478
21509
|
return callee.name === "startsWith" ? startsWith(value) : endsWith(value);
|
|
21479
21510
|
}
|
|
21480
21511
|
if (callee.type === "Identifier" && callee.name === "matches") {
|
|
21481
21512
|
if (node2.arguments.length !== 1 || node2.arguments[0]?.type === "SpreadElement") return null;
|
|
21482
|
-
const value = anyValue(node2.arguments[0],
|
|
21513
|
+
const value = anyValue(node2.arguments[0], scope2, code, mfs);
|
|
21483
21514
|
if (!(value instanceof RegExp)) return null;
|
|
21484
21515
|
return matches(value);
|
|
21485
21516
|
}
|
|
21486
21517
|
if (callee.type === "Identifier" && (callee.name === "when" || callee.name === "otherwise")) {
|
|
21487
|
-
return dispatchArmValue(node2,
|
|
21518
|
+
return dispatchArmValue(node2, scope2, code, mfs);
|
|
21488
21519
|
}
|
|
21489
|
-
if (callee.type === "Identifier" && isWhenFactory(
|
|
21490
|
-
return dispatchArmValue(node2,
|
|
21520
|
+
if (callee.type === "Identifier" && isWhenFactory(scope2.get(callee.name))) {
|
|
21521
|
+
return dispatchArmValue(node2, scope2, code, mfs);
|
|
21491
21522
|
}
|
|
21492
|
-
return exprToCombi(node2,
|
|
21523
|
+
return exprToCombi(node2, scope2, code, mfs);
|
|
21493
21524
|
}
|
|
21494
21525
|
return null;
|
|
21495
21526
|
}
|
|
21496
|
-
function evaluateWordFactory(node2,
|
|
21527
|
+
function evaluateWordFactory(node2, scope2, code) {
|
|
21497
21528
|
if (node2.type !== "CallExpression") return null;
|
|
21498
21529
|
const callee = node2.callee;
|
|
21499
21530
|
if (callee.type !== "Identifier" || callee.name !== "makeWord") return null;
|
|
21500
|
-
return wordFactoryFromArgs(node2.arguments,
|
|
21531
|
+
return wordFactoryFromArgs(node2.arguments, scope2, code);
|
|
21501
21532
|
}
|
|
21502
|
-
function evaluateWhenFactory(node2,
|
|
21533
|
+
function evaluateWhenFactory(node2, scope2, code) {
|
|
21503
21534
|
if (node2.type !== "CallExpression") return null;
|
|
21504
21535
|
const callee = node2.callee;
|
|
21505
21536
|
if (callee.type !== "Identifier" || callee.name !== "makeWhen") return null;
|
|
21506
|
-
return whenFactoryFromArgs(node2.arguments,
|
|
21537
|
+
return whenFactoryFromArgs(node2.arguments, scope2, code);
|
|
21507
21538
|
}
|
|
21508
|
-
function evaluateExpr(node2,
|
|
21509
|
-
return exprToCombi(node2,
|
|
21539
|
+
function evaluateExpr(node2, scope2, code, mapFnSources) {
|
|
21540
|
+
return exprToCombi(node2, scope2, code, mapFnSources);
|
|
21510
21541
|
}
|
|
21511
|
-
function evaluateCombinatorArray(node2,
|
|
21512
|
-
const val = anyValue(node2,
|
|
21542
|
+
function evaluateCombinatorArray(node2, scope2, code) {
|
|
21543
|
+
const val = anyValue(node2, scope2, code, []);
|
|
21513
21544
|
if (!Array.isArray(val) || val.length === 0) return null;
|
|
21514
21545
|
if (!val.every(isCombinator3)) return null;
|
|
21515
21546
|
return val;
|
|
@@ -21523,15 +21554,15 @@ function collectRuleKeys(retObj) {
|
|
|
21523
21554
|
}
|
|
21524
21555
|
return out;
|
|
21525
21556
|
}
|
|
21526
|
-
function evaluateStaticValue(node2,
|
|
21527
|
-
return anyValue(node2,
|
|
21557
|
+
function evaluateStaticValue(node2, scope2, code) {
|
|
21558
|
+
return anyValue(node2, scope2, code, []);
|
|
21528
21559
|
}
|
|
21529
|
-
function flattenRuleEntries(retObj,
|
|
21560
|
+
function flattenRuleEntries(retObj, scope2, code) {
|
|
21530
21561
|
const out = [];
|
|
21531
21562
|
for (const prop of retObj.properties) {
|
|
21532
21563
|
const key = propName(prop);
|
|
21533
21564
|
if (!key) return null;
|
|
21534
|
-
out.push({ key, value: prop.value, scope, code });
|
|
21565
|
+
out.push({ key, value: prop.value, scope: scope2, code });
|
|
21535
21566
|
}
|
|
21536
21567
|
return out;
|
|
21537
21568
|
}
|
|
@@ -21549,7 +21580,7 @@ function identifierNamesIn(node2, out = /* @__PURE__ */ new Set()) {
|
|
|
21549
21580
|
}
|
|
21550
21581
|
return out;
|
|
21551
21582
|
}
|
|
21552
|
-
function evalBodyStatements(statements,
|
|
21583
|
+
function evalBodyStatements(statements, scope2, code, out) {
|
|
21553
21584
|
const bodyMfs = [];
|
|
21554
21585
|
const laterNames = [];
|
|
21555
21586
|
{
|
|
@@ -21579,7 +21610,7 @@ function evalBodyStatements(statements, scope, code, out) {
|
|
|
21579
21610
|
return false;
|
|
21580
21611
|
}
|
|
21581
21612
|
const before = bodyMfs.length;
|
|
21582
|
-
const val = anyValue(decl.init,
|
|
21613
|
+
const val = anyValue(decl.init, scope2, code, bodyMfs);
|
|
21583
21614
|
if (val === null) {
|
|
21584
21615
|
if (out) {
|
|
21585
21616
|
const used = identifierNamesIn(decl.init);
|
|
@@ -21589,14 +21620,14 @@ function evalBodyStatements(statements, scope, code, out) {
|
|
|
21589
21620
|
return false;
|
|
21590
21621
|
}
|
|
21591
21622
|
const thisDeclMfSrcs = bodyMfs.slice(before);
|
|
21592
|
-
if (isCombinator3(val))
|
|
21593
|
-
else if (isDispatchArm(val))
|
|
21594
|
-
else
|
|
21623
|
+
if (isCombinator3(val)) scope2.set(name, { combi: val, mfSrcs: thisDeclMfSrcs });
|
|
21624
|
+
else if (isDispatchArm(val)) scope2.set(name, { value: val, mfSrcs: thisDeclMfSrcs });
|
|
21625
|
+
else scope2.set(name, val);
|
|
21595
21626
|
}
|
|
21596
21627
|
}
|
|
21597
21628
|
return true;
|
|
21598
21629
|
}
|
|
21599
|
-
function evaluateParserFactory(factoryNode,
|
|
21630
|
+
function evaluateParserFactory(factoryNode, scope2, code, mapFnSources, out, options) {
|
|
21600
21631
|
if (factoryNode.type !== "ArrowFunctionExpression" && factoryNode.type !== "FunctionDeclaration" && factoryNode.type !== "FunctionExpression") return null;
|
|
21601
21632
|
const factory = factoryNode;
|
|
21602
21633
|
const params = factory.params;
|
|
@@ -21639,7 +21670,7 @@ function evaluateParserFactory(factoryNode, scope, code, mapFnSources, out, opti
|
|
|
21639
21670
|
let built;
|
|
21640
21671
|
try {
|
|
21641
21672
|
built = rules(options ?? {}, (g, prior) => {
|
|
21642
|
-
const localScope =
|
|
21673
|
+
const localScope = scope2 instanceof ModuleScope ? scope2.fork() : new Map(scope2);
|
|
21643
21674
|
localScope.set(proxyName, g);
|
|
21644
21675
|
if (priorName !== void 0) localScope.set(priorName, prior);
|
|
21645
21676
|
if (!evalBodyStatements(statements, localScope, code, out)) throw ABORT;
|
|
@@ -21672,16 +21703,16 @@ var externalAccesses = /* @__PURE__ */ new WeakMap();
|
|
|
21672
21703
|
function isDefinableRef2(v) {
|
|
21673
21704
|
return isCombinator3(v) && typeof v.define === "function" && v._def.tag === "lazy";
|
|
21674
21705
|
}
|
|
21675
|
-
function evaluateRefDeclaration(init, name,
|
|
21706
|
+
function evaluateRefDeclaration(init, name, scope2) {
|
|
21676
21707
|
if (init.type !== "CallExpression") return null;
|
|
21677
21708
|
const callee = init.callee;
|
|
21678
21709
|
if (callee.type !== "Identifier" || callee.name !== "ref") return null;
|
|
21679
21710
|
if (init.arguments.length !== 0) return null;
|
|
21680
21711
|
const slot = ref();
|
|
21681
|
-
|
|
21712
|
+
scope2.set(name, { combi: slot, mfSrcs: [] });
|
|
21682
21713
|
return slot;
|
|
21683
21714
|
}
|
|
21684
|
-
function applyDefineStatement(callExpr,
|
|
21715
|
+
function applyDefineStatement(callExpr, scope2, code) {
|
|
21685
21716
|
if (callExpr.type !== "CallExpression") return false;
|
|
21686
21717
|
const callee = callExpr.callee;
|
|
21687
21718
|
if (callee.type !== "MemberExpression") return false;
|
|
@@ -21689,12 +21720,12 @@ function applyDefineStatement(callExpr, scope, code) {
|
|
|
21689
21720
|
if (mem.computed) return false;
|
|
21690
21721
|
if (mem.property.type !== "Identifier" || mem.property.name !== "define") return false;
|
|
21691
21722
|
if (mem.object.type !== "Identifier" || !mem.object.name) return false;
|
|
21692
|
-
const target =
|
|
21723
|
+
const target = scope2.get(mem.object.name);
|
|
21693
21724
|
const refCombi = isScopeEntry(target) ? target.combi : isCombinator3(target) ? target : null;
|
|
21694
21725
|
if (!refCombi || !isDefinableRef2(refCombi)) return false;
|
|
21695
21726
|
const args = callExpr.arguments;
|
|
21696
21727
|
if (args.length !== 1 || args[0].type === "SpreadElement") return false;
|
|
21697
|
-
const inner = anyValue(args[0],
|
|
21728
|
+
const inner = anyValue(args[0], scope2, code, []);
|
|
21698
21729
|
if (!isCombinator3(inner)) return false;
|
|
21699
21730
|
try {
|
|
21700
21731
|
refCombi.define(inner);
|
|
@@ -21703,17 +21734,17 @@ function applyDefineStatement(callExpr, scope, code) {
|
|
|
21703
21734
|
}
|
|
21704
21735
|
return true;
|
|
21705
21736
|
}
|
|
21706
|
-
function referencesAny(node2, names,
|
|
21737
|
+
function referencesAny(node2, names, scope2) {
|
|
21707
21738
|
if (node2.type === "Identifier") {
|
|
21708
|
-
return names.has(node2.name) || Map.prototype.has.call(
|
|
21739
|
+
return names.has(node2.name) || Map.prototype.has.call(scope2, node2.name);
|
|
21709
21740
|
}
|
|
21710
21741
|
for (const key of Object.keys(node2)) {
|
|
21711
21742
|
const child = node2[key];
|
|
21712
21743
|
if (!child || typeof child !== "object") continue;
|
|
21713
21744
|
if (Array.isArray(child)) {
|
|
21714
|
-
if (child.some((c) => c && typeof c === "object" && "type" in c && referencesAny(c, names,
|
|
21745
|
+
if (child.some((c) => c && typeof c === "object" && "type" in c && referencesAny(c, names, scope2))) return true;
|
|
21715
21746
|
} else if ("type" in child) {
|
|
21716
|
-
if (referencesAny(child, names,
|
|
21747
|
+
if (referencesAny(child, names, scope2)) return true;
|
|
21717
21748
|
}
|
|
21718
21749
|
}
|
|
21719
21750
|
return false;
|
|
@@ -21765,30 +21796,30 @@ function patternNames(pat, out) {
|
|
|
21765
21796
|
return;
|
|
21766
21797
|
}
|
|
21767
21798
|
}
|
|
21768
|
-
function declare(
|
|
21769
|
-
const prev =
|
|
21799
|
+
function declare(scope2, name, b) {
|
|
21800
|
+
const prev = scope2.bindings.get(name);
|
|
21770
21801
|
if (prev) prev.reassigned = true;
|
|
21771
|
-
else
|
|
21802
|
+
else scope2.bindings.set(name, b);
|
|
21772
21803
|
}
|
|
21773
|
-
function functionScope(
|
|
21774
|
-
let s =
|
|
21804
|
+
function functionScope(scope2) {
|
|
21805
|
+
let s = scope2;
|
|
21775
21806
|
while (!s.isFunction && s.parent) s = s.parent;
|
|
21776
21807
|
return s;
|
|
21777
21808
|
}
|
|
21778
21809
|
function buildScopeTree(body, moduleEnd) {
|
|
21779
21810
|
const root = newScope(0, moduleEnd, null, true);
|
|
21780
|
-
const declarePattern = (
|
|
21811
|
+
const declarePattern = (scope2, pat, kind, init) => {
|
|
21781
21812
|
const names = [];
|
|
21782
21813
|
patternNames(pat, names);
|
|
21783
|
-
const target = kind === "var" ? functionScope(
|
|
21814
|
+
const target = kind === "var" ? functionScope(scope2) : scope2;
|
|
21784
21815
|
for (const name of names) {
|
|
21785
21816
|
declare(target, name, init !== void 0 && names.length === 1 ? { kind, init } : { kind });
|
|
21786
21817
|
}
|
|
21787
21818
|
};
|
|
21788
|
-
const walk = (n,
|
|
21819
|
+
const walk = (n, scope2) => {
|
|
21789
21820
|
if (!n || typeof n !== "object") return;
|
|
21790
21821
|
if (Array.isArray(n)) {
|
|
21791
|
-
for (const item of n) walk(item,
|
|
21822
|
+
for (const item of n) walk(item, scope2);
|
|
21792
21823
|
return;
|
|
21793
21824
|
}
|
|
21794
21825
|
const node2 = n;
|
|
@@ -21797,15 +21828,15 @@ function buildScopeTree(body, moduleEnd) {
|
|
|
21797
21828
|
case "VariableDeclaration": {
|
|
21798
21829
|
const kind = node2.kind ?? "var";
|
|
21799
21830
|
for (const d of node2.declarations ?? []) {
|
|
21800
|
-
declarePattern(
|
|
21831
|
+
declarePattern(scope2, d.id, kind, d.init ?? void 0);
|
|
21801
21832
|
}
|
|
21802
21833
|
break;
|
|
21803
21834
|
}
|
|
21804
21835
|
case "FunctionDeclaration":
|
|
21805
|
-
if (node2.id) declare(functionScope(
|
|
21836
|
+
if (node2.id) declare(functionScope(scope2), node2.id.name, { kind: "function", init: node2 });
|
|
21806
21837
|
break;
|
|
21807
21838
|
case "ClassDeclaration":
|
|
21808
|
-
if (node2.id) declare(
|
|
21839
|
+
if (node2.id) declare(scope2, node2.id.name, { kind: "class" });
|
|
21809
21840
|
break;
|
|
21810
21841
|
case "ImportDeclaration": {
|
|
21811
21842
|
const specifier = node2.source?.value ?? "";
|
|
@@ -21813,7 +21844,7 @@ function buildScopeTree(body, moduleEnd) {
|
|
|
21813
21844
|
const local = sp.local?.name;
|
|
21814
21845
|
if (!local) continue;
|
|
21815
21846
|
const imported = sp.type === "ImportDefaultSpecifier" ? "default" : sp.type === "ImportNamespaceSpecifier" ? "*" : sp.imported?.name ?? local;
|
|
21816
|
-
declare(
|
|
21847
|
+
declare(scope2, local, { kind: "import", importRef: { specifier, imported } });
|
|
21817
21848
|
}
|
|
21818
21849
|
break;
|
|
21819
21850
|
}
|
|
@@ -21822,7 +21853,7 @@ function buildScopeTree(body, moduleEnd) {
|
|
|
21822
21853
|
}
|
|
21823
21854
|
if (SCOPE_TYPES.has(node2.type)) {
|
|
21824
21855
|
const isFn = FUNCTION_TYPES.has(node2.type);
|
|
21825
|
-
const inner = newScope(node2.start, node2.end,
|
|
21856
|
+
const inner = newScope(node2.start, node2.end, scope2, isFn);
|
|
21826
21857
|
if (isFn) {
|
|
21827
21858
|
for (const p of node2.params ?? []) declarePattern(inner, p, "param");
|
|
21828
21859
|
if (node2.type === "FunctionExpression" && node2.id) {
|
|
@@ -21838,7 +21869,7 @@ function buildScopeTree(body, moduleEnd) {
|
|
|
21838
21869
|
}
|
|
21839
21870
|
for (const key of Object.keys(node2)) {
|
|
21840
21871
|
if (key === "type" || key === "start" || key === "end") continue;
|
|
21841
|
-
walk(node2[key],
|
|
21872
|
+
walk(node2[key], scope2);
|
|
21842
21873
|
}
|
|
21843
21874
|
};
|
|
21844
21875
|
for (const stmt of body) walk(stmt, root);
|
|
@@ -21852,8 +21883,8 @@ function scopeAt(root, offset) {
|
|
|
21852
21883
|
cur = next;
|
|
21853
21884
|
}
|
|
21854
21885
|
}
|
|
21855
|
-
function lookup(
|
|
21856
|
-
for (let s =
|
|
21886
|
+
function lookup(scope2, name) {
|
|
21887
|
+
for (let s = scope2; s; s = s.parent) {
|
|
21857
21888
|
const b = s.bindings.get(name);
|
|
21858
21889
|
if (b) return { binding: b, scope: s };
|
|
21859
21890
|
}
|
|
@@ -23579,7 +23610,7 @@ function transformMacroImpl(code, id, moduleAliases, warnUnloweredRegex, recover
|
|
|
23579
23610
|
const stuck = rebaseCarriedBuilderImports(combi2, m.file);
|
|
23580
23611
|
return stuck ? { unresolved: `has a node() builder reading \`${stuck.local}\` from '${stuck.source}' inside ${m.file}, which this module cannot import \u2014 import it there by package name` } : { value: { combi: combi2, mfSrcs: [] } };
|
|
23581
23612
|
}
|
|
23582
|
-
const
|
|
23613
|
+
const scope3 = moduleValueScope(m);
|
|
23583
23614
|
reducerResolver.register(m.file);
|
|
23584
23615
|
builderImports = (name2) => {
|
|
23585
23616
|
const b = m.imports.get(name2);
|
|
@@ -23587,11 +23618,11 @@ function transformMacroImpl(code, id, moduleAliases, warnUnloweredRegex, recover
|
|
|
23587
23618
|
return b && source !== null ? { source, imported: b.imported } : null;
|
|
23588
23619
|
};
|
|
23589
23620
|
const mfs = [];
|
|
23590
|
-
const combi = evaluateExpr(init,
|
|
23621
|
+
const combi = evaluateExpr(init, scope3, m.src, mfs);
|
|
23591
23622
|
if (combi) return { value: { combi, mfSrcs: mfs } };
|
|
23592
|
-
const factory = evaluateWordFactory(init,
|
|
23623
|
+
const factory = evaluateWordFactory(init, scope3, m.src) ?? evaluateWhenFactory(init, scope3, m.src);
|
|
23593
23624
|
if (factory) return { value: factory };
|
|
23594
|
-
const value = evaluateStaticValue(init,
|
|
23625
|
+
const value = evaluateStaticValue(init, scope3, m.src);
|
|
23595
23626
|
if (value !== null && value !== void 0 || isStaticNullishExpression(init)) return { value };
|
|
23596
23627
|
return {
|
|
23597
23628
|
unresolved: /\btableRules\b/.test(m.src.slice(init.start, init.end)) ? `is a compiled parser in ${m.file} that carries no combinator IR \u2014 rebuild that module with parseman v${PARSEMAN_VERSION}` : `is not a statically-known combinator or value (${m.file})`
|
|
@@ -23632,12 +23663,12 @@ function transformMacroImpl(code, id, moduleAliases, warnUnloweredRegex, recover
|
|
|
23632
23663
|
}
|
|
23633
23664
|
return { unresolved: `is not exported by ${m.file}` };
|
|
23634
23665
|
}
|
|
23635
|
-
const
|
|
23636
|
-
if (!
|
|
23637
|
-
|
|
23666
|
+
const scope3 = moduleValueScope(m);
|
|
23667
|
+
if (!scope3.has(local)) {
|
|
23668
|
+
scope3.get(local);
|
|
23638
23669
|
return { unresolved: `could not be resolved in ${m.file}` };
|
|
23639
23670
|
}
|
|
23640
|
-
return { value:
|
|
23671
|
+
return { value: scope3.get(local) };
|
|
23641
23672
|
};
|
|
23642
23673
|
const importedValue = (from, binding) => {
|
|
23643
23674
|
const file = resolveValueFile(from, binding.source);
|
|
@@ -23656,7 +23687,7 @@ function transformMacroImpl(code, id, moduleAliases, warnUnloweredRegex, recover
|
|
|
23656
23687
|
deferredLocals.delete(name);
|
|
23657
23688
|
const outer = [...unresolvedImports];
|
|
23658
23689
|
unresolvedImports.clear();
|
|
23659
|
-
const value = evaluateStaticValue(deferred,
|
|
23690
|
+
const value = evaluateStaticValue(deferred, scope2, code);
|
|
23660
23691
|
const why = [...unresolvedImports];
|
|
23661
23692
|
unresolvedImports.clear();
|
|
23662
23693
|
for (const n of outer) unresolvedImports.add(n);
|
|
@@ -23770,7 +23801,7 @@ function transformMacroImpl(code, id, moduleAliases, warnUnloweredRegex, recover
|
|
|
23770
23801
|
});
|
|
23771
23802
|
reducerResolver.register(file);
|
|
23772
23803
|
}
|
|
23773
|
-
const
|
|
23804
|
+
const scope2 = new ModuleScope(resolveMainFree, unresolvedImports);
|
|
23774
23805
|
const replacements = [];
|
|
23775
23806
|
const warnings = [];
|
|
23776
23807
|
beginDegradationCapture();
|
|
@@ -23852,7 +23883,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
23852
23883
|
const out = evaluate(value);
|
|
23853
23884
|
if (out === null) {
|
|
23854
23885
|
const id2 = value.type === "Identifier" ? value.name : null;
|
|
23855
|
-
if (id2 !== null &&
|
|
23886
|
+
if (id2 !== null && scope2.has(id2) && scope2.get(id2) == null) return void 0;
|
|
23856
23887
|
return unevaluable(value.start, `${label2}: rules({ ${name} })`);
|
|
23857
23888
|
}
|
|
23858
23889
|
unresolvedImports.clear();
|
|
@@ -23862,7 +23893,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
23862
23893
|
const assertPlainOptions = (optExpr, label2) => {
|
|
23863
23894
|
for (const p of optExpr?.type === "ObjectExpression" ? optExpr.properties : []) {
|
|
23864
23895
|
if (propName(p) !== null) continue;
|
|
23865
|
-
const key = p.type === "Property" ? evaluateStaticValue(p.key,
|
|
23896
|
+
const key = p.type === "Property" ? evaluateStaticValue(p.key, scope2, code) : null;
|
|
23866
23897
|
if (typeof key !== "string" || RULES_OPTIONS.has(key)) {
|
|
23867
23898
|
unevaluable(p.start, `${label2}: an options ${p.type === "Property" ? "computed key" : "spread"}`);
|
|
23868
23899
|
}
|
|
@@ -23870,7 +23901,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
23870
23901
|
};
|
|
23871
23902
|
const triviaOption = (optExpr, label2) => {
|
|
23872
23903
|
assertPlainOptions(optExpr, label2);
|
|
23873
|
-
return requiredOption(label2, "trivia", optionProp(optExpr, "trivia"), (v) => evaluateExpr(v,
|
|
23904
|
+
return requiredOption(label2, "trivia", optionProp(optExpr, "trivia"), (v) => evaluateExpr(v, scope2, code, []));
|
|
23874
23905
|
};
|
|
23875
23906
|
const evaluateRulesFactory = (init, label2) => {
|
|
23876
23907
|
const args = init.arguments;
|
|
@@ -23884,7 +23915,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
23884
23915
|
}
|
|
23885
23916
|
const namedFactory = factoryArgRaw.type === "Identifier" ? factoryDecls.get(factoryArgRaw.name) : void 0;
|
|
23886
23917
|
const factoryArg = namedFactory !== void 0 && namedFactory.declaredAt <= init.start ? namedFactory.fn : factoryArgRaw;
|
|
23887
|
-
const factoryScope = namedFactory?.scope ??
|
|
23918
|
+
const factoryScope = namedFactory?.scope ?? scope2;
|
|
23888
23919
|
const factoryCode = namedFactory?.code ?? code;
|
|
23889
23920
|
const importedFactory = namedFactory?.imported === true && factoryArg === namedFactory.fn ? factoryArgRaw.name : void 0;
|
|
23890
23921
|
const failedFactory = factoryArgRaw.type === "Identifier" ? factoryFailures.get(factoryArgRaw.name) : void 0;
|
|
@@ -23911,9 +23942,9 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
23911
23942
|
}
|
|
23912
23943
|
const gTrivia = triviaOption(optionsArg, label2);
|
|
23913
23944
|
const scanSkipArray = requiredOption(label2, "scanSkip", optionValue("scanSkip"), (v) => {
|
|
23914
|
-
const units = evaluateCombinatorArray(v,
|
|
23945
|
+
const units = evaluateCombinatorArray(v, scope2, code);
|
|
23915
23946
|
if (units) return units;
|
|
23916
|
-
const value = evaluateStaticValue(v,
|
|
23947
|
+
const value = evaluateStaticValue(v, scope2, code);
|
|
23917
23948
|
return Array.isArray(value) && value.length === 0 ? [] : null;
|
|
23918
23949
|
});
|
|
23919
23950
|
const gScanSkip = scanSkipArray?.length ? scanSkipArray : void 0;
|
|
@@ -24432,7 +24463,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
24432
24463
|
for (const stmt of body) {
|
|
24433
24464
|
if (stmt.type === "ExpressionStatement") {
|
|
24434
24465
|
const expr = stmt.expression;
|
|
24435
|
-
if (applyDefineStatement(expr,
|
|
24466
|
+
if (applyDefineStatement(expr, scope2, code)) {
|
|
24436
24467
|
defineRemovals.push({ start: stmt.start, end: stmt.end });
|
|
24437
24468
|
}
|
|
24438
24469
|
continue;
|
|
@@ -24444,11 +24475,11 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
24444
24475
|
if (!d.init || d.id.type !== "Identifier") continue;
|
|
24445
24476
|
const name = d.id.name;
|
|
24446
24477
|
const init = d.init;
|
|
24447
|
-
if (evaluateRefDeclaration(init, name,
|
|
24448
|
-
if (
|
|
24449
|
-
if (!referencesAny(init, allNames,
|
|
24450
|
-
const combi = evaluateExpr(init,
|
|
24451
|
-
if (combi)
|
|
24478
|
+
if (evaluateRefDeclaration(init, name, scope2)) continue;
|
|
24479
|
+
if (scope2.has(name)) continue;
|
|
24480
|
+
if (!referencesAny(init, allNames, scope2)) continue;
|
|
24481
|
+
const combi = evaluateExpr(init, scope2, code, []);
|
|
24482
|
+
if (combi) scope2.set(name, { combi, mfSrcs: [] });
|
|
24452
24483
|
}
|
|
24453
24484
|
}
|
|
24454
24485
|
}
|
|
@@ -24474,12 +24505,12 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
24474
24505
|
const kind = vd.kind ?? "const";
|
|
24475
24506
|
if (d.id.type === "Identifier") {
|
|
24476
24507
|
const varName = d.id.name;
|
|
24477
|
-
if (!referencesAny(init, allNames,
|
|
24508
|
+
if (!referencesAny(init, allNames, scope2)) {
|
|
24478
24509
|
deferredLocals.set(varName, init);
|
|
24479
24510
|
continue;
|
|
24480
24511
|
}
|
|
24481
24512
|
if (refNames.has(varName)) {
|
|
24482
|
-
const refEntry =
|
|
24513
|
+
const refEntry = scope2.get(varName);
|
|
24483
24514
|
const refCombi = refEntry?.combi ?? null;
|
|
24484
24515
|
if (refCombi) {
|
|
24485
24516
|
const compiled2 = compile(refCombi, refEntry?.mfSrcs, { recovery, coverage: grammarCoverage });
|
|
@@ -24564,32 +24595,32 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
24564
24595
|
}
|
|
24565
24596
|
const mapFnSources = [];
|
|
24566
24597
|
unresolvedImports.clear();
|
|
24567
|
-
const parser2 = evaluateExpr(init,
|
|
24598
|
+
const parser2 = evaluateExpr(init, scope2, code, mapFnSources);
|
|
24568
24599
|
if (parser2 === null) {
|
|
24569
|
-
const wordFactory = evaluateWordFactory(init,
|
|
24600
|
+
const wordFactory = evaluateWordFactory(init, scope2, code);
|
|
24570
24601
|
if (wordFactory) {
|
|
24571
24602
|
;
|
|
24572
|
-
|
|
24603
|
+
scope2.set(varName, wordFactory);
|
|
24573
24604
|
replacements.push({ start: init.start, end: init.end, replacement: "undefined" });
|
|
24574
24605
|
continue;
|
|
24575
24606
|
}
|
|
24576
|
-
const whenFactory = evaluateWhenFactory(init,
|
|
24607
|
+
const whenFactory = evaluateWhenFactory(init, scope2, code);
|
|
24577
24608
|
if (whenFactory) {
|
|
24578
24609
|
;
|
|
24579
|
-
|
|
24610
|
+
scope2.set(varName, whenFactory);
|
|
24580
24611
|
replacements.push({ start: init.start, end: init.end, replacement: "undefined" });
|
|
24581
24612
|
continue;
|
|
24582
24613
|
}
|
|
24583
|
-
const combiArray = evaluateCombinatorArray(init,
|
|
24614
|
+
const combiArray = evaluateCombinatorArray(init, scope2, code);
|
|
24584
24615
|
if (combiArray) {
|
|
24585
24616
|
;
|
|
24586
|
-
|
|
24617
|
+
scope2.set(varName, combiArray);
|
|
24587
24618
|
continue;
|
|
24588
24619
|
}
|
|
24589
|
-
const staticValue = evaluateStaticValue(init,
|
|
24620
|
+
const staticValue = evaluateStaticValue(init, scope2, code);
|
|
24590
24621
|
if (staticValue !== null && staticValue !== void 0 || isStaticNullishExpression(init)) {
|
|
24591
24622
|
;
|
|
24592
|
-
|
|
24623
|
+
scope2.set(varName, staticValue);
|
|
24593
24624
|
continue;
|
|
24594
24625
|
}
|
|
24595
24626
|
if (factoryDecls.has(varName)) {
|
|
@@ -24612,9 +24643,9 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
24612
24643
|
replacement: compiled.inlineExpression,
|
|
24613
24644
|
carry: { name: varName, combi: parser2, exported: exportPrefix !== "" }
|
|
24614
24645
|
});
|
|
24615
|
-
|
|
24646
|
+
scope2.set(varName, { combi: parser2, mfSrcs: mapFnSources });
|
|
24616
24647
|
} else if (d.id.type === "ObjectPattern") {
|
|
24617
|
-
if (!referencesAny(init, allNames,
|
|
24648
|
+
if (!referencesAny(init, allNames, scope2)) continue;
|
|
24618
24649
|
if (!isRulesCall(init)) {
|
|
24619
24650
|
warn(init.start, `destructured macro binding must come from rules(...)`);
|
|
24620
24651
|
continue;
|
|
@@ -24648,7 +24679,7 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
24648
24679
|
}
|
|
24649
24680
|
bindings.push({ ruleKey, localName });
|
|
24650
24681
|
const rule = compiledRules.ruleMap.get(ruleKey);
|
|
24651
|
-
if (rule)
|
|
24682
|
+
if (rule) scope2.set(localName, { combi: rule, mfSrcs: [] });
|
|
24652
24683
|
}
|
|
24653
24684
|
if (!allOk) continue;
|
|
24654
24685
|
const holderVar = `__rules${ruleMapHolderCounter++}`;
|