parseman 0.14.0 → 0.15.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 CHANGED
@@ -4,10 +4,29 @@
4
4
 
5
5
  # Parséman (PAR-zə-mahn)
6
6
 
7
- Write parsers in TypeScript — fast enough to run as-is, and blazing fast when the bundler macro kicks in. Same grammar either way; no grammar files, no generated output to check in. Drop the plugin in tests or anywhere a bundler isn't around and everything still works.
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;AAEtD,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"}
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;AAGnF,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;;;OAMG;IACH,O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C,CAwCH"}
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,CAuBlE;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CA2BvE;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
+ {"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,CAuD9B"}
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,8 @@
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
+ export declare function firstSetCond(codeVar: string, fs: FirstSet): string;
10
11
  export declare function __setForceDisjointIf(on: boolean): void;
11
12
  export type CompiledParser<T> = {
12
13
  parse(input: string, pos?: number): ParseResult<T>;
@@ -50,35 +51,6 @@ export declare function ruleDependencies(ruleMap: ReadonlyArray<readonly [string
50
51
  * @see https://www.greadme.com/blog/security/what-is-content-security-policy-complete-guide
51
52
  */
52
53
  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
54
  export declare function compileRuleMap(ruleMap: ReadonlyArray<readonly [string, Combinator<unknown>]>): {
83
55
  keys: string[];
84
56
  replacement: string;
@@ -106,6 +78,12 @@ export type LinkablePieces = {
106
78
  prelude: string[];
107
79
  ruleFns: Map<string, string>;
108
80
  wrappers: Map<string, string>;
81
+ /**
82
+ * Per-rule first-set (this artifact's own rules). fusedBody() uses the WINNING
83
+ * artifact's entry to resolve `/*@FS:rule:codevar@*​/true` dispatch placeholders
84
+ * emitted for rule-ref choice arms — sound under compose override.
85
+ */
86
+ firstSets: Map<string, FirstSet>;
109
87
  deps: Map<string, string[]>;
110
88
  needsEmptyTl: boolean;
111
89
  needsCollator: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/compiler/codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAuB,WAAW,EAAE,YAAY,EAAE,UAAU,EAAkB,MAAM,aAAa,CAAA;AAodzH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAA0B;AAwiDjF,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAC9B,KAAK,CAAC,KAAK,EAAE,MA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,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"}
@@ -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"}
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/functional/run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEpF;;;;;;;;;;;;GAYG;AAEH,+EAA+E;AAC/E,MAAM,MAAM,QAAQ,GAChB,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,KAA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