parseman 0.34.0 → 0.36.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 +94 -72
- package/dist/combinators/expect.d.ts +13 -1
- package/dist/combinators/expect.d.ts.map +1 -1
- package/dist/combinators/trivia-skip.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/cst/capture-buffer.d.ts.map +1 -1
- package/dist/index.cjs +51 -31
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +51 -31
- package/dist/index.js.map +3 -3
- package/dist/language-service/index.cjs.map +1 -1
- package/dist/language-service/index.js.map +1 -1
- package/dist/plugin/index.cjs +51 -31
- package/dist/plugin/index.cjs.map +3 -3
- package/dist/plugin/index.js +51 -31
- package/dist/plugin/index.js.map +3 -3
- package/dist/run/index.cjs +216 -0
- package/dist/run/index.cjs.map +7 -0
- package/dist/run/index.d.ts +28 -0
- package/dist/run/index.d.ts.map +1 -0
- package/dist/run/index.js +193 -0
- package/dist/run/index.js.map +7 -0
- package/dist/version.d.ts +1 -1
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -6,29 +6,17 @@
|
|
|
6
6
|
|
|
7
7
|
Write parsers as TypeScript functions. Ship them like hand-written parsers.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Parser combinators are pleasant to write and usually slow. Parser generators are fast and
|
|
10
|
+
usually mean grammar files, generated code, and extra tooling. Parséman is a TypeScript
|
|
11
|
+
combinator library with an optional compiler: write ordinary TypeScript, and a build-time
|
|
12
|
+
macro turns it into flat JavaScript that behaves like a parser you wrote by hand.
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
14
|
+
Reach for it when you want normal TypeScript instead of grammar files, CST/AST nodes with
|
|
15
|
+
spans and trivia, error recovery and incremental re-parsing for editor tooling, or simply
|
|
16
|
+
a fast parser for a DSL, config language, formatter, or linter.
|
|
19
17
|
|
|
20
18
|
> **📖 Full documentation: [matthew-dean.github.io/parseman](https://matthew-dean.github.io/parseman/)**
|
|
21
19
|
|
|
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
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
20
|
## Install
|
|
33
21
|
|
|
34
22
|
```bash
|
|
@@ -36,8 +24,8 @@ npm install parseman
|
|
|
36
24
|
# pnpm add parseman
|
|
37
25
|
```
|
|
38
26
|
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
Pre-1.0: minor versions may carry breaking changes — check the [changelog](./CHANGELOG.md)
|
|
28
|
+
before upgrading. Requires Node `^20.19.0 || >=22.12.0`.
|
|
41
29
|
|
|
42
30
|
## Quick start
|
|
43
31
|
|
|
@@ -57,64 +45,95 @@ parse(requestLine, 'GET /api/v1 HTTP/1.1')
|
|
|
57
45
|
// { ok: true, value: { verb: 'GET', path: '/api/v1', version: 'HTTP/1.1' }, span: ... }
|
|
58
46
|
```
|
|
59
47
|
|
|
48
|
+
New here? **[What is Parséman?](https://matthew-dean.github.io/parseman/guide/getting-started)**
|
|
49
|
+
walks the same ground more slowly.
|
|
50
|
+
|
|
60
51
|
## Three modes, one grammar
|
|
61
52
|
|
|
62
53
|
The same combinator code runs three ways, with identical results:
|
|
63
54
|
|
|
64
55
|
- **Interpreter** — zero setup, works anywhere (tests, REPLs, dynamic grammars).
|
|
65
|
-
- **Macro build** — a [bundler plugin](https://matthew-dean.github.io/parseman/guide/macro-mode)
|
|
66
|
-
|
|
56
|
+
- **Macro build** — a [bundler plugin](https://matthew-dean.github.io/parseman/guide/macro-mode)
|
|
57
|
+
evaluates your grammar at build time and inlines the result. The combinator import you
|
|
58
|
+
mark `with { type: 'macro' }` disappears entirely; what ships is flat JavaScript with no
|
|
59
|
+
parseman import in it. (Executing that parser still goes through `run()`/`parse()`, so an
|
|
60
|
+
app keeps parseman as an ordinary dependency — see
|
|
61
|
+
[the three modes](https://matthew-dean.github.io/parseman/guide/modes).)
|
|
62
|
+
- **`compile()`** — the same optimizer, on demand at runtime.
|
|
67
63
|
|
|
68
64
|
```ts
|
|
69
65
|
// Add the plugin (vite.config.ts) and one import attribute — that's the whole change:
|
|
70
66
|
import { literal, sequence, choice } from 'parseman' with { type: 'macro' }
|
|
71
67
|
```
|
|
72
68
|
|
|
73
|
-
See **[The three modes](https://matthew-dean.github.io/parseman/guide/modes)
|
|
69
|
+
See **[The three modes](https://matthew-dean.github.io/parseman/guide/modes)**.
|
|
74
70
|
|
|
75
71
|
## What's in the box
|
|
76
72
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
- **[
|
|
80
|
-
|
|
81
|
-
- **[
|
|
82
|
-
|
|
83
|
-
- **[
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
-
|
|
102
|
-
-
|
|
103
|
-
-
|
|
104
|
-
|
|
105
|
-
|
|
73
|
+
**✍️ Writing grammars**
|
|
74
|
+
|
|
75
|
+
- 🧩 **[Combinators](https://matthew-dean.github.io/parseman/guide/combinators)** — `literal`,
|
|
76
|
+
`regex`, `sequence`, `choice`, `many`, `sepBy`, `token`, `peek`, `not`, and more.
|
|
77
|
+
- 🌀 **[Recursive rules](https://matthew-dean.github.io/parseman/guide/recursive-rules)** —
|
|
78
|
+
`rules()` for mutually recursive grammars; fully macro-compilable.
|
|
79
|
+
- 🫧 **[Whitespace & trivia](https://matthew-dean.github.io/parseman/guide/trivia)** —
|
|
80
|
+
grammar-defined filler skipping, with per-chunk kind capture.
|
|
81
|
+
- 🎯 **[Ordered choice, done right](https://matthew-dean.github.io/parseman/guide/keywords)** —
|
|
82
|
+
PEG semantics you control by ordering, with keyword boundaries that don't bite.
|
|
83
|
+
- 🪶 **[Grammars the way you write them](https://matthew-dean.github.io/parseman/guide/natural-grammars)** —
|
|
84
|
+
no FIRST/FOLLOW sets to compute, no left-factoring `choice(a·x, a·y)` into `a·(x | y)`
|
|
85
|
+
to satisfy the tool. The compiler does that for you.
|
|
86
|
+
- 🧬 **[Extending grammars](https://matthew-dean.github.io/parseman/guide/extending)** —
|
|
87
|
+
`compose()` a dialect onto a base grammar instead of forking it.
|
|
88
|
+
- 🎛️ **[Context-sensitive parsing](https://matthew-dean.github.io/parseman/guide/context)** —
|
|
89
|
+
`withCtx` / `gate` without mutating shared state.
|
|
90
|
+
|
|
91
|
+
**🌳 Getting structure out**
|
|
92
|
+
|
|
93
|
+
- 🌲 **[CST / AST nodes](https://matthew-dean.github.io/parseman/guide/ast)** — `node()`
|
|
94
|
+
captures terminals, named fields, and trivia, with policies for wrapping and collapsing.
|
|
95
|
+
- 🩹 **[Error recovery](https://matthew-dean.github.io/parseman/guide/error-recovery)** —
|
|
96
|
+
keep parsing broken input and report every error.
|
|
97
|
+
- ⚡ **[Incremental re-parsing](https://matthew-dean.github.io/parseman/guide/incremental)** —
|
|
98
|
+
`parseDoc` re-parses just the edited subtree on each keystroke.
|
|
99
|
+
- 💡 **[Editor / LSP integration](https://matthew-dean.github.io/parseman/guide/editor-integration)** —
|
|
100
|
+
completions and lint keyed by rule name; the grammar stays pure structure.
|
|
101
|
+
|
|
102
|
+
**🔬 Seeing what your grammar does**
|
|
103
|
+
|
|
104
|
+
- 🚂 **[Railroad diagrams & EBNF](https://matthew-dean.github.io/parseman/guide/spec-generation)** —
|
|
105
|
+
`toRailroadHtml()` and `toEBNF()` generate the grammar reference *from the parser*, so
|
|
106
|
+
the spec can't drift from what actually parses.
|
|
107
|
+
- 🔎 **[Grammar observability](https://matthew-dean.github.io/parseman/guide/grammar-observability)** —
|
|
108
|
+
coverage ("which rules and choice arms ran?") and trace ("what did it try, select, and
|
|
109
|
+
backtrack through?").
|
|
110
|
+
- 🚦 **[First-char gating diagnostics](https://matthew-dean.github.io/parseman/guide/first-char-gating)** —
|
|
111
|
+
the build tells you which `choice` lost its O(1) dispatch, names the overlapping arms,
|
|
112
|
+
and says how to fix it.
|
|
113
|
+
- 📈 **[Performance guide](https://matthew-dean.github.io/parseman/guide/performance)** —
|
|
114
|
+
the levers that actually move a grammar, and [how regexes lower](https://matthew-dean.github.io/parseman/guide/regex-lowering).
|
|
115
|
+
|
|
116
|
+
Full API in the **[reference](https://matthew-dean.github.io/parseman/reference/api)**; how
|
|
117
|
+
it stacks up against Peggy, Chevrotain, Lezer, tree-sitter, Parsimmon, Nearley and
|
|
118
|
+
hand-written parsers in
|
|
119
|
+
**[How Parséman compares](https://matthew-dean.github.io/parseman/guide/comparison)**.
|
|
106
120
|
|
|
107
121
|
## Benchmarks
|
|
108
122
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
123
|
+
Benchmarked against [Peggy](https://peggyjs.org/),
|
|
124
|
+
[Parsimmon](https://github.com/jneen/parsimmon), [Chevrotain](https://chevrotain.io/),
|
|
125
|
+
[Nearley](https://nearley.js.org/), [Jison](https://github.com/zaach/jison) and
|
|
126
|
+
[Lezer](https://lezer.codemirror.net/) on JSON, CSV and GraphQL — each building real output
|
|
127
|
+
(objects, row arrays, AST nodes), not validating syntax.
|
|
114
128
|
|
|
115
|
-
|
|
129
|
+
**Parsing to JS values, the macro build is the fastest general-purpose JS parser in the
|
|
130
|
+
suite** — ahead of every library above at every grammar and size (GraphQL large: **142 µs**
|
|
131
|
+
vs Peggy's 339 µs). Only a purpose-built native edges it out, `JSON.parse` on JSON.
|
|
116
132
|
|
|
117
|
-
|
|
133
|
+
Two more results worth calling out: the compiled CST path beats Lezer on the JSON CST
|
|
134
|
+
fixture while producing a richer tree carrying spans and trivia, and `parseDoc` stores
|
|
135
|
+
parent-relative spans so an in-place edit costs a fraction of a full reparse rather than a
|
|
136
|
+
multiple of it.
|
|
118
137
|
|
|
119
138
|

|
|
120
139
|
|
|
@@ -124,26 +143,29 @@ Compared parsers: **Parséman**, [Peggy](https://peggyjs.org/), [Parsimmon](http
|
|
|
124
143
|
|
|
125
144
|

|
|
126
145
|
|
|
127
|
-
|
|
146
|
+
Per-fixture figures, initialization costs, hardware, grammar provenance and how to reproduce
|
|
147
|
+
any of it: **[benchmarks guide](https://matthew-dean.github.io/parseman/guide/benchmarks)**.
|
|
148
|
+
Results move with grammar shape, input size and runtime — which is why the suite ships with
|
|
149
|
+
the library rather than only its conclusions. Speed levers for your own grammars:
|
|
150
|
+
[performance guide](https://matthew-dean.github.io/parseman/guide/performance).
|
|
128
151
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
152
|
+
The GraphQL fixture is a [real grammar](./examples/graphql/parser.ts), parsing executable
|
|
153
|
+
documents — queries, mutations, fragments, directives, every value type — into typed AST
|
|
154
|
+
nodes, so the numbers come from a spec-shaped language rather than a toy.
|
|
132
155
|
|
|
133
156
|
## Developing
|
|
134
157
|
|
|
135
158
|
```bash
|
|
136
159
|
pnpm install
|
|
137
|
-
pnpm test
|
|
138
|
-
pnpm typecheck
|
|
139
|
-
pnpm build
|
|
140
|
-
pnpm
|
|
141
|
-
pnpm bench:parseman # Parseman interpreted vs compiled regression report
|
|
142
|
-
pnpm bench:svg # chart-only benchmarks + refresh assets/bench-*.svg
|
|
143
|
-
pnpm bench:compile-grammars # regenerate Peggy / Nearley / Jison parser output in bench/
|
|
144
|
-
pnpm docs:dev # run this documentation site locally
|
|
160
|
+
pnpm test # interpreter + compiled parity, ordered-choice semantics
|
|
161
|
+
pnpm typecheck
|
|
162
|
+
pnpm build # ESM + CJS + .d.ts → dist/
|
|
163
|
+
pnpm docs:dev # this documentation site, locally
|
|
145
164
|
```
|
|
146
165
|
|
|
166
|
+
Benchmark and chart tasks (`pnpm bench`, `bench:svg`, `bench:parseman`, …) are described in
|
|
167
|
+
the [benchmarks guide](https://matthew-dean.github.io/parseman/guide/benchmarks#reproducing-the-numbers).
|
|
168
|
+
|
|
147
169
|
## License
|
|
148
170
|
|
|
149
171
|
MIT © [Matthew Dean](https://github.com/matthew-dean)
|
|
@@ -7,12 +7,24 @@ export type { ParseError };
|
|
|
7
7
|
* literal('}') -> ['"}"']
|
|
8
8
|
* keywords(['a','b']) -> ['"a"', '"b"']
|
|
9
9
|
* choice(x, y) -> expected(x) ++ expected(y) (all alternatives)
|
|
10
|
-
* sequence(a, b, …) -> expected(a)
|
|
10
|
+
* sequence(a, b, …) -> expected(a) ++ … through the NULLABLE prefix
|
|
11
11
|
* label('s', x) -> ['s'] (an explicit name wins)
|
|
12
12
|
*
|
|
13
13
|
* This is what lets expect() report a meaningful, IDENTICAL expectation in both
|
|
14
14
|
* the interpreter and the compiled output (the compiled path does not rebuild the
|
|
15
15
|
* runtime `expected` array, so it reads this precomputed set instead).
|
|
16
|
+
*
|
|
17
|
+
* The result is DEDUPLICATED. Deriving through a nullable prefix re-reaches the
|
|
18
|
+
* same token from several terms — a value grammar whose leading terms are all
|
|
19
|
+
* optional names its value-start set once per term — and an expectation list that
|
|
20
|
+
* offers `"@{"` five times is wrong for a reader and expensive for a parser: a
|
|
21
|
+
* choice that loses every arm materializes `[...arm0, ...arm1, …]` at runtime, and
|
|
22
|
+
* those arrays feed the enclosing choice's concat in turn, so duplicates compound
|
|
23
|
+
* multiplicatively up the nesting. On jess's Less grammar the un-deduped sets cost
|
|
24
|
+
* 32% of parse time on `benchmark.less` (medians 20.7 → 14.2 ms over 100
|
|
25
|
+
* interleaved pairs, 99/100 wins, min 19.1 → 13.0), which is the whole of the Less
|
|
26
|
+
* regression 0.35.0 shipped. Dedup is not an optimisation bolted onto the
|
|
27
|
+
* derivation — a SET is what the derivation always meant.
|
|
16
28
|
*/
|
|
17
29
|
export declare function deriveExpected(c: Combinator<unknown>): string[];
|
|
18
30
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/combinators/expect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,UAAU,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/combinators/expect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,UAAU,EAAE,MAAM,aAAa,CAAA;AAIhG,YAAY,EAAE,UAAU,EAAE,CAAA;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,MAAM,EAAE,CAE/D;AAkED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CA2B/F;AAED,+DAA+D;AAC/D,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trivia-skip.d.ts","sourceRoot":"","sources":["../../src/combinators/trivia-skip.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAetE;;;;;;GAMG;AACH,M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GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,GACjB,IAAI,CAkBN;AAED,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,GACjB,IAAI,CAON;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAElE"}
|
package/dist/index.cjs
CHANGED
|
@@ -441,28 +441,28 @@ function rollbackBufList(b, keyMulti, keySingle, len) {
|
|
|
441
441
|
else if (len === 1) {
|
|
442
442
|
b[keySingle] = arr[0];
|
|
443
443
|
b[keyMulti] = void 0;
|
|
444
|
-
} else arr.length = len;
|
|
444
|
+
} else if (arr.length !== len) arr.length = len;
|
|
445
445
|
return;
|
|
446
446
|
}
|
|
447
447
|
if (len === 0) b[keySingle] = void 0;
|
|
448
448
|
}
|
|
449
449
|
function rollbackCstCapture(ctx, mark) {
|
|
450
|
-
if (ctx._errors && mark.errors !== void 0) ctx._errors.length = mark.errors;
|
|
450
|
+
if (ctx._errors && mark.errors !== void 0 && ctx._errors.length !== mark.errors) ctx._errors.length = mark.errors;
|
|
451
451
|
const b = ctx._cstBuf;
|
|
452
452
|
if (b) {
|
|
453
453
|
rollbackBufList(b, "raw", "rawSingle", mark.raw);
|
|
454
454
|
rollbackBufList(b, "ch", "single", mark.leaves);
|
|
455
455
|
if (b.tl) {
|
|
456
456
|
if (mark.tlog === 0) b.tl = void 0;
|
|
457
|
-
else b.tl.length = mark.tlog;
|
|
457
|
+
else if (b.tl.length !== mark.tlog) b.tl.length = mark.tlog;
|
|
458
458
|
}
|
|
459
|
-
if (ctx._fields) ctx._fields.length = mark.fields;
|
|
459
|
+
if (ctx._fields && ctx._fields.length !== mark.fields) ctx._fields.length = mark.fields;
|
|
460
460
|
return;
|
|
461
461
|
}
|
|
462
|
-
if (ctx._cstRawChildren) ctx._cstRawChildren.length = mark.raw;
|
|
463
|
-
if (ctx._cstTriviaLog) ctx._cstTriviaLog.length = mark.tlog;
|
|
464
|
-
if (ctx._cstLeaves) ctx._cstLeaves.length = mark.leaves;
|
|
465
|
-
if (ctx._fields) ctx._fields.length = mark.fields;
|
|
462
|
+
if (ctx._cstRawChildren && ctx._cstRawChildren.length !== mark.raw) ctx._cstRawChildren.length = mark.raw;
|
|
463
|
+
if (ctx._cstTriviaLog && ctx._cstTriviaLog.length !== mark.tlog) ctx._cstTriviaLog.length = mark.tlog;
|
|
464
|
+
if (ctx._cstLeaves && ctx._cstLeaves.length !== mark.leaves) ctx._cstLeaves.length = mark.leaves;
|
|
465
|
+
if (ctx._fields && ctx._fields.length !== mark.fields) ctx._fields.length = mark.fields;
|
|
466
466
|
}
|
|
467
467
|
function pushCstTriviaEntry(ctx, start, end, kindIndex) {
|
|
468
468
|
const insertIdx = cstRawLen(ctx);
|
|
@@ -1155,6 +1155,10 @@ var REC = { scan: recoverScan, at: matchesAt, or: orSentinel, sentinel: firstSet
|
|
|
1155
1155
|
|
|
1156
1156
|
// src/combinators/expect.ts
|
|
1157
1157
|
function deriveExpected(c) {
|
|
1158
|
+
return [...new Set(derive(c, /* @__PURE__ */ new Set()))];
|
|
1159
|
+
}
|
|
1160
|
+
function derive(c, seen) {
|
|
1161
|
+
const deriveExpected2 = (p) => derive(p, seen);
|
|
1158
1162
|
const def = c._def;
|
|
1159
1163
|
switch (def.tag) {
|
|
1160
1164
|
case "literal":
|
|
@@ -1166,20 +1170,32 @@ function deriveExpected(c) {
|
|
|
1166
1170
|
case "label":
|
|
1167
1171
|
return [def.label];
|
|
1168
1172
|
case "choice":
|
|
1169
|
-
return def.parsers.flatMap(
|
|
1170
|
-
|
|
1171
|
-
|
|
1173
|
+
return def.parsers.flatMap(deriveExpected2);
|
|
1174
|
+
// Union through the NULLABLE prefix, mirroring `sequenceFirstSet`. A leading
|
|
1175
|
+
// `optional(…)`/`many(…)` can match nothing, so the term after it is equally
|
|
1176
|
+
// able to fail first — deriving from term 0 alone named a token the parse
|
|
1177
|
+
// never actually required. A leading `not(…)` is zero-width and contributes
|
|
1178
|
+
// nothing (its own expectation is about what must NOT be here), but it is
|
|
1179
|
+
// nullable, so keep scanning past it. Stop at the first term that must match.
|
|
1180
|
+
case "sequence": {
|
|
1181
|
+
const out = [];
|
|
1182
|
+
for (const term of def.parsers) {
|
|
1183
|
+
if (!isZeroWidthAssertion(term)) out.push(...deriveExpected2(term));
|
|
1184
|
+
if (!matchesEmpty(term)) break;
|
|
1185
|
+
}
|
|
1186
|
+
return out;
|
|
1187
|
+
}
|
|
1172
1188
|
case "attempt":
|
|
1173
|
-
return
|
|
1189
|
+
return deriveExpected2(def.parser);
|
|
1174
1190
|
// Delegating wrappers whose first-token failure is their inner parser's — must
|
|
1175
1191
|
// pass through so a start-failure (and the first-set-miss fast-path in attempt/
|
|
1176
1192
|
// node, which reads this) names the real expected token, not the wrapper tag.
|
|
1177
1193
|
case "field":
|
|
1178
1194
|
case "withCtx":
|
|
1179
1195
|
case "recover":
|
|
1180
|
-
return
|
|
1196
|
+
return deriveExpected2(def.parser);
|
|
1181
1197
|
case "skip":
|
|
1182
|
-
return
|
|
1198
|
+
return deriveExpected2(def.main);
|
|
1183
1199
|
case "expect":
|
|
1184
1200
|
return def.expected;
|
|
1185
1201
|
case "node":
|
|
@@ -1193,13 +1209,17 @@ function deriveExpected(c) {
|
|
|
1193
1209
|
case "transform":
|
|
1194
1210
|
case "not":
|
|
1195
1211
|
case "peek":
|
|
1196
|
-
return
|
|
1212
|
+
return deriveExpected2(def.parser);
|
|
1197
1213
|
case "lazy": {
|
|
1198
1214
|
const name = c._ruleName;
|
|
1215
|
+
if (seen.has(c)) return name ? [name] : [];
|
|
1216
|
+
seen.add(c);
|
|
1199
1217
|
try {
|
|
1200
|
-
return
|
|
1218
|
+
return deriveExpected2(def.thunk());
|
|
1201
1219
|
} catch {
|
|
1202
1220
|
return name ? [name] : [];
|
|
1221
|
+
} finally {
|
|
1222
|
+
seen.delete(c);
|
|
1203
1223
|
}
|
|
1204
1224
|
}
|
|
1205
1225
|
default:
|
|
@@ -1330,14 +1350,14 @@ function choice(...args) {
|
|
|
1330
1350
|
const result = parsers[i].parse(input, pos, ctx);
|
|
1331
1351
|
if (!result.ok) {
|
|
1332
1352
|
rollbackCstCapture(ctx, mark);
|
|
1333
|
-
if (logLen !== void 0 && ctx._triviaLog) ctx._triviaLog.length = logLen;
|
|
1353
|
+
if (logLen !== void 0 && ctx._triviaLog && ctx._triviaLog.length !== logLen) ctx._triviaLog.length = logLen;
|
|
1334
1354
|
expected.push(...result.expected);
|
|
1335
1355
|
continue;
|
|
1336
1356
|
}
|
|
1337
1357
|
const checks = autoNot[i];
|
|
1338
1358
|
if (checks && autoNotFires(input, result.span.end, checks)) {
|
|
1339
1359
|
rollbackCstCapture(ctx, mark);
|
|
1340
|
-
if (logLen !== void 0 && ctx._triviaLog) ctx._triviaLog.length = logLen;
|
|
1360
|
+
if (logLen !== void 0 && ctx._triviaLog && ctx._triviaLog.length !== logLen) ctx._triviaLog.length = logLen;
|
|
1341
1361
|
continue;
|
|
1342
1362
|
}
|
|
1343
1363
|
return result;
|
|
@@ -1664,7 +1684,7 @@ function saveTriviaMark(ctx) {
|
|
|
1664
1684
|
}
|
|
1665
1685
|
function rollbackTrivia(ctx, mark) {
|
|
1666
1686
|
rollbackCstCapture(ctx, { raw: mark.raw, tlog: mark.tlog, leaves: mark.leaves, fields: mark.fields, errors: mark.errors });
|
|
1667
|
-
if (ctx._triviaLog) ctx._triviaLog.length = mark.log;
|
|
1687
|
+
if (ctx._triviaLog && ctx._triviaLog.length !== mark.log) ctx._triviaLog.length = mark.log;
|
|
1668
1688
|
}
|
|
1669
1689
|
function saveLookaheadMark(ctx) {
|
|
1670
1690
|
return { ...saveTriviaMark(ctx), probeBest: ctx._probe ? ctx._probe.best : null };
|
|
@@ -2032,7 +2052,7 @@ function attempt(parser2) {
|
|
|
2032
2052
|
const result = parser2.parse(input, pos, ctx);
|
|
2033
2053
|
if (result.ok) return result;
|
|
2034
2054
|
rollbackCstCapture(ctx, mark);
|
|
2035
|
-
if (log !== void 0 && ctx._triviaLog) ctx._triviaLog.length = log;
|
|
2055
|
+
if (log !== void 0 && ctx._triviaLog && ctx._triviaLog.length !== log) ctx._triviaLog.length = log;
|
|
2036
2056
|
return { ok: false, expected: result.expected, span: { start: pos, end: pos } };
|
|
2037
2057
|
}
|
|
2038
2058
|
};
|
|
@@ -3106,7 +3126,7 @@ function leaf(root, fn) {
|
|
|
3106
3126
|
}
|
|
3107
3127
|
|
|
3108
3128
|
// src/version.ts
|
|
3109
|
-
var PARSEMAN_VERSION = "0.
|
|
3129
|
+
var PARSEMAN_VERSION = "0.36.0";
|
|
3110
3130
|
|
|
3111
3131
|
// src/analysis/gating.ts
|
|
3112
3132
|
var isAny = (fs) => fs.kind === "any";
|
|
@@ -5297,9 +5317,9 @@ function planDisjointDispatch(parsers) {
|
|
|
5297
5317
|
return total >= SWITCH_MIN_CASES ? { kind: "switch", cases } : { kind: "if" };
|
|
5298
5318
|
}
|
|
5299
5319
|
function captureRestoreBody(mL, mR, mTl, mLg, mF = null) {
|
|
5300
|
-
const fieldRestore = mF ? `; if (_ctx._fields) _ctx._fields.length = ${mF}` : "";
|
|
5301
|
-
const base = `if (_ctx._cstLeaves) _ctx._cstLeaves.length = ${mL}; if (_ctx._cstRawChildren) _ctx._cstRawChildren.length = ${mR}; if (_ctx._cstTriviaLog) _ctx._cstTriviaLog.length = ${mTl}${fieldRestore}`;
|
|
5302
|
-
return mLg ? `${base}; if (_ctx._triviaLog) _ctx._triviaLog.length = ${mLg}` : base;
|
|
5320
|
+
const fieldRestore = mF ? `; if (_ctx._fields && _ctx._fields.length !== ${mF}) _ctx._fields.length = ${mF}` : "";
|
|
5321
|
+
const base = `if (_ctx._cstLeaves && _ctx._cstLeaves.length !== ${mL}) _ctx._cstLeaves.length = ${mL}; if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${mR}) _ctx._cstRawChildren.length = ${mR}; if (_ctx._cstTriviaLog && _ctx._cstTriviaLog.length !== ${mTl}) _ctx._cstTriviaLog.length = ${mTl}${fieldRestore}`;
|
|
5322
|
+
return mLg ? `${base}; if (_ctx._triviaLog && _ctx._triviaLog.length !== ${mLg}) _ctx._triviaLog.length = ${mLg}` : base;
|
|
5303
5323
|
}
|
|
5304
5324
|
function mayLeavePartialCapture(p, seen = /* @__PURE__ */ new Set()) {
|
|
5305
5325
|
if (seen.has(p)) return false;
|
|
@@ -5661,7 +5681,7 @@ function emitSeqValues(def, ctx, pos) {
|
|
|
5661
5681
|
const endAfterV = v(ctx, "_sea");
|
|
5662
5682
|
stmts.push(
|
|
5663
5683
|
`${ind(ctx)}const ${endAfterV} = ${r2.endVar}`,
|
|
5664
|
-
`${ind(ctx)}if (${endAfterV} > ${scanEndV}) { ${curV} = ${endAfterV} } else { if (_ctx._cstRawChildren) _ctx._cstRawChildren.length = ${markV}; if (_ctx._cstTriviaLog) _ctx._cstTriviaLog.length = ${markTl}; if (_ctx._triviaLog) _ctx._triviaLog.length = ${markLog}; }`
|
|
5684
|
+
`${ind(ctx)}if (${endAfterV} > ${scanEndV}) { ${curV} = ${endAfterV} } else { if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${markV}) _ctx._cstRawChildren.length = ${markV}; if (_ctx._cstTriviaLog && _ctx._cstTriviaLog.length !== ${markTl}) _ctx._cstTriviaLog.length = ${markTl}; if (_ctx._triviaLog && _ctx._triviaLog.length !== ${markLog}) _ctx._triviaLog.length = ${markLog}; }`
|
|
5665
5685
|
);
|
|
5666
5686
|
valueVars.push(r2.valueVar);
|
|
5667
5687
|
continue;
|
|
@@ -6148,7 +6168,7 @@ function emitMany(def, ctx, pos) {
|
|
|
6148
6168
|
`${ind(ctx)}const ${npV} = ${capFn}(input, ${curV}, _ctx, 1)`
|
|
6149
6169
|
);
|
|
6150
6170
|
itemPos = npV;
|
|
6151
|
-
rollback = `if (_ctx._cstRawChildren) _ctx._cstRawChildren.length = ${markV}; if (_ctx._cstTriviaLog) _ctx._cstTriviaLog.length = ${markTl}; if (_ctx._triviaLog) _ctx._triviaLog.length = ${markLog}; `;
|
|
6171
|
+
rollback = `if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${markV}) _ctx._cstRawChildren.length = ${markV}; if (_ctx._cstTriviaLog && _ctx._cstTriviaLog.length !== ${markTl}) _ctx._cstTriviaLog.length = ${markTl}; if (_ctx._triviaLog && _ctx._triviaLog.length !== ${markLog}) _ctx._triviaLog.length = ${markLog}; `;
|
|
6152
6172
|
} else {
|
|
6153
6173
|
const trivFn = ensureTriviaFn(ctx);
|
|
6154
6174
|
const npV = v(ctx, "_np");
|
|
@@ -6211,7 +6231,7 @@ function emitAttempt(p, def, ctx, pos) {
|
|
|
6211
6231
|
const log = v(ctx, "_atg");
|
|
6212
6232
|
const fields = v(ctx, "_atf");
|
|
6213
6233
|
const errors = v(ctx, "_ate");
|
|
6214
|
-
const rollback = `if (_ctx._cstLeaves) _ctx._cstLeaves.length = ${leaves}; if (_ctx._cstRawChildren) _ctx._cstRawChildren.length = ${raw}; if (_ctx._cstTriviaLog) _ctx._cstTriviaLog.length = ${trivia2}; if (_ctx._triviaLog) _ctx._triviaLog.length = ${log}; if (_ctx._fields) _ctx._fields.length = ${fields}; if (_ctx._errors) _ctx._errors.length = ${errors}`;
|
|
6234
|
+
const rollback = `if (_ctx._cstLeaves && _ctx._cstLeaves.length !== ${leaves}) _ctx._cstLeaves.length = ${leaves}; if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${raw}) _ctx._cstRawChildren.length = ${raw}; if (_ctx._cstTriviaLog && _ctx._cstTriviaLog.length !== ${trivia2}) _ctx._cstTriviaLog.length = ${trivia2}; if (_ctx._triviaLog && _ctx._triviaLog.length !== ${log}) _ctx._triviaLog.length = ${log}; if (_ctx._fields && _ctx._fields.length !== ${fields}) _ctx._fields.length = ${fields}; if (_ctx._errors && _ctx._errors.length !== ${errors}) _ctx._errors.length = ${errors}`;
|
|
6215
6235
|
const traceId = ctx.coverage?.plan.attempts.get(p);
|
|
6216
6236
|
const traceRollback = traceId === void 0 ? "" : ` _ctx._grammarTrace?.write({ id: ${JSON.stringify(traceId)}, phase: 'rollback', offset: ${pos} });`;
|
|
6217
6237
|
const preGuard = [];
|
|
@@ -6274,7 +6294,7 @@ function emitSepBy(_p, def, ctx, pos) {
|
|
|
6274
6294
|
`${ind(ctx)}const ${tl} = _ctx._cstTriviaLog ? _ctx._cstTriviaLog.length : 0`,
|
|
6275
6295
|
`${ind(ctx)}const ${lg} = _ctx._triviaLog ? _ctx._triviaLog.length : 0`
|
|
6276
6296
|
],
|
|
6277
|
-
rb: `if (_ctx._cstLeaves) _ctx._cstLeaves.length = ${lv}; if (_ctx._cstRawChildren) _ctx._cstRawChildren.length = ${rw}; if (_ctx._cstTriviaLog) _ctx._cstTriviaLog.length = ${tl}; if (_ctx._triviaLog) _ctx._triviaLog.length = ${lg}; `
|
|
6297
|
+
rb: `if (_ctx._cstLeaves && _ctx._cstLeaves.length !== ${lv}) _ctx._cstLeaves.length = ${lv}; if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${rw}) _ctx._cstRawChildren.length = ${rw}; if (_ctx._cstTriviaLog && _ctx._cstTriviaLog.length !== ${tl}) _ctx._cstTriviaLog.length = ${tl}; if (_ctx._triviaLog && _ctx._triviaLog.length !== ${lg}) _ctx._triviaLog.length = ${lg}; `
|
|
6278
6298
|
};
|
|
6279
6299
|
};
|
|
6280
6300
|
if (rec) {
|
|
@@ -6320,7 +6340,7 @@ function emitSepBy(_p, def, ctx, pos) {
|
|
|
6320
6340
|
`${ind(ctx)}const ${spV} = ${capFn}(input, ${curV}, _ctx, 1)`
|
|
6321
6341
|
);
|
|
6322
6342
|
sepAtPos = spV;
|
|
6323
|
-
const rollbackToSep = `if (_ctx._cstLeaves) _ctx._cstLeaves.length = ${markLv}; if (_ctx._cstRawChildren) _ctx._cstRawChildren.length = ${markV}; if (_ctx._cstTriviaLog) _ctx._cstTriviaLog.length = ${markTl}; if (_ctx._triviaLog) _ctx._triviaLog.length = ${markLog}; `;
|
|
6343
|
+
const rollbackToSep = `if (_ctx._cstLeaves && _ctx._cstLeaves.length !== ${markLv}) _ctx._cstLeaves.length = ${markLv}; if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${markV}) _ctx._cstRawChildren.length = ${markV}; if (_ctx._cstTriviaLog && _ctx._cstTriviaLog.length !== ${markTl}) _ctx._cstTriviaLog.length = ${markTl}; if (_ctx._triviaLog && _ctx._triviaLog.length !== ${markLog}) _ctx._triviaLog.length = ${markLog}; `;
|
|
6324
6344
|
const { stmts: sepStmts, okVar: sepOk, endVar: sepEnd } = emitFallible(def.separator, ctx, sepAtPos, true);
|
|
6325
6345
|
stmts.push(...sepStmts, `${ind(ctx)}if (!${sepOk}) { ${rollbackToSep}break }`);
|
|
6326
6346
|
const post = postSepMarks();
|
|
@@ -6362,7 +6382,7 @@ function emitSepBy(_p, def, ctx, pos) {
|
|
|
6362
6382
|
}
|
|
6363
6383
|
const { stmts: sepStmts, okVar: sepOk, endVar: sepEnd } = emitFallible(def.separator, ctx, sepAtPos, true);
|
|
6364
6384
|
stmts.push(...sepStmts, `${ind(ctx)}if (!${sepOk}) break`);
|
|
6365
|
-
const nextRb = markLv ? `if (_ctx._cstLeaves) _ctx._cstLeaves.length = ${markLv}; if (_ctx._cstRawChildren) _ctx._cstRawChildren.length = ${markRw}; ` : "";
|
|
6385
|
+
const nextRb = markLv ? `if (_ctx._cstLeaves && _ctx._cstLeaves.length !== ${markLv}) _ctx._cstLeaves.length = ${markLv}; if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${markRw}) _ctx._cstRawChildren.length = ${markRw}; ` : "";
|
|
6366
6386
|
const post = postSepMarks();
|
|
6367
6387
|
stmts.push(...post.decl);
|
|
6368
6388
|
const { stmts: nextStmts, okVar: nextOk, valVar: nextVal, endVar: nextEnd } = emitFallible(def.parser, ctx, sepEnd, true);
|
|
@@ -6447,7 +6467,7 @@ function emitNot(def, ctx, pos) {
|
|
|
6447
6467
|
] : [],
|
|
6448
6468
|
...stmts,
|
|
6449
6469
|
...sinksLive ? [
|
|
6450
|
-
`${ind(ctx)}if (_ctx._cstLeaves) _ctx._cstLeaves.length = ${leaves}; if (_ctx._cstRawChildren) _ctx._cstRawChildren.length = ${raw}; if (_ctx._cstTriviaLog) _ctx._cstTriviaLog.length = ${tl}; if (_ctx._triviaLog) _ctx._triviaLog.length = ${log}; if (_ctx._fields) _ctx._fields.length = ${fields}; if (_ctx._errors) _ctx._errors.length = ${errors}`
|
|
6470
|
+
`${ind(ctx)}if (_ctx._cstLeaves && _ctx._cstLeaves.length !== ${leaves}) _ctx._cstLeaves.length = ${leaves}; if (_ctx._cstRawChildren && _ctx._cstRawChildren.length !== ${raw}) _ctx._cstRawChildren.length = ${raw}; if (_ctx._cstTriviaLog && _ctx._cstTriviaLog.length !== ${tl}) _ctx._cstTriviaLog.length = ${tl}; if (_ctx._triviaLog && _ctx._triviaLog.length !== ${log}) _ctx._triviaLog.length = ${log}; if (_ctx._fields && _ctx._fields.length !== ${fields}) _ctx._fields.length = ${fields}; if (_ctx._errors && _ctx._errors.length !== ${errors}) _ctx._errors.length = ${errors}`
|
|
6451
6471
|
] : [],
|
|
6452
6472
|
...emitIfFail(ctx, okVar, failBody(ctx, label2, pos))
|
|
6453
6473
|
],
|