parseman 0.4.0 → 0.6.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 +48 -17
- package/dist/combinators/choice.d.ts.map +1 -1
- package/dist/combinators/completions.d.ts +1 -1
- package/dist/combinators/completions.d.ts.map +1 -1
- package/dist/combinators/grammar.d.ts.map +1 -1
- package/dist/combinators/keywords.d.ts +22 -0
- package/dist/combinators/keywords.d.ts.map +1 -1
- package/dist/combinators/literal.d.ts.map +1 -1
- package/dist/combinators/map.d.ts +8 -2
- package/dist/combinators/map.d.ts.map +1 -1
- package/dist/combinators/node.d.ts +10 -11
- package/dist/combinators/node.d.ts.map +1 -1
- package/dist/combinators/not.d.ts +3 -3
- package/dist/combinators/not.d.ts.map +1 -1
- package/dist/combinators/recover.d.ts +2 -2
- package/dist/combinators/recover.d.ts.map +1 -1
- package/dist/combinators/regex.d.ts.map +1 -1
- package/dist/combinators/repeat.d.ts +4 -4
- package/dist/combinators/repeat.d.ts.map +1 -1
- package/dist/combinators/scanTo.d.ts.map +1 -1
- package/dist/combinators/sequence.d.ts.map +1 -1
- package/dist/combinators/trivia-skip.d.ts +16 -10
- package/dist/combinators/trivia-skip.d.ts.map +1 -1
- package/dist/combinators/withCtx.d.ts +2 -2
- package/dist/combinators/withCtx.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts +4 -2
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/inline-build.d.ts +11 -0
- package/dist/compiler/inline-build.d.ts.map +1 -0
- package/dist/compiler/inline-callback.d.ts +12 -0
- package/dist/compiler/inline-callback.d.ts.map +1 -0
- package/dist/compiler/trivia-fast-path.d.ts +24 -0
- package/dist/compiler/trivia-fast-path.d.ts.map +1 -0
- package/dist/cst/capture-buffer.d.ts +46 -0
- package/dist/cst/capture-buffer.d.ts.map +1 -0
- package/dist/cst/trivia-entries.d.ts +20 -0
- package/dist/cst/trivia-entries.d.ts.map +1 -0
- package/dist/cst/trivia-index.d.ts +11 -11
- package/dist/cst/trivia-index.d.ts.map +1 -1
- package/dist/cst/trivia-kinds.d.ts +47 -0
- package/dist/cst/trivia-kinds.d.ts.map +1 -0
- package/dist/cst/types.d.ts +9 -13
- package/dist/cst/types.d.ts.map +1 -1
- package/dist/functional/doc.d.ts +2 -20
- package/dist/functional/doc.d.ts.map +1 -1
- package/dist/index.cjs +1238 -662
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1256 -6241
- package/dist/index.js.map +4 -4
- package/dist/plugin/evaluator.d.ts +7 -0
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.cjs +1249 -369
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +1249 -369
- package/dist/plugin/index.js.map +4 -4
- package/dist/types.d.ts +32 -9
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -3
- package/dist/cst/grammar.d.ts +0 -115
- package/dist/cst/grammar.d.ts.map +0 -1
- package/dist/cst/incremental.d.ts +0 -40
- package/dist/cst/incremental.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -8,7 +8,9 @@ Write parsers in TypeScript — fast enough to run as-is, and blazing fast when
|
|
|
8
8
|
|
|
9
9
|
## Benchmarks
|
|
10
10
|
|
|
11
|
-
Measured on Apple M2 Pro. Bars show µs per parse — shorter is faster.
|
|
11
|
+
Measured on Apple M2 Pro. Bars show µs per parse — shorter is faster. Refresh: `pnpm bench`, then `pnpm bench:svg` (updates `assets/bench-*.svg`).
|
|
12
|
+
|
|
13
|
+
Compared parsers: **Parséman**, Peggy, Parsimmon, Chevrotain, Nearley, and Jison (plus `JSON.parse` on JSON). Each implements the same parsing work on the bench fixtures — building JS values / row arrays / GraphQL AST nodes, not syntax-only validation. Peggy grammars in `bench/*.pegjs` are the reference; Nearley JSON uses [kach/nearley `examples/json.ne`](https://github.com/kach/nearley/blob/master/examples/json.ne); other Nearley and Jison grammars are ports of those Peggy files (`bench/vendor/`).
|
|
12
14
|
|
|
13
15
|

|
|
14
16
|
|
|
@@ -16,9 +18,9 @@ Measured on Apple M2 Pro. Bars show µs per parse — shorter is faster.
|
|
|
16
18
|
|
|
17
19
|

|
|
18
20
|
|
|
19
|
-
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.
|
|
21
|
+
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.)
|
|
20
22
|
|
|
21
|
-
On JSON, CSV, and GraphQL, Parséman macro beats Peggy at every fixture size in the charts above. For CST-building grammars (`node()` rules with trivia capture), the interpreter runs ~2× faster than Chevrotain on the JSON CST fixture while building an equivalent tree.
|
|
23
|
+
On JSON, CSV, and GraphQL, Parséman macro beats Peggy at every fixture size in the charts above (e.g. GraphQL large: **142 µs** vs Peggy **400 µs**). For CST-building grammars (`node()` rules with trivia capture), the interpreter runs ~2× faster than Chevrotain on the JSON CST fixture while building an equivalent tree.
|
|
22
24
|
|
|
23
25
|
---
|
|
24
26
|
|
|
@@ -136,6 +138,7 @@ A combinator reads from the input at the current position and succeeds or fails
|
|
|
136
138
|
| `sepBy(combinator, sep)` | Zero or more combinator matches separated by `sep`. |
|
|
137
139
|
| `transform(combinator, fn)` | Map the result: `fn(value, span) → newValue`. |
|
|
138
140
|
| `skip(main, skipped)` | Match `main` then `skipped`; return `main`'s value. |
|
|
141
|
+
| `label(name, combinator)` | Attach a string label to a combinator arm (metadata). Used on trivia `choice` branches for per-chunk kind capture — see [Whitespace and comment skipping](#whitespace-and-comment-skipping). |
|
|
139
142
|
| `node(type, combinator, build)` | CST/AST rule: captures the combinator's terminals into `children`/`rawChildren` and trivia offsets into a flat `triviaLog`, then calls `build(children, rawChildren, span, triviaLog)`. |
|
|
140
143
|
| `ref<T>()` | Low-level forward declaration slot (use `rules()` in most cases). |
|
|
141
144
|
| `not(combinator)` | Negative lookahead — succeeds (consuming nothing) when the combinator fails. |
|
|
@@ -153,6 +156,7 @@ A combinator reads from the input at the current position and succeeds or fails
|
|
|
153
156
|
| `makeWord(boundary?)` | Returns `(str) => Combinator` with a fixed word-boundary class. Not a combinator — see [keyword disambiguation](#ordered-choice-and-keyword-disambiguation). |
|
|
154
157
|
| `rules(factory)` | Named, mutually-recursive rule bundle. See [Named and recursive rules](#named-and-recursive-rules). |
|
|
155
158
|
| `parser({ trivia }, combinator)` | Wrap a root combinator with document-level trivia skipping. See [Whitespace and comment skipping](#whitespace-and-comment-skipping). |
|
|
159
|
+
| `triviaEntries(log, labels?, opts?)` | View over a flat trivia log: `.kind(i)`, `.text(i, input)`, `.start(i)`, `.end(i)`. Stride is 2/3 for root `_triviaLog`, 3/4 for per-node `triviaLog` when kinds are enabled. |
|
|
156
160
|
|
|
157
161
|
---
|
|
158
162
|
|
|
@@ -177,6 +181,8 @@ Two takeaways:
|
|
|
177
181
|
|
|
178
182
|
**When NOT to collapse:** keep the parts as separate combinators wherever the builder needs them as distinct CST children — for per-field source spans (`fieldSpans`/`valueSpans`), for trivia recovered *between* the parts, or for distinct typed nodes. Correctness first; collapse only the genuinely opaque runs.
|
|
179
183
|
|
|
184
|
+
For library-level codegen and macro optimizations (not grammar authoring), see [PERF_IDEAS.md](./PERF_IDEAS.md).
|
|
185
|
+
|
|
180
186
|
---
|
|
181
187
|
|
|
182
188
|
## Whitespace and comment skipping
|
|
@@ -205,6 +211,25 @@ const blockComment = sequence(literal('/*'), scanTo(literal('*/'), []))
|
|
|
205
211
|
const ws = trivia(many(choice(regex(/\s+/), lineComment, blockComment)))
|
|
206
212
|
```
|
|
207
213
|
|
|
214
|
+
Label trivia arms so each captured chunk records its kind in `_triviaLog` / per-node `triviaLog`:
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
const rw = trivia(oneOrMore(choice(
|
|
218
|
+
label('whitespace', regex(/[ \t\n\r\f]+/)),
|
|
219
|
+
label('blockComment', regex(/\/\*(?:[^*]|\*(?!\/))*\*\//)),
|
|
220
|
+
)))
|
|
221
|
+
|
|
222
|
+
// After parse, resolve kinds lazily:
|
|
223
|
+
import { triviaEntries } from 'parseman'
|
|
224
|
+
const entries = triviaEntries(triviaLog, rw._meta.triviaKindLabels)
|
|
225
|
+
entries.kind(0) // 'whitespace'
|
|
226
|
+
entries.text(0, input) // slice on demand
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
`label(name, parser)` names a trivia arm; `node('Ruleset', …)` names a CST node — different namespaces, no conflict.
|
|
230
|
+
|
|
231
|
+
When all trivia arms are labeled, each captured chunk appends a **kind index** to the log (stride +1). Root `_triviaLog` entries are `[start, end, kind]`; per-node `triviaLog` entries are `[start, end, insertIdx, kind]`. Without labels, strides are 2 and 3 respectively.
|
|
232
|
+
|
|
208
233
|
---
|
|
209
234
|
|
|
210
235
|
## Ordered choice and keyword disambiguation
|
|
@@ -314,7 +339,7 @@ value.define(choice(object, array, str, num, bool, nil))
|
|
|
314
339
|
|
|
315
340
|
## Grammars that build an AST
|
|
316
341
|
|
|
317
|
-
For grammars that produce a typed CST/AST, support incremental re-parsing, or care about trivia, wrap each rule in `node(type, combinator, build)`. parseman captures the rule's terminals into `children` / `rawChildren` and records trivia as flat `[start, end, insertIdx, …]`
|
|
342
|
+
For grammars that produce a typed CST/AST, support incremental re-parsing, or care about trivia, wrap each rule in `node(type, combinator, build)`. parseman captures the rule's terminals into `children` / `rawChildren` and records trivia as flat `[start, end, insertIdx, …]` **entries** in `triviaLog` (three numbers per whitespace/comment chunk), then hands all four to `build(children, rawChildren, span, triviaLog)`. **Capture is the library's job:** you don't wrap terminals to recover their spans, and you don't reconstruct trivia — it's collected as the parser runs, in both the interpreter and the compiled build. Use `buildTriviaIndex(tree, input)` to turn `triviaLog` into a before/after lookup table.
|
|
318
343
|
|
|
319
344
|
```ts
|
|
320
345
|
import { rules, parser, node, regex, literal, sequence, many, trivia } from 'parseman'
|
|
@@ -338,7 +363,7 @@ Expr.parse('1 + 2 + 3', 0, { trackLines: false })
|
|
|
338
363
|
|
|
339
364
|
- **`children`** — structural items in source order: spanned `CSTLeaf` terminals (`{ _tag:'leaf', value, span }`) and sub-nodes (whatever a nested `node()`'s `build` returned). A `build` that returns a bare string is recorded by the parent as a spanned leaf, so single-item "collapsing" rules keep their source span.
|
|
340
365
|
- **`rawChildren`** — structural children only (same items as `children`, without trivia tokens).
|
|
341
|
-
- **`triviaLog`** — flat `[start, end, insertIdx, …]`
|
|
366
|
+
- **`triviaLog`** — flat `[start, end, insertIdx, …]` entries for whitespace/comments consumed between terms. `insertIdx` is the `rawChildren` index before which the trivia was consumed. Pass the tree to `buildTriviaIndex(tree, input)` for a `before`/`after` map of trivia tokens — useful for whitespace-sensitive syntax (e.g. CSS `div p` vs `div.p`).
|
|
342
367
|
|
|
343
368
|
Each rule returned from the factory is independently callable — `Expr`, `Num` above are the **rule registry** incremental re-parsing needs. Wrap a rule's inner combinator in `parser({ trivia }, combinator)` so trivia-skipping is baked in regardless of which rule you start from; the macro compiles the wrapper (and all capture) away to flat JS.
|
|
344
369
|
|
|
@@ -385,22 +410,26 @@ vscode.workspace.onDidChangeTextDocument(event => {
|
|
|
385
410
|
})
|
|
386
411
|
```
|
|
387
412
|
|
|
388
|
-
###
|
|
413
|
+
### Extending grammars
|
|
414
|
+
|
|
415
|
+
Don't copy a `rules()` factory to make a variant — export what stays the same and pass in (or wrap) what changes. `examples/json/` is the template:
|
|
389
416
|
|
|
390
|
-
|
|
417
|
+
| File | What changes |
|
|
418
|
+
|------|----------------|
|
|
419
|
+
| `parser.ts` | Base grammar + `makeJSONParser(customWs)` |
|
|
420
|
+
| `jsonc.ts` | Trivia only — `makeJSONParser(jsoncWs)` |
|
|
421
|
+
| `jsonl.ts` | Document shape — `sepBy(jsonValue, '\n')` with tighter trivia |
|
|
391
422
|
|
|
392
423
|
```ts
|
|
393
|
-
//
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
// a JSX variant would use regex(/[a-zA-Z_$][\w$]*/) here instead
|
|
399
|
-
/* ...rules referencing ident... */
|
|
400
|
-
return { Expr: /* ... */ }
|
|
401
|
-
})
|
|
424
|
+
// jsonc.ts — same recursive grammar, different trivia
|
|
425
|
+
export const jsoncValue = makeJSONParser(jsoncWs)
|
|
426
|
+
|
|
427
|
+
// jsonl.ts — reuse jsonValue, wrap at the top
|
|
428
|
+
export const jsonl = parser({ trivia: lineWs }, sepBy(jsonValue, literal('\n')))
|
|
402
429
|
```
|
|
403
430
|
|
|
431
|
+
`makeJSONParser` in `parser.ts` is the knob: one `rules()` body, trivia passed in, `parser({ trivia }, value)` returned. Unchanged core → parameterize; unchanged rule, different document → wrap the export.
|
|
432
|
+
|
|
404
433
|
---
|
|
405
434
|
|
|
406
435
|
## Context-sensitive parsing
|
|
@@ -561,7 +590,9 @@ pnpm install
|
|
|
561
590
|
pnpm test # Vitest — interpreter + compiler parity + ordered-choice semantics
|
|
562
591
|
pnpm typecheck # TypeScript 7
|
|
563
592
|
pnpm build # ESM + CJS + .d.ts → dist/
|
|
564
|
-
pnpm bench
|
|
593
|
+
pnpm bench # Parséman vs Peggy, Parsimmon, Chevrotain, Nearley, Jison
|
|
594
|
+
pnpm bench:svg # refresh assets/bench-*.svg after bench
|
|
595
|
+
pnpm bench:compile-grammars # regenerate Peggy / Nearley / Jison parser output in bench/
|
|
565
596
|
```
|
|
566
597
|
|
|
567
598
|
## License
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"choice.d.ts","sourceRoot":"","sources":["../../src/combinators/choice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAC+B,QAAQ,EAClD,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"choice.d.ts","sourceRoot":"","sources":["../../src/combinators/choice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAC+B,QAAQ,EAClD,MAAM,aAAa,CAAA;AAIpB,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,CAAA;AACvH,KAAK,SAAS,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI;KACrE,CAAC,IAAI,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAChC,CAAC,MAAM,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAEjD,wBAAgB,MAAM,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EACxH,GAAG,IAAI,EAAE,CAAC,GACT,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAiI1B;AAwFD,uEAAuE;AACvE,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAKzE;AAED,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAMhG"}
|
|
@@ -13,5 +13,5 @@ import type { Combinator } from '../types.ts';
|
|
|
13
13
|
* The returned strings use the same labels as ParseFail.expected:
|
|
14
14
|
* quoted literals like `"\"{\""` and regex patterns like `"/[0-9]+/"`.
|
|
15
15
|
*/
|
|
16
|
-
export declare function completionsAt(
|
|
16
|
+
export declare function completionsAt(combinator: Combinator<unknown>, input: string, offset: number): string[];
|
|
17
17
|
//# sourceMappingURL=completions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completions.d.ts","sourceRoot":"","sources":["../../src/combinators/completions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,aAAa,CAAA;AAEtE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,
|
|
1
|
+
{"version":3,"file":"completions.d.ts","sourceRoot":"","sources":["../../src/combinators/completions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,aAAa,CAAA;AAEtE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,EAC/B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,MAAM,EAAE,CAYV"}
|
|
@@ -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,EAAE,MAAM,aAAa,CAAA;AAGxE,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,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;IAC5B,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,
|
|
1
|
+
{"version":3,"file":"grammar.d.ts","sourceRoot":"","sources":["../../src/combinators/grammar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGxE,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,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;IAC5B,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,CAkCrF;AAED,wBAAgB,KAAK,CAAC,CAAC,EACrB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EACzB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,YAAiB,GACtB,WAAW,CAAC,CAAC,CAAC,CAehB"}
|
|
@@ -8,6 +8,28 @@ export type KeywordsOptions = {
|
|
|
8
8
|
*/
|
|
9
9
|
boundary?: string;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Match a single keyword with an automatic word-boundary guard. Prevents
|
|
13
|
+
* matching `true` inside `trueish`. The boundary defaults to `_0-9A-Za-z`,
|
|
14
|
+
* which covers most programming-language identifiers.
|
|
15
|
+
*
|
|
16
|
+
* word('true') // matches "true" but not "trueish"
|
|
17
|
+
* word('color', 'A-Za-z-') // CSS-style identifier boundary
|
|
18
|
+
*/
|
|
19
|
+
export declare function word(str: string, boundary?: string): Combinator<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Create a keyword factory with a fixed word-boundary class. Use when many
|
|
22
|
+
* keywords share the same boundary (e.g. CSS identifiers). For a single keyword,
|
|
23
|
+
* `word(str, boundary?)` is enough; you can also roll your own factory with
|
|
24
|
+
* `(s) => word(s, boundary)`.
|
|
25
|
+
*
|
|
26
|
+
* const kw = makeWord() // default: '_0-9A-Za-z'
|
|
27
|
+
* const cssKw = makeWord('A-Za-z0-9_-') // dashes allowed in CSS idents
|
|
28
|
+
*
|
|
29
|
+
* const query = kw('query')
|
|
30
|
+
* const color = cssKw('color') // matches "color" but not "color-scheme"
|
|
31
|
+
*/
|
|
32
|
+
export declare function makeWord(boundary?: string): (str: string) => Combinator<string>;
|
|
11
33
|
/**
|
|
12
34
|
* Match any one of a set of fixed keywords, longest-first (so `border` wins over
|
|
13
35
|
* `bord`), with an optional trailing word-boundary guard. Compiles to a single
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keywords.d.ts","sourceRoot":"","sources":["../../src/combinators/keywords.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAmD,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"keywords.d.ts","sourceRoot":"","sources":["../../src/combinators/keywords.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAmD,MAAM,aAAa,CAAA;AAK9F,MAAM,MAAM,eAAe,GAAG;IAC5B,gCAAgC;IAChC,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,SAAe,GAAG,UAAU,CAAC,MAAM,CAAC,CAE7E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,SAAe,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,UAAU,CAAC,MAAM,CAAC,CAErF;AAMD;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,GAAE,eAAoB,GAAG,UAAU,CAAC,MAAM,CAAC,CA2CjG"}
|
|
@@ -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;AAapF,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,CA+CpF"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { Combinator } from '../types.ts';
|
|
2
|
-
export declare function transform<T, U>(
|
|
2
|
+
export declare function transform<T, U>(combinator: Combinator<T>, fn: (value: T, span: {
|
|
3
3
|
start: number;
|
|
4
4
|
end: number;
|
|
5
5
|
}) => U): Combinator<U>;
|
|
6
6
|
export declare function skip<T, S>(main: Combinator<T>, skipped: Combinator<S>): Combinator<T>;
|
|
7
|
-
export declare function trivia<T>(
|
|
7
|
+
export declare function trivia<T>(combinator: Combinator<T>): Combinator<T>;
|
|
8
|
+
/**
|
|
9
|
+
* Attach a string label to a parser arm (e.g. trivia `choice` branches).
|
|
10
|
+
* Parse behavior is unchanged; the label is metadata for tooling and future
|
|
11
|
+
* trivia-kind capture (`'whitespace'`, `'blockComment'`, …).
|
|
12
|
+
*/
|
|
13
|
+
export declare function label<T>(name: string, combinator: Combinator<T>): Combinator<T>;
|
|
8
14
|
//# sourceMappingURL=map.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/combinators/map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA6B,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/combinators/map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA6B,MAAM,aAAa,CAAA;AAGxE,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAC5B,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EACzB,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,KAAK,CAAC,GACxD,UAAU,CAAC,CAAC,CAAC,CAWf;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAarF;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAYlE;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAO/E"}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import type { Combinator } from '../types.ts';
|
|
2
2
|
/**
|
|
3
|
-
* A CST/AST node rule. Runs `
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* This is the functional replacement for the class `Parser`'s capital-letter
|
|
8
|
-
* rules + `buildNode`: capture is owned by the library (here and in the
|
|
9
|
-
* compiler), so grammar authors don't hand-wrap terminals or reconstruct trivia.
|
|
3
|
+
* A CST/AST node rule. Runs `combinator` while collecting its terminals into
|
|
4
|
+
* `children` / `rawChildren` arrays and trivia spans into `triviaLog`, then
|
|
5
|
+
* calls `build(children, rawChildren, span, triviaLog)` to produce the node.
|
|
10
6
|
*
|
|
11
7
|
* - `children` — structural items in source order: spanned CSTLeaf terminals
|
|
12
8
|
* and sub-nodes (whatever `build` returned for inner nodes).
|
|
13
|
-
* - `rawChildren` —
|
|
14
|
-
*
|
|
9
|
+
* - `rawChildren` — structural children only (same items as `children`).
|
|
10
|
+
* - `triviaLog` — flat log of trivia entries: each entry is `[start, end, insertIdx]`
|
|
11
|
+
* consumed between terms. `insertIdx` is the rawChildren index
|
|
12
|
+
* before which the trivia was consumed. Use `buildTriviaIndex`
|
|
13
|
+
* to turn this into a before/after lookup table.
|
|
15
14
|
*
|
|
16
15
|
* If `build` returns a non-node value (e.g. a bare string for a collapsed rule),
|
|
17
16
|
* the parent records it as a spanned leaf so its source span is still recoverable.
|
|
@@ -19,6 +18,6 @@ import type { Combinator } from '../types.ts';
|
|
|
19
18
|
export type BuildNode<N> = (children: ReadonlyArray<unknown>, rawChildren: ReadonlyArray<unknown>, span: {
|
|
20
19
|
start: number;
|
|
21
20
|
end: number;
|
|
22
|
-
}) => N;
|
|
23
|
-
export declare function node<N>(type: string,
|
|
21
|
+
}, triviaLog: readonly number[], state: unknown) => N;
|
|
22
|
+
export declare function node<N>(type: string, combinator: Combinator<unknown>, build: BuildNode<N>): Combinator<N>;
|
|
24
23
|
//# sourceMappingURL=node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/combinators/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/combinators/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAGpF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CACzB,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,EAChC,WAAW,EAAE,aAAa,CAAC,OAAO,CAAC,EACnC,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACpC,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,KAAK,EAAE,OAAO,KACX,CAAC,CAAA;AAEN,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CA+BzG"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Combinator } from '../types.ts';
|
|
2
2
|
/**
|
|
3
|
-
* Negative lookahead. Succeeds (consuming nothing) when `
|
|
4
|
-
* fails when `
|
|
3
|
+
* Negative lookahead. Succeeds (consuming nothing) when `combinator` fails;
|
|
4
|
+
* fails when `combinator` succeeds.
|
|
5
5
|
*
|
|
6
6
|
* The standard way to match a keyword without also matching the prefix
|
|
7
7
|
* of a longer identifier:
|
|
@@ -9,5 +9,5 @@ import type { Combinator } from '../types.ts';
|
|
|
9
9
|
* const kwTrue = sequence(literal('true'), not(regex(/\w/)))
|
|
10
10
|
* // matches "true" in "true && x" but NOT in "trueish" or "trueness"
|
|
11
11
|
*/
|
|
12
|
-
export declare function not(
|
|
12
|
+
export declare function not(combinator: Combinator<unknown>): Combinator<null>;
|
|
13
13
|
//# sourceMappingURL=not.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"not.d.ts","sourceRoot":"","sources":["../../src/combinators/not.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAGpF;;;;;;;;;GASG;AACH,wBAAgB,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"not.d.ts","sourceRoot":"","sources":["../../src/combinators/not.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAGpF;;;;;;;;;GASG;AACH,wBAAgB,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAmBrE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Combinator, ParseError } from '../types.ts';
|
|
2
2
|
export type { ParseError };
|
|
3
3
|
/**
|
|
4
|
-
* Error-recovery combinator. Tries `
|
|
4
|
+
* Error-recovery combinator. Tries `combinator`; on success returns normally.
|
|
5
5
|
* On failure, scans forward one character at a time until `sentinel` matches
|
|
6
6
|
* (or EOF), then returns a ParseError node spanning the skipped range.
|
|
7
7
|
* The sentinel is NOT consumed — the caller's grammar continues from there.
|
|
@@ -15,6 +15,6 @@ export type { ParseError };
|
|
|
15
15
|
* recover(exprStmt, literal(';'))
|
|
16
16
|
* )
|
|
17
17
|
*/
|
|
18
|
-
export declare function recover<T>(
|
|
18
|
+
export declare function recover<T>(combinator: Combinator<T>, sentinel: Combinator<unknown>): Combinator<T | ParseError>;
|
|
19
19
|
export declare function isParseError(value: unknown): value is ParseError;
|
|
20
20
|
//# sourceMappingURL=recover.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recover.d.ts","sourceRoot":"","sources":["../../src/combinators/recover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,UAAU,EAAE,MAAM,aAAa,CAAA;AAEhG,YAAY,EAAE,UAAU,EAAE,CAAA;AAE1B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,
|
|
1
|
+
{"version":3,"file":"recover.d.ts","sourceRoot":"","sources":["../../src/combinators/recover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,UAAU,EAAE,MAAM,aAAa,CAAA;AAEhG,YAAY,EAAE,UAAU,EAAE,CAAA;AAE1B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EACzB,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,GAC5B,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CA6B5B;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../src/combinators/regex.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAmD,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../src/combinators/regex.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAmD,MAAM,aAAa,CAAA;AA6H9F,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,SAAK,GAAG,UAAU,CAAC,MAAM,CAAC,CA0B9E"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Combinator } from '../types.ts';
|
|
2
|
-
export declare function many<T>(
|
|
3
|
-
export declare function oneOrMore<T>(
|
|
4
|
-
export declare function optional<T>(
|
|
5
|
-
export declare function sepBy<T, S>(
|
|
2
|
+
export declare function many<T>(combinator: Combinator<T>): Combinator<T[]>;
|
|
3
|
+
export declare function oneOrMore<T>(combinator: Combinator<T>): Combinator<T[]>;
|
|
4
|
+
export declare function optional<T>(combinator: Combinator<T>): Combinator<T | null>;
|
|
5
|
+
export declare function sepBy<T, S>(combinator: Combinator<T>, separator: Combinator<S>): Combinator<T[]>;
|
|
6
6
|
//# sourceMappingURL=repeat.d.ts.map
|
|
@@ -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;
|
|
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,CAiB3E;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,CAuDhG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanTo.d.ts","sourceRoot":"","sources":["../../src/combinators/scanTo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"scanTo.d.ts","sourceRoot":"","sources":["../../src/combinators/scanTo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAOpF,MAAM,MAAM,aAAa,GAAG;IAC1B,uGAAuG;IACvG,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,CAAA;IAC5B;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,EAC7B,EAAE,IAAS,EAAE,KAAa,EAAE,GAAE,aAAkB,GAC/C,UAAU,CAAC,MAAM,CAAC,CA8DpB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,aAAkB,GAC1B,UAAU,CAAC,MAAM,CAAC,CAYpB"}
|
|
@@ -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,CAuD9B"}
|
|
@@ -10,19 +10,25 @@ export type TriviaScan = {
|
|
|
10
10
|
end: number;
|
|
11
11
|
commit: () => void;
|
|
12
12
|
};
|
|
13
|
+
/** Saved lengths for rolling back speculative trivia commits. */
|
|
14
|
+
export type TriviaRollbackMark = {
|
|
15
|
+
raw: number;
|
|
16
|
+
tlog: number;
|
|
17
|
+
leaves: number;
|
|
18
|
+
log: number;
|
|
19
|
+
};
|
|
20
|
+
/** True when trivia recording must be deferred until the following term commits. */
|
|
21
|
+
export declare function needsDeferredTriviaCommit(ctx: ParseContext): boolean;
|
|
22
|
+
export declare function saveTriviaMark(ctx: ParseContext): TriviaRollbackMark;
|
|
23
|
+
export declare function rollbackTrivia(ctx: ParseContext, mark: TriviaRollbackMark): void;
|
|
24
|
+
/**
|
|
25
|
+
* Skip trivia at `cur` and return the new position. No recording, no wrapper
|
|
26
|
+
* object — use between sequence/repeat terms when CST trivia capture is off.
|
|
27
|
+
*/
|
|
28
|
+
export declare function advanceTrivia(input: string, cur: number, ctx: ParseContext): number;
|
|
13
29
|
/**
|
|
14
30
|
* Scan trivia at `cur` using `ctx.trivia`, WITHOUT recording it. Returns the
|
|
15
31
|
* position after the trivia (or `cur` if none) and a `commit()` to record it.
|
|
16
|
-
*
|
|
17
|
-
* Recording is gated on `ctx.captureTrivia`:
|
|
18
|
-
* - capture off (default): commit() is a no-op; trivia is skipped silently.
|
|
19
|
-
* - capture on (and a rawChildren collector is active): commit() records each
|
|
20
|
-
* maximal trivia sub-match (a whitespace run or a comment) as a separate
|
|
21
|
-
* CSTTrivia token. Relies on the trivia parser being structured so each
|
|
22
|
-
* token is a distinct leaf match.
|
|
23
|
-
*
|
|
24
|
-
* The trivia parser always runs with `trivia` unset in its sub-context so it
|
|
25
|
-
* cannot recurse into itself.
|
|
26
32
|
*/
|
|
27
33
|
export declare function scanTrivia(input: string, cur: number, ctx: ParseContext): TriviaScan;
|
|
28
34
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trivia-skip.d.ts","sourceRoot":"","sources":["../../src/combinators/trivia-skip.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"trivia-skip.d.ts","sourceRoot":"","sources":["../../src/combinators/trivia-skip.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAc/C;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,CAAA;AAE5D,iEAAiE;AACjE,MAAM,MAAM,kBAAkB,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AAI3F,oFAAoF;AACpF,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAEpE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,YAAY,GAAG,kBAAkB,CAGpE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAGhF;AAiBD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,MAAM,CASnF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,UAAU,CA6BpF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,MAAM,CAKnF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Combinator } from '../types.ts';
|
|
2
2
|
/**
|
|
3
|
-
* Runs `
|
|
3
|
+
* Runs `combinator` with `ctx.state` set to `extra` for the duration of the parse.
|
|
4
4
|
* The outer user context is restored on exit (lexical scoping).
|
|
5
5
|
*
|
|
6
6
|
* const functionBody = withCtx({ inFn: true },
|
|
@@ -9,5 +9,5 @@ import type { Combinator } from '../types.ts';
|
|
|
9
9
|
*
|
|
10
10
|
* Read back with guard() or from within a transform's span argument.
|
|
11
11
|
*/
|
|
12
|
-
export declare function withCtx<U, T>(extra: U,
|
|
12
|
+
export declare function withCtx<U, T>(extra: U, combinator: Combinator<T>): Combinator<T>;
|
|
13
13
|
//# sourceMappingURL=withCtx.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withCtx.d.ts","sourceRoot":"","sources":["../../src/combinators/withCtx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAEpF;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"withCtx.d.ts","sourceRoot":"","sources":["../../src/combinators/withCtx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAEpF;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAchF"}
|
|
@@ -6,9 +6,11 @@
|
|
|
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, ParseError } from '../types.ts';
|
|
9
|
+
import type { Combinator, ParseResult, ParseContext, ParseError } from '../types.ts';
|
|
10
10
|
export type CompiledParser<T> = {
|
|
11
11
|
parse(input: string, pos?: number): ParseResult<T>;
|
|
12
|
+
/** Like parse(), but with a caller-supplied ParseContext (e.g. `_triviaLog` for CST grammars). */
|
|
13
|
+
parseWithContext(input: string, ctx: ParseContext, pos?: number): ParseResult<T>;
|
|
12
14
|
/**
|
|
13
15
|
* Like parse(), but activates error recovery. recover() nodes collect their
|
|
14
16
|
* ParseErrors into result.errors instead of (only) embedding them as values.
|
|
@@ -28,5 +30,5 @@ export type CompiledParser<T> = {
|
|
|
28
30
|
*/
|
|
29
31
|
inlineExpression: string | null;
|
|
30
32
|
};
|
|
31
|
-
export declare function compile<T>(
|
|
33
|
+
export declare function compile<T>(combinator: Combinator<T>, mapFnSources?: string[]): CompiledParser<T>;
|
|
32
34
|
//# sourceMappingURL=codegen.d.ts.map
|
|
@@ -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,
|
|
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;AAuwCzH,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;AAiCD,wBAAgB,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC,CAgGhG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ParserDef } from '../types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* When a node() build is a thin `mk(type, …)` wrapper, emit the object literal
|
|
4
|
+
* at the call site instead of `_build[n](…)`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function analyzeMkInlineBuild(def: Extract<ParserDef, {
|
|
7
|
+
tag: 'node';
|
|
8
|
+
}>): string | null;
|
|
9
|
+
/** Object literal matching `stub-build.ts` `mk()` without the function call. */
|
|
10
|
+
export declare function emitInlineMkNodeExpr(type: string, chV: string, rawV: string, pos: string, endVar: string, tlV: string): string;
|
|
11
|
+
//# sourceMappingURL=inline-build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-build.d.ts","sourceRoot":"","sources":["../../src/compiler/inline-build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAiB5C;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,CAAC,SAAS,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,MAAM,GAAG,IAAI,CAS5F;AAED,gFAAgF;AAChF,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,MAAM,CAER"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Source text for a transform callback — macro `fnSrc` or arrow `toString()`. */
|
|
2
|
+
export declare function transformFnSource(fn: Function, fnSrc?: string | null): string | null;
|
|
3
|
+
/** `s => expr` / `() => expr` when expr only uses the param (+ builtins). */
|
|
4
|
+
export declare function tryInlineUnaryTransform(src: string, valueVar: string): string | null;
|
|
5
|
+
/** Parse `[a, , c]` destructuring slots (null = ignore). */
|
|
6
|
+
export declare function parseArrayDestructure(pattern: string, arity: number): (string | null)[];
|
|
7
|
+
/**
|
|
8
|
+
* `([x, y]) => body` — substitute destructure names with sequence value vars.
|
|
9
|
+
* Caller must ensure body only references slotted params (+ builtins).
|
|
10
|
+
*/
|
|
11
|
+
export declare function tryInlineDestructureTransform(src: string, valueVars: string[]): string | null;
|
|
12
|
+
//# sourceMappingURL=inline-callback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-callback.d.ts","sourceRoot":"","sources":["../../src/compiler/inline-callback.ts"],"names":[],"mappings":"AAUA,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAKpF;AAwBD,6EAA6E;AAC7E,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAWpF;AAED,4DAA4D;AAC5D,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAQvF;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EAAE,GAClB,MAAM,GAAG,IAAI,CAWf"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Combinator } from '../types.ts';
|
|
2
|
+
import type { LabeledTriviaSpec } from '../cst/trivia-kinds.ts';
|
|
3
|
+
export type TriviaFastKind = 'wsComments' | 'wsOnly';
|
|
4
|
+
/**
|
|
5
|
+
* Detect trivia shapes safe to lower to a hand-rolled scan loop in compiled output.
|
|
6
|
+
* Matches CSS `rw` (`oneOrMore(choice(ws, blockComment))`) and ASCII ws-only grammars.
|
|
7
|
+
* Single alternation regexes are excluded — one regex exec matches only one arm per call.
|
|
8
|
+
*/
|
|
9
|
+
export declare function analyzeTriviaFastPath(trivia: Combinator<unknown>): TriviaFastKind | null;
|
|
10
|
+
/** Emit a specialized `_tfN` that skips trivia without regex / combinator dispatch. */
|
|
11
|
+
export declare function buildFastTriviaFnDecl(fnName: string, kind: TriviaFastKind, kindIndices?: {
|
|
12
|
+
ws: number;
|
|
13
|
+
comment: number;
|
|
14
|
+
}): string;
|
|
15
|
+
/** Labeled trivia with regex arms — per-chunk kind capture in compiled output. */
|
|
16
|
+
export declare function buildLabeledRegexTriviaFnDecl(fnName: string, spec: LabeledTriviaSpec, reNames: string[]): string;
|
|
17
|
+
export declare function labeledTriviaKindIndices(trivia: Combinator<unknown>): {
|
|
18
|
+
ws: number;
|
|
19
|
+
comment: number;
|
|
20
|
+
} | null;
|
|
21
|
+
export declare function labeledTriviaRegexArms(trivia: Combinator<unknown>): LabeledTriviaSpec | null;
|
|
22
|
+
/** Labeled trivia via per-arm runtime parsers (non-regex or mixed arms). */
|
|
23
|
+
export declare function buildLabeledRuntimeTriviaFnDecl(fnName: string, spec: LabeledTriviaSpec, rpStartIndex: number): string;
|
|
24
|
+
//# sourceMappingURL=trivia-fast-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trivia-fast-path.d.ts","sourceRoot":"","sources":["../../src/compiler/trivia-fast-path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAG/D,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,QAAQ,CAAA;AAsCpD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,cAAc,GAAG,IAAI,CA6BxF;AAmED,uFAAuF;AACvF,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,cAAc,EACpB,WAAW,CAAC,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC5C,MAAM,CAeR;AAYD,kFAAkF;AAClF,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,MAAM,EAAE,GAChB,MAAM,CA+BR;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAO5G;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,iBAAiB,GAAG,IAAI,CAO5F;AAED,4EAA4E;AAC5E,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,iBAAiB,EACvB,YAAY,EAAE,MAAM,GACnB,MAAM,CA8BR"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ParseContext } from '../types.ts';
|
|
2
|
+
/** Lazy per-node capture state — arrays materialized on first push. */
|
|
3
|
+
export type CstCaptureBuf = {
|
|
4
|
+
single?: unknown | undefined;
|
|
5
|
+
ch?: unknown[] | undefined;
|
|
6
|
+
rawSingle?: unknown | undefined;
|
|
7
|
+
raw?: unknown[] | undefined;
|
|
8
|
+
tl?: number[] | undefined;
|
|
9
|
+
};
|
|
10
|
+
export declare function cstCaptureActive(ctx: ParseContext): boolean;
|
|
11
|
+
export type CstNodeCaptureSaved = {
|
|
12
|
+
ch: ParseContext['_cstChildren'];
|
|
13
|
+
lv: ParseContext['_cstLeaves'];
|
|
14
|
+
raw: ParseContext['_cstRawChildren'];
|
|
15
|
+
tl: ParseContext['_cstTriviaLog'];
|
|
16
|
+
cap: boolean | undefined;
|
|
17
|
+
buf: CstCaptureBuf | undefined;
|
|
18
|
+
};
|
|
19
|
+
export declare function beginCstNodeCapture(ctx: ParseContext): CstNodeCaptureSaved;
|
|
20
|
+
export declare function finishCstBuf(buf: CstCaptureBuf | undefined): {
|
|
21
|
+
children: unknown[];
|
|
22
|
+
rawChildren: unknown[];
|
|
23
|
+
triviaLog: number[];
|
|
24
|
+
};
|
|
25
|
+
export declare function endCstNodeCapture(ctx: ParseContext, saved: CstNodeCaptureSaved): {
|
|
26
|
+
children: unknown[];
|
|
27
|
+
rawChildren: unknown[];
|
|
28
|
+
triviaLog: number[];
|
|
29
|
+
};
|
|
30
|
+
export declare function pushCstLeaf(ctx: ParseContext, leaf: unknown): void;
|
|
31
|
+
/** Record a built sub-node into the active collector (children vs rawChildren may differ). */
|
|
32
|
+
export declare function pushCstChild(ctx: ParseContext, built: unknown, rawEntry: unknown): void;
|
|
33
|
+
export declare function cstRawLen(ctx: ParseContext): number;
|
|
34
|
+
export declare function cstLeavesLen(ctx: ParseContext): number;
|
|
35
|
+
export declare function cstTlLen(ctx: ParseContext): number;
|
|
36
|
+
export type CstRollbackMark = {
|
|
37
|
+
raw: number;
|
|
38
|
+
tlog: number;
|
|
39
|
+
leaves: number;
|
|
40
|
+
};
|
|
41
|
+
export declare function saveCstMark(ctx: ParseContext): CstRollbackMark;
|
|
42
|
+
export declare function rollbackCstCapture(ctx: ParseContext, mark: CstRollbackMark): void;
|
|
43
|
+
export declare function pushCstTriviaEntry(ctx: ParseContext, start: number, end: number, kindIndex?: number): void;
|
|
44
|
+
export declare function pushTriviaLogEntry(ctx: ParseContext, start: number, end: number, kindIndex?: number): void;
|
|
45
|
+
export declare function cstDeferredTriviaActive(ctx: ParseContext): boolean;
|
|
46
|
+
//# sourceMappingURL=capture-buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture-buffer.d.ts","sourceRoot":"","sources":["../../src/cst/capture-buffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,uEAAuE;AACvE,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC5B,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,SAAS,CAAA;IAC1B,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC/B,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,SAAS,CAAA;IAC3B,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;CAC1B,CAAA;AAKD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAE3D;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,YAAY,CAAC,cAAc,CAAC,CAAA;IAChC,EAAE,EAAE,YAAY,CAAC,YAAY,CAAC,CAAA;IAC9B,GAAG,EAAE,YAAY,CAAC,iBAAiB,CAAC,CAAA;IACpC,EAAE,EAAE,YAAY,CAAC,eAAe,CAAC,CAAA;IACjC,GAAG,EAAE,OAAO,GAAG,SAAS,CAAA;IACxB,GAAG,EAAE,aAAa,GAAG,SAAS,CAAA;CAC/B,CAAA;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,GAAG,mBAAmB,CAgB1E;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,aAAa,GAAG,SAAS,GAAG;IAC5D,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,WAAW,EAAE,OAAO,EAAE,CAAA;IACtB,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB,CAMA;AAED,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,mBAAmB,GACzB;IAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;IAAC,WAAW,EAAE,OAAO,EAAE,CAAC;IAAC,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,CAStE;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAElE;AAED,8FAA8F;AAC9F,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI,CAevF;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAOnD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAOtD;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAIlD;AAED,MAAM,MAAM,eAAe,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAE3E,wBAAgB,WAAW,CAAC,GAAG,EAAE,YAAY,GAAG,eAAe,CAM9D;AAkBD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,eAAe,GAAG,IAAI,CAcjF;AAED,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,MAAM,EACb,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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** View over a flat trivia log (`_triviaLog` or per-node `triviaLog`). */
|
|
2
|
+
export type TriviaEntriesView = {
|
|
3
|
+
readonly length: number;
|
|
4
|
+
readonly labels: readonly string[] | undefined;
|
|
5
|
+
readonly stride: number;
|
|
6
|
+
start(i: number): number;
|
|
7
|
+
end(i: number): number;
|
|
8
|
+
kindIndex(i: number): number | undefined;
|
|
9
|
+
kind(i: number): string | undefined;
|
|
10
|
+
text(i: number, input: string): string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Wrap a flat trivia log. Stride is inferred from `labels`:
|
|
14
|
+
* - root `_triviaLog`: 2 (start, end) or 3 (+ kindIndex)
|
|
15
|
+
* - node `triviaLog`: 3 (start, end, insertIdx) or 4 (+ kindIndex)
|
|
16
|
+
*/
|
|
17
|
+
export declare function triviaEntries(log: readonly number[], labels?: readonly string[], opts?: {
|
|
18
|
+
nodeLog?: boolean;
|
|
19
|
+
}): TriviaEntriesView;
|
|
20
|
+
//# sourceMappingURL=trivia-entries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trivia-entries.d.ts","sourceRoot":"","sources":["../../src/cst/trivia-entries.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAA;IAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACtB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IACxC,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IACnC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CACvC,CAAA;AAMD;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,SAAS,MAAM,EAAE,EACtB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,EAC1B,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAC3B,iBAAiB,CA6BnB"}
|