parseman 0.47.1 → 0.48.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.
Files changed (124) hide show
  1. package/README.md +27 -21
  2. package/dist/analysis/diagnostics.js +2863 -353
  3. package/dist/analysis/diagnostics.js.map +3 -3
  4. package/dist/cli/index.js +2854 -344
  5. package/dist/cli/index.js.map +3 -3
  6. package/dist/combinators/expect.d.ts +1 -0
  7. package/dist/combinators/expect.d.ts.map +1 -1
  8. package/dist/combinators/expected.d.ts +8 -0
  9. package/dist/combinators/expected.d.ts.map +1 -0
  10. package/dist/combinators/first-set.d.ts +8 -0
  11. package/dist/combinators/first-set.d.ts.map +1 -1
  12. package/dist/combinators/grammar.d.ts.map +1 -1
  13. package/dist/combinators/keywords.d.ts +4 -0
  14. package/dist/combinators/keywords.d.ts.map +1 -1
  15. package/dist/combinators/literal.d.ts.map +1 -1
  16. package/dist/combinators/not.d.ts.map +1 -1
  17. package/dist/combinators/peek.d.ts.map +1 -1
  18. package/dist/combinators/regex.d.ts.map +1 -1
  19. package/dist/combinators/repeat.d.ts.map +1 -1
  20. package/dist/combinators/sequence.d.ts.map +1 -1
  21. package/dist/combinators/trivia-skip.d.ts +16 -3
  22. package/dist/combinators/trivia-skip.d.ts.map +1 -1
  23. package/dist/compiler/direct-projection.d.ts +12 -0
  24. package/dist/compiler/direct-projection.d.ts.map +1 -0
  25. package/dist/compiler/token-alphabet.d.ts +845 -5
  26. package/dist/compiler/token-alphabet.d.ts.map +1 -1
  27. package/dist/compiler/token-capability.d.ts +3 -0
  28. package/dist/compiler/token-capability.d.ts.map +1 -0
  29. package/dist/compiler/token-capability.js +3192 -0
  30. package/dist/compiler/token-capability.js.map +6 -0
  31. package/dist/cst/trivia-charscan.d.ts +3 -0
  32. package/dist/cst/trivia-charscan.d.ts.map +1 -1
  33. package/dist/cst/trivia-css-scanner.d.ts +5 -0
  34. package/dist/cst/trivia-css-scanner.d.ts.map +1 -0
  35. package/dist/cst/trivia-kinds.d.ts.map +1 -1
  36. package/dist/index.js +2862 -339
  37. package/dist/index.js.map +3 -3
  38. package/dist/language-service/index.js +5 -1
  39. package/dist/language-service/index.js.map +1 -1
  40. package/dist/plugin/index.js +2870 -347
  41. package/dist/plugin/index.js.map +3 -3
  42. package/dist/spec/index.js +315 -46
  43. package/dist/spec/index.js.map +2 -2
  44. package/dist/table/assemble.d.ts.map +1 -1
  45. package/dist/table/child-slots.d.ts.map +1 -1
  46. package/dist/table/compile-rule-map.d.ts +3 -1
  47. package/dist/table/compile-rule-map.d.ts.map +1 -1
  48. package/dist/table/emit-assembly.d.ts +12 -13
  49. package/dist/table/emit-assembly.d.ts.map +1 -1
  50. package/dist/table/emit.d.ts.map +1 -1
  51. package/dist/table/encode.d.ts.map +1 -1
  52. package/dist/table/exec-baseline.d.ts.map +1 -1
  53. package/dist/table/exec.d.ts.map +1 -1
  54. package/dist/table/index.js +2819 -300
  55. package/dist/table/index.js.map +3 -3
  56. package/dist/table/lex-body.d.ts +9 -0
  57. package/dist/table/lex-body.d.ts.map +1 -0
  58. package/dist/table/lex-program.d.ts +25 -0
  59. package/dist/table/lex-program.d.ts.map +1 -0
  60. package/dist/table/ops.d.ts +43 -7
  61. package/dist/table/ops.d.ts.map +1 -1
  62. package/dist/table/program.d.ts +50 -2
  63. package/dist/table/program.d.ts.map +1 -1
  64. package/dist/table/scalar-terminal.d.ts +13 -0
  65. package/dist/table/scalar-terminal.d.ts.map +1 -0
  66. package/dist/table/site-labels.d.ts.map +1 -1
  67. package/dist/types.d.ts +2 -0
  68. package/dist/types.d.ts.map +1 -1
  69. package/dist/version.d.ts +1 -1
  70. package/package.json +11 -11
  71. package/src/combinators/expect.ts +1 -0
  72. package/src/combinators/expected.ts +17 -0
  73. package/src/combinators/first-set.ts +58 -5
  74. package/src/combinators/grammar.ts +8 -3
  75. package/src/combinators/keywords.ts +22 -6
  76. package/src/combinators/literal.ts +2 -1
  77. package/src/combinators/not.ts +5 -1
  78. package/src/combinators/peek.ts +5 -1
  79. package/src/combinators/regex.ts +5 -3
  80. package/src/combinators/repeat.ts +4 -10
  81. package/src/combinators/sequence.ts +17 -14
  82. package/src/combinators/trivia-skip.ts +46 -13
  83. package/src/compiler/direct-projection.ts +43 -0
  84. package/src/compiler/token-alphabet.ts +4316 -12
  85. package/src/compiler/token-capability.ts +6 -0
  86. package/src/cst/trivia-charscan.ts +34 -0
  87. package/src/cst/trivia-css-scanner.ts +142 -0
  88. package/src/cst/trivia-kinds.ts +3 -1
  89. package/src/plugin/index.ts +4 -4
  90. package/src/table/assemble.ts +1211 -221
  91. package/src/table/child-slots.ts +2 -1
  92. package/src/table/compile-rule-map.ts +21 -3
  93. package/src/table/emit-assembly.ts +328 -85
  94. package/src/table/emit.ts +16 -2
  95. package/src/table/encode.ts +242 -50
  96. package/src/table/exec-baseline.ts +3 -7
  97. package/src/table/exec.ts +121 -7
  98. package/src/table/lex-body.ts +30 -0
  99. package/src/table/lex-program.ts +422 -0
  100. package/src/table/ops.ts +45 -7
  101. package/src/table/program.ts +46 -2
  102. package/src/table/scalar-terminal.ts +51 -0
  103. package/src/table/site-labels.ts +11 -1
  104. package/src/table/stamp.ts +1 -1
  105. package/src/types.ts +1 -1
  106. package/src/version.ts +1 -1
  107. package/dist/analysis/diagnostics.cjs +0 -13824
  108. package/dist/analysis/diagnostics.cjs.map +0 -6
  109. package/dist/cli/index.cjs +0 -14925
  110. package/dist/cli/index.cjs.map +0 -6
  111. package/dist/index.cjs +0 -16391
  112. package/dist/index.cjs.map +0 -6
  113. package/dist/language-service/index.cjs +0 -1304
  114. package/dist/language-service/index.cjs.map +0 -6
  115. package/dist/oracle/index.cjs +0 -254
  116. package/dist/oracle/index.cjs.map +0 -6
  117. package/dist/plugin/index.cjs +0 -16097
  118. package/dist/plugin/index.cjs.map +0 -6
  119. package/dist/run/index.cjs +0 -577
  120. package/dist/run/index.cjs.map +0 -6
  121. package/dist/spec/index.cjs +0 -6236
  122. package/dist/spec/index.cjs.map +0 -6
  123. package/dist/table/index.cjs +0 -11463
  124. package/dist/table/index.cjs.map +0 -6
package/README.md CHANGED
@@ -10,27 +10,28 @@ Parser combinators are pleasant to write and usually slow. Parser generators are
10
10
  usually mean grammar files, generated code, and extra tooling. Parséman is a combinator
11
11
  library with an optional compiler, and it gives you both.
12
12
 
13
- **Parsing to JS values, the macro build is the fastest general-purpose JS parser in the
14
- suite** — ahead of every other library measured, at every grammar and every input size in
15
- that suite.
13
+ **Parsing to JS values, the runtime-compiled artifact is the fastest general-purpose JS
14
+ parser in the suite** — ahead of every other library measured, at every grammar and every
15
+ input size in that suite.
16
16
  Every parser in the suite builds real output: objects, row arrays, AST nodes. On a 7.7 kB
17
- GraphQL document Parséman takes **131 µs**; Peggy takes 328 µs. Only a purpose-built native
18
- edges it out, `JSON.parse` on JSON.
17
+ GraphQL document Parséman takes **188 µs**; Peggy takes 323 µs. Only a purpose-built native
18
+ edges it out: `JSON.parse` on JSON.
19
19
 
20
20
  ![GraphQL parsing benchmarks](https://raw.githubusercontent.com/matthew-dean/parseman/main/assets/bench-graphql.svg)
21
21
 
22
- Two more results. The compiled CST path beats Lezer on the JSON CST fixture — **174 µs** vs
23
- 594 µs at 11.9 kB — while producing a richer tree carrying spans and trivia. And `parseDoc`
22
+ Two more results. The compiled CST path beats Lezer on the JSON CST fixture — **242 µs** vs
23
+ 570 µs at 11.9 kB — while producing a richer tree carrying spans and trivia. And `parseDoc`
24
24
  stores parent-relative spans, so an in-place edit costs a fraction of a full reparse rather
25
25
  than a multiple of it. Results move with grammar shape, input size and runtime — which is
26
26
  why [the suite](#benchmarks) ships with the library rather than only its conclusions.
27
27
 
28
28
  You get there by writing normal code. Add the bundler plugin, mark one import, and the
29
- combinators you already wrote compile to flat JavaScript — the compiler computes the first
30
- sets and left-factors the choices for you.
29
+ combinators you already wrote compile to an optimized `TableProgram` artifact — the compiler
30
+ computes first sets, links direct bodies for proven shapes, and left-factors choices for you.
31
31
 
32
32
  Grammars work the same in plain JavaScript: the macro compiles a `.js` grammar to the same
33
- output as a `.ts` one, and the package ships both ESM and CJS. Write in TypeScript and result
33
+ output as a `.ts` one. The package ships one ESM implementation, loadable through either
34
+ `import` or `require()` on the supported Node versions. Write in TypeScript and result
34
35
  types are inferred across the whole combinator chain — types you didn't have to write out.
35
36
 
36
37
  Reach for it when you want CST/AST nodes with spans and trivia, error recovery and
@@ -54,7 +55,7 @@ npm install parseman
54
55
  ```
55
56
 
56
57
  Pre-1.0: minor versions may carry breaking changes — check the [changelog](./CHANGELOG.md)
57
- before upgrading. Requires Node `^20.19.0 || >=22.12.0`.
58
+ before upgrading. Requires Node `^20.19.0 || >=22.13.0`.
58
59
 
59
60
  ## Quick start
60
61
 
@@ -84,9 +85,9 @@ The same combinator code runs three ways, with identical results:
84
85
  - **Interpreter** — zero setup, works anywhere (tests, REPLs, dynamic grammars).
85
86
  - **Macro build** — a [bundler plugin](https://matthew-dean.github.io/parseman/guide/macro-mode)
86
87
  evaluates your grammar at build time and inlines the result. The combinator import you
87
- mark `with { type: 'macro' }` disappears entirely; what ships is flat JavaScript with no
88
- parseman import in it. (Executing that parser still goes through `run()`/`parse()`, so an
89
- app keeps parseman as an ordinary dependency — see
88
+ mark `with { type: 'macro' }` disappears entirely; what ships is a compact table artifact
89
+ using the shared `parseman/table` runtime. Executing it still goes through `run()`/`parse()`,
90
+ so an app keeps Parseman as an ordinary dependency — see
90
91
  [the three modes](https://matthew-dean.github.io/parseman/guide/modes).)
91
92
  - **`compile()`** — the same optimizer, on demand at runtime.
92
93
 
@@ -158,13 +159,13 @@ Benchmarked against [Peggy](https://peggyjs.org/),
158
159
  [Lezer](https://lezer.codemirror.net/) on JSON, CSV and GraphQL, at three input sizes each.
159
160
  Each chart's legend names the libraries measured for that grammar.
160
161
 
161
- Largest fixture of each, macro build against the fastest other library on that chart:
162
- GraphQL **131 µs** vs Peggy's 328 µs, JSON **133 µs** vs Chevrotain's 241 µs, CSV
163
- **75.3 µs** vs Peggy's 420 µs. Native `JSON.parse` does JSON large in 51.6 µs. On the CST
164
- chart, macro build runs 174 µs against Lezer's 594 µs parse-only.
162
+ Largest fixture of each, runtime compile against the fastest other library on that chart:
163
+ GraphQL **188 µs** vs Peggy's 323 µs, JSON **223 µs** vs Chevrotain's 238 µs, CSV
164
+ **114 µs** vs Peggy's 422 µs. Native `JSON.parse` does JSON large in 50.3 µs. On the CST
165
+ chart, runtime compile runs 242 µs against Lezer's 570 µs parse-only.
165
166
 
166
- Those are the committed charts, regenerated at 0.29.0 (2026-07-22) on an M4 Pro, measuring
167
- the JS-codegen lowering that `compile()` and the macro build emit.
167
+ Those are the committed 0.48.0 charts, regenerated on 2026-08-14 on an M4 Pro with
168
+ Node 25.9.0. They include the restored small rows for JSON, CSV, GraphQL, and CST.
168
169
 
169
170
  ![JSON parsing benchmarks](https://raw.githubusercontent.com/matthew-dean/parseman/main/assets/bench-json.svg)
170
171
 
@@ -188,13 +189,18 @@ nodes, so the numbers come from a spec-shaped language rather than a toy.
188
189
  pnpm install
189
190
  pnpm test # interpreter + compiled parity, ordered-choice semantics
190
191
  pnpm typecheck
191
- pnpm build # ESM + CJS + .d.ts → dist/
192
+ pnpm build # ESM + .d.ts → dist/
192
193
  pnpm docs:dev # this documentation site, locally
193
194
  ```
194
195
 
195
196
  Benchmark and chart tasks (`pnpm bench`, `bench:svg`, `bench:parseman`, …) are described in
196
197
  the [benchmarks guide](https://matthew-dean.github.io/parseman/guide/benchmarks#reproducing-the-numbers).
197
198
 
199
+ The frozen 0.48 runtime architecture and release specification is
200
+ [`docs/design/parseman-0.48.md`](./docs/design/parseman-0.48.md). Detailed measurements
201
+ and rejected experiments remain in the linked evidence registers rather than being
202
+ treated as current design.
203
+
198
204
  ## License
199
205
 
200
206
  MIT © [Matthew Dean](https://github.com/matthew-dean)