parseman 0.15.0 → 0.16.0
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/combinators/literal.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts +16 -2
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/scannable-run.d.ts +2 -0
- package/dist/compiler/scannable-run.d.ts.map +1 -1
- package/dist/index.cjs +150 -49
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +150 -49
- package/dist/index.js.map +2 -2
- package/dist/plugin/index.cjs +169 -56
- package/dist/plugin/index.cjs.map +3 -3
- package/dist/plugin/index.d.ts +9 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +169 -56
- package/dist/plugin/index.js.map +3 -3
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../../src/combinators/literal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../../src/combinators/literal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAwBpF,MAAM,MAAM,cAAc,GAAG;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,cAAmB,GAAG,UAAU,CAAC,MAAM,CAAC,CAqDpF"}
|
|
@@ -7,6 +7,20 @@
|
|
|
7
7
|
* object allocation per node.
|
|
8
8
|
*/
|
|
9
9
|
import type { Combinator, FirstSet, ParseResult, ParseContext, ParseError } from '../types.ts';
|
|
10
|
+
/**
|
|
11
|
+
* Runtime prelude helper for the structural-node capture gate. Answers "does the
|
|
12
|
+
* injected `_ctx.build` host read its (n+1)th positional arg?" — `.length` alone
|
|
13
|
+
* under-counts with rest/default params and can't see through a bound fn, so a
|
|
14
|
+
* rest/default param or an `arguments` reference forces full capture (output-safe).
|
|
15
|
+
* Plain positional and bound-native hosts (the common case) trust `.length`.
|
|
16
|
+
* Emitted (memoized on `_ctx._pmCapTL`/`_pmCapST`) wherever a structural node()
|
|
17
|
+
* arity-gates host capture; shared, un-namespaced, mirrors `_EMPTY_TL` placement.
|
|
18
|
+
*/
|
|
19
|
+
export declare const HOST_READS_DECL = "const _hostReads = (b, n) => { if (b === undefined) return false; let s; try { s = Function.prototype.toString.call(b) } catch (e) { return true } if (/\\barguments\\b/.test(s)) return true; const m = /^[^(]*\\(([\\s\\S]*?)\\)/.exec(s); if (m && /\\.\\.\\.|=/.test(m[1])) return true; return b.length > n }";
|
|
20
|
+
/** Begin capturing regexes that fall back to `RegExp.exec` (didn't lower). */
|
|
21
|
+
export declare function beginLoweringCapture(): void;
|
|
22
|
+
/** Stop capturing and return the un-lowered regex sources seen since begin. */
|
|
23
|
+
export declare function endLoweringCapture(): string[];
|
|
10
24
|
export declare function firstSetCond(codeVar: string, fs: FirstSet): string;
|
|
11
25
|
export declare function __setForceDisjointIf(on: boolean): void;
|
|
12
26
|
export type CompiledParser<T> = {
|
|
@@ -63,7 +77,7 @@ export declare function compileRuleMap(ruleMap: ReadonlyArray<readonly [string,
|
|
|
63
77
|
* derives it — module identity in the macro, a counter in `compile()`).
|
|
64
78
|
*
|
|
65
79
|
* prelude — namespaced hoisted decls (regexes, expected, `_mf`/`_build`, and
|
|
66
|
-
* private `_pf` helper fns). Sentinels / `_EMPTY_TL`
|
|
80
|
+
* private `_pf` helper fns). Sentinels / `_EMPTY_TL`
|
|
67
81
|
* are NOT here — they are SHARED, emitted once by the linker.
|
|
68
82
|
* ruleFns — name → `function _r_<Name>(…) { … }` source (the composition
|
|
69
83
|
* surface; siblings call these by name).
|
|
@@ -86,7 +100,7 @@ export type LinkablePieces = {
|
|
|
86
100
|
firstSets: Map<string, FirstSet>;
|
|
87
101
|
deps: Map<string, string[]>;
|
|
88
102
|
needsEmptyTl: boolean;
|
|
89
|
-
|
|
103
|
+
needsHostReads: boolean;
|
|
90
104
|
/**
|
|
91
105
|
* Transform (`_mf`) / build (`_build`) callback FUNCTIONS, injected into the
|
|
92
106
|
* fused scope via `_env` when their SOURCE isn't available (runtime `compile()`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/compiler/codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAa,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAkB,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/compiler/codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAa,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAkB,MAAM,aAAa,CAAA;AAwBzH;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,uTAC0R,CAAA;AActT,8EAA8E;AAC9E,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED,+EAA+E;AAC/E,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAI7C;AAkbD,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,GAAG,MAAM,CAQlE;AAcD,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAA0B;AAglDjF,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAC9B,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;IAClD,kGAAkG;IAClG,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,GAAG,CAAC,EA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,EAAE,QAAQ,CAAC,CAAA;IAChC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IAC3B,YAAY,EAAE,OAAO,CAAA;IACrB,cAAc,EAAE,OAAO,CAAA;IACvB;;;;;OAKG;IACH,KAAK,EAAE,aAAa,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAAA;IACrD,QAAQ,EAAE,aAAa,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAAA;CACzD,CAAA;AAED,wBAAgB,eAAe,CAC7B,UAAU,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EACjE,EAAE,EAAE,MAAM,GACT,cAAc,GAAG,IAAI,CAyKvB"}
|
|
@@ -105,6 +105,8 @@ export declare const BACKSLASH = 92;
|
|
|
105
105
|
*/
|
|
106
106
|
export declare const SPACE_RANGES: Array<[number, number]>;
|
|
107
107
|
export declare function parseClassRanges(body: string): Array<[number, number]> | null;
|
|
108
|
+
/** ASCII case-insensitive letter check for `i`-flag literal lowering. */
|
|
109
|
+
export declare const foldEq: (cVar: string, cp: number) => string;
|
|
108
110
|
type CharSet = {
|
|
109
111
|
ranges: Array<[number, number]>;
|
|
110
112
|
negated: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scannable-run.d.ts","sourceRoot":"","sources":["../../src/compiler/scannable-run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,OAAO,GACf;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GACjD;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC,CAAC,MA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,IAAI,CAAU,CAAA;AAE7D,0FAA0F;AAC1F,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,GAC5C,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAIzB;AAED,sEAAsE;AACtE,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;AAE9C;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AAoCrE,wBAAgB,cAAc,CAC5B,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,GACjB,UAAU,CA6SZ;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAG/D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAazF"}
|
package/dist/index.cjs
CHANGED
|
@@ -358,12 +358,16 @@ function pushTriviaLogEntry(ctx, start, end, kindIndex) {
|
|
|
358
358
|
}
|
|
359
359
|
|
|
360
360
|
// src/combinators/literal.ts
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
361
|
+
function asciiFoldEq(a, b) {
|
|
362
|
+
if (a.length !== b.length) return false;
|
|
363
|
+
for (let i = 0; i < a.length; i++) {
|
|
364
|
+
let ca = a.charCodeAt(i);
|
|
365
|
+
let cb = b.charCodeAt(i);
|
|
366
|
+
if (ca >= 65 && ca <= 90) ca += 32;
|
|
367
|
+
if (cb >= 65 && cb <= 90) cb += 32;
|
|
368
|
+
if (ca !== cb) return false;
|
|
365
369
|
}
|
|
366
|
-
return
|
|
370
|
+
return true;
|
|
367
371
|
}
|
|
368
372
|
function literal(value, opts = {}) {
|
|
369
373
|
const caseInsensitive = opts.caseInsensitive ?? false;
|
|
@@ -378,8 +382,9 @@ function literal(value, opts = {}) {
|
|
|
378
382
|
const lower = value.toLowerCase();
|
|
379
383
|
const firstUpper = upper.codePointAt(0);
|
|
380
384
|
const firstLower = lower.codePointAt(0);
|
|
381
|
-
meta.firstSet = firstLower !== void 0 && firstUpper !== void 0 ? { kind: "ranges", ranges: [
|
|
382
|
-
{ lo:
|
|
385
|
+
meta.firstSet = firstLower !== void 0 && firstUpper !== void 0 ? firstLower === firstUpper ? { kind: "ranges", ranges: [{ lo: firstLower, hi: firstLower }] } : { kind: "ranges", ranges: [
|
|
386
|
+
{ lo: firstLower, hi: firstLower },
|
|
387
|
+
{ lo: firstUpper, hi: firstUpper }
|
|
383
388
|
] } : firstSet;
|
|
384
389
|
}
|
|
385
390
|
return {
|
|
@@ -392,7 +397,7 @@ function literal(value, opts = {}) {
|
|
|
392
397
|
return failAt(ctx, [JSON.stringify(value)], pos);
|
|
393
398
|
}
|
|
394
399
|
const slice = input.slice(pos, end);
|
|
395
|
-
const matched = caseInsensitive ?
|
|
400
|
+
const matched = caseInsensitive ? asciiFoldEq(slice, value) : slice === value;
|
|
396
401
|
if (matched) {
|
|
397
402
|
const span = { start: pos, end };
|
|
398
403
|
const leaf = { _tag: "leaf", value: slice, span };
|
|
@@ -1726,8 +1731,8 @@ function classToRanges(cls) {
|
|
|
1726
1731
|
return parseClassRanges(body);
|
|
1727
1732
|
}
|
|
1728
1733
|
var foldEq = (cVar, cp) => {
|
|
1729
|
-
if (cp >= 65 && cp <= 90) return `(${cVar}
|
|
1730
|
-
if (cp >= 97 && cp <= 122) return `(${cVar}
|
|
1734
|
+
if (cp >= 65 && cp <= 90) return `(${cVar} | 32) === ${cp + 32}`;
|
|
1735
|
+
if (cp >= 97 && cp <= 122) return `(${cVar} | 32) === ${cp}`;
|
|
1731
1736
|
return `${cVar} === ${cp}`;
|
|
1732
1737
|
};
|
|
1733
1738
|
function literalCodePoints(frag) {
|
|
@@ -1978,6 +1983,12 @@ function firstSetsDisjoint(a, b) {
|
|
|
1978
1983
|
return classDisjoint(a, b);
|
|
1979
1984
|
}
|
|
1980
1985
|
function fixedClassSeq(shape) {
|
|
1986
|
+
if (shape.kind === "litFold") {
|
|
1987
|
+
return shape.open.map((cp) => {
|
|
1988
|
+
const other = cp >= 65 && cp <= 90 ? cp + 32 : cp >= 97 && cp <= 122 ? cp - 32 : cp;
|
|
1989
|
+
return other === cp ? { ranges: [[cp, cp]], negated: false } : { ranges: [[Math.min(cp, other), Math.min(cp, other)], [Math.max(cp, other), Math.max(cp, other)]], negated: false };
|
|
1990
|
+
});
|
|
1991
|
+
}
|
|
1981
1992
|
if (shape.kind !== "seq") return null;
|
|
1982
1993
|
const out = [];
|
|
1983
1994
|
for (const p of shape.parts) {
|
|
@@ -2399,12 +2410,34 @@ function parseScanShapeCore(source) {
|
|
|
2399
2410
|
}
|
|
2400
2411
|
function scanShapeFromRegex(source, flags) {
|
|
2401
2412
|
if (/[msu]/.test(flags)) return null;
|
|
2402
|
-
if (/i/.test(flags))
|
|
2403
|
-
const open = literalCodePoints(source);
|
|
2404
|
-
return open ? { kind: "litFold", open } : null;
|
|
2405
|
-
}
|
|
2413
|
+
if (/i/.test(flags)) return caseFoldShape(source);
|
|
2406
2414
|
return parseScanShape(source);
|
|
2407
2415
|
}
|
|
2416
|
+
function caseFoldShape(source) {
|
|
2417
|
+
const la = stripTrailingLookahead(source);
|
|
2418
|
+
if (la) {
|
|
2419
|
+
const inner = caseFoldLiteralOrAlt(la.base);
|
|
2420
|
+
if (!inner) return null;
|
|
2421
|
+
const operand = { ranges: la.ranges, negated: la.classNegated };
|
|
2422
|
+
if (!lookaheadUnambiguous(inner, operand, la.negative)) return null;
|
|
2423
|
+
return { kind: "lookahead", inner, ranges: la.ranges, classNegated: la.classNegated, negative: la.negative };
|
|
2424
|
+
}
|
|
2425
|
+
return caseFoldLiteralOrAlt(source);
|
|
2426
|
+
}
|
|
2427
|
+
function caseFoldLiteralOrAlt(source) {
|
|
2428
|
+
const asciiOnly = (cps) => cps.every((cp) => cp <= 127);
|
|
2429
|
+
const open = literalCodePoints(source);
|
|
2430
|
+
if (open) return asciiOnly(open) ? { kind: "litFold", open } : null;
|
|
2431
|
+
const arms = splitTopLevelAlternation(source);
|
|
2432
|
+
if (!arms || arms.length < 2) return null;
|
|
2433
|
+
const litArms = [];
|
|
2434
|
+
for (const arm of arms) {
|
|
2435
|
+
const cp = literalCodePoints(arm);
|
|
2436
|
+
if (!cp || !asciiOnly(cp)) return null;
|
|
2437
|
+
litArms.push({ kind: "litFold", open: cp });
|
|
2438
|
+
}
|
|
2439
|
+
return { kind: "alt", arms: litArms, disjoint: false, firsts: litArms.map(() => null) };
|
|
2440
|
+
}
|
|
2408
2441
|
var classCond = (cVar, ranges) => ranges.map(([lo, hi]) => lo === hi ? `${cVar} === ${lo}` : `(${cVar} >= ${lo} && ${cVar} <= ${hi})`).join(" || ");
|
|
2409
2442
|
var litCond = (base, cps, firstVar) => cps.map(
|
|
2410
2443
|
(cp, k) => k === 0 && firstVar ? `${firstVar} === ${cp}` : `input.charCodeAt(${base}${k ? ` + ${k}` : ""}) === ${cp}`
|
|
@@ -2416,6 +2449,25 @@ function stringHardStop(shape) {
|
|
|
2416
2449
|
);
|
|
2417
2450
|
}
|
|
2418
2451
|
var codeAt = (start, firstChar) => firstChar ?? `input.charCodeAt(${start})`;
|
|
2452
|
+
var ALT_SWITCH_RANGE_LIMIT = 4;
|
|
2453
|
+
var ALT_SWITCH_MAX_CASES = 48;
|
|
2454
|
+
var ALT_SWITCH_MIN_CASES = 3;
|
|
2455
|
+
function planAltSwitch(firsts) {
|
|
2456
|
+
const cases = [];
|
|
2457
|
+
let total = 0;
|
|
2458
|
+
for (const fs of firsts) {
|
|
2459
|
+
if (!fs || fs.negated) return { kind: "if" };
|
|
2460
|
+
const pts = [];
|
|
2461
|
+
for (const [lo, hi] of fs.ranges) {
|
|
2462
|
+
if (hi - lo + 1 > ALT_SWITCH_RANGE_LIMIT) return { kind: "if" };
|
|
2463
|
+
for (let cp = lo; cp <= hi; cp++) pts.push(cp);
|
|
2464
|
+
}
|
|
2465
|
+
total += pts.length;
|
|
2466
|
+
if (total > ALT_SWITCH_MAX_CASES) return { kind: "if" };
|
|
2467
|
+
cases.push(pts);
|
|
2468
|
+
}
|
|
2469
|
+
return total >= ALT_SWITCH_MIN_CASES ? { kind: "switch", cases } : { kind: "if" };
|
|
2470
|
+
}
|
|
2419
2471
|
function emitShapeMatch(shape, start, mint, ind2, firstChar) {
|
|
2420
2472
|
if (shape.kind === "lookahead") {
|
|
2421
2473
|
const inner = emitShapeMatch(shape.inner, start, mint, ind2, firstChar);
|
|
@@ -2440,18 +2492,57 @@ function emitShapeMatch(shape, start, mint, ind2, firstChar) {
|
|
|
2440
2492
|
const okV = mint("_ok");
|
|
2441
2493
|
const endV2 = mint("_end");
|
|
2442
2494
|
const lines = [`${ind2}let ${okV} = false`, `${ind2}let ${endV2} = ${start}`];
|
|
2495
|
+
if (shape.arms.length >= 2 && shape.arms.every((a) => a.kind === "litFold" && a.open.length >= 1)) {
|
|
2496
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2497
|
+
for (const a of shape.arms) {
|
|
2498
|
+
const open = a.open;
|
|
2499
|
+
const f = open[0];
|
|
2500
|
+
const lower = f >= 65 && f <= 90 ? f + 32 : f;
|
|
2501
|
+
(groups.get(lower) ?? groups.set(lower, []).get(lower)).push(open);
|
|
2502
|
+
}
|
|
2503
|
+
lines.push(`${ind2}if (${start} < input.length) switch (${codeAt(start, firstChar)}) {`);
|
|
2504
|
+
for (const [lower, arms] of groups) {
|
|
2505
|
+
const labels = lower >= 97 && lower <= 122 ? `case ${lower}: case ${lower - 32}:` : `case ${lower}:`;
|
|
2506
|
+
lines.push(`${ind2} ${labels} {`);
|
|
2507
|
+
for (const open of arms) {
|
|
2508
|
+
const tail = open.slice(1).map((cp, i) => foldEq(`input.charCodeAt(${start} + ${i + 1})`, cp));
|
|
2509
|
+
const cond = tail.length ? ` && ${tail.join(" && ")}` : "";
|
|
2510
|
+
lines.push(`${ind2} if (${start} + ${open.length} <= input.length${cond}) { ${okV} = true; ${endV2} = ${start} + ${open.length}; break }`);
|
|
2511
|
+
}
|
|
2512
|
+
lines.push(`${ind2} break`);
|
|
2513
|
+
lines.push(`${ind2} }`);
|
|
2514
|
+
}
|
|
2515
|
+
lines.push(`${ind2}}`);
|
|
2516
|
+
return { setup: lines, ok: okV, end: endV2 };
|
|
2517
|
+
}
|
|
2443
2518
|
if (shape.disjoint) {
|
|
2444
|
-
const
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2519
|
+
const plan = planAltSwitch(shape.firsts);
|
|
2520
|
+
if (plan.kind === "switch") {
|
|
2521
|
+
lines.push(`${ind2}if (${start} < input.length) switch (${codeAt(start, firstChar)}) {`);
|
|
2522
|
+
shape.arms.forEach((arm, k) => {
|
|
2523
|
+
const labels = plan.cases[k].map((cp) => `case ${cp}:`).join(" ");
|
|
2524
|
+
const m = emitShapeMatch(arm, start, mint, `${ind2} `, firstChar);
|
|
2525
|
+
lines.push(`${ind2} ${labels} {`);
|
|
2526
|
+
lines.push(...m.setup);
|
|
2527
|
+
lines.push(`${ind2} ${okV} = ${m.ok}`);
|
|
2528
|
+
lines.push(`${ind2} ${endV2} = ${m.ok} ? ${m.end} : ${start}`);
|
|
2529
|
+
lines.push(`${ind2} break`);
|
|
2530
|
+
lines.push(`${ind2} }`);
|
|
2531
|
+
});
|
|
2453
2532
|
lines.push(`${ind2}}`);
|
|
2454
|
-
}
|
|
2533
|
+
} else {
|
|
2534
|
+
const c0 = codeAt(start, firstChar);
|
|
2535
|
+
shape.arms.forEach((arm, k) => {
|
|
2536
|
+
const fs = shape.firsts[k];
|
|
2537
|
+
const cond = fs.negated ? `!(${classCond(c0, fs.ranges)})` : `(${classCond(c0, fs.ranges)})`;
|
|
2538
|
+
const m = emitShapeMatch(arm, start, mint, `${ind2} `, firstChar);
|
|
2539
|
+
lines.push(`${ind2}${k === 0 ? "if" : "else if"} (${start} < input.length && ${cond}) {`);
|
|
2540
|
+
lines.push(...m.setup);
|
|
2541
|
+
lines.push(`${ind2} ${okV} = ${m.ok}`);
|
|
2542
|
+
lines.push(`${ind2} ${endV2} = ${m.ok} ? ${m.end} : ${start}`);
|
|
2543
|
+
lines.push(`${ind2}}`);
|
|
2544
|
+
});
|
|
2545
|
+
}
|
|
2455
2546
|
} else {
|
|
2456
2547
|
const lbl = mint("_alt");
|
|
2457
2548
|
lines.push(`${ind2}${lbl}: {`);
|
|
@@ -2939,6 +3030,8 @@ function tryInlineDestructureTransform(src, valueVars) {
|
|
|
2939
3030
|
}
|
|
2940
3031
|
|
|
2941
3032
|
// src/compiler/codegen.ts
|
|
3033
|
+
var HOST_READS_DECL = "const _hostReads = (b, n) => { if (b === undefined) return false; let s; try { s = Function.prototype.toString.call(b) } catch (e) { return true } if (/\\barguments\\b/.test(s)) return true; const m = /^[^(]*\\(([\\s\\S]*?)\\)/.exec(s); if (m && /\\.\\.\\.|=/.test(m[1])) return true; return b.length > n }";
|
|
3034
|
+
var _loweringSink = null;
|
|
2942
3035
|
function v(ctx, prefix = "_v") {
|
|
2943
3036
|
return `${prefix}${ctx.vars++}`;
|
|
2944
3037
|
}
|
|
@@ -3337,13 +3430,14 @@ function emitLit(def, ctx, pos) {
|
|
|
3337
3430
|
const vv = v(ctx);
|
|
3338
3431
|
const expectedStr = JSON.stringify(JSON.stringify(value));
|
|
3339
3432
|
const stmts = [];
|
|
3340
|
-
if (caseInsensitive) {
|
|
3341
|
-
|
|
3433
|
+
if (caseInsensitive && len > 0) {
|
|
3434
|
+
const match = Array.from(
|
|
3435
|
+
{ length: len },
|
|
3436
|
+
(_, i) => `(${foldEq(`input.charCodeAt(${pos}${i > 0 ? ` + ${i}` : ""})`, value.charCodeAt(i))})`
|
|
3437
|
+
).join(" && ");
|
|
3342
3438
|
stmts.push(
|
|
3343
|
-
...emitIfFail(ctx, `${pos} + ${len} > input.length`, failBody(ctx, expectedStr, pos)),
|
|
3344
|
-
`${ind(ctx)}const ${vv}
|
|
3345
|
-
...emitIfFail(ctx, `_collator.compare(${vv}_s, ${JSON.stringify(value)}) !== 0`, failBody(ctx, expectedStr, pos)),
|
|
3346
|
-
`${ind(ctx)}const ${vv} = ${vv}_s`
|
|
3439
|
+
...emitIfFail(ctx, `${pos} + ${len} > input.length || !(${match})`, failBody(ctx, expectedStr, pos)),
|
|
3440
|
+
`${ind(ctx)}const ${vv} = input.slice(${pos}, ${pos} + ${len})`
|
|
3347
3441
|
);
|
|
3348
3442
|
} else if (len === 0) {
|
|
3349
3443
|
stmts.push(`${ind(ctx)}const ${vv} = ''`);
|
|
@@ -3464,6 +3558,7 @@ function emitRegex(def, ctx, pos) {
|
|
|
3464
3558
|
return { stmts: stmts2, valueVar: vv2, endVar: scanned.endVar };
|
|
3465
3559
|
}
|
|
3466
3560
|
}
|
|
3561
|
+
_loweringSink?.add(`/${def.source}/${def.flags}`);
|
|
3467
3562
|
const flags = "y" + def.flags.replace(/[gy]/g, "");
|
|
3468
3563
|
const key = `${def.source}/${flags}`;
|
|
3469
3564
|
let rName = ctx.regexMap.get(key);
|
|
@@ -4044,15 +4139,19 @@ function emitNode(def, ctx, pos) {
|
|
|
4044
4139
|
ctx.buildSrcs.push(def.buildSrc ?? null);
|
|
4045
4140
|
}
|
|
4046
4141
|
const i = ind(ctx);
|
|
4047
|
-
const capturesTrivia = mkType !== null || structural
|
|
4048
|
-
const clonesState = structural
|
|
4142
|
+
const capturesTrivia = mkType !== null || !structural && buildReadsTrivia(def);
|
|
4143
|
+
const clonesState = !structural && buildReadsState(def);
|
|
4049
4144
|
const chV = v(ctx, "_ch");
|
|
4050
4145
|
const rawV = v(ctx, "_raw");
|
|
4051
|
-
const
|
|
4146
|
+
const capTLv = structural ? v(ctx, "_ctl") : null;
|
|
4147
|
+
const capSTv = structural ? v(ctx, "_cst") : null;
|
|
4148
|
+
const tlV = capturesTrivia || structural ? v(ctx, "_tl") : "_EMPTY_TL";
|
|
4052
4149
|
if (!capturesTrivia) ctx.needsEmptyTl = true;
|
|
4053
4150
|
const sc = v(ctx, "_sc"), sl = v(ctx, "_sl"), sr = v(ctx, "_sr"), st = v(ctx, "_st"), stl = v(ctx, "_stl");
|
|
4054
|
-
|
|
4055
|
-
const
|
|
4151
|
+
if (structural) ctx.needsHostReads = true;
|
|
4152
|
+
const allocStmt = structural ? `${i}const ${capTLv} = _ctx._pmCapTL ??= _hostReads(_ctx.build, 4), ${capSTv} = _ctx._pmCapST ??= (_ctx.build === undefined || _hostReads(_ctx.build, 5))
|
|
4153
|
+
${i}const ${chV} = [], ${rawV} = [], ${tlV} = ${capTLv} ? [] : _EMPTY_TL` : capturesTrivia ? `${i}const ${chV} = [], ${rawV} = [], ${tlV} = []` : `${i}const ${chV} = [], ${rawV} = []`;
|
|
4154
|
+
const innerTl = structural ? `${capTLv} ? ${tlV} : undefined` : capturesTrivia ? tlV : "undefined";
|
|
4056
4155
|
const stmts = [
|
|
4057
4156
|
allocStmt,
|
|
4058
4157
|
`${i}const ${sc} = _ctx._cstChildren, ${sl} = _ctx._cstLeaves, ${sr} = _ctx._cstRawChildren, ${st} = _ctx.captureTrivia, ${stl} = _ctx._cstTriviaLog`,
|
|
@@ -4063,7 +4162,10 @@ function emitNode(def, ctx, pos) {
|
|
|
4063
4162
|
stmts.push(`${i}_ctx._cstChildren = ${sc}; _ctx._cstLeaves = ${sl}; _ctx._cstRawChildren = ${sr}; _ctx.captureTrivia = ${st}; _ctx._cstTriviaLog = ${stl}`);
|
|
4064
4163
|
stmts.push(...emitIfFail(ctx, `!${okVar}`, propagateFailBody(ctx)));
|
|
4065
4164
|
let stV = "undefined";
|
|
4066
|
-
if (
|
|
4165
|
+
if (structural) {
|
|
4166
|
+
stV = v(ctx, "_nst");
|
|
4167
|
+
stmts.push(`${i}const ${stV} = ${capSTv} && _ctx.state !== undefined ? Object.assign({}, _ctx.state) : undefined`);
|
|
4168
|
+
} else if (clonesState) {
|
|
4067
4169
|
stV = v(ctx, "_nst");
|
|
4068
4170
|
stmts.push(`${i}const ${stV} = _ctx.state !== undefined ? Object.assign({}, _ctx.state) : undefined`);
|
|
4069
4171
|
}
|
|
@@ -4499,7 +4601,6 @@ function compile(combinator, mapFnSources) {
|
|
|
4499
4601
|
buildFns: [],
|
|
4500
4602
|
buildSrcs: [],
|
|
4501
4603
|
runtimeParsers: [],
|
|
4502
|
-
needsCollator: false,
|
|
4503
4604
|
namedParsers: /* @__PURE__ */ new Map(),
|
|
4504
4605
|
triviaCaptureNames: /* @__PURE__ */ new Map(),
|
|
4505
4606
|
triviaFnNames: /* @__PURE__ */ new Map(),
|
|
@@ -4508,18 +4609,18 @@ function compile(combinator, mapFnSources) {
|
|
|
4508
4609
|
lazyUsage: analyzeLazyUsage(combinator)
|
|
4509
4610
|
};
|
|
4510
4611
|
const r = emit(combinator, ctx, "_pos");
|
|
4511
|
-
const collatorDecl = ctx.needsCollator ? `const _collator = new Intl.Collator(undefined, { sensitivity: 'accent' })
|
|
4512
|
-
` : "";
|
|
4513
4612
|
const namedPrelude = ctx.namedFnDecls.length > 0 ? [...namedFnPrelude(), ""] : [];
|
|
4514
4613
|
const emptyTlDecls = ctx.needsEmptyTl ? ["const _EMPTY_TL = Object.freeze([])"] : [];
|
|
4614
|
+
const hostReadsDecls = ctx.needsHostReads ? [HOST_READS_DECL] : [];
|
|
4515
4615
|
const source = [
|
|
4516
4616
|
...emptyTlDecls,
|
|
4617
|
+
...hostReadsDecls,
|
|
4517
4618
|
...ctx.regexDecls,
|
|
4518
4619
|
...ctx.expectedDecls,
|
|
4519
4620
|
"",
|
|
4520
4621
|
...namedPrelude,
|
|
4521
4622
|
ctx.namedFnDecls.join("\n\n"),
|
|
4522
|
-
|
|
4623
|
+
`function _parse(input, _pos, _rp, _mf, _build, _ctx) {`,
|
|
4523
4624
|
` let pos = _pos`,
|
|
4524
4625
|
...r.stmts,
|
|
4525
4626
|
` return { ok: true, value: ${r.valueVar}, span: { start: _pos, end: ${r.endVar} } }`,
|
|
@@ -4527,9 +4628,9 @@ function compile(combinator, mapFnSources) {
|
|
|
4527
4628
|
].join("\n");
|
|
4528
4629
|
const fn = new Function("input", "_pos", "_rp", "_mf", "_build", "_ctx", [
|
|
4529
4630
|
...emptyTlDecls,
|
|
4631
|
+
...hostReadsDecls,
|
|
4530
4632
|
...ctx.regexDecls,
|
|
4531
4633
|
...ctx.expectedDecls,
|
|
4532
|
-
collatorDecl,
|
|
4533
4634
|
...namedPrelude,
|
|
4534
4635
|
...ctx.namedFnDecls.flatMap((decl, i) => i > 0 ? ["", decl] : [decl]),
|
|
4535
4636
|
`let pos = _pos`,
|
|
@@ -4546,7 +4647,7 @@ function compile(combinator, mapFnSources) {
|
|
|
4546
4647
|
const buildSources = ctx.buildFns.length === 0 ? void 0 : ctx.buildSrcs;
|
|
4547
4648
|
const mfCovered = ctx.mapFns.length === 0 || effectiveSources !== void 0 && effectiveSources.length === ctx.mapFns.length;
|
|
4548
4649
|
const canInline = ctx.runtimeParsers.length === 0 && mfCovered && buildCovered;
|
|
4549
|
-
const inlineExpression = canInline ? buildInlineExpression(ctx, r,
|
|
4650
|
+
const inlineExpression = canInline ? buildInlineExpression(ctx, r, effectiveSources, buildSources) : null;
|
|
4550
4651
|
return {
|
|
4551
4652
|
source,
|
|
4552
4653
|
inlineExpression,
|
|
@@ -4602,7 +4703,6 @@ function compileLinkable(ruleMapArg, ns) {
|
|
|
4602
4703
|
buildFns: [],
|
|
4603
4704
|
buildSrcs: [],
|
|
4604
4705
|
runtimeParsers: [],
|
|
4605
|
-
needsCollator: false,
|
|
4606
4706
|
namedParsers: /* @__PURE__ */ new Map(),
|
|
4607
4707
|
triviaCaptureNames: /* @__PURE__ */ new Map(),
|
|
4608
4708
|
triviaFnNames: /* @__PURE__ */ new Map(),
|
|
@@ -4733,12 +4833,12 @@ function compileLinkable(ruleMapArg, ns) {
|
|
|
4733
4833
|
firstSets,
|
|
4734
4834
|
deps: ruleDependencies(ruleMap),
|
|
4735
4835
|
needsEmptyTl: !!ctx.needsEmptyTl,
|
|
4736
|
-
|
|
4836
|
+
needsHostReads: !!ctx.needsHostReads,
|
|
4737
4837
|
mfFns: mfSrcs ? [] : ctx.mapFns,
|
|
4738
4838
|
buildFns: buildSrcs ? [] : ctx.buildFns
|
|
4739
4839
|
};
|
|
4740
4840
|
}
|
|
4741
|
-
function buildInlineExpression(ctx, r,
|
|
4841
|
+
function buildInlineExpression(ctx, r, mapFnSources, buildSources) {
|
|
4742
4842
|
const bodyLines = [
|
|
4743
4843
|
` let pos = _pos`,
|
|
4744
4844
|
...r.stmts,
|
|
@@ -4752,14 +4852,15 @@ function buildInlineExpression(ctx, r, collatorDecl, mapFnSources, buildSources)
|
|
|
4752
4852
|
const mfDecl = mapFnSources?.length ? ` const _mf = [${mapFnSources.join(", ")}]` : "";
|
|
4753
4853
|
const buildDecl = buildSources?.length ? ` const _build = [${buildSources.join(", ")}]` : "";
|
|
4754
4854
|
const emptyTlDecl = ctx.needsEmptyTl ? ` const _EMPTY_TL = Object.freeze([])` : "";
|
|
4755
|
-
const
|
|
4855
|
+
const hostReadsDecl = ctx.needsHostReads ? ` ${HOST_READS_DECL}` : "";
|
|
4856
|
+
const needsWrapper = ctx.regexDecls.length > 0 || ctx.expectedDecls.length > 0 || ctx.namedFnDecls.length > 0 || !!mfDecl || !!buildDecl || !!emptyTlDecl || !!hostReadsDecl;
|
|
4756
4857
|
if (!needsWrapper) return innerFn;
|
|
4757
4858
|
const namedPrelude = ctx.namedFnDecls.length > 0 ? namedFnPrelude() : [];
|
|
4758
4859
|
const hoistedDecls = [
|
|
4759
4860
|
emptyTlDecl,
|
|
4861
|
+
hostReadsDecl,
|
|
4760
4862
|
...ctx.regexDecls.map((d) => ` ${d}`),
|
|
4761
4863
|
...ctx.expectedDecls.map((d) => ` ${d}`),
|
|
4762
|
-
collatorDecl ? ` ${collatorDecl.trim()}` : "",
|
|
4763
4864
|
mfDecl,
|
|
4764
4865
|
buildDecl,
|
|
4765
4866
|
...namedPrelude.map((l) => ` ${l}`),
|
|
@@ -4818,13 +4919,13 @@ function fusedBody(pieces) {
|
|
|
4818
4919
|
}
|
|
4819
4920
|
const contributing = new Set(winner.values());
|
|
4820
4921
|
const needsEmptyTl = [...contributing].some((p) => p.needsEmptyTl);
|
|
4821
|
-
const
|
|
4922
|
+
const needsHostReads = [...contributing].some((p) => p.needsHostReads);
|
|
4822
4923
|
const lines = [
|
|
4823
4924
|
// Shared sentinel protocol (must match NAMED_FN_FAIL / NAMED_FN_END in codegen).
|
|
4824
4925
|
"const _pfFail = {}",
|
|
4825
4926
|
"let _pfEnd",
|
|
4826
4927
|
...needsEmptyTl ? ["const _EMPTY_TL = Object.freeze([])"] : [],
|
|
4827
|
-
...
|
|
4928
|
+
...needsHostReads ? [HOST_READS_DECL] : [],
|
|
4828
4929
|
// Each contributing artifact's namespaced private prelude (regexes, _pf, …).
|
|
4829
4930
|
...[...contributing].flatMap((p) => p.prelude),
|
|
4830
4931
|
// The winning `_r_<Name>` function for each rule (one per name → no redeclare).
|