parseman 0.48.0 → 0.49.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 (45) hide show
  1. package/dist/analysis/diagnostics.js +158 -51
  2. package/dist/analysis/diagnostics.js.map +2 -2
  3. package/dist/cli/index.js +160 -52
  4. package/dist/cli/index.js.map +2 -2
  5. package/dist/combinators/choice.d.ts.map +1 -1
  6. package/dist/compiler/ir-serialize.d.ts.map +1 -1
  7. package/dist/compiler/linker.d.ts.map +1 -1
  8. package/dist/index.js +169 -55
  9. package/dist/index.js.map +2 -2
  10. package/dist/language-service/index.js.map +1 -1
  11. package/dist/plugin/direct-builder-static.d.ts +20 -0
  12. package/dist/plugin/direct-builder-static.d.ts.map +1 -1
  13. package/dist/plugin/evaluator.d.ts +13 -0
  14. package/dist/plugin/evaluator.d.ts.map +1 -1
  15. package/dist/plugin/index.d.ts.map +1 -1
  16. package/dist/plugin/index.js +365 -71
  17. package/dist/plugin/index.js.map +2 -2
  18. package/dist/spec/index.js +12 -2
  19. package/dist/spec/index.js.map +2 -2
  20. package/dist/table/assemble.d.ts.map +1 -1
  21. package/dist/table/emit-assembly.d.ts.map +1 -1
  22. package/dist/table/encode.d.ts.map +1 -1
  23. package/dist/table/exec.d.ts.map +1 -1
  24. package/dist/table/index.js +158 -51
  25. package/dist/table/index.js.map +1 -1
  26. package/dist/table/lex-program.d.ts.map +1 -1
  27. package/dist/table/ops.d.ts +4 -4
  28. package/dist/types.d.ts +6 -1
  29. package/dist/types.d.ts.map +1 -1
  30. package/dist/version.d.ts +1 -1
  31. package/package.json +1 -1
  32. package/src/combinators/choice.ts +10 -1
  33. package/src/compiler/ir-serialize.ts +15 -3
  34. package/src/compiler/linker.ts +14 -1
  35. package/src/plugin/direct-builder-static.ts +116 -12
  36. package/src/plugin/evaluator.ts +50 -2
  37. package/src/plugin/index.ts +140 -1
  38. package/src/table/assemble.ts +82 -59
  39. package/src/table/emit-assembly.ts +10 -5
  40. package/src/table/encode.ts +6 -10
  41. package/src/table/exec.ts +13 -18
  42. package/src/table/lex-program.ts +15 -6
  43. package/src/table/ops.ts +4 -4
  44. package/src/types.ts +1 -1
  45. package/src/version.ts +1 -1
@@ -150,7 +150,8 @@ function sequence5(
150
150
  }
151
151
 
152
152
  type ChoiceTail = (
153
- input: string, pos: number, ctx: ParseContext, lead: number, acc: string[] | undefined,
153
+ input: string, pos: number, ctx: ParseContext, lead: number,
154
+ acc: string[] | undefined, best: number,
154
155
  ) => number
155
156
 
156
157
  function appendExpected(acc: string[] | undefined, values: readonly string[] | undefined): string[] | undefined {
@@ -181,24 +182,32 @@ function choiceNode(
181
182
  }
182
183
  for (let i = arms.length - 1; i >= 0; i--) {
183
184
  const arm = arms[i]!, cls = classes[i], staticExpected = armExpected[i]!, next = tail
184
- tail = (input, pos, ctx, lead, acc) => {
185
+ tail = (input, pos, ctx, lead, acc, best) => {
185
186
  if (cls !== undefined && !classHas(cls, lead)) {
186
- return next(input, pos, ctx, lead, appendExpected(acc, staticExpected))
187
+ return next(
188
+ input, pos, ctx, lead,
189
+ best === pos ? appendExpected(acc, staticExpected) : acc,
190
+ best,
191
+ )
187
192
  }
188
193
  ctx._fc = false
189
194
  const end = arm.run(input, pos, ctx)
190
195
  if (end >= 0) return end
191
- const nextAcc = appendExpected(acc, ctx._fx)
196
+ const at = ctx._fe ?? pos
197
+ if (at > best) { best = at; acc = undefined }
198
+ const nextAcc = at === best ? appendExpected(acc, ctx._fx) : acc
192
199
  if (committed(ctx)) {
193
200
  if (nextAcc !== undefined) ctx._fx = nextAcc
194
201
  return -1
195
202
  }
196
- return next(input, pos, ctx, lead, nextAcc)
203
+ return next(input, pos, ctx, lead, nextAcc, best)
197
204
  }
198
205
  }
199
206
  return {
200
207
  match: matchTail,
201
- run: (input, pos, ctx) => tail(input, pos, ctx, pos < input.length ? input.codePointAt(pos)! : -1, undefined),
208
+ run: (input, pos, ctx) => tail(
209
+ input, pos, ctx, pos < input.length ? input.codePointAt(pos)! : -1, undefined, pos,
210
+ ),
202
211
  }
203
212
  }
204
213
 
package/src/table/ops.ts CHANGED
@@ -30,10 +30,10 @@ export const OP_SEQV = 4
30
30
  * `CHOICE d n fx c1 … cn` — `d` indexes a dispatch table (or −1 for ordered
31
31
  * try); `fx` indexes the choice's OWN expected set.
32
32
  *
33
- * Both shipped engines report the UNION of the arms' expectations when a choice
34
- * fails. The driver reported whatever the last attempted arm left behind — or,
35
- * on a dispatch miss with no arm claiming the lead character, NOTHING, so a user
36
- * got an error naming nothing at all.
33
+ * Ordered failure keeps the expected sets at the deepest arm offset, merging
34
+ * exact ties in source order. Exclusive dispatch propagates its sole selected
35
+ * arm. A pure dispatch miss uses `fx`, the static union of every arm opener, so
36
+ * the result never names nothing merely because no arm claimed the lead.
37
37
  */
38
38
  export const OP_CHOICE = 5
39
39
  /**
package/src/types.ts CHANGED
@@ -89,7 +89,7 @@ export type ParserDef =
89
89
  // it requires, so it carries `parser`'s first-set and a leading `peek()` gates
90
90
  // its choice arm (see `isPositiveLookahead` / `sequenceFirstSet`).
91
91
  | { tag: 'peek'; parser: Combinator<unknown> }
92
- | { tag: 'node'; type?: string; parser: Combinator<unknown>; build?: ((children: ReadonlyArray<unknown>, fields: FieldMap | undefined, span: { start: number; end: number }, rawChildren: ReadonlyArray<unknown>, triviaLog: readonly number[], state: unknown) => unknown) | undefined; buildSrc?: string; /** The IDENTIFIER the type argument was written as at the `node()` call site, when it was a plain identifier rather than a literal — ANALYSIS ONLY, never emitted. Lets the inline-`mk` matcher recognise `node(t, …, (…) => mk(t, …))` from a factory, where the two `t`s are provably one binding. */ typeSrc?: string; /** Resolved source of a NAMED `buildSrc` — ANALYSIS ONLY, never emitted. See `buildAnalysisSrc`. */ buildSigSrc?: string; /** Declared positional arity of `build`: author-declared via `node(..., { buildArity })`, or resolved from the reducer's declaration. Wins over source inspection. */ buildArity?: number; /** Why arity could not be resolved, for the diagnostic. */ buildArityUnresolved?: string; buildStaticError?: readonly string[]; unwrap?: boolean; collapse?: boolean; project?: number; captureTrivia?: boolean; trailingTrivia?: boolean; tags?: readonly string[] }
92
+ | { tag: 'node'; type?: string; parser: Combinator<unknown>; build?: ((children: ReadonlyArray<unknown>, fields: FieldMap | undefined, span: { start: number; end: number }, rawChildren: ReadonlyArray<unknown>, triviaLog: readonly number[], state: unknown) => unknown) | undefined; buildSrc?: string; /** The IDENTIFIER the type argument was written as at the `node()` call site, when it was a plain identifier rather than a literal — ANALYSIS ONLY, never emitted. Lets the inline-`mk` matcher recognise `node(t, …, (…) => mk(t, …))` from a factory, where the two `t`s are provably one binding. */ typeSrc?: string; /** Resolved source of a NAMED `buildSrc` — ANALYSIS ONLY, never emitted. See `buildAnalysisSrc`. */ buildSigSrc?: string; /** Declared positional arity of `build`: author-declared via `node(..., { buildArity })`, or resolved from the reducer's declaration. Wins over source inspection. */ buildArity?: number; /** Why arity could not be resolved, for the diagnostic. */ buildArityUnresolved?: string; buildStaticError?: readonly string[]; /** Import provenance for a direct builder's free names — each `{ local, source, imported }` lets a downstream compose() re-emit `import { imported as local } from source` so the inlined builder source can bind. Carried through the IR round-trip. */ buildImports?: ReadonlyArray<{ local: string; source: string; imported: string }>; unwrap?: boolean; collapse?: boolean; project?: number; captureTrivia?: boolean; trailingTrivia?: boolean; tags?: readonly string[] }
93
93
  // `predSrc`/`extraSrc` (set by the macro evaluator): SOURCE TEXT of the guard
94
94
  // predicate / the withCtx `extra` value, so codegen inlines them into `_mf`
95
95
  // rather than pushing a `null` source. Absent under runtime compile() (the real
package/src/version.ts CHANGED
@@ -13,4 +13,4 @@
13
13
  * Kept in sync with `package.json` by `test/unit/version-sync.test.ts`, which fails
14
14
  * the build if this constant drifts from the published version.
15
15
  */
16
- export const PARSEMAN_VERSION = '0.48.0'
16
+ export const PARSEMAN_VERSION = '0.49.0'