parseman 0.60.5 → 0.61.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 (59) hide show
  1. package/dist/analysis/diagnostics.js +77 -40
  2. package/dist/analysis/diagnostics.js.map +3 -3
  3. package/dist/cli/index.js +77 -40
  4. package/dist/cli/index.js.map +3 -3
  5. package/dist/combinators/choice.d.ts.map +1 -1
  6. package/dist/combinators/expect.d.ts.map +1 -1
  7. package/dist/combinators/link-scope.d.ts +7 -0
  8. package/dist/combinators/link-scope.d.ts.map +1 -0
  9. package/dist/combinators/node.d.ts.map +1 -1
  10. package/dist/combinators/parser.d.ts.map +1 -1
  11. package/dist/combinators/trivia-boundary.d.ts +5 -3
  12. package/dist/combinators/trivia-boundary.d.ts.map +1 -1
  13. package/dist/compiler/token-capability.js +7 -0
  14. package/dist/compiler/token-capability.js.map +1 -1
  15. package/dist/compiler/value-usage.d.ts.map +1 -1
  16. package/dist/functional/run.d.ts.map +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +121 -70
  20. package/dist/index.js.map +3 -3
  21. package/dist/language-service/index.js +1 -1
  22. package/dist/language-service/index.js.map +1 -1
  23. package/dist/plugin/index.js +284 -233
  24. package/dist/plugin/index.js.map +3 -3
  25. package/dist/run/index.js +1 -1
  26. package/dist/run/index.js.map +1 -1
  27. package/dist/spec/index.js.map +1 -1
  28. package/dist/table/assemble.d.ts.map +1 -1
  29. package/dist/table/emit-assembly.d.ts.map +1 -1
  30. package/dist/table/emit.d.ts.map +1 -1
  31. package/dist/table/encode.d.ts.map +1 -1
  32. package/dist/table/exec.d.ts.map +1 -1
  33. package/dist/table/index.js +41 -10
  34. package/dist/table/index.js.map +3 -3
  35. package/dist/table/ops.d.ts +6 -0
  36. package/dist/table/ops.d.ts.map +1 -1
  37. package/dist/table/program.d.ts +3 -1
  38. package/dist/table/program.d.ts.map +1 -1
  39. package/dist/version.d.ts +1 -1
  40. package/package.json +1 -1
  41. package/src/combinators/choice.ts +3 -1
  42. package/src/combinators/expect.ts +1 -0
  43. package/src/combinators/grammar.ts +1 -1
  44. package/src/combinators/link-scope.ts +19 -0
  45. package/src/combinators/node.ts +11 -2
  46. package/src/combinators/parser.ts +37 -31
  47. package/src/combinators/trivia-boundary.ts +11 -3
  48. package/src/compiler/value-usage.ts +16 -29
  49. package/src/functional/run.ts +3 -1
  50. package/src/index.ts +1 -1
  51. package/src/table/assemble.ts +11 -1
  52. package/src/table/emit-assembly.ts +10 -1
  53. package/src/table/emit.ts +5 -1
  54. package/src/table/encode.ts +16 -9
  55. package/src/table/exec.ts +11 -9
  56. package/src/table/ops.ts +6 -0
  57. package/src/table/program.ts +8 -2
  58. package/src/table/site-labels.ts +3 -3
  59. package/src/version.ts +1 -1
@@ -6,6 +6,7 @@ import { leadRanges } from '../lead-ranges.ts'
6
6
  import { choice } from '../combinators/choice.ts'
7
7
  import { many } from '../combinators/repeat.ts'
8
8
  import type { EmittedFactory, PoolPlan } from './emit-assembly.ts'
9
+ import { PARSEMAN_VERSION } from '../version.ts'
9
10
  import { buildLexBodyRecognizer, type LexBodyRecognizer } from './lex-body.ts'
10
11
  import { buildLexProgramRunner, type LexProgramRunner } from './lex-program.ts'
11
12
 
@@ -328,7 +329,9 @@ export type CompactProgram = {
328
329
  readonly c: readonly number[]
329
330
  readonly k: readonly unknown[]
330
331
  readonly x: readonly string[]
331
- readonly e: readonly (readonly string[])[]
332
+ /** Expected sets, as indices into `es`. */
333
+ readonly e: readonly (readonly number[])[]
334
+ readonly es: readonly string[]
332
335
  readonly d: readonly (readonly number[])[]
333
336
  readonly r: Readonly<Record<string, number>>
334
337
  readonly f: readonly unknown[]
@@ -351,8 +354,11 @@ export type CompactProgram = {
351
354
 
352
355
  export function expandCompact(p: TableProgram | CompactProgram): TableProgram {
353
356
  if ('code' in p) return p
357
+ // A table from before the token pool has no `es`. Refuse it here, at load, instead of
358
+ // failing on the first expected set read below.
359
+ if (p.es === undefined) throw new Error(`parseman: this parser was printed by an earlier parseman; reprint it with parseman ${PARSEMAN_VERSION}`)
354
360
  return ownTableProgram({
355
- code: p.c, k: p.k, cc: p.x, fx: p.e, disp: p.d, rules: p.r, fns: p.f,
361
+ code: p.c, k: p.k, cc: p.x, fx: p.e.map(set => set.map(i => p.es[i]!)), disp: p.d, rules: p.r, fns: p.f,
356
362
  lines: p.l ?? 0, dsp: p.p ?? [],
357
363
  ...(p.lx === undefined ? {} : { lex: p.lx }),
358
364
  ...(p.lp === undefined ? {} : { lexPrograms: p.lp }),
@@ -62,7 +62,7 @@
62
62
  import {
63
63
  OP_ATTEMPT, OP_CHOICE, OP_DISPATCH, OP_EXPECT, OP_FIELD, OP_GATE, OP_LABEL, OP_LEAF, OP_LIT, OP_SOURCE_LEAF,
64
64
  OP_NODE, OP_NODE_TRACK, OP_NOT, OP_OPT, OP_PEEK, OP_REP, OP_REPV, OP_ROUTED, OP_RULE,
65
- OP_SCAN, OP_SCOPE, OP_SCOPE_CAP, OP_SCOPE_PLAIN, OP_SEQ, OP_SEQV, OP_SEQX, OP_TOKEN, OP_XFORM,
65
+ OP_SCAN, OP_SCOPE, OP_SCOPE_CAP, OP_SCOPE_PLAIN, SCOPE_INHERIT, OP_SEQ, OP_SEQV, OP_SEQX, OP_TOKEN, OP_XFORM,
66
66
  } from './ops.ts'
67
67
  import { childSlots } from './child-slots.ts'
68
68
  import { leadRanges } from '../lead-ranges.ts'
@@ -206,7 +206,7 @@ function transfer(code: Int32Array, ip: number, at: SiteLabel, hostCst: boolean)
206
206
  const op = code[ip]
207
207
  if (op === OP_SCOPE || op === OP_SCOPE_CAP || op === OP_SCOPE_PLAIN) {
208
208
  const ki = code[ip + 1]!
209
- const tri = ki < 0 ? TRI_NONE : ki
209
+ const tri = ki === SCOPE_INHERIT ? at.tri : ki < 0 ? TRI_NONE : ki
210
210
  // `OP_SCOPE_CAP` is an OR with the inherited context, never a switch-off
211
211
  // (`encode.ts:1153-1158`), so it can only ever raise `cap` to `CAP_ON`.
212
212
  const cap = op === OP_SCOPE_CAP ? CAP_ON : at.cap
@@ -358,7 +358,7 @@ export function scanHandoffNeeded(code: Int32Array, ip: number, labels: SiteLabe
358
358
  const op = code[at]
359
359
  // A scan runs interpreted combinators that reach pieces through `prog.scans`.
360
360
  if (op === OP_SCAN) return true
361
- if (op === OP_TOKEN || op === OP_SCOPE_CAP) continue
361
+ if (op === OP_TOKEN || (op === OP_SCOPE_CAP && code[at + 1] !== SCOPE_INHERIT)) continue
362
362
  if ((op === OP_SCOPE_PLAIN || op === OP_SCOPE) && !(code[at + 1]! >= 0 && l.tri === code[at + 1]!
363
363
  && (op === OP_SCOPE_PLAIN || code[at + 3]! === 0))) continue
364
364
  kids.length = 0
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.60.5'
16
+ export const PARSEMAN_VERSION = '0.61.0'