parseman 0.55.3 → 0.56.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 (89) hide show
  1. package/dist/analysis/choice-cost.d.ts.map +1 -1
  2. package/dist/analysis/commitment.d.ts.map +1 -1
  3. package/dist/analysis/diagnostics.js +3360 -3098
  4. package/dist/analysis/diagnostics.js.map +3 -3
  5. package/dist/analysis/duplication.d.ts.map +1 -1
  6. package/dist/analysis/gating.d.ts.map +1 -1
  7. package/dist/cli/index.js +1820 -1558
  8. package/dist/cli/index.js.map +3 -3
  9. package/dist/combinators/attempt.d.ts.map +1 -1
  10. package/dist/combinators/choice.d.ts.map +1 -1
  11. package/dist/combinators/dispatch.d.ts.map +1 -1
  12. package/dist/combinators/expect.d.ts.map +1 -1
  13. package/dist/combinators/first-set.d.ts.map +1 -1
  14. package/dist/combinators/lines.d.ts +79 -0
  15. package/dist/combinators/lines.d.ts.map +1 -0
  16. package/dist/combinators/trivia-skip.d.ts +1 -0
  17. package/dist/combinators/trivia-skip.d.ts.map +1 -1
  18. package/dist/compiler/fields.d.ts.map +1 -1
  19. package/dist/compiler/grammar-coverage-ids.d.ts.map +1 -1
  20. package/dist/compiler/ir-serialize.d.ts.map +1 -1
  21. package/dist/compiler/token-alphabet.d.ts.map +1 -1
  22. package/dist/compiler/token-capability.js +25 -0
  23. package/dist/compiler/token-capability.js.map +1 -1
  24. package/dist/coverage.d.ts.map +1 -1
  25. package/dist/cst/reflection.d.ts.map +1 -1
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +1912 -1628
  29. package/dist/index.js.map +3 -3
  30. package/dist/language-service/index.js +2 -0
  31. package/dist/language-service/index.js.map +1 -1
  32. package/dist/parse-context.d.ts.map +1 -1
  33. package/dist/plugin/evaluator.d.ts.map +1 -1
  34. package/dist/plugin/index.js +1325 -1048
  35. package/dist/plugin/index.js.map +3 -3
  36. package/dist/plugin/ir-eval.d.ts +0 -4
  37. package/dist/plugin/ir-eval.d.ts.map +1 -1
  38. package/dist/run/index.js +2 -0
  39. package/dist/run/index.js.map +1 -1
  40. package/dist/spec/index.js +15 -0
  41. package/dist/spec/index.js.map +1 -1
  42. package/dist/spec/model.d.ts.map +1 -1
  43. package/dist/table/assemble.d.ts +0 -65
  44. package/dist/table/assemble.d.ts.map +1 -1
  45. package/dist/table/emit.d.ts.map +1 -1
  46. package/dist/table/encode.d.ts.map +1 -1
  47. package/dist/table/exec.d.ts.map +1 -1
  48. package/dist/table/index.js +3449 -3195
  49. package/dist/table/index.js.map +3 -3
  50. package/dist/table/line-scan.d.ts +9 -0
  51. package/dist/table/line-scan.d.ts.map +1 -0
  52. package/dist/table/program.d.ts +11 -2
  53. package/dist/table/program.d.ts.map +1 -1
  54. package/dist/types.d.ts +26 -1
  55. package/dist/types.d.ts.map +1 -1
  56. package/dist/version.d.ts +1 -1
  57. package/package.json +1 -1
  58. package/src/analysis/choice-cost.ts +1 -0
  59. package/src/analysis/commitment.ts +13 -0
  60. package/src/analysis/duplication.ts +3 -0
  61. package/src/analysis/gating.ts +5 -0
  62. package/src/analysis/rebuild.ts +2 -2
  63. package/src/combinators/attempt.ts +2 -0
  64. package/src/combinators/choice.ts +3 -0
  65. package/src/combinators/dispatch.ts +3 -0
  66. package/src/combinators/expect.ts +5 -0
  67. package/src/combinators/first-set.ts +9 -1
  68. package/src/combinators/lines.ts +244 -0
  69. package/src/combinators/trivia-skip.ts +4 -2
  70. package/src/compiler/fields.ts +3 -0
  71. package/src/compiler/grammar-coverage-ids.ts +1 -0
  72. package/src/compiler/ir-serialize.ts +10 -0
  73. package/src/compiler/token-alphabet.ts +3 -1
  74. package/src/coverage.ts +6 -0
  75. package/src/cst/reflection.ts +3 -0
  76. package/src/index.ts +2 -0
  77. package/src/parse-context.ts +2 -0
  78. package/src/plugin/evaluator.ts +4 -0
  79. package/src/plugin/ir-eval.ts +3 -0
  80. package/src/spec/model.ts +15 -0
  81. package/src/table/assemble.ts +10 -13
  82. package/src/table/compile.ts +5 -2
  83. package/src/table/emit.ts +7 -6
  84. package/src/table/encode.ts +18 -6
  85. package/src/table/exec.ts +7 -1
  86. package/src/table/line-scan.ts +19 -0
  87. package/src/table/program.ts +17 -2
  88. package/src/types.ts +19 -1
  89. package/src/version.ts +1 -1
@@ -0,0 +1,19 @@
1
+ import type { Combinator } from '../types.ts'
2
+ import type { ScanSpec, SubtreeRef } from './program.ts'
3
+ import { columns, lines } from '../combinators/lines.ts'
4
+
5
+ /**
6
+ * Rebuild a `lines()` (kind 2) or `columns()` (kind 3) scan spec as the
7
+ * combinator it was constructed as, its subtrees bound to the table's pieces.
8
+ * Both drivers run the result through its own `parse`, as they do `scanTo`.
9
+ */
10
+ export function rebuildLineScan(s: ScanSpec, subtree: (r: SubtreeRef) => Combinator<unknown>): Combinator<unknown> | undefined {
11
+ if (s.kind === 2) {
12
+ return lines(subtree(s.prefix!), subtree(s.body!), {
13
+ ...(s.first === undefined ? {} : { first: subtree(s.first) }),
14
+ ...(s.lazy === undefined ? {} : { lazy: subtree(s.lazy) }),
15
+ }) as Combinator<unknown>
16
+ }
17
+ if (s.kind === 3) return columns(s.n!) as Combinator<unknown>
18
+ return undefined
19
+ }
@@ -241,13 +241,13 @@ export type SubtreeRef = readonly [ip: number, cls: number]
241
241
  /**
242
242
  * A scanning construct as its CONSTRUCTOR ARGUMENTS.
243
243
  *
244
- * `kind` 0 is `scanTo`, 1 is `balanced`. `flags` bit 0 = `raw`, bit 1 = `orEOF`
244
+ * `kind` 0 is `scanTo`, 1 is `balanced`, 2 is `lines`, 3 is `columns`. `flags` bit 0 = `raw`, bit 1 = `orEOF`
245
245
  * (scanTo), bit 2 = `strict` (balanced). `sent` is the sentinel's literal text
246
246
  * when it is a `literal()`, so the rebuilt scan reports the same expected set as
247
247
  * the interpreter, and `null` otherwise (which reports `"sentinel"`).
248
248
  */
249
249
  export type ScanSpec = {
250
- readonly kind: 0 | 1
250
+ readonly kind: 0 | 1 | 2 | 3
251
251
  readonly flags: number
252
252
  readonly skip: readonly SubtreeRef[]
253
253
  readonly sentinel?: SubtreeRef
@@ -256,6 +256,21 @@ export type ScanSpec = {
256
256
  readonly sent?: string | null
257
257
  readonly open?: string
258
258
  readonly close?: string
259
+ /** `lines()` (kind 2): the continuation prefix, the body, and the optional first-line prefix and lazy check. */
260
+ readonly prefix?: SubtreeRef
261
+ readonly body?: SubtreeRef
262
+ readonly first?: SubtreeRef
263
+ readonly lazy?: SubtreeRef
264
+ /** `columns()` (kind 3): the column count. */
265
+ readonly n?: number
266
+ }
267
+
268
+ /** Every subtree a scan spec references, which the table links as roots. */
269
+ export function scanRefs(s: ScanSpec): SubtreeRef[] {
270
+ const refs: SubtreeRef[] = []
271
+ for (const r of [s.sentinel, s.recoverAt, s.stopAt, s.prefix, s.body, s.first, s.lazy]) if (r !== undefined) refs.push(r)
272
+ refs.push(...s.skip)
273
+ return refs
259
274
  }
260
275
 
261
276
  /** A trivia combinator as data. `arms` empty means a plain `trivia(regex)`. */
package/src/types.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { LineView } from './combinators/lines.ts'
1
2
  import type { LabeledTriviaSpec } from './cst/trivia-kinds.ts'
2
3
 
3
4
  export type Span = {
@@ -113,6 +114,11 @@ export type ParserDef =
113
114
  // pre-ambient raw byte-walk.
114
115
  | { tag: 'scanTo'; sentinel: Combinator<unknown>; skip: Combinator<unknown>[]; raw: boolean; orEOF: boolean; recoverAt?: Combinator<unknown>; stopAt?: Combinator<unknown> }
115
116
  | { tag: 'keywords'; words: readonly string[]; caseInsensitive: boolean; boundary: string | undefined }
117
+ // `lines()`: `body` parses a run of lines with `prefix` (`first` on the first
118
+ // line) removed from each; `lazy` admits a line the prefix does not match.
119
+ | { tag: 'lines'; prefix: Combinator<unknown>; body: Combinator<unknown>; first?: Combinator<unknown>; lazy?: Combinator<unknown> }
120
+ // `columns(n)`: n columns of indentation, a tab reaching the next stop of four.
121
+ | { tag: 'columns'; n: number }
116
122
  | { tag: 'unknown' }
117
123
 
118
124
  export type Combinator<T> = {
@@ -280,6 +286,14 @@ export type ParseContext = {
280
286
  trackLines: boolean
281
287
  /** Grammar-author-provided state, scoped with withCtx() and read in guard(). */
282
288
  state?: unknown
289
+ /**
290
+ * Inside a `lines()` body, the run's lines: where each line's content sits in
291
+ * the body's input and in the run's own input, and the column it starts at.
292
+ * Undefined outside any run.
293
+ */
294
+ lineView?: LineView | undefined
295
+ /** Framework-internal: where `columns()` last stopped inside a tab, for `lines()`. */
296
+ _columnsSplit?: { at: number; split: number } | undefined
283
297
  /**
284
298
  * Mode host (RULE_ABI_PLAN §7): when set, a linkable/fused grammar's `node()`
285
299
  * rules build via `build(type, children, fields, span, rawChildren, triviaLog, state)`
@@ -554,7 +568,11 @@ export type GatedArm<T = unknown> = {
554
568
  * deleted.
555
569
  */
556
570
  export type CompiledParser<T> = {
557
- parse(input: string, pos?: number): ParseResult<T>
571
+ /**
572
+ * Parse from `pos`. With `ctx`, the parse runs in that context, as a combinator's
573
+ * own `parse(input, pos, ctx)` does; without it, in a fresh one.
574
+ */
575
+ parse(input: string, pos?: number, ctx?: ParseContext): ParseResult<T>
558
576
  /** Like parse(), but with a caller-supplied ParseContext (e.g. `_triviaLog` for CST grammars). */
559
577
  parseWithContext(input: string, ctx: ParseContext, pos?: number): ParseResult<T>
560
578
  /**
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.55.3'
16
+ export const PARSEMAN_VERSION = '0.56.0'