parseman 0.46.0 → 0.47.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 (316) hide show
  1. package/README.md +8 -3
  2. package/dist/analysis/choice-cost-render.d.ts +12 -4
  3. package/dist/analysis/choice-cost-render.d.ts.map +1 -1
  4. package/dist/analysis/choice-cost.d.ts +2 -2
  5. package/dist/analysis/choice-cost.d.ts.map +1 -1
  6. package/dist/analysis/commitment.d.ts +131 -0
  7. package/dist/analysis/commitment.d.ts.map +1 -0
  8. package/dist/analysis/diagnostics.cjs +9929 -7465
  9. package/dist/analysis/diagnostics.cjs.map +3 -4
  10. package/dist/analysis/diagnostics.d.ts +2 -2
  11. package/dist/analysis/diagnostics.js +9929 -7465
  12. package/dist/analysis/diagnostics.js.map +3 -4
  13. package/dist/analysis/duplication.d.ts.map +1 -1
  14. package/dist/analysis/fix.d.ts +3 -3
  15. package/dist/analysis/fix.d.ts.map +1 -1
  16. package/dist/analysis/format-number.d.ts +23 -0
  17. package/dist/analysis/format-number.d.ts.map +1 -0
  18. package/dist/analysis/gating.d.ts +39 -2
  19. package/dist/analysis/gating.d.ts.map +1 -1
  20. package/dist/analysis/rebuild.d.ts.map +1 -1
  21. package/dist/analysis/terminal.d.ts +5 -2
  22. package/dist/analysis/terminal.d.ts.map +1 -1
  23. package/dist/cli/index.cjs +10865 -8535
  24. package/dist/cli/index.cjs.map +3 -4
  25. package/dist/cli/index.js +10865 -8535
  26. package/dist/cli/index.js.map +3 -4
  27. package/dist/combinators/adjacency.d.ts +100 -0
  28. package/dist/combinators/adjacency.d.ts.map +1 -0
  29. package/dist/combinators/choice.d.ts.map +1 -1
  30. package/dist/combinators/completions.d.ts.map +1 -1
  31. package/dist/combinators/dispatch.d.ts +8 -1
  32. package/dist/combinators/dispatch.d.ts.map +1 -1
  33. package/dist/combinators/expect.d.ts.map +1 -1
  34. package/dist/combinators/first-set.d.ts.map +1 -1
  35. package/dist/combinators/gate.d.ts.map +1 -1
  36. package/dist/combinators/grammar.d.ts +22 -0
  37. package/dist/combinators/grammar.d.ts.map +1 -1
  38. package/dist/combinators/literal.d.ts +8 -0
  39. package/dist/combinators/literal.d.ts.map +1 -1
  40. package/dist/combinators/map.d.ts +0 -1
  41. package/dist/combinators/map.d.ts.map +1 -1
  42. package/dist/combinators/node.d.ts +13 -3
  43. package/dist/combinators/node.d.ts.map +1 -1
  44. package/dist/combinators/parser.d.ts +1 -1
  45. package/dist/combinators/parser.d.ts.map +1 -1
  46. package/dist/combinators/ref.d.ts.map +1 -1
  47. package/dist/combinators/regex.d.ts +1 -16
  48. package/dist/combinators/regex.d.ts.map +1 -1
  49. package/dist/combinators/repeat.d.ts +30 -2
  50. package/dist/combinators/repeat.d.ts.map +1 -1
  51. package/dist/combinators/scanTo.d.ts +71 -1
  52. package/dist/combinators/scanTo.d.ts.map +1 -1
  53. package/dist/combinators/sequence.d.ts.map +1 -1
  54. package/dist/combinators/token.d.ts.map +1 -1
  55. package/dist/combinators/trivia-boundary.d.ts +26 -0
  56. package/dist/combinators/trivia-boundary.d.ts.map +1 -0
  57. package/dist/combinators/trivia-skip.d.ts +40 -1
  58. package/dist/combinators/trivia-skip.d.ts.map +1 -1
  59. package/dist/combinators/withCtx.d.ts.map +1 -1
  60. package/dist/compiler/compile-linkable-table.d.ts +104 -0
  61. package/dist/compiler/compile-linkable-table.d.ts.map +1 -0
  62. package/dist/compiler/degradation.d.ts +0 -2
  63. package/dist/compiler/degradation.d.ts.map +1 -1
  64. package/dist/compiler/fields.d.ts +13 -0
  65. package/dist/compiler/fields.d.ts.map +1 -1
  66. package/dist/compiler/grammar-coverage-ids.d.ts +5 -5
  67. package/dist/compiler/grammar-coverage-ids.d.ts.map +1 -1
  68. package/dist/compiler/ir-serialize.d.ts.map +1 -1
  69. package/dist/compiler/linker.d.ts +47 -53
  70. package/dist/compiler/linker.d.ts.map +1 -1
  71. package/dist/compiler/token-alphabet.d.ts +81 -0
  72. package/dist/compiler/token-alphabet.d.ts.map +1 -0
  73. package/dist/compiler/token-dispatch.d.ts +95 -0
  74. package/dist/compiler/token-dispatch.d.ts.map +1 -0
  75. package/dist/compiler/token-scanner.d.ts +53 -0
  76. package/dist/compiler/token-scanner.d.ts.map +1 -0
  77. package/dist/compiler/value-usage.d.ts.map +1 -1
  78. package/dist/coverage.d.ts +1 -1
  79. package/dist/coverage.d.ts.map +1 -1
  80. package/dist/cst/capture-buffer.d.ts +35 -0
  81. package/dist/cst/capture-buffer.d.ts.map +1 -1
  82. package/dist/cst/reflection-attach.d.ts +8 -0
  83. package/dist/cst/reflection-attach.d.ts.map +1 -0
  84. package/dist/cst/reflection-symbols.d.ts +10 -0
  85. package/dist/cst/reflection-symbols.d.ts.map +1 -0
  86. package/dist/cst/reflection.d.ts +2 -4
  87. package/dist/cst/reflection.d.ts.map +1 -1
  88. package/dist/cst/root-trivia-scope.d.ts +26 -0
  89. package/dist/cst/root-trivia-scope.d.ts.map +1 -0
  90. package/dist/cst/trivia-charscan.d.ts +18 -0
  91. package/dist/cst/trivia-charscan.d.ts.map +1 -0
  92. package/dist/cst/trivia-kinds.d.ts +19 -0
  93. package/dist/cst/trivia-kinds.d.ts.map +1 -1
  94. package/dist/functional/doc.d.ts.map +1 -1
  95. package/dist/functional/run-tabled.d.ts +12 -0
  96. package/dist/functional/run-tabled.d.ts.map +1 -0
  97. package/dist/functional/run.d.ts +25 -42
  98. package/dist/functional/run.d.ts.map +1 -1
  99. package/dist/grammar-metadata.d.ts +3 -0
  100. package/dist/grammar-metadata.d.ts.map +1 -0
  101. package/dist/index.cjs +9224 -7203
  102. package/dist/index.cjs.map +3 -4
  103. package/dist/index.d.ts +18 -9
  104. package/dist/index.d.ts.map +1 -1
  105. package/dist/index.js +9219 -7198
  106. package/dist/index.js.map +3 -4
  107. package/dist/language-service/index.cjs +311 -121
  108. package/dist/language-service/index.cjs.map +3 -4
  109. package/dist/language-service/index.js +311 -121
  110. package/dist/language-service/index.js.map +3 -4
  111. package/dist/oracle/index.cjs.map +0 -1
  112. package/dist/oracle/index.js.map +0 -1
  113. package/dist/parse-context.d.ts +49 -0
  114. package/dist/parse-context.d.ts.map +1 -0
  115. package/dist/plugin/evaluator.d.ts +40 -1
  116. package/dist/plugin/evaluator.d.ts.map +1 -1
  117. package/dist/plugin/index.cjs +11146 -9593
  118. package/dist/plugin/index.cjs.map +3 -4
  119. package/dist/plugin/index.d.ts.map +1 -1
  120. package/dist/plugin/index.js +11146 -9593
  121. package/dist/plugin/index.js.map +3 -4
  122. package/dist/regex/classes.d.ts +28 -0
  123. package/dist/regex/classes.d.ts.map +1 -1
  124. package/dist/regex/first-set.d.ts +14 -0
  125. package/dist/regex/first-set.d.ts.map +1 -1
  126. package/dist/run/index.cjs +136 -51
  127. package/dist/run/index.cjs.map +2 -3
  128. package/dist/run/index.js +136 -51
  129. package/dist/run/index.js.map +2 -3
  130. package/dist/spec/index.cjs +2898 -1623
  131. package/dist/spec/index.cjs.map +3 -4
  132. package/dist/spec/index.js +2898 -1623
  133. package/dist/spec/index.js.map +3 -4
  134. package/dist/spec/model.d.ts +8 -0
  135. package/dist/spec/model.d.ts.map +1 -1
  136. package/dist/table/assemble.d.ts +307 -0
  137. package/dist/table/assemble.d.ts.map +1 -0
  138. package/dist/table/cell.d.ts +42 -0
  139. package/dist/table/cell.d.ts.map +1 -0
  140. package/dist/table/child-slots.d.ts +30 -0
  141. package/dist/table/child-slots.d.ts.map +1 -0
  142. package/dist/table/compile-rule-map.d.ts +136 -0
  143. package/dist/table/compile-rule-map.d.ts.map +1 -0
  144. package/dist/table/compile.d.ts +56 -0
  145. package/dist/table/compile.d.ts.map +1 -0
  146. package/dist/table/duplication-hook.d.ts +32 -0
  147. package/dist/table/duplication-hook.d.ts.map +1 -0
  148. package/dist/table/emit-assembly.d.ts +139 -0
  149. package/dist/table/emit-assembly.d.ts.map +1 -0
  150. package/dist/table/emit.d.ts +113 -0
  151. package/dist/table/emit.d.ts.map +1 -0
  152. package/dist/table/encode-baseline.d.ts +16 -0
  153. package/dist/table/encode-baseline.d.ts.map +1 -0
  154. package/dist/table/encode.d.ts +71 -0
  155. package/dist/table/encode.d.ts.map +1 -0
  156. package/dist/table/exec-baseline.d.ts +9 -0
  157. package/dist/table/exec-baseline.d.ts.map +1 -0
  158. package/dist/table/exec.d.ts +72 -0
  159. package/dist/table/exec.d.ts.map +1 -0
  160. package/dist/table/fold.d.ts +25 -0
  161. package/dist/table/fold.d.ts.map +1 -0
  162. package/dist/table/index.cjs +11375 -0
  163. package/dist/table/index.cjs.map +6 -0
  164. package/dist/table/index.d.ts +100 -0
  165. package/dist/table/index.d.ts.map +1 -0
  166. package/dist/table/index.js +11352 -0
  167. package/dist/table/index.js.map +6 -0
  168. package/dist/table/inspect.d.ts +17 -0
  169. package/dist/table/inspect.d.ts.map +1 -0
  170. package/dist/table/ops.d.ts +446 -0
  171. package/dist/table/ops.d.ts.map +1 -0
  172. package/dist/table/program.d.ts +493 -0
  173. package/dist/table/program.d.ts.map +1 -0
  174. package/dist/table/run-support.d.ts +38 -0
  175. package/dist/table/run-support.d.ts.map +1 -0
  176. package/dist/{compiler/scannable-run.d.ts → table/scan-shapes.d.ts} +14 -13
  177. package/dist/table/scan-shapes.d.ts.map +1 -0
  178. package/dist/table/site-labels.d.ts +58 -0
  179. package/dist/table/site-labels.d.ts.map +1 -0
  180. package/dist/table/stamp.d.ts +70 -0
  181. package/dist/table/stamp.d.ts.map +1 -0
  182. package/dist/types.d.ts +80 -24
  183. package/dist/types.d.ts.map +1 -1
  184. package/dist/version.d.ts +1 -1
  185. package/package.json +25 -2
  186. package/src/analysis/choice-cost-gate.ts +359 -0
  187. package/src/analysis/choice-cost-render.ts +293 -0
  188. package/src/analysis/choice-cost.ts +1008 -0
  189. package/src/analysis/commitment.ts +557 -0
  190. package/src/analysis/corpus.ts +130 -0
  191. package/src/analysis/diagnose-render.ts +625 -0
  192. package/src/analysis/diagnose.ts +317 -0
  193. package/src/analysis/diagnostics.ts +33 -0
  194. package/src/analysis/duplication.ts +1955 -0
  195. package/src/analysis/fix-render.ts +217 -0
  196. package/src/analysis/fix.ts +669 -0
  197. package/src/analysis/format-number.ts +31 -0
  198. package/src/analysis/gating.ts +792 -0
  199. package/src/analysis/grammar.ts +72 -0
  200. package/src/analysis/rebuild.ts +287 -0
  201. package/src/analysis/terminal.ts +336 -0
  202. package/src/cli/index.ts +413 -0
  203. package/src/combinators/adjacency.ts +171 -0
  204. package/src/combinators/attempt.ts +41 -0
  205. package/src/combinators/case-fold.ts +90 -0
  206. package/src/combinators/choice.ts +466 -0
  207. package/src/combinators/completions.ts +64 -0
  208. package/src/combinators/dispatch.ts +358 -0
  209. package/src/combinators/expect.ts +159 -0
  210. package/src/combinators/first-set.ts +322 -0
  211. package/src/combinators/gate.ts +50 -0
  212. package/src/combinators/grammar.ts +272 -0
  213. package/src/combinators/keywords.ts +145 -0
  214. package/src/combinators/literal.ts +102 -0
  215. package/src/combinators/map.ts +106 -0
  216. package/src/combinators/node.ts +345 -0
  217. package/src/combinators/not.ts +55 -0
  218. package/src/combinators/parser.ts +266 -0
  219. package/src/combinators/peek.ts +63 -0
  220. package/src/combinators/probe.ts +25 -0
  221. package/src/combinators/ref.ts +109 -0
  222. package/src/combinators/regex.ts +170 -0
  223. package/src/combinators/repeat.ts +561 -0
  224. package/src/combinators/scanTo.ts +393 -0
  225. package/src/combinators/sequence.ts +221 -0
  226. package/src/combinators/token.ts +120 -0
  227. package/src/combinators/trivia-boundary.ts +48 -0
  228. package/src/combinators/trivia-skip.ts +821 -0
  229. package/src/combinators/withCtx.ts +45 -0
  230. package/src/compiler/build-arity.ts +330 -0
  231. package/src/compiler/compile-linkable-table.ts +209 -0
  232. package/src/compiler/degradation.ts +266 -0
  233. package/src/compiler/fields.ts +191 -0
  234. package/src/compiler/grammar-coverage-ids.ts +129 -0
  235. package/src/compiler/ir-serialize.ts +615 -0
  236. package/src/compiler/linker.ts +954 -0
  237. package/src/compiler/token-alphabet.ts +209 -0
  238. package/src/compiler/token-dispatch.ts +353 -0
  239. package/src/compiler/token-scanner.ts +318 -0
  240. package/src/compiler/value-usage.ts +147 -0
  241. package/src/coverage.ts +383 -0
  242. package/src/cst/capture-buffer.ts +297 -0
  243. package/src/cst/host-mode.ts +69 -0
  244. package/src/cst/reflection-attach.ts +11 -0
  245. package/src/cst/reflection-symbols.ts +9 -0
  246. package/src/cst/reflection.ts +149 -0
  247. package/src/cst/relative-spans.ts +207 -0
  248. package/src/cst/root-trivia-scope.ts +30 -0
  249. package/src/cst/trivia-charscan.ts +312 -0
  250. package/src/cst/trivia-entries.ts +285 -0
  251. package/src/cst/trivia-index.ts +131 -0
  252. package/src/cst/trivia-kinds.ts +358 -0
  253. package/src/cst/types.ts +76 -0
  254. package/src/cst/walk.ts +101 -0
  255. package/src/functional/doc.ts +959 -0
  256. package/src/functional/run-tabled.ts +153 -0
  257. package/src/functional/run.ts +558 -0
  258. package/src/grammar-metadata.ts +2 -0
  259. package/src/index.ts +189 -0
  260. package/src/language-service/index.ts +221 -0
  261. package/src/line-index.ts +131 -0
  262. package/src/oracle/digest.ts +620 -0
  263. package/src/oracle/index.ts +55 -0
  264. package/src/parse-context.ts +91 -0
  265. package/src/plugin/direct-builder-static.ts +102 -0
  266. package/src/plugin/evaluator.ts +1505 -0
  267. package/src/plugin/free-identifiers.ts +338 -0
  268. package/src/plugin/index.ts +2281 -0
  269. package/src/plugin/reducer-resolver.ts +606 -0
  270. package/src/recovery/scan.ts +155 -0
  271. package/src/regex/classes.ts +183 -0
  272. package/src/regex/first-set.ts +316 -0
  273. package/src/run/index.ts +31 -0
  274. package/src/spec/ebnf.ts +128 -0
  275. package/src/spec/index.ts +54 -0
  276. package/src/spec/model.ts +636 -0
  277. package/src/spec/railroad-lib.ts +559 -0
  278. package/src/spec/railroad.ts +256 -0
  279. package/src/table/assemble.ts +2994 -0
  280. package/src/table/cell.ts +42 -0
  281. package/src/table/child-slots.ts +113 -0
  282. package/src/table/compile-rule-map.ts +336 -0
  283. package/src/table/compile.ts +244 -0
  284. package/src/table/duplication-hook.ts +89 -0
  285. package/src/table/emit-assembly.ts +1766 -0
  286. package/src/table/emit.ts +418 -0
  287. package/src/table/encode-baseline.ts +340 -0
  288. package/src/table/encode.ts +1569 -0
  289. package/src/table/exec-baseline.ts +537 -0
  290. package/src/table/exec.ts +1672 -0
  291. package/src/table/fold.ts +38 -0
  292. package/src/table/index.ts +108 -0
  293. package/src/table/inspect.ts +52 -0
  294. package/src/table/ops.ts +459 -0
  295. package/src/table/program.ts +855 -0
  296. package/src/table/run-support.ts +66 -0
  297. package/src/table/scan-shapes.ts +1578 -0
  298. package/src/table/site-labels.ts +228 -0
  299. package/src/table/stamp.ts +229 -0
  300. package/src/types.ts +563 -0
  301. package/src/version.ts +16 -0
  302. package/dist/compiler/codegen.d.ts +0 -334
  303. package/dist/compiler/codegen.d.ts.map +0 -1
  304. package/dist/compiler/inline-build.d.ts +0 -11
  305. package/dist/compiler/inline-build.d.ts.map +0 -1
  306. package/dist/compiler/inline-callback.d.ts +0 -21
  307. package/dist/compiler/inline-callback.d.ts.map +0 -1
  308. package/dist/compiler/line-index.d.ts +0 -2
  309. package/dist/compiler/line-index.d.ts.map +0 -1
  310. package/dist/compiler/module-hoist.d.ts +0 -106
  311. package/dist/compiler/module-hoist.d.ts.map +0 -1
  312. package/dist/compiler/scannable-run.d.ts.map +0 -1
  313. package/dist/compiler/scannable-terminal.d.ts +0 -23
  314. package/dist/compiler/scannable-terminal.d.ts.map +0 -1
  315. package/dist/compiler/trivia-fast-path.d.ts +0 -38
  316. package/dist/compiler/trivia-fast-path.d.ts.map +0 -1
@@ -0,0 +1,32 @@
1
+ import type { Combinator } from '../types.ts';
2
+ import { type DuplicationReport, type DuplicationWarnLevel } from '../analysis/duplication.ts';
3
+ /**
4
+ * THE DUPLICATION DIAGNOSTIC'S LOWERING HOOK.
5
+ *
6
+ * This ran inside the source lowering, so deleting that lowering would have silently
7
+ * taken it with it — the analysis in `analysis/duplication.ts` would survive and
8
+ * nothing would call it, which reads exactly like a clean grammar. It is not a
9
+ * property of how a grammar is lowered, so it lives with the lowering that remains.
10
+ */
11
+ /**
12
+ * The `duplication` compile option. A bare level is shorthand for `{ level }`; the
13
+ * object form adds the `accept` allowlist (finding ids acknowledged as intentional)
14
+ * and the ranking knobs.
15
+ *
16
+ * DEFAULT IS `'off'`, unlike gating. An ungated hot choice is a cliff with no other
17
+ * symptom; a duplicated subtree is a maintenance cost the author may have chosen.
18
+ * More to the point, most findings here are CANDIDATES that need an AST check
19
+ * before they are applied — a diagnostic that prints "candidate, verify" on every
20
+ * build teaches people to stop reading it. Run it deliberately (a lint script, a
21
+ * review pass, `PARSEMAN_DUPLICATION=warn`), not on every compile.
22
+ */
23
+ export type DuplicationOption = DuplicationWarnLevel | {
24
+ level?: DuplicationWarnLevel;
25
+ accept?: Iterable<string>;
26
+ minSize?: number;
27
+ maxFindings?: number;
28
+ entryName?: string;
29
+ };
30
+ export declare function runDuplicationDiagnostic<T>(combinator: Combinator<T>, opt: DuplicationOption | undefined): DuplicationReport | undefined;
31
+ export declare function runDuplicationDiagnosticRules(ruleMap: ReadonlyArray<readonly [string, Combinator<unknown>]>, opt: DuplicationOption | undefined): DuplicationReport | undefined;
32
+ //# sourceMappingURL=duplication-hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duplication-hook.d.ts","sourceRoot":"","sources":["../../src/table/duplication-hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAmG,KAAK,iBAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAE/L;;;;;;;GAOG;AACH;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,iBAAiB,GACzB,oBAAoB,GACpB;IAAE,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAsD3H,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,iBAAiB,GAAG,SAAS,GAAG,iBAAiB,GAAG,SAAS,CAExI;AAED,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAC9D,GAAG,EAAE,iBAAiB,GAAG,SAAS,GACjC,iBAAiB,GAAG,SAAS,CAE/B"}
@@ -0,0 +1,139 @@
1
+ /**
2
+ * U4 — THE ASSEMBLY, AS EMITTED SOURCE.
3
+ *
4
+ * `assemble.ts` lowers each reachable site to a closure. This file lowers the
5
+ * same sites to TEXT, compiled once per (grammar × option set) at run start.
6
+ * Semantics are `assemble.ts`'s, site for site; the identity sweep
7
+ * (`bench/table-lowering-identity.ts`) gates the two against each other and
8
+ * against the interpreter, and `expected` is inside the digest it compares.
9
+ *
10
+ * ## Why text, and not a rearrangement of `assemble.ts`
11
+ *
12
+ * V8 attaches inline-cache feedback per FUNCTION LITERAL, not per closure. The
13
+ * second closure minted from a `CreateClosure` site moves its `FeedbackCell` to
14
+ * `kManyClosures`, and the vector is shared from then on. `assemble.ts` mints 18
15
+ * arity-2 `SEQV` closures for `less/stylesheet` from ONE literal, so the two
16
+ * child call sites inside that literal see 18 unrelated callees and go
17
+ * megamorphic — a hash lookup in the megamorphic stub cache, no inlining, no
18
+ * type feedback for the callee body. No rearrangement of a file that MINTS
19
+ * closures can produce a distinct literal per site. Emitting one
20
+ * `function _pf<N>` per site can: inside `_pf12` the call `_pf7(…)` names ONE
21
+ * binding and stays monomorphic.
22
+ *
23
+ * ## What may be shared, and what must be emitted
24
+ *
25
+ * A body containing a call to another PIECE must be emitted per site, or the
26
+ * megamorphism relocates from `assemble.ts` into a shared helper and nothing
27
+ * changes. That is why `nextTerm` is INLINED at every sequence term here rather
28
+ * than called.
29
+ *
30
+ * The rule this file applies is narrower than "no helpers", and it is the whole
31
+ * criterion: **a shared emitted-scope helper is sound exactly when it takes no
32
+ * piece as an argument**, because then it has no call site whose feedback a
33
+ * second caller could pollute. `_skipTrivia` qualifies — it calls the installed
34
+ * trivia scanner, which is runtime state in either engine. `nextTerm` does not.
35
+ *
36
+ * ## Cycles
37
+ *
38
+ * `assemble.ts` needs one forwarding stub per recursive site,
39
+ * `const fwd = (input, pos, ctx) => target!(input, pos, ctx)` — a SINGLE
40
+ * function literal that every back-edge in the process funnels through.
41
+ * Emitted `function` declarations hoist, so a back-edge here is a direct name
42
+ * reference and the stub does not exist.
43
+ *
44
+ * ## Refusal
45
+ *
46
+ * Any construct not lowered raises `Unemittable`, naming it. `assemble.ts`
47
+ * catches that, RECORDS it on the assembly, and falls back to the closure path.
48
+ * The fallback is observable (`Assembly.emitRefusal`): a silent one would make
49
+ * a permanently slow path indistinguishable from a fast one, which is exactly
50
+ * what `encode.ts:1208-1213` refuses to allow for `OP_LIVE`.
51
+ */
52
+ import type { ParseContext } from '../types.ts';
53
+ import type { ResolvedClass, ResolvedTable, TableProgram } from './program.ts';
54
+ /** What the compiled factory hands back — the emitted twin of `Assembly`. */
55
+ export type EmittedPiece = (input: string, pos: number, ctx: ParseContext) => unknown;
56
+ export type EmittedAssembly = {
57
+ readonly pieces: Record<string, EmittedPiece>;
58
+ /** Sites named for `subtreeComb` — the scan pool and the scan-skip sets. */
59
+ readonly byIp: Record<number, EmittedPiece | undefined>;
60
+ readonly end: () => number;
61
+ readonly begin: (ctx: ParseContext) => void;
62
+ readonly finish: () => void;
63
+ };
64
+ /** The `new Function` result. Its parameters are `EMITTED_PARAMS`, in order. */
65
+ export type EmittedFactory = (...args: readonly unknown[]) => EmittedAssembly;
66
+ /** A construct the emitter does not lower. Names the CONSTRUCT, never a type. */
67
+ export declare class Unemittable extends Error {
68
+ readonly construct: string;
69
+ constructor(construct: string);
70
+ }
71
+ /**
72
+ * The names the emitted scope is closed over, in the order the factory takes
73
+ * them. ONE list, so the parameter list and the argument list cannot drift — a
74
+ * mismatch binds the wrong function to the wrong name and yields a parser that
75
+ * runs and is wrong, which no type in this file would catch.
76
+ */
77
+ export declare const EMITTED_PARAMS: readonly ['EC', 'FAIL', 'K', 'FX', 'FNS', 'MASK', 'CLS', 'AFX', 'TRIVIA', 'TRIVIALABELS', 'TRIVIASCAN', 'SCANS', 'DISP', 'DSP', 'EMPTY_FX', 'EMPTY_CH', 'EMPTY_TLOG', 'EMPTY_TL', 'cstCaptureActive', 'pushCstLeaf', 'pushCstChild', 'rollbackTriviaAt', 'failAt', 'classHas', 'consumeTrivia', 'buildFieldMap', 'projectChild', 'unwrapChild', 'demoteCapturedToRaw', 'cstLeavesLen', 'skipTriviaScanned', 'needsDeferredTriviaCommit', 'scanTrivia', 'advanceTrivia', 'refuseUnclassifiedRootScope', 'spanLines', 'rawEntry', 'lead', 'asciiFoldKey', 'ROUTED_FX', 'SENTS', 'matchesAt', 'recoverScan', 'orSentinel', 'captureError'];
78
+ /**
79
+ * THE THREE POOLS, SAID AS INDICES INTO THE PROGRAM.
80
+ *
81
+ * The pools themselves are `Uint32Array`s, `{ascii, hi}` class objects and
82
+ * string arrays — printable, but at 129 words per mask and 128 bytes per class
83
+ * they would dwarf the table they belong to. Every entry is already IN the
84
+ * program: a class is `cc[i]`, an arm's expected set is `fx[i]`, and a mask is a
85
+ * pure function of its class row. So the plan is three arrays of small integers,
86
+ * and `rebuildPools` turns it back into the pools with allocation only — no
87
+ * string building, and in particular no `Function` constructor.
88
+ *
89
+ * This is what lets the macro pre-compile an assembly: the FACTORY is printed as
90
+ * a real function literal, and its data arguments are rebuilt from this.
91
+ */
92
+ export type PoolPlan = {
93
+ /** Per `CLS` row: the `cc` index of each entry, `-1` for a null (ungated) arm. */
94
+ readonly classes: readonly (readonly number[])[];
95
+ /** Per `AFX` row: the `fx` index of each arm's expected set. */
96
+ readonly armExpected: readonly (readonly number[])[];
97
+ /** Per `MASK` row: the `CLS` index the mask is computed from. */
98
+ readonly masks: readonly number[];
99
+ };
100
+ /** Everything the compiled factory needs bound, beside the emitted text. */
101
+ export type EmitResult = {
102
+ readonly source: string;
103
+ /** Site offsets the emitter reached — the emitted twin of `Assembly.reached`. */
104
+ readonly reached: ReadonlySet<number>;
105
+ /** Hoisted per-choice candidate masks, in `MASK` order. */
106
+ readonly masks: readonly Uint32Array[];
107
+ /** Hoisted per-arm class gates, in `CLS` order. */
108
+ readonly classes: readonly (ResolvedClass | null)[][];
109
+ /** Hoisted per-arm expected sets, in `AFX` order. */
110
+ readonly armExpected: readonly (readonly string[])[][];
111
+ /** The same three pools as indices, for a build-time emitter. */
112
+ readonly plan: PoolPlan;
113
+ };
114
+ /**
115
+ * Rebuild the three pools a pre-compiled factory takes, from the resolved table
116
+ * and the plan the emitter printed. Allocation only.
117
+ */
118
+ export declare function rebuildPools(cc: readonly ResolvedClass[], fx: readonly (readonly string[])[], plan: PoolPlan): {
119
+ masks: Uint32Array[];
120
+ classes: (ResolvedClass | null)[][];
121
+ armExpected: (readonly string[])[][];
122
+ };
123
+ /**
124
+ * Emit the whole assembly for one resolved table and one option set.
125
+ *
126
+ * Throws `Unemittable` for any construct not lowered. It does NOT compile the
127
+ * text — `assemble.ts` does — so a refusal and a compile failure stay two
128
+ * distinguishable outcomes at the call site.
129
+ */
130
+ export declare function emitAssemblySource(t: ResolvedTable, prog: TableProgram, cfg: {
131
+ hostCst: boolean;
132
+ hostReadsChildren?: boolean;
133
+ hostCaptureTrivia?: ((type: string) => boolean) | undefined;
134
+ trackLines: boolean;
135
+ tolerant: boolean;
136
+ coverage: boolean;
137
+ probe: boolean;
138
+ }, extraIps?: readonly number[]): EmitResult;
139
+ //# sourceMappingURL=emit-assembly.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit-assembly.d.ts","sourceRoot":"","sources":["../../src/table/emit-assembly.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAO/C,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAM9E,6EAA6E;AAC7E,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,KAAK,OAAO,CAAA;AACrF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IAC7C,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,CAAC,CAAA;IACvD,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,IAAI,CAAA;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAA;CAC5B,CAAA;AACD,gFAAgF;AAChF,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,EAAE,SAAS,OAAO,EAAE,KAAK,eAAe,CAAA;AAE7E,iFAAiF;AACjF,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,YAAY,SAAS,EAAE,MAAM,EAI5B;CACF;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,YACzB,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAC5F,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EACxE,kBAAkB,EAAE,aAAa,EAAE,cAAc,EAAE,kBAAkB,EAAE,QAAQ,EAC/E,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAC3E,qBAAqB,EAAE,cAAc,EAAE,mBAAmB,EAAE,2BAA2B,EACvF,YAAY,EAAE,eAAe,EAAE,6BAA6B,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAC7F,cAAc,EAAE,WAAW,EAO3B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,CACzD,CAAA;AAgPV;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,kFAAkF;IAClF,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAA;IAChD,gEAAgE;IAChE,QAAQ,CAAC,WAAW,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAA;IACpD,iEAAiE;IACjE,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;CAClC,CAAA;AAED,4EAA4E;AAC5E,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,iFAAiF;IACjF,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IACrC,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,CAAA;IACtC,mDAAmD;IACnD,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,aAAa,GAAG,IAAI,CAAC,EAAE,EAAE,CAAA;IACrD,qDAAqD;IACrD,QAAQ,CAAC,WAAW,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EAAE,CAAA;IACtD,iEAAiE;IACjE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CACxB,CAAA;AAcD;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,EAAE,EAAE,SAAS,aAAa,EAAE,EAC5B,EAAE,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EAClC,IAAI,EAAE,QAAQ,GACb;IAAE,KAAK,EAAE,WAAW,EAAE,CAAC;IAAC,OAAO,EAAE,CAAC,aAAa,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;IAAC,WAAW,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EAAE,CAAA;CAAE,CAOrG;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,EAAE,aAAa,EAChB,IAAI,EAAE,YAAY,EAClB,GAAG,EAAE;IACH,OAAO,EAAE,OAAO,CAAA;IAChB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,iBAAiB,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,SAAS,CAAA;IAC3D,UAAU,EAAE,OAAO,CAAA;IACnB,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,OAAO,CAAA;CACf,EACD,QAAQ,GAAE,SAAS,MAAM,EAAO,GAC/B,UAAU,CAkzCZ"}
@@ -0,0 +1,113 @@
1
+ import type { FoldedProgram, TableProgram } from './program.ts';
2
+ import { type RunCfg } from './assemble.ts';
3
+ /**
4
+ * THE OPTION SETS A BUILD PRE-COMPILES, by default.
5
+ *
6
+ * `hostCst` and `trackLines` are ENCODE settings (`TableSettings`), so a program
7
+ * already fixes them — a table encoded for `hostMode: 'ast'` has no CST rows to
8
+ * select. `tolerant` is a per-CALL option (`run({ tolerant })`), so both answers
9
+ * are live for one artifact and both are emitted.
10
+ *
11
+ * `coverage` is never emitted: `emitAssemblySource` refuses a coverage assembly
12
+ * outright, so there is nothing to pre-compile and the closure engine is the
13
+ * correct answer. `probe` (`completionsAt`) is not emitted by default either —
14
+ * it is a language-service path, cold, and doubling every artifact for it is a
15
+ * cost with no reader. Both fall to the closure engine, which is OBSERVABLE on
16
+ * `Assembly.emitRefusal` rather than silent.
17
+ *
18
+ * Overgeneration is deliberate: an emitted variant nobody selects costs bytes
19
+ * and zero runtime.
20
+ */
21
+ export declare function defaultAssemblyCfgs(prog: TableProgram): RunCfg[];
22
+ export type EmitOptions = {
23
+ /** Name of the exported binding. */
24
+ readonly name?: string;
25
+ /**
26
+ * Optional experimental emitted factories — see `defaultAssemblyCfgs`.
27
+ *
28
+ * The normal compiler and macro both emit `a:[]`: that is the canonical
29
+ * compact closure artifact and it never reaches the `Function` constructor.
30
+ * Supplying factories here is a low-level serialization experiment, not a
31
+ * second normal compilation path; it is not used by the macro plugin.
32
+ */
33
+ readonly assemblies?: readonly RunCfg[];
34
+ /**
35
+ * Sources for the author callbacks, in `prog.fns` order. A build has these
36
+ * from the module it is lowering; pass `undefined` to emit a placeholder and
37
+ * measure only the machinery.
38
+ */
39
+ readonly fnSources?: readonly string[];
40
+ /** Import specifier for the shared driver. */
41
+ readonly runtime?: string;
42
+ /**
43
+ * NAME of the driver export to import from `runtime`, defaulting to the
44
+ * shipped one.
45
+ *
46
+ * `runtime` alone was not enough to say which engine a module binds, and that
47
+ * gap was load-bearing: `parseman/table` exports the ASSEMBLER as `tableRules`
48
+ * while `src/table/exec.ts` exports the reference INTERPRETER under a name
49
+ * that used to be identical. Pointing `runtime` at `exec.ts` therefore emitted
50
+ * a module that read as the shipped artifact and ran the reference engine.
51
+ * The reference export is now `execRules`, and a differential that wants it
52
+ * has to SAY so here — which is the whole point of separating the names.
53
+ */
54
+ readonly runtimeRef?: string;
55
+ };
56
+ export declare function emitTableModule(prog: TableProgram, opts?: EmitOptions): string;
57
+ export type ExpressionEmitOptions = EmitOptions & {
58
+ /**
59
+ * Which rule the expression evaluates to, or `null` for THE WHOLE RULE MAP.
60
+ *
61
+ * `null` is what a `rules()` call site needs: its initialiser evaluates to the
62
+ * `{ name: fn, … }` object, exactly what `tableRules(…)` already returns, so
63
+ * the map form is the expression WITHOUT the trailing index — not a second
64
+ * emitter. `compileRuleMap`'s replacement has the same shape and the same
65
+ * splice point, which is what makes the two lowerings interchangeable there.
66
+ */
67
+ readonly entry?: string | null;
68
+ /** Static metadata object passed to `tableRules` as its second argument. */
69
+ readonly metadataSource?: string;
70
+ };
71
+ /**
72
+ * The table as an EXPRESSION rather than a module — for an inliner that replaces
73
+ * a grammar's initialiser in place.
74
+ *
75
+ * It references `tableRules` by name instead of carrying the driver, so it is
76
+ * not self-contained. That is deliberate and it is not a cost: the reference
77
+ * resolves to `parseman/table`, a package the consumer already depends on for
78
+ * `run()`. The alternative — inlining the driver per grammar — is precisely the
79
+ * 2.10 MB that this lowering exists to replace with 0.56 MB.
80
+ *
81
+ * The caller owns the import. `emitTableModule` writes its own; an inliner
82
+ * splicing this into existing source must ensure the binding is in scope.
83
+ */
84
+ export declare function emitTableExpression(prog: TableProgram, opts?: ExpressionEmitOptions): string;
85
+ export type FoldedEmitOptions = EmitOptions & {
86
+ /**
87
+ * Exported binding per variant name. A variant with no entry is still carried
88
+ * in the table and simply not given a name of its own.
89
+ */
90
+ readonly names?: Readonly<Record<string, string>>;
91
+ };
92
+ /**
93
+ * Print a FOLDED program: one base table, plus the row edits per variant.
94
+ *
95
+ * This is G4's deliverable. The four `trackLines` x `hostMode` artifacts a
96
+ * dialect ships stop being four near-copies of one table and become one table
97
+ * and three short lists of `(offset, word)` pairs — which is what the measured
98
+ * difference between them actually is. The reducer pool, the const pool, the
99
+ * char classes, the expected sets, the dispatch tables and the rule index are
100
+ * printed ONCE, because they are byte-identical in every variant.
101
+ *
102
+ * The base's own `l`/`h` scalars are NOT printed: every variant, base included,
103
+ * carries its own on its delta, so no variant inherits the base's line-tracking
104
+ * or host mode by accident.
105
+ */
106
+ export declare function emitFoldedModule(folded: FoldedProgram, opts?: FoldedEmitOptions): string;
107
+ /**
108
+ * The part of the emitted module that is MACHINERY — the table, excluding the
109
+ * author's reducers, which every lowering must emit alike. This is the number
110
+ * that is comparable to codegen's per-rule cost.
111
+ */
112
+ export declare function emitTableOnly(prog: TableProgram): string;
113
+ //# sourceMappingURL=emit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/table/emit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAG/D,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,eAAe,CAAA;AAkGnD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,EAAE,CAMhE;AAkFD,MAAM,MAAM,WAAW,GAAG;IACxB,oCAAoC;IACpC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB;;;;;;;OAOG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACvC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACtC,8CAA8C;IAC9C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAC7B,CAAA;AAiED,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,GAAE,WAAgB,GAAG,MAAM,CAYlF;AAED,MAAM,MAAM,qBAAqB,GAAG,WAAW,GAAG;IAChD;;;;;;;;OAQG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,4EAA4E;IAC5E,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CACjC,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,GAAE,qBAA0B,GAAG,MAAM,CAWhG;AAED,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG;IAC5C;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAClD,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,GAAE,iBAAsB,GAAG,MAAM,CA0B5F;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAExD"}
@@ -0,0 +1,16 @@
1
+ import type { Combinator } from '../types.ts';
2
+ import type { TableProgram } from './program.ts';
3
+ /** Settings that select the TABLE'S CONTENTS. They never reach the driver. */
4
+ export type TableSettings = {
5
+ readonly hostMode?: 'ast' | 'cst';
6
+ readonly trackLines?: boolean;
7
+ };
8
+ /**
9
+ * Encode a rule map into ONE table for ONE settings pair.
10
+ *
11
+ * Two settings pairs give two programs and therefore two cached reference
12
+ * tables; the driver that reads them is the same function in both cases and
13
+ * never sees `settings`.
14
+ */
15
+ export declare function encodeTableBaseline(ruleMap: Record<string, Combinator<unknown>>, settings?: TableSettings): TableProgram;
16
+ //# sourceMappingURL=encode-baseline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-baseline.d.ts","sourceRoot":"","sources":["../../src/table/encode-baseline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAuB,MAAM,aAAa,CAAA;AASlE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAQhD,8EAA8E;AAC9E,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAC9B,CAAA;AAgTD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC5C,QAAQ,GAAE,aAAkB,GAC3B,YAAY,CAId"}
@@ -0,0 +1,71 @@
1
+ import type { Combinator } from '../types.ts';
2
+ import type { TableProgram } from './program.ts';
3
+ import type { GrammarCoveragePlan } from '../compiler/grammar-coverage-ids.ts';
4
+ /** Raised when a construct has no opcode yet. Prototype scope is explicit. */
5
+ export declare class UnsupportedConstruct extends Error {
6
+ readonly tag: string;
7
+ constructor(tag: string);
8
+ }
9
+ /** Settings that select the TABLE'S CONTENTS. They never reach the driver. */
10
+ export type TableSettings = {
11
+ readonly hostMode?: 'ast' | 'cst';
12
+ readonly trackLines?: boolean;
13
+ /**
14
+ * ACCEPTED AND IGNORED. RECOVERY IS ALWAYS LOWERED (owner ruling).
15
+ *
16
+ * It used to be opt-in because the sync sentinel a list resyncs to is derived
17
+ * from grammar structure and so has to be known before the table exists — a
18
+ * BUILD setting for the same reason `hostMode` is. The consequence was a
19
+ * `CompiledParser` whose `parseWithErrors()` THREW unless the caller had
20
+ * happened to pass a flag `compile()` does not require, which is a contract
21
+ * break against the source lowering, not a trade.
22
+ *
23
+ * The cost of always lowering it is the extra rows, measured on the emitted
24
+ * module: json 1,081 → 1,214 B (+12.3%), graphql 2,925 → 3,397 B (+16.1%).
25
+ * Against codegen's 15,138 B for the same json root the table is still ~12×
26
+ * smaller, so the size argument for making it optional no longer holds.
27
+ *
28
+ * LOWERING RECOVERY IS NOT RUNNING IT. Every recovery path stays gated on
29
+ * `ctx._tolerant` — the same dormancy the source lowering emits
30
+ * (`codegen.ts:3153`) and the interpreter tests (`repeat.ts:163`) — so a strict
31
+ * parse is strict, and `test/parity/table-recovery-always.test.ts` pins that.
32
+ *
33
+ * The field is kept rather than deleted so `compile` stays signature-
34
+ * compatible with `compile()`, whose `{ recovery: true }` is real. Passing it
35
+ * is harmless; passing `false` does NOT switch recovery off, and saying so here
36
+ * is the point — a setting that silently means nothing is the defect class this
37
+ * project keeps finding.
38
+ */
39
+ readonly recovery?: boolean;
40
+ /**
41
+ * THE COVERAGE PLAN, when this table is being encoded for grammar coverage.
42
+ *
43
+ * Its maps are keyed by COMBINATOR IDENTITY, which is what makes threading the
44
+ * plan through the encoder exact: at the moment a choice, dispatch, label or
45
+ * rule body is laid down, the combinator being encoded IS the key, so no code
46
+ * offset has to be matched back to a structural path after the fact. `OP_COV`
47
+ * rows go in beside those sites and the plan's definitions become `prog.cov`.
48
+ *
49
+ * A plan is a BUILD input for the same reason `hostMode` is: the rows either
50
+ * exist in the table or they do not, and no per-parse flag can conjure them.
51
+ * Which of the resulting assemblies actually counts is the separate,
52
+ * assembly-selected question `RunCfg.coverage` answers.
53
+ */
54
+ readonly coverage?: GrammarCoveragePlan;
55
+ };
56
+ export declare function encodeTable(ruleMap: Record<string, Combinator<unknown>>, settings?: TableSettings): TableProgram;
57
+ /**
58
+ * `encodeTable` PLUS the reducer sources, for a caller that must PRINT the table.
59
+ *
60
+ * The sources are not on `TableProgram` because they are not data the driver
61
+ * reads and must never travel in an emitted artifact; they are the printer's
62
+ * input, in `prog.fns` order. A build that lowers macro-evaluated combinators
63
+ * gets a real source per entry (`fnSrc` / `buildSrc` / `predSrc` / `gateSrcs`,
64
+ * set by the macro evaluator); a runtime caller gets `null`s and must therefore
65
+ * refuse to print rather than emit `() => {}` placeholders.
66
+ */
67
+ export declare function encodeTableProgram(ruleMap: Record<string, Combinator<unknown>>, settings?: TableSettings): {
68
+ prog: TableProgram;
69
+ fnSrcs: (string | null)[];
70
+ };
71
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/table/encode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,UAAU,EAAuB,MAAM,aAAa,CAAA;AAqBhF,OAAO,KAAK,EAAsC,YAAY,EAAc,MAAM,cAAc,CAAA;AAEhG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AAoD9E,8EAA8E;AAC9E,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,YAAY,GAAG,EAAE,MAAM,EAAqE;CAC7F;AAED,8EAA8E;AAC9E,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;IAC7B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAA;CACxC,CAAA;AAm3CD,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC5C,QAAQ,GAAE,aAAkB,GAC3B,YAAY,CAEd;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC5C,QAAQ,GAAE,aAAkB,GAC3B;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAA;CAAE,CA0BnD"}
@@ -0,0 +1,9 @@
1
+ import { type CompactProgram, type TableProgram, type TableRule } from './program.ts';
2
+ /**
3
+ * Turn a program into the rule map a compiled artifact exports.
4
+ *
5
+ * The entries have the SAME signature as codegen rule functions, so `run()`,
6
+ * the linker's public wrappers and every consumer are unchanged.
7
+ */
8
+ export declare function execRulesBaseline(source: TableProgram | CompactProgram): Record<string, TableRule>;
9
+ //# sourceMappingURL=exec-baseline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec-baseline.d.ts","sourceRoot":"","sources":["../../src/table/exec-baseline.ts"],"names":[],"mappings":"AAWA,OAAO,EAEL,KAAK,cAAc,EAA6C,KAAK,YAAY,EAAE,KAAK,SAAS,EAClG,MAAM,cAAc,CAAA;AA4erB;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,YAAY,GAAG,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAwBlG"}
@@ -0,0 +1,72 @@
1
+ import { type CompactProgram, type TableProgram, type TableRule } from './program.ts';
2
+ /**
3
+ * DIAGNOSTIC ROW COUNTER — off unless `PM_TABLE_COUNT=1` at process start.
4
+ *
5
+ * Read ONCE, at module load, into a module const, so this is not the per-parse
6
+ * option branch G5 forbids: with the variable false the whole thing folds away
7
+ * after tier-up. It exists because "too many rows" and "each row too slow" are
8
+ * different defects with the same symptom, and only a count separates them.
9
+ * No timing run in this repo may set it — see `bench/jess/table-rows.ts`.
10
+ */
11
+ export declare const tableCounters: {
12
+ rows: number;
13
+ byOp: Int32Array;
14
+ /** Distinct reducer/host functions actually reaching each shared call site. */
15
+ sites: Map<string, Set<unknown>>;
16
+ /**
17
+ * SPECULATION AT UNGATED CHOICES. `encode.ts:368-376` gives a choice its
18
+ * first-char dispatch only when NO arm is nullable, ALL arms are pairwise
19
+ * disjoint and ALL map to a char class; any one failure ungates every arm of
20
+ * the site, which then runs the linear loop below. Codegen has no such
21
+ * all-or-nothing rule — `emitFirstMatch` guards each arm on its OWN first set
22
+ * — so these counts are work the table does and the compiled engine does not.
23
+ *
24
+ * `ungatedEntries` is arms entered there; `ungatedFails` is those that then
25
+ * failed, which is pure waste by construction: a failing arm consumed nothing
26
+ * the winning arm will not scan again.
27
+ */
28
+ ungatedEntries: number;
29
+ ungatedFails: number;
30
+ /** Rows executed INSIDE failed ungated arms — the subtree each wasted entry drags. */
31
+ ungatedFailRows: number;
32
+ gatedEntries: number;
33
+ /** Arm entries DECLINED by the per-arm class gate — the work this change removes. */
34
+ armGateSkips: number;
35
+ };
36
+ export declare function resetTableCounters(): void;
37
+ /**
38
+ * THE REFERENCE DRIVER. Turn a program into a rule map, by INTERPRETING the
39
+ * bytecode. Nothing ships on this — `tableRules` (`table/assemble.ts`) is
40
+ * what `parseman/table` exports as `tableRules`, and what every artifact binds.
41
+ *
42
+ * IT IS CALLED `execRules` AND NOT `tableRules` FOR A MEASURED REASON. Until
43
+ * this rename the two engines exported the SAME name with the SAME signature
44
+ * across a module boundary, so `import { tableRules } from '…/table/exec.ts'`
45
+ * and `import { tableRules } from 'parseman/table'` type-checked identically
46
+ * and silently selected different engines. Three modules picked the wrong one:
47
+ * `compiler/linker.ts` (the whole `compose()`/`fuse()` path), `table/fold.ts`
48
+ * (every folded artifact's variant load), and `bench/jess/fixture.ts` — the
49
+ * CANONICAL fixture harness, whose column printed as `table` was this function
50
+ * for the entire cycle it was quoted in.
51
+ *
52
+ * A name that two engines can answer to is not a naming preference; it is a
53
+ * defect with no diagnostic. Do not re-alias this to `tableRules` anywhere.
54
+ *
55
+ * The entries have the SAME signature as the assembler's, so `run()`, the
56
+ * linker's public wrappers and every consumer are unchanged — which is exactly
57
+ * why the substitution was invisible.
58
+ */
59
+ export declare function execRules(source: TableProgram | CompactProgram,
60
+ /**
61
+ * MEASUREMENT CONTROL, not a feature. `leafSwap: false` hands the driver a
62
+ * `triviaScan` of all nulls, so `SCAN` is never installed and every skip takes
63
+ * the shared generic functions — the exact pre-swap behaviour, from the SAME
64
+ * driver code, differing only in TABLE DATA. That is what makes an in-process
65
+ * A/B of the swap possible on a machine where cross-run comparison is not, and
66
+ * it is G5-legal for the same reason `lines` is: it is read once, at rule-map
67
+ * construction, and the parse path never sees an option.
68
+ */
69
+ opts?: {
70
+ leafSwap?: boolean;
71
+ }, artifactMetadata?: Readonly<Record<symbol, unknown>>): Record<string, TableRule>;
72
+ //# sourceMappingURL=exec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../src/table/exec.ts"],"names":[],"mappings":"AAyCA,OAAO,EAEL,KAAK,cAAc,EACF,KAAK,YAAY,EAAE,KAAK,SAAS,EACnD,MAAM,cAAc,CAAA;AAyBrB;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,EAAE;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,UAAU,CAAA;IAChB,+EAA+E;IAC/E,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;IAChC;;;;;;;;;;;OAWG;IACH,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,EAAE,MAAM,CAAA;IACpB,sFAAsF;IACtF,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,qFAAqF;IACrF,YAAY,EAAE,MAAM,CAAA;CAC+H,CAAA;AAUrJ,wBAAgB,kBAAkB,IAAI,IAAI,CASzC;AA48CD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,YAAY,GAAG,cAAc;AACrC;;;;;;;;GAQG;AACH,IAAI,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,EACjC,gBAAgB,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM,GACvD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CA8B3B"}
@@ -0,0 +1,25 @@
1
+ import { type CompactFolded, type FoldedProgram, type TableRule } from './program.ts';
2
+ export { expandCompactFolded } from './program.ts';
3
+ /**
4
+ * Select ONE variant of a folded table and build its rule map.
5
+ *
6
+ * This is the load-time half of G4. A folded artifact ships one table plus, per
7
+ * variant, the words that differ from it; this materialises the named variant
8
+ * and hands the driver an ordinary `TableProgram`. The driver is not told which
9
+ * variant it got and has no way to ask — the fold is finished before the driver
10
+ * sees anything, exactly as `trackLines` is resolved before it today.
11
+ *
12
+ * Its own module rather than a second export from the driver so that a bundle
13
+ * shipping a single-variant table does not pull the fold in, and so the driver
14
+ * keeps having no import of its own.
15
+ *
16
+ * IT DRIVES `tableRules`, the shipped engine. This module predates
17
+ * `63666b6`, which made the assembler `tableRules` by editing `table/index.ts`
18
+ * ALONE; `fold.ts` imports `exec.ts` directly and so kept the interpreter. Every
19
+ * folded artifact ships `import { tableVariants }` (`emit.ts`), so that was a
20
+ * product path on the reference engine. Bound by its own name now.
21
+ */
22
+ export declare function tableVariants(source: FoldedProgram | CompactFolded, name: string): Record<string, TableRule>;
23
+ /** The variant names a folded table carries, for a caller that wants to check. */
24
+ export declare function variantNames(source: FoldedProgram | CompactFolded): string[];
25
+ //# sourceMappingURL=fold.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fold.d.ts","sourceRoot":"","sources":["../../src/table/fold.ts"],"names":[],"mappings":"AACA,OAAO,EAAsC,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAA;AAIzH,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAElD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,aAAa,GAAG,aAAa,EACrC,IAAI,EAAE,MAAM,GACX,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAG3B;AAED,kFAAkF;AAClF,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,GAAG,MAAM,EAAE,CAE5E"}