parseman 0.60.4 → 0.60.5
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/commitment.d.ts.map +1 -1
- package/dist/analysis/diagnostics.js +1 -1
- package/dist/cli/index.js +420 -420
- package/dist/cli/index.js.map +3 -3
- package/dist/combinators/parser.d.ts +34 -3
- package/dist/combinators/parser.d.ts.map +1 -1
- package/dist/compiler/compile-linkable-table.d.ts.map +1 -1
- package/dist/compiler/linker.d.ts +11 -3
- package/dist/compiler/linker.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -21
- package/dist/index.js.map +1 -1
- package/dist/plugin/evaluator.d.ts +3 -1
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +86 -71
- package/dist/plugin/index.js.map +1 -1
- package/dist/spec/index.js +3 -1
- package/dist/spec/index.js.map +1 -1
- package/dist/spec/model.d.ts.map +1 -1
- package/dist/table/index.js +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/analysis/commitment.ts +3 -1
- package/src/combinators/parser.ts +82 -9
- package/src/compiler/compile-linkable-table.ts +4 -1
- package/src/compiler/ir-serialize.ts +10 -4
- package/src/compiler/linker.ts +22 -12
- package/src/index.ts +1 -0
- package/src/plugin/evaluator.ts +16 -5
- package/src/plugin/index.ts +27 -104
- package/src/spec/model.ts +3 -1
- package/src/version.ts +1 -1
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { Expression, Node } from '@oxc-project/types';
|
|
9
9
|
import type { Combinator } from '../types.ts';
|
|
10
|
-
import { type RulesOptions } from '../combinators/parser.ts';
|
|
10
|
+
import { type RulesOptions, type RulesRecipe } from '../combinators/parser.ts';
|
|
11
11
|
import type { ReducerResolver } from './reducer-resolver.ts';
|
|
12
12
|
/** Install (or clear, with `null`) the resolver for the module being transformed. */
|
|
13
13
|
export declare function setReducerResolver(r: ReducerResolver | null, entrySource?: string | null): void;
|
|
@@ -143,6 +143,8 @@ out?: {
|
|
|
143
143
|
* (`parser.ts:228-242`), which the macro's stamp-only copy never did.
|
|
144
144
|
*/
|
|
145
145
|
options?: RulesOptions): Map<string, Combinator<unknown>> | null;
|
|
146
|
+
/** The recipe an evaluated rule map came from, for a composition that links it. */
|
|
147
|
+
export declare const ruleMapRecipes: WeakMap<ReadonlyMap<string, Combinator<unknown>>, readonly RulesRecipe[]>;
|
|
146
148
|
/**
|
|
147
149
|
* Every EXTERNAL name an evaluated factory read through `g`, keyed by the map
|
|
148
150
|
* `evaluateParserFactory` returned. The map holds declared rules only, so a `g.X`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/plugin/evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,UAAU,EAAE,IAAI,EAMjB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG7C,OAAO,
|
|
1
|
+
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/plugin/evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,UAAU,EAAE,IAAI,EAMjB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG7C,OAAO,EAAwC,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAIpH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAsG5D,qFAAqF;AACrF,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,eAAe,GAAG,IAAI,EAAE,WAAW,GAAE,MAAM,GAAG,IAAW,GAAG,IAAI,CAGrG;AAED;;;;;;GAMG;AACH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E,MAAM,EAAE,CAAA;CACnB,CAAA;AA0CD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,aAAa,cAA6B,EAC1C,kBAAkB,UAAQ,EAC1B,QAAQ,UAAQ,EAChB,eAAe,UAAQ,EACvB,eAAe,CAAC,EAAE,eAAe,EACjC,cAAc,SAA0B,EACxC,WAAW,CAAC,EAAE,WAAW,GACxB,oBAAoB,GAAG,IAAI,CAW7B"}
|
package/dist/plugin/index.js
CHANGED
|
@@ -1926,11 +1926,16 @@ function tagRule(r, key) {
|
|
|
1926
1926
|
function isDefinableRef(v) {
|
|
1927
1927
|
return !!v && typeof v === "object" && "_def" in v && v._def.tag === "lazy" && typeof v.define === "function";
|
|
1928
1928
|
}
|
|
1929
|
+
function priorNameOf(r) {
|
|
1930
|
+
return r._priorOf;
|
|
1931
|
+
}
|
|
1929
1932
|
function ruleNameOf(r) {
|
|
1930
1933
|
return r._ruleName;
|
|
1931
1934
|
}
|
|
1932
1935
|
function isNamedRuleRefForAnotherRule(r, key) {
|
|
1933
|
-
|
|
1936
|
+
if (r._def.tag !== "lazy") return false;
|
|
1937
|
+
if (priorNameOf(r) !== void 0) return true;
|
|
1938
|
+
const name = ruleNameOf(r);
|
|
1934
1939
|
return name !== void 0 && name !== key;
|
|
1935
1940
|
}
|
|
1936
1941
|
var claimedRules = /* @__PURE__ */ new WeakSet();
|
|
@@ -1943,6 +1948,20 @@ function ownRule(p, copies) {
|
|
|
1943
1948
|
}
|
|
1944
1949
|
return own;
|
|
1945
1950
|
}
|
|
1951
|
+
var priorUnfilled = (key) => new Error(`compose: prior.${key} is read, but no grammar composed before it defines "${key}"`);
|
|
1952
|
+
function priorHole(key) {
|
|
1953
|
+
const unfilled = priorUnfilled(key);
|
|
1954
|
+
const fail = () => {
|
|
1955
|
+
throw unfilled;
|
|
1956
|
+
};
|
|
1957
|
+
return {
|
|
1958
|
+
_tag: "lazy",
|
|
1959
|
+
_meta: { firstSet: any(), canMatchNewline: true, isTrivia: false },
|
|
1960
|
+
_def: { tag: "lazy", thunk: fail },
|
|
1961
|
+
parse: fail,
|
|
1962
|
+
_priorOf: key
|
|
1963
|
+
};
|
|
1964
|
+
}
|
|
1946
1965
|
function rules(a, b) {
|
|
1947
1966
|
const factory = typeof a === "function" ? a : b;
|
|
1948
1967
|
const options = typeof a === "function" ? b : a;
|
|
@@ -1967,8 +1986,20 @@ function linkRules(recipes, link) {
|
|
|
1967
1986
|
}
|
|
1968
1987
|
});
|
|
1969
1988
|
const winners = /* @__PURE__ */ new Map();
|
|
1989
|
+
const priorHoles = /* @__PURE__ */ new Map();
|
|
1990
|
+
const prior = new Proxy({}, {
|
|
1991
|
+
get(_target, key) {
|
|
1992
|
+
if (typeof key !== "string") return void 0;
|
|
1993
|
+
const earlier = winners.get(key)?.parser;
|
|
1994
|
+
if (earlier !== void 0) return earlier._def.tag === "node" ? earlier._def.parser : earlier;
|
|
1995
|
+
if (link !== void 0) throw priorUnfilled(key);
|
|
1996
|
+
let hole = priorHoles.get(key);
|
|
1997
|
+
if (hole === void 0) priorHoles.set(key, hole = priorHole(key));
|
|
1998
|
+
return hole;
|
|
1999
|
+
}
|
|
2000
|
+
});
|
|
1970
2001
|
for (const recipe of recipes) {
|
|
1971
|
-
const definitions = recipe.factory(proxy);
|
|
2002
|
+
const definitions = recipe.factory(proxy, prior);
|
|
1972
2003
|
for (const key of Object.keys(definitions)) {
|
|
1973
2004
|
winners.set(key, { parser: definitions[key], options: recipe.options });
|
|
1974
2005
|
}
|
|
@@ -6934,7 +6965,8 @@ function classifyRuleMap(ruleMap) {
|
|
|
6934
6965
|
resolved = void 0;
|
|
6935
6966
|
}
|
|
6936
6967
|
if (resolved === void 0) {
|
|
6937
|
-
|
|
6968
|
+
const hole = p;
|
|
6969
|
+
if (hole._ruleName !== void 0 || hole._priorOf !== void 0) externalRefs.add(p);
|
|
6938
6970
|
return;
|
|
6939
6971
|
}
|
|
6940
6972
|
scanExternal(resolved);
|
|
@@ -13498,7 +13530,7 @@ function clearOf(ranges, input, from, to) {
|
|
|
13498
13530
|
}
|
|
13499
13531
|
|
|
13500
13532
|
// src/version.ts
|
|
13501
|
-
var PARSEMAN_VERSION = "0.60.
|
|
13533
|
+
var PARSEMAN_VERSION = "0.60.5";
|
|
13502
13534
|
|
|
13503
13535
|
// src/table/assemble.ts
|
|
13504
13536
|
import { PlainBuf as PlainBuf2, PlainField, PlainLeaf as PlainLeaf9, PlainNode as PlainNode2, PlainSpan as PlainSpan10 } from "../cst/plain.js";
|
|
@@ -17662,7 +17694,7 @@ function buildGrammarPlan(entry, winners) {
|
|
|
17662
17694
|
const dispatches = /* @__PURE__ */ new Map();
|
|
17663
17695
|
const attempts = /* @__PURE__ */ new Map();
|
|
17664
17696
|
const labels = /* @__PURE__ */ new Map();
|
|
17665
|
-
const
|
|
17697
|
+
const rules3 = /* @__PURE__ */ new Map();
|
|
17666
17698
|
const winnerNames = /* @__PURE__ */ new Map();
|
|
17667
17699
|
if (winners) {
|
|
17668
17700
|
for (const [name, winner] of Object.entries(winners)) {
|
|
@@ -17696,7 +17728,7 @@ function buildGrammarPlan(entry, winners) {
|
|
|
17696
17728
|
const ownRule2 = (parser2, rule) => {
|
|
17697
17729
|
const id = `rule:${rule}`;
|
|
17698
17730
|
definitions.set(id, { id, kind: "rule" });
|
|
17699
|
-
|
|
17731
|
+
rules3.set(parser2, id);
|
|
17700
17732
|
};
|
|
17701
17733
|
const seen = /* @__PURE__ */ new Set();
|
|
17702
17734
|
const visit = (parser2, path3) => {
|
|
@@ -17736,7 +17768,7 @@ function buildGrammarPlan(entry, winners) {
|
|
|
17736
17768
|
}
|
|
17737
17769
|
visit(body ?? root, name);
|
|
17738
17770
|
}
|
|
17739
|
-
return { definitions: [...definitions.values()].sort((a, b) => a.id.localeCompare(b.id)), choices, dispatches, attempts, labels, rules:
|
|
17771
|
+
return { definitions: [...definitions.values()].sort((a, b) => a.id.localeCompare(b.id)), choices, dispatches, attempts, labels, rules: rules3 };
|
|
17740
17772
|
}
|
|
17741
17773
|
|
|
17742
17774
|
// src/analysis/duplication.ts
|
|
@@ -19532,6 +19564,8 @@ var Serializer = class {
|
|
|
19532
19564
|
localRuleNames = /* @__PURE__ */ new Map();
|
|
19533
19565
|
ruleMap;
|
|
19534
19566
|
scanSkip;
|
|
19567
|
+
/** Whether any rule reads a `prior.X` hole, so the factory takes `(g, prior)`. */
|
|
19568
|
+
usesPrior = false;
|
|
19535
19569
|
accessed;
|
|
19536
19570
|
referenced = /* @__PURE__ */ new Set();
|
|
19537
19571
|
constructor(ruleMap, scanSkip = [], accessed = []) {
|
|
@@ -19552,7 +19586,7 @@ var Serializer = class {
|
|
|
19552
19586
|
if (seen.has(c)) return;
|
|
19553
19587
|
seen.add(c);
|
|
19554
19588
|
if (c._def.tag === "lazy") {
|
|
19555
|
-
if (ruleNameOf3(c) !== void 0) throw new Unserializable("scanSkip unit references a grammar rule");
|
|
19589
|
+
if (ruleNameOf3(c) !== void 0 || priorNameOf(c) !== void 0) throw new Unserializable("scanSkip unit references a grammar rule");
|
|
19556
19590
|
const target = lazyTarget(c);
|
|
19557
19591
|
if (target) this.assertNoRuleRef(target, seen);
|
|
19558
19592
|
return;
|
|
@@ -19616,9 +19650,10 @@ var Serializer = class {
|
|
|
19616
19650
|
for (const name of this.accessed) {
|
|
19617
19651
|
if (!this.referenced.has(name)) innerDecls.push(`void g[${JSON.stringify(name)}]`);
|
|
19618
19652
|
}
|
|
19619
|
-
const
|
|
19653
|
+
const params = this.usesPrior ? "(g, prior)" : "(g)";
|
|
19654
|
+
const factory = innerDecls.length === 0 ? `${params} => ({
|
|
19620
19655
|
${body}
|
|
19621
|
-
})` :
|
|
19656
|
+
})` : `${params} => {
|
|
19622
19657
|
${innerDecls.map((d) => " " + d).join("\n")}
|
|
19623
19658
|
return ({
|
|
19624
19659
|
${body}
|
|
@@ -19635,6 +19670,10 @@ ${outerDecls.map((d) => " " + d).join("\n")}
|
|
|
19635
19670
|
analyze(c, active) {
|
|
19636
19671
|
const def = c._def;
|
|
19637
19672
|
if (def.tag === "lazy") {
|
|
19673
|
+
if (priorNameOf(c) !== void 0) {
|
|
19674
|
+
this.usesPrior = true;
|
|
19675
|
+
return;
|
|
19676
|
+
}
|
|
19638
19677
|
if (ruleNameOf3(c) !== void 0) return;
|
|
19639
19678
|
const target = lazyTarget(c);
|
|
19640
19679
|
if (!target) throw new Unserializable("unresolved unnamed ref");
|
|
@@ -19713,6 +19752,8 @@ ${outerDecls.map((d) => " " + d).join("\n")}
|
|
|
19713
19752
|
}
|
|
19714
19753
|
switch (def.tag) {
|
|
19715
19754
|
case "lazy": {
|
|
19755
|
+
const prior = priorNameOf(c);
|
|
19756
|
+
if (prior !== void 0) return `prior[${JSON.stringify(prior)}]`;
|
|
19716
19757
|
const name = this.localRuleNames.get(c) ?? ruleNameOf3(c);
|
|
19717
19758
|
if (name !== void 0) {
|
|
19718
19759
|
this.referenced.add(name);
|
|
@@ -19893,7 +19934,8 @@ function externalNames(ruleMap) {
|
|
|
19893
19934
|
resolved = void 0;
|
|
19894
19935
|
}
|
|
19895
19936
|
if (resolved === void 0) {
|
|
19896
|
-
const
|
|
19937
|
+
const prior = priorNameOf(p);
|
|
19938
|
+
const name = prior === void 0 ? p._ruleName : `prior.${prior}`;
|
|
19897
19939
|
if (name !== void 0 && !out.includes(name)) out.push(name);
|
|
19898
19940
|
return;
|
|
19899
19941
|
}
|
|
@@ -21532,10 +21574,15 @@ function evaluateParserFactory(factoryNode, scope, code, mapFnSources, out, opti
|
|
|
21532
21574
|
if (factoryNode.type !== "ArrowFunctionExpression" && factoryNode.type !== "FunctionDeclaration" && factoryNode.type !== "FunctionExpression") return null;
|
|
21533
21575
|
const factory = factoryNode;
|
|
21534
21576
|
const params = factory.params;
|
|
21535
|
-
if (params.length !== 1) return null;
|
|
21536
|
-
const
|
|
21537
|
-
|
|
21577
|
+
if (params.length !== 1 && params.length !== 2) return null;
|
|
21578
|
+
const paramName = (param) => {
|
|
21579
|
+
const p = param;
|
|
21580
|
+
return p.type === "Identifier" ? p.name ?? null : null;
|
|
21581
|
+
};
|
|
21582
|
+
const proxyName = paramName(params[0]);
|
|
21538
21583
|
if (!proxyName) return null;
|
|
21584
|
+
const priorName = params.length === 2 ? paramName(params[1]) : void 0;
|
|
21585
|
+
if (priorName === null) return null;
|
|
21539
21586
|
const body = factory.body;
|
|
21540
21587
|
if (!body) return null;
|
|
21541
21588
|
const statements = [];
|
|
@@ -21565,9 +21612,10 @@ function evaluateParserFactory(factoryNode, scope, code, mapFnSources, out, opti
|
|
|
21565
21612
|
const ABORT = /* @__PURE__ */ Symbol("parseman: factory not statically evaluable");
|
|
21566
21613
|
let built;
|
|
21567
21614
|
try {
|
|
21568
|
-
built = rules(options ?? {}, (g) => {
|
|
21615
|
+
built = rules(options ?? {}, (g, prior) => {
|
|
21569
21616
|
const localScope = scope instanceof ModuleScope ? scope.fork() : new Map(scope);
|
|
21570
21617
|
localScope.set(proxyName, g);
|
|
21618
|
+
if (priorName !== void 0) localScope.set(priorName, prior);
|
|
21571
21619
|
if (!evalBodyStatements(statements, localScope, code, out)) throw ABORT;
|
|
21572
21620
|
const entries = flattenRuleEntries(retObj, localScope, code);
|
|
21573
21621
|
if (!entries) throw ABORT;
|
|
@@ -21590,8 +21638,10 @@ function evaluateParserFactory(factoryNode, scope, code, mapFnSources, out, opti
|
|
|
21590
21638
|
for (const key of keys) map.set(key, built[key]);
|
|
21591
21639
|
const declared = new Set(keys);
|
|
21592
21640
|
externalAccesses.set(map, Object.keys(built).filter((name) => !declared.has(name)));
|
|
21641
|
+
ruleMapRecipes.set(map, built[RULES_RECIPE]);
|
|
21593
21642
|
return map;
|
|
21594
21643
|
}
|
|
21644
|
+
var ruleMapRecipes = /* @__PURE__ */ new WeakMap();
|
|
21595
21645
|
var externalAccesses = /* @__PURE__ */ new WeakMap();
|
|
21596
21646
|
function isDefinableRef2(v) {
|
|
21597
21647
|
return isCombinator3(v) && typeof v.define === "function" && v._def.tag === "lazy";
|
|
@@ -22935,15 +22985,6 @@ var PARSEMAN_MODULE = "parseman";
|
|
|
22935
22985
|
var DEFAULT_ASSEMBLY_BUDGET = 0.25;
|
|
22936
22986
|
var LinkRefusal = class extends Error {
|
|
22937
22987
|
};
|
|
22938
|
-
function isResolved(rule) {
|
|
22939
|
-
if (rule._def.tag !== "lazy") return true;
|
|
22940
|
-
try {
|
|
22941
|
-
rule._def.thunk();
|
|
22942
|
-
return true;
|
|
22943
|
-
} catch {
|
|
22944
|
-
return false;
|
|
22945
|
-
}
|
|
22946
|
-
}
|
|
22947
22988
|
function reasonSuffix(runtimeOnly) {
|
|
22948
22989
|
return runtimeOnly === void 0 || runtimeOnly.length === 0 ? "" : ` \u2014 ${runtimeOnly.join("; ")}`;
|
|
22949
22990
|
}
|
|
@@ -24076,22 +24117,6 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
24076
24117
|
}
|
|
24077
24118
|
return { pieces, trackLines };
|
|
24078
24119
|
};
|
|
24079
|
-
const mergeRuleMaps = (maps) => {
|
|
24080
|
-
const winners = /* @__PURE__ */ new Map();
|
|
24081
|
-
for (const map of maps) {
|
|
24082
|
-
for (const [name, rule] of map) {
|
|
24083
|
-
if (rule._def.tag === "lazy") {
|
|
24084
|
-
try {
|
|
24085
|
-
rule._def.thunk();
|
|
24086
|
-
} catch {
|
|
24087
|
-
continue;
|
|
24088
|
-
}
|
|
24089
|
-
}
|
|
24090
|
-
winners.set(name, rule);
|
|
24091
|
-
}
|
|
24092
|
-
}
|
|
24093
|
-
return [...winners];
|
|
24094
|
-
};
|
|
24095
24120
|
const mergedCarriedRules = (items, link) => {
|
|
24096
24121
|
const carriedMaps = carriedRuleMaps(items);
|
|
24097
24122
|
if (carriedMaps === null) return null;
|
|
@@ -24099,12 +24124,6 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
24099
24124
|
const dangling = danglingReference(linked);
|
|
24100
24125
|
return { rules: Object.entries(linked), trackLines: carriedMaps.trackLines, dangling };
|
|
24101
24126
|
};
|
|
24102
|
-
const applyComposingTrivia = (ruleMap, composing) => {
|
|
24103
|
-
for (const [, rule] of ruleMap) {
|
|
24104
|
-
if (rule._meta.isTrivia) continue;
|
|
24105
|
-
rule._meta.grammarTrivia = composing;
|
|
24106
|
-
}
|
|
24107
|
-
};
|
|
24108
24127
|
const localCarried = (rm, label2, composing, scanSkip) => {
|
|
24109
24128
|
const entries = [...rm];
|
|
24110
24129
|
const ns = nsFor(label2);
|
|
@@ -24192,10 +24211,15 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
24192
24211
|
carried.push(...r.carried);
|
|
24193
24212
|
importedFactories.push(...r.importedFactories ?? []);
|
|
24194
24213
|
}
|
|
24195
|
-
|
|
24196
|
-
|
|
24197
|
-
|
|
24198
|
-
|
|
24214
|
+
let merged;
|
|
24215
|
+
try {
|
|
24216
|
+
merged = mergedCarriedRules(carried, {
|
|
24217
|
+
trivia: composing,
|
|
24218
|
+
...cHostMode ? { hostMode: cHostMode } : {}
|
|
24219
|
+
});
|
|
24220
|
+
} catch (e) {
|
|
24221
|
+
throw new Error(`${id}:${lineOf(init.start)} \u2014 ${e.message}`, { cause: e });
|
|
24222
|
+
}
|
|
24199
24223
|
if (merged?.dangling !== void 0) throw new Error(`${id}:${lineOf(init.start)} \u2014 compose: ${merged.dangling}`);
|
|
24200
24224
|
if (merged !== null) {
|
|
24201
24225
|
collectBuilderImports(merged.rules);
|
|
@@ -24256,8 +24280,8 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
24256
24280
|
const type = fn?.[INERT_BUILDER];
|
|
24257
24281
|
return type === void 0 ? fn : (children3, _fields, span) => ({ type, span, children: children3 });
|
|
24258
24282
|
});
|
|
24259
|
-
const counts = countSiteVisits(compiled.prog, (
|
|
24260
|
-
const entry =
|
|
24283
|
+
const counts = countSiteVisits(compiled.prog, (rules3) => {
|
|
24284
|
+
const entry = rules3[assemblyProfile.entry];
|
|
24261
24285
|
for (const text of corpusTexts(assemblyProfile)) {
|
|
24262
24286
|
try {
|
|
24263
24287
|
if (run(entry, text).ok) parsed++;
|
|
@@ -24284,17 +24308,14 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
24284
24308
|
}
|
|
24285
24309
|
const localArg = elements[elements.length - 1];
|
|
24286
24310
|
let localRules = null;
|
|
24287
|
-
let localScanSkip;
|
|
24288
24311
|
const importedFactories = [];
|
|
24289
24312
|
if (isRulesCall(localArg)) {
|
|
24290
24313
|
const evaluated = evaluateRulesFactory(localArg, `composeLeaf${init.start}`);
|
|
24291
24314
|
localRules = evaluated?.ruleMap ?? null;
|
|
24292
|
-
localScanSkip = evaluated?.scanSkip;
|
|
24293
24315
|
if (evaluated?.importedFactory) importedFactories.push(evaluated.importedFactory);
|
|
24294
24316
|
} else if (localArg.type === "Identifier") {
|
|
24295
24317
|
const name = localArg.name;
|
|
24296
24318
|
localRules = localRuleMaps.get(name) ?? null;
|
|
24297
|
-
localScanSkip = localGrammarScanSkip.get(name);
|
|
24298
24319
|
}
|
|
24299
24320
|
if (!localRules) {
|
|
24300
24321
|
const named = localArg.type === "Identifier" ? localArg.name : null;
|
|
@@ -24313,8 +24334,6 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
24313
24334
|
importedFactories.push(...r.importedFactories ?? []);
|
|
24314
24335
|
}
|
|
24315
24336
|
try {
|
|
24316
|
-
const localNs = nsFor(`composeLeaf${init.start}`);
|
|
24317
|
-
const localEntries = [...localRules];
|
|
24318
24337
|
const carriedMaps = carriedRuleMaps(carried);
|
|
24319
24338
|
if (carriedMaps !== null) {
|
|
24320
24339
|
const unproven = carriedMaps.pieces.find((p) => {
|
|
@@ -24325,24 +24344,20 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
24325
24344
|
warn(init.start, "composeLeaf(): every pre-final grammar must explicitly prove recognition-only");
|
|
24326
24345
|
return null;
|
|
24327
24346
|
}
|
|
24328
|
-
|
|
24329
|
-
|
|
24330
|
-
|
|
24331
|
-
|
|
24332
|
-
|
|
24333
|
-
|
|
24347
|
+
let linked;
|
|
24348
|
+
try {
|
|
24349
|
+
linked = linkRules(
|
|
24350
|
+
[...carriedMaps.pieces.flatMap((p) => p.recipes), ...ruleMapRecipes.get(localRules)],
|
|
24351
|
+
{ trivia: composing }
|
|
24352
|
+
);
|
|
24353
|
+
} catch (e) {
|
|
24354
|
+
throw new LinkRefusal(`${id}:${lineOf(init.start)} \u2014 composeLeaf: ${e.message.replace(/^compose: /, "")}`, { cause: e });
|
|
24334
24355
|
}
|
|
24335
|
-
const
|
|
24336
|
-
const accessed = [
|
|
24337
|
-
...carriedMaps.pieces.flatMap((p) => p.rules).filter(([, rule]) => !isResolved(rule)).map(([name]) => name),
|
|
24338
|
-
...localRules instanceof Map ? externalAccesses.get(localRules) ?? [] : []
|
|
24339
|
-
];
|
|
24340
|
-
const dangling = danglingReference(Object.fromEntries(leafMerged), accessed);
|
|
24356
|
+
const dangling = danglingReference(linked);
|
|
24341
24357
|
if (dangling !== void 0) throw new LinkRefusal(`${id}:${lineOf(init.start)} \u2014 composeLeaf: ${dangling}`);
|
|
24342
|
-
if (composing) applyComposingTrivia(carriedMaps.pieces.flatMap((p) => p.rules), composing);
|
|
24343
24358
|
const refusals = [];
|
|
24344
24359
|
const compiled = compileRuleMap(
|
|
24345
|
-
|
|
24360
|
+
Object.entries(linked),
|
|
24346
24361
|
{
|
|
24347
24362
|
...composing ? { trivia: composing } : {},
|
|
24348
24363
|
...carriedMaps.trackLines ? { trackLines: true } : {},
|