parseman 0.51.2 → 0.53.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 (98) hide show
  1. package/dist/analysis/commitment.d.ts.map +1 -1
  2. package/dist/analysis/diagnostics.js +411 -28
  3. package/dist/analysis/diagnostics.js.map +3 -3
  4. package/dist/cli/index.js +6162 -6372
  5. package/dist/cli/index.js.map +3 -3
  6. package/dist/combinators/attempt.d.ts +11 -1
  7. package/dist/combinators/attempt.d.ts.map +1 -1
  8. package/dist/combinators/map.d.ts.map +1 -1
  9. package/dist/combinators/node.d.ts +6 -2
  10. package/dist/combinators/node.d.ts.map +1 -1
  11. package/dist/combinators/parser.d.ts +34 -0
  12. package/dist/combinators/parser.d.ts.map +1 -1
  13. package/dist/combinators/ref.d.ts +0 -13
  14. package/dist/combinators/ref.d.ts.map +1 -1
  15. package/dist/compiler/borrowed-rules.d.ts +30 -0
  16. package/dist/compiler/borrowed-rules.d.ts.map +1 -0
  17. package/dist/compiler/compile-linkable-table.d.ts +1 -1
  18. package/dist/compiler/grammar-coverage-ids.d.ts.map +1 -1
  19. package/dist/compiler/ir-serialize.d.ts +10 -4
  20. package/dist/compiler/ir-serialize.d.ts.map +1 -1
  21. package/dist/compiler/linker.d.ts +48 -91
  22. package/dist/compiler/linker.d.ts.map +1 -1
  23. package/dist/compiler/token-capability.js +4 -0
  24. package/dist/compiler/token-capability.js.map +1 -1
  25. package/dist/coverage.d.ts +1 -1
  26. package/dist/coverage.d.ts.map +1 -1
  27. package/dist/cst/reflection.d.ts.map +1 -1
  28. package/dist/cst/trivia-kinds.d.ts.map +1 -1
  29. package/dist/index.d.ts +1 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +470 -725
  32. package/dist/index.js.map +3 -3
  33. package/dist/language-service/index.js.map +1 -1
  34. package/dist/plugin/evaluator.d.ts +38 -2
  35. package/dist/plugin/evaluator.d.ts.map +1 -1
  36. package/dist/plugin/index.d.ts.map +1 -1
  37. package/dist/plugin/index.js +1127 -544
  38. package/dist/plugin/index.js.map +3 -3
  39. package/dist/plugin/ir-eval.d.ts +21 -0
  40. package/dist/plugin/ir-eval.d.ts.map +1 -0
  41. package/dist/plugin/reducer-resolver.d.ts +6 -0
  42. package/dist/plugin/reducer-resolver.d.ts.map +1 -1
  43. package/dist/spec/index.js +555 -6086
  44. package/dist/spec/index.js.map +3 -3
  45. package/dist/spec/railroad-lib.d.ts +7 -2
  46. package/dist/spec/railroad-lib.d.ts.map +1 -1
  47. package/dist/spec/railroad.d.ts.map +1 -1
  48. package/dist/table/assemble.d.ts.map +1 -1
  49. package/dist/table/compile-rule-map.d.ts +11 -4
  50. package/dist/table/compile-rule-map.d.ts.map +1 -1
  51. package/dist/table/compile.d.ts +16 -0
  52. package/dist/table/compile.d.ts.map +1 -1
  53. package/dist/table/emit-assembly.d.ts.map +1 -1
  54. package/dist/table/encode-baseline.d.ts.map +1 -1
  55. package/dist/table/exec.d.ts.map +1 -1
  56. package/dist/table/index.js +272 -102
  57. package/dist/table/index.js.map +2 -2
  58. package/dist/table/ops.d.ts +7 -5
  59. package/dist/table/ops.d.ts.map +1 -1
  60. package/dist/table/site-labels.d.ts.map +1 -1
  61. package/dist/types.d.ts +8 -1
  62. package/dist/types.d.ts.map +1 -1
  63. package/dist/version.d.ts +1 -1
  64. package/package.json +1 -1
  65. package/src/analysis/commitment.ts +3 -1
  66. package/src/analysis/rebuild.ts +1 -1
  67. package/src/combinators/attempt.ts +26 -3
  68. package/src/combinators/first-set.ts +5 -1
  69. package/src/combinators/map.ts +5 -1
  70. package/src/combinators/node.ts +12 -3
  71. package/src/combinators/parser.ts +133 -67
  72. package/src/combinators/ref.ts +10 -1
  73. package/src/compiler/borrowed-rules.ts +88 -0
  74. package/src/compiler/compile-linkable-table.ts +1 -1
  75. package/src/compiler/grammar-coverage-ids.ts +35 -6
  76. package/src/compiler/ir-serialize.ts +13 -119
  77. package/src/compiler/linker.ts +190 -666
  78. package/src/coverage.ts +7 -5
  79. package/src/cst/reflection.ts +6 -1
  80. package/src/cst/trivia-kinds.ts +6 -0
  81. package/src/index.ts +1 -0
  82. package/src/plugin/evaluator.ts +114 -14
  83. package/src/plugin/index.ts +588 -110
  84. package/src/plugin/ir-eval.ts +165 -0
  85. package/src/plugin/reducer-resolver.ts +20 -3
  86. package/src/spec/railroad-lib.ts +18 -8
  87. package/src/spec/railroad.ts +3 -4
  88. package/src/table/assemble.ts +22 -8
  89. package/src/table/compile-rule-map.ts +18 -8
  90. package/src/table/compile.ts +61 -0
  91. package/src/table/emit-assembly.ts +8 -3
  92. package/src/table/encode-baseline.ts +5 -1
  93. package/src/table/encode.ts +13 -13
  94. package/src/table/exec.ts +6 -2
  95. package/src/table/ops.ts +7 -5
  96. package/src/table/site-labels.ts +3 -1
  97. package/src/types.ts +8 -1
  98. package/src/version.ts +1 -1
package/src/table/exec.ts CHANGED
@@ -1535,7 +1535,8 @@ function makeDriver(
1535
1535
  // `attempt()` verbatim: mark, run, and on failure restore every capture
1536
1536
  // sink and re-anchor the report at the transaction's entry. A COMMITTED
1537
1537
  // failure is still rolled back and then propagated untouched — the
1538
- // interpreter returns `result` itself on that branch.
1538
+ // interpreter returns `result` itself on that branch — unless the row
1539
+ // contains commitment (`k`), where it is reported like any other failure.
1539
1540
  const need = rollbackNeeded(ctx)
1540
1541
  const mRaw = need ? cstRawLen(ctx) : 0
1541
1542
  const mTl = need ? cstTlLen(ctx) : 0
@@ -1547,7 +1548,10 @@ function makeDriver(
1547
1548
  const v = exec(code[ip + 1]!, input, pos, ctx)
1548
1549
  if (v !== FAIL) return v
1549
1550
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot)
1550
- if (ctx._fc === true) return FAIL
1551
+ if (ctx._fc === true) {
1552
+ if (code[ip + 2] !== 1) return FAIL
1553
+ ctx._fc = false
1554
+ }
1551
1555
  ctx._fe = pos
1552
1556
  return FAIL
1553
1557
  }
package/src/table/ops.ts CHANGED
@@ -378,7 +378,9 @@ export const OP_ARMGATE = 36
378
378
  */
379
379
  export const OP_LIVE = 37
380
380
  /**
381
- * `ATTEMPT c` — `attempt()`, the transactional ordered-choice arm.
381
+ * `ATTEMPT c k` — `attempt()`, the transactional ordered-choice arm. `k` is 1
382
+ * for `attempt(p, { contain: true })`: a committed inner failure is reported
383
+ * uncommitted — `_fc` cleared and `_fe` re-anchored, like any other failure.
382
384
  *
383
385
  * WAS A TRANSPARENT WRAPPER (`case 'attempt': return this.node(d.parser).ip`),
384
386
  * which is correct for exactly one placement — an arm of an `OP_CHOICE`, whose
@@ -389,10 +391,10 @@ export const OP_LIVE = 37
389
391
  * re-anchored at the transaction's entry. Both are `attempt()`'s whole contract
390
392
  * (`combinators/attempt.ts`), not a choice-arm detail.
391
393
  *
392
- * One child operand and no expected-set operand: on a non-committed inner
393
- * failure the row keeps the inner's `_fx` VERBATIM and only re-anchors `_fe` to
394
- * `pos`, exactly as `attempt.ts` returns `{ expected: result.expected, span:
395
- * { start: pos, end: pos } }`. A committed failure propagates untouched — the
394
+ * No expected-set operand: on a non-committed inner failure the row keeps the
395
+ * inner's `_fx` VERBATIM and only re-anchors `_fe` to `pos`, exactly as
396
+ * `attempt.ts` returns `{ expected: result.expected, span: { start: pos, end:
397
+ * pos } }`. A committed failure propagates untouched when `k` is 0 — the
396
398
  * rollback still happens, the re-anchor does not.
397
399
  *
398
400
  * The interpreter's first-set fail-fast guard is NOT lowered. It is an
@@ -159,8 +159,10 @@ function transfer(code: Int32Array, ip: number, at: SiteLabel, hostCst: boolean)
159
159
  }
160
160
  if (op === OP_NODE || op === OP_NODE_TRACK) {
161
161
  const flags = code[ip + 3]!
162
+ // The same selection `emit-assembly.ts` makes: the trailing-trivia bit (128)
163
+ // keeps the children-only shape.
162
164
  const directChildren = !hostCst && op === OP_NODE && code[ip + 1]! >= 0 && code[ip + 4]! < 0
163
- && (flags === 2 || flags === 18 || flags === 34)
165
+ && ((flags & ~128) === 2 || flags === 18 || flags === 34)
164
166
  if (directChildren) {
165
167
  // The confirmed low-arity builder projection installs split child/leaf
166
168
  // arrays instead of a CstCaptureBuf. Descendants still capture, but they
package/src/types.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { LabeledTriviaSpec } from './cst/trivia-kinds.ts'
2
+
1
3
  export type Span = {
2
4
  start: number
3
5
  end: number
@@ -56,7 +58,7 @@ export type ParserDef =
56
58
  // closures live in `gates`.
57
59
  | { tag: 'choice'; parsers: Combinator<unknown>[]; gates: (((state: unknown) => boolean) | null)[]; gateSrcs?: (string | null)[]; disjoint: boolean; strategy: ChoiceStrategy; autoNot: (AutoNotCheck[] | null)[] }
58
60
  | { tag: 'dispatch'; selector: Combinator<string>; cases: readonly DispatchCase[]; matchers?: readonly DispatchMatcherCase[] | undefined; otherwise?: Combinator<unknown> | undefined; otherwiseUsesRouted?: boolean | undefined }
59
- | { tag: 'attempt'; parser: Combinator<unknown> }
61
+ | { tag: 'attempt'; parser: Combinator<unknown>; /** `attempt(p, { contain: true })`: a committed failure inside is reported uncommitted. */ contain?: true }
60
62
  // The TAG carries NULLABILITY (what every downstream switch keys on): `many` is
61
63
  // the nullable min-0 repeat, `oneOrMore` the non-nullable min>=1 one. `min`/`max`
62
64
  // carry the actual ITEM bounds (`many(x, { min: 3, max: 8 })` is a `oneOrMore`
@@ -433,6 +435,11 @@ export type ParserMeta = {
433
435
  isTrivia: boolean
434
436
  /** User-defined labels for labeled trivia arms (`label(name, parser)`). */
435
437
  triviaKindLabels?: readonly string[]
438
+ /**
439
+ * Set only by `trivia()`: the labeled-arm spec of this trivia (`null` when it is
440
+ * not labeled), built once so a labeled scan never re-derives it.
441
+ */
442
+ labeledTriviaSpec?: LabeledTriviaSpec | null
436
443
  /** Preclassified lightweight trivia scanner for the ordinary skip path. */
437
444
  triviaScanner?: ((input: string, cur: number) => number) | null
438
445
  /** Set only by `classifiedTrivia()`: each root-visible category is a separate
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.51.2'
16
+ export const PARSEMAN_VERSION = '0.53.0'