parseman 0.14.1 → 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/README.md +41 -2
- package/dist/combinators/first-set.d.ts +18 -1
- package/dist/combinators/first-set.d.ts.map +1 -1
- package/dist/combinators/grammar.d.ts.map +1 -1
- package/dist/combinators/literal.d.ts.map +1 -1
- package/dist/combinators/parser.d.ts.map +1 -1
- package/dist/combinators/repeat.d.ts.map +1 -1
- package/dist/combinators/sequence.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts +24 -32
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/linker.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/compiler/value-usage.d.ts +24 -0
- package/dist/compiler/value-usage.d.ts.map +1 -0
- package/dist/index.cjs +377 -77
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +377 -77
- package/dist/index.js.map +4 -4
- package/dist/plugin/index.cjs +391 -85
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.d.ts +9 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +391 -85
- package/dist/plugin/index.js.map +4 -4
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,10 +4,29 @@
|
|
|
4
4
|
|
|
5
5
|
# Parséman (PAR-zə-mahn)
|
|
6
6
|
|
|
7
|
-
Write parsers
|
|
7
|
+
Write parsers as TypeScript functions. Ship them like hand-written parsers.
|
|
8
|
+
|
|
9
|
+
Parséman is a TypeScript parser-combinator library with an optional compiler/macro path that turns your grammar into flat JavaScript. Use the same grammar interpreted in tests and REPLs, macro-compiled at build time in production, or `.compile()`d on demand at runtime.
|
|
10
|
+
|
|
11
|
+
Use Parséman when you want:
|
|
12
|
+
|
|
13
|
+
- normal TypeScript instead of grammar files
|
|
14
|
+
- parser-combinator ergonomics without parser-combinator slowness
|
|
15
|
+
- CST/AST nodes with spans and trivia
|
|
16
|
+
- error recovery for editor tooling
|
|
17
|
+
- incremental re-parsing
|
|
18
|
+
- fast parsers for DSLs, config languages, formatters, linters, and language servers
|
|
8
19
|
|
|
9
20
|
> **📖 Full documentation: [matthew-dean.github.io/parseman](https://matthew-dean.github.io/parseman/)**
|
|
10
21
|
|
|
22
|
+
## Why Parséman?
|
|
23
|
+
|
|
24
|
+
Most parser tools make you choose between ergonomics and performance.
|
|
25
|
+
|
|
26
|
+
Parser combinators are pleasant to write, but often slow. Parser generators can be fast, but usually involve grammar files, generated code, and extra tooling. Hand-written parsers are fast, but expensive to design and maintain.
|
|
27
|
+
|
|
28
|
+
Parséman aims for the useful middle: write your parser as ordinary TypeScript, then compile it into code that behaves more like a hand-written parser.
|
|
29
|
+
|
|
11
30
|
---
|
|
12
31
|
|
|
13
32
|
## Install
|
|
@@ -64,8 +83,28 @@ Full API in the **[reference](https://matthew-dean.github.io/parseman/reference/
|
|
|
64
83
|
|
|
65
84
|
---
|
|
66
85
|
|
|
86
|
+
## Compared to other parser tools
|
|
87
|
+
|
|
88
|
+
Wondering how Parséman compares to Peggy, Chevrotain, Lezer, tree-sitter, Parsimmon, Nearley, or hand-written parsers?
|
|
89
|
+
|
|
90
|
+
See the full comparison: **[How Parséman compares](https://matthew-dean.github.io/parseman/guide/comparison)**
|
|
91
|
+
|
|
92
|
+
## Real grammar example: GraphQL
|
|
93
|
+
|
|
94
|
+
Parséman includes a [GraphQL grammar](./examples/graphql/parser.ts) used in the benchmark suite. It parses executable GraphQL documents (queries, mutations, subscriptions, fragments, directives, variables, all value types) into typed AST nodes — not just syntax-validating them.
|
|
95
|
+
|
|
96
|
+
This is a real-world example of Parséman on a non-trivial, spec-shaped language, not a toy grammar.
|
|
97
|
+
|
|
98
|
+
- Source: [`examples/graphql/parser.ts`](./examples/graphql/parser.ts)
|
|
99
|
+
- Benchmark results: [GraphQL benchmarks](https://matthew-dean.github.io/parseman/guide/benchmarks#graphql)
|
|
100
|
+
- Benchmark runner: [`bench/run.ts`](./bench/run.ts)
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
67
104
|
## Benchmarks
|
|
68
105
|
|
|
106
|
+
Parséman includes benchmarks against several JavaScript/TypeScript parser libraries across JSON, CSV, and GraphQL fixtures. Benchmarks are not universal truth tablets — results depend on grammar shape, input size, runtime, and what each parser is asked to produce. The benchmark suite is included so results can be inspected and reproduced (see [Reproducing the numbers](https://matthew-dean.github.io/parseman/guide/benchmarks#reproducing-the-numbers)).
|
|
107
|
+
|
|
69
108
|
**When parsing to JS values** — objects, row arrays, AST nodes — **Parséman's macro build is the fastest general-purpose JS parser we benchmark**, beating [Peggy](https://peggyjs.org/), [Parsimmon](https://github.com/jneen/parsimmon), [Chevrotain](https://chevrotain.io/), [Nearley](https://nearley.js.org/), and [Jison](https://github.com/zaach/jison) at every grammar and size. The only thing that edges it out is a purpose-built native like `JSON.parse`; for anything that *doesn't* have a built-in, Parséman is the one to beat.
|
|
70
109
|
|
|
71
110
|
For **syntax tree building**, the compiled CST path (macro build) beats [Lezer](https://lezer.codemirror.net/) on the JSON CST fixture too — while producing a richer object tree with spans and trivia. For **incremental re-parse**, the two trade places by edit type: Parséman's `parseDoc` is ~300× faster than a full reparse on in-place value edits (and ahead of Lezer), while Lezer's buffer reuse wins on structural edits. Full breakdown in the [benchmarks guide](https://matthew-dean.github.io/parseman/guide/benchmarks).
|
|
@@ -84,7 +123,7 @@ Compared parsers: **Parséman**, [Peggy](https://peggyjs.org/), [Parsimmon](http
|
|
|
84
123
|
|
|
85
124
|
Parséman has three modes — **interpreter** (zero setup, works anywhere), **macro build** (compiled by the bundler plugin at build time, zero runtime cost), and **`.compile()`** (optional runtime JIT). Most production use lands on one of the first two. The initialization section only shows parsers with a nonzero setup cost: `.compile()` costs 75–650 µs depending on grammar size; Chevrotain always costs 840–1,400 µs. Parsers not listed there start for free. (Init numbers are pinned on the charts — they're noisy run-to-run; warm-parse bars are the meaningful comparison.)
|
|
86
125
|
|
|
87
|
-
On JSON, CSV, and GraphQL, Parséman macro beats every other library at every fixture size in the charts above — e.g. GraphQL large **154 µs** vs Peggy **423 µs**, JSON large **125 µs** vs Peggy **472 µs** / Chevrotain **1,946 µs**. Native `JSON.parse` is the one thing faster on JSON (**45 µs** large). Even the zero-setup interpreter is highly competitive: on JSON and CSV it's the fastest option after the macro build — ahead of Peggy and every other generator — with Peggy edging it out only on GraphQL. On the CST chart, macro build beats Lezer at every size (**344 µs** vs **587 µs** large, parse-only). Full write-up and how to refresh the charts: **[benchmarks guide](https://matthew-dean.github.io/parseman/guide/benchmarks)**. Grammar-level speed levers: [performance guide](https://matthew-dean.github.io/parseman/guide/performance); library-level codegen: [PERF_IDEAS.md](./PERF_IDEAS.md).
|
|
126
|
+
On JSON, CSV, and GraphQL, Parséman macro beats every other library at every fixture size in the charts above — e.g. GraphQL large **154 µs** vs Peggy **423 µs**, JSON large **125 µs** vs Peggy **472 µs** / Chevrotain **1,946 µs**. Native `JSON.parse` is the one thing faster on JSON (**45 µs** large). Even the zero-setup interpreter is highly competitive: on JSON and CSV it's the fastest option after the macro build — ahead of Peggy and every other generator — with Peggy edging it out only on GraphQL. On the CST chart, macro build beats Lezer at every size (**344 µs** vs **587 µs** large, parse-only). Full write-up and how to refresh the charts: **[benchmarks guide](https://matthew-dean.github.io/parseman/guide/benchmarks)**. Grammar-level speed levers: [performance guide](https://matthew-dean.github.io/parseman/guide/performance); library-level codegen: [PERF_IDEAS.md](./notes/PERF_IDEAS.md).
|
|
88
127
|
|
|
89
128
|
---
|
|
90
129
|
|
|
@@ -1,8 +1,25 @@
|
|
|
1
|
-
import type { FirstSet } from '../types.ts';
|
|
1
|
+
import type { FirstSet, Combinator } from '../types.ts';
|
|
2
2
|
export declare function union(a: FirstSet, b: FirstSet): FirstSet;
|
|
3
3
|
export declare function intersects(a: FirstSet, b: FirstSet): boolean;
|
|
4
4
|
export declare function fromChar(code: number): FirstSet;
|
|
5
5
|
export declare function fromRange(lo: number, hi: number): FirstSet;
|
|
6
6
|
export declare function any(): FirstSet;
|
|
7
7
|
export declare function empty(): FirstSet;
|
|
8
|
+
/**
|
|
9
|
+
* Can this parser SUCCEED consuming zero characters (nullable / matches-empty)?
|
|
10
|
+
* Used to compute a sound sequence first-set: a nullable leading term lets the
|
|
11
|
+
* NEXT term's first chars start the whole sequence. MUST err toward `true` when
|
|
12
|
+
* unsure — over-estimating nullability only widens the (over-approximated) first
|
|
13
|
+
* set, which stays sound; under-estimating would drop valid start chars and make
|
|
14
|
+
* first-char dispatch skip a matching arm.
|
|
15
|
+
*/
|
|
16
|
+
export declare function matchesEmpty(p: Combinator<unknown>, seen?: Set<Combinator<unknown>>): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* First-set of a sequence: union each term's first-set through the NULLABLE
|
|
19
|
+
* PREFIX — a leading `optional(…)` / `many(…)` / nullable term can be skipped, so
|
|
20
|
+
* the sequence can begin with a LATER term's first char. Stop at (and include)
|
|
21
|
+
* the first non-nullable term. (`parsers[0].firstSet` alone under-approximates
|
|
22
|
+
* and silently breaks first-char dispatch — see the InterpolatedSelector bug.)
|
|
23
|
+
*/
|
|
24
|
+
export declare function sequenceFirstSet(parsers: readonly Combinator<unknown>[]): FirstSet;
|
|
8
25
|
//# sourceMappingURL=first-set.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"first-set.d.ts","sourceRoot":"","sources":["../../src/combinators/first-set.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,QAAQ,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"first-set.d.ts","sourceRoot":"","sources":["../../src/combinators/first-set.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,QAAQ,EAAE,UAAU,EAAa,MAAM,aAAa,CAAA;AAE7E,wBAAgB,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAKxD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,OAAO,CAS5D;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAE/C;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,QAAQ,CAE1D;AAED,wBAAgB,GAAG,IAAI,QAAQ,CAE9B;AAED,wBAAgB,KAAK,IAAI,QAAQ,CAEhC;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,OAAO,CAmCxG;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,UAAU,CAAC,OAAO,CAAC,EAAE,GAAG,QAAQ,CAOlF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grammar.d.ts","sourceRoot":"","sources":["../../src/combinators/grammar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAa,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"grammar.d.ts","sourceRoot":"","sources":["../../src/combinators/grammar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAa,MAAM,aAAa,CAAA;AAInF,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG;IACzC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;IACnC,gFAAgF;IAChF,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IACtD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;IACpC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;CACrE;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAwCrF;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAElE;AAOD,wBAAgB,KAAK,CAAC,CAAC,EACrB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EACzB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,YAAiB,GACtB,WAAW,CAAC,CAAC,CAAC,CA2BhB"}
|
|
@@ -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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/combinators/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/combinators/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAI7C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EACjE,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,GACxB,CAAC,CA+CH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repeat.d.ts","sourceRoot":"","sources":["../../src/combinators/repeat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAkDpF,wBAAgB,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"repeat.d.ts","sourceRoot":"","sources":["../../src/combinators/repeat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAkDpF,wBAAgB,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CA4BlE;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CA+BvE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,CAoB3E;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAyDhG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../../src/combinators/sequence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAoD,MAAM,aAAa,CAAA;AAI/F,KAAK,aAAa,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI;KACnD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAC7D,CAAA;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,EAChF,GAAG,OAAO,EAAE,CAAC,GACZ,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../../src/combinators/sequence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAoD,MAAM,aAAa,CAAA;AAI/F,KAAK,aAAa,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI;KACnD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAC7D,CAAA;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,EAChF,GAAG,OAAO,EAAE,CAAC,GACZ,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CA+D9B"}
|
|
@@ -6,7 +6,22 @@
|
|
|
6
6
|
* `break <label>` rather than an IIFE return — no function call, no result
|
|
7
7
|
* object allocation per node.
|
|
8
8
|
*/
|
|
9
|
-
import type { Combinator, ParseResult, ParseContext, ParseError } from '../types.ts';
|
|
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[];
|
|
24
|
+
export declare function firstSetCond(codeVar: string, fs: FirstSet): string;
|
|
10
25
|
export declare function __setForceDisjointIf(on: boolean): void;
|
|
11
26
|
export type CompiledParser<T> = {
|
|
12
27
|
parse(input: string, pos?: number): ParseResult<T>;
|
|
@@ -50,35 +65,6 @@ export declare function ruleDependencies(ruleMap: ReadonlyArray<readonly [string
|
|
|
50
65
|
* @see https://www.greadme.com/blog/security/what-is-content-security-policy-complete-guide
|
|
51
66
|
*/
|
|
52
67
|
export declare function compile<T>(combinator: Combinator<T>, mapFnSources?: string[]): CompiledParser<T>;
|
|
53
|
-
/**
|
|
54
|
-
* Compile every entry of a `rules(factory)` map's returned object using ONE
|
|
55
|
-
* shared codegen Ctx (regexes, named functions, map/build-fn arrays) instead
|
|
56
|
-
* of running `compile()` independently per entry.
|
|
57
|
-
*
|
|
58
|
-
* Why this exists: `compile()` per entry gives each entry its own namedParsers
|
|
59
|
-
* cache, so a sub-rule reachable from N different top-level entries (e.g.
|
|
60
|
-
* `valueList` reachable from `Declaration`, `CustomDeclaration`, `Guard`, …)
|
|
61
|
-
* gets fully re-compiled N times — on a richly cross-referential grammar
|
|
62
|
-
* (Less: ~125 rule-map entries, deep mutual reference) this multiplies total
|
|
63
|
-
* compiled size far past what the source grammar actually needs, independent
|
|
64
|
-
* of the per-ref single-use inlining `analyzeLazyUsage` already handles
|
|
65
|
-
* within one compile() call. Sharing one Ctx here means a sub-rule compiles
|
|
66
|
-
* exactly once for the WHOLE rule map, however many entries reach it.
|
|
67
|
-
*
|
|
68
|
-
* Returns a single `replacement` — ONE shared IIFE, evaluated once, whose
|
|
69
|
-
* result is the `{ key: fn, ... }` map — meant to replace the entire
|
|
70
|
-
* `rules(factory)` call-expression (not one expression per key; splicing a
|
|
71
|
-
* separate self-contained expression per key would either re-run the shared
|
|
72
|
-
* prelude once per entry or duplicate its text per entry, undoing the win).
|
|
73
|
-
* `keys` lists every entry compileRuleMap() saw, for the caller to validate
|
|
74
|
-
* against the source's own key list.
|
|
75
|
-
*
|
|
76
|
-
* Returns null (same all-or-nothing contract the per-entry `compile()` +
|
|
77
|
-
* `inlineExpression === null` check gave the plugin before) when the map
|
|
78
|
-
* contains anything that can't be inlined — a runtime-fallback parser, or an
|
|
79
|
-
* uncaptured transform/build closure source. The plugin's existing "warn and
|
|
80
|
-
* leave this rules() call interpreted" fallback covers this case unchanged.
|
|
81
|
-
*/
|
|
82
68
|
export declare function compileRuleMap(ruleMap: ReadonlyArray<readonly [string, Combinator<unknown>]>): {
|
|
83
69
|
keys: string[];
|
|
84
70
|
replacement: string;
|
|
@@ -91,7 +77,7 @@ export declare function compileRuleMap(ruleMap: ReadonlyArray<readonly [string,
|
|
|
91
77
|
* derives it — module identity in the macro, a counter in `compile()`).
|
|
92
78
|
*
|
|
93
79
|
* prelude — namespaced hoisted decls (regexes, expected, `_mf`/`_build`, and
|
|
94
|
-
* private `_pf` helper fns). Sentinels / `_EMPTY_TL`
|
|
80
|
+
* private `_pf` helper fns). Sentinels / `_EMPTY_TL`
|
|
95
81
|
* are NOT here — they are SHARED, emitted once by the linker.
|
|
96
82
|
* ruleFns — name → `function _r_<Name>(…) { … }` source (the composition
|
|
97
83
|
* surface; siblings call these by name).
|
|
@@ -106,9 +92,15 @@ export type LinkablePieces = {
|
|
|
106
92
|
prelude: string[];
|
|
107
93
|
ruleFns: Map<string, string>;
|
|
108
94
|
wrappers: Map<string, string>;
|
|
95
|
+
/**
|
|
96
|
+
* Per-rule first-set (this artifact's own rules). fusedBody() uses the WINNING
|
|
97
|
+
* artifact's entry to resolve `/*@FS:rule:codevar@*/true` dispatch placeholders
|
|
98
|
+
* emitted for rule-ref choice arms — sound under compose override.
|
|
99
|
+
*/
|
|
100
|
+
firstSets: Map<string, FirstSet>;
|
|
109
101
|
deps: Map<string, string[]>;
|
|
110
102
|
needsEmptyTl: boolean;
|
|
111
|
-
|
|
103
|
+
needsHostReads: boolean;
|
|
112
104
|
/**
|
|
113
105
|
* Transform (`_mf`) / build (`_build`) callback FUNCTIONS, injected into the
|
|
114
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,
|
|
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,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;IAChF;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG;QAAE,MAAM,EAAE,UAAU,EAAE,CAAA;KAAE,CAAA;IACvF,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAA;IACd;;;;;;OAMG;IACH,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;CAChC,CAAA;AAoJD;;;;;;;GAOG;AACH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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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linker.d.ts","sourceRoot":"","sources":["../../src/compiler/linker.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"linker.d.ts","sourceRoot":"","sources":["../../src/compiler/linker.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,aAAa,CAAA;AAavD,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC7C,EAAE,CAAC,EAAE,MAAM,GACV,cAAc,CAIhB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,EAChC,YAAY,EAAE,aAAa,CAAC,OAAO,CAAC,EACpC,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACpC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,EAC9B,KAAK,CAAC,EAAE,OAAO,GACd,OAAO,CAIT;AAED,MAAM,MAAM,SAAS,GAAG,CACtB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACzB;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAA;AAE3E;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAClB,OAAO,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC7D,KAAK,EAAE,MAAM,EAAE,GACd,cAAc,CA2BhB;AAmED;qFACqF;AACrF,wBAAgB,SAAS,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAI7E;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,CAMhE;AA8BD,wBAAgB,OAAO,CACrB,KAAK,EAAE,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACrD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAK3B"}
|
|
@@ -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,EAA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OxD,CAAA;AAEjB,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB,YAAI,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,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"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Combinator } from '../types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Dead-value analysis (shared by the interpreter and codegen). A container
|
|
4
|
+
* combinator — `many` / `oneOrMore` / `optional` / `sequence` — builds an
|
|
5
|
+
* aggregate value (array / tuple / nullable). Under a `node()`, the node builds
|
|
6
|
+
* from the *captured children*, never from that aggregate, so the aggregate is
|
|
7
|
+
* built and thrown away. This pass marks those containers `valueUnused`; the
|
|
8
|
+
* interpreter and the emitter then skip building the aggregate entirely (the
|
|
9
|
+
* elements still parse and self-capture, so trees are identical).
|
|
10
|
+
*
|
|
11
|
+
* Walks ONE combinator tree (a single rule body, or a standalone root), stopping
|
|
12
|
+
* at `lazy`/ref boundaries — other rules are analyzed on their own root. Starts
|
|
13
|
+
* `consumed = true` (a rule's own value is assumed read — conservative); `node()`
|
|
14
|
+
* flips it to false for its inner parser; `transform` forces it true (its map fn
|
|
15
|
+
* reads the value). Sharing-safe: any `consumed = true` visit wins and is sticky,
|
|
16
|
+
* so a container reachable from BOTH a consuming and a non-consuming site keeps
|
|
17
|
+
* its aggregate (never wrongly elided).
|
|
18
|
+
*
|
|
19
|
+
* Soundness: a container is marked ONLY when every path to it passes through a
|
|
20
|
+
* `node()` (value-discarding) without an intervening value-reader — i.e. its
|
|
21
|
+
* aggregate provably isn't observed. Idempotent; safe to re-run.
|
|
22
|
+
*/
|
|
23
|
+
export declare function markUnusedValues(root: Combinator<unknown>): void;
|
|
24
|
+
//# sourceMappingURL=value-usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-usage.d.ts","sourceRoot":"","sources":["../../src/compiler/value-usage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,aAAa,CAAA;AAExD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,IAAI,CAuGhE"}
|