parseman 0.47.0 → 0.48.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 (124) hide show
  1. package/README.md +27 -21
  2. package/dist/analysis/diagnostics.js +2955 -357
  3. package/dist/analysis/diagnostics.js.map +3 -3
  4. package/dist/cli/index.js +2946 -348
  5. package/dist/cli/index.js.map +3 -3
  6. package/dist/combinators/expect.d.ts +1 -0
  7. package/dist/combinators/expect.d.ts.map +1 -1
  8. package/dist/combinators/expected.d.ts +8 -0
  9. package/dist/combinators/expected.d.ts.map +1 -0
  10. package/dist/combinators/first-set.d.ts +8 -0
  11. package/dist/combinators/first-set.d.ts.map +1 -1
  12. package/dist/combinators/grammar.d.ts.map +1 -1
  13. package/dist/combinators/keywords.d.ts +4 -0
  14. package/dist/combinators/keywords.d.ts.map +1 -1
  15. package/dist/combinators/literal.d.ts.map +1 -1
  16. package/dist/combinators/not.d.ts.map +1 -1
  17. package/dist/combinators/peek.d.ts.map +1 -1
  18. package/dist/combinators/regex.d.ts.map +1 -1
  19. package/dist/combinators/repeat.d.ts.map +1 -1
  20. package/dist/combinators/sequence.d.ts.map +1 -1
  21. package/dist/combinators/trivia-skip.d.ts +19 -1
  22. package/dist/combinators/trivia-skip.d.ts.map +1 -1
  23. package/dist/compiler/direct-projection.d.ts +12 -0
  24. package/dist/compiler/direct-projection.d.ts.map +1 -0
  25. package/dist/compiler/token-alphabet.d.ts +845 -5
  26. package/dist/compiler/token-alphabet.d.ts.map +1 -1
  27. package/dist/compiler/token-capability.d.ts +3 -0
  28. package/dist/compiler/token-capability.d.ts.map +1 -0
  29. package/dist/compiler/token-capability.js +3192 -0
  30. package/dist/compiler/token-capability.js.map +6 -0
  31. package/dist/cst/trivia-charscan.d.ts +3 -0
  32. package/dist/cst/trivia-charscan.d.ts.map +1 -1
  33. package/dist/cst/trivia-css-scanner.d.ts +5 -0
  34. package/dist/cst/trivia-css-scanner.d.ts.map +1 -0
  35. package/dist/cst/trivia-kinds.d.ts.map +1 -1
  36. package/dist/index.js +2959 -348
  37. package/dist/index.js.map +3 -3
  38. package/dist/language-service/index.js +7 -1
  39. package/dist/language-service/index.js.map +1 -1
  40. package/dist/plugin/index.js +2969 -358
  41. package/dist/plugin/index.js.map +3 -3
  42. package/dist/spec/index.js +366 -49
  43. package/dist/spec/index.js.map +2 -2
  44. package/dist/table/assemble.d.ts.map +1 -1
  45. package/dist/table/child-slots.d.ts.map +1 -1
  46. package/dist/table/compile-rule-map.d.ts +3 -1
  47. package/dist/table/compile-rule-map.d.ts.map +1 -1
  48. package/dist/table/emit-assembly.d.ts +13 -14
  49. package/dist/table/emit-assembly.d.ts.map +1 -1
  50. package/dist/table/emit.d.ts.map +1 -1
  51. package/dist/table/encode.d.ts.map +1 -1
  52. package/dist/table/exec-baseline.d.ts.map +1 -1
  53. package/dist/table/exec.d.ts.map +1 -1
  54. package/dist/table/index.js +4839 -2232
  55. package/dist/table/index.js.map +3 -3
  56. package/dist/table/lex-body.d.ts +9 -0
  57. package/dist/table/lex-body.d.ts.map +1 -0
  58. package/dist/table/lex-program.d.ts +25 -0
  59. package/dist/table/lex-program.d.ts.map +1 -0
  60. package/dist/table/ops.d.ts +47 -4
  61. package/dist/table/ops.d.ts.map +1 -1
  62. package/dist/table/program.d.ts +53 -2
  63. package/dist/table/program.d.ts.map +1 -1
  64. package/dist/table/scalar-terminal.d.ts +13 -0
  65. package/dist/table/scalar-terminal.d.ts.map +1 -0
  66. package/dist/table/site-labels.d.ts.map +1 -1
  67. package/dist/types.d.ts +2 -0
  68. package/dist/types.d.ts.map +1 -1
  69. package/dist/version.d.ts +1 -1
  70. package/package.json +12 -11
  71. package/src/combinators/expect.ts +1 -0
  72. package/src/combinators/expected.ts +17 -0
  73. package/src/combinators/first-set.ts +82 -3
  74. package/src/combinators/grammar.ts +8 -3
  75. package/src/combinators/keywords.ts +22 -6
  76. package/src/combinators/literal.ts +2 -1
  77. package/src/combinators/not.ts +5 -1
  78. package/src/combinators/peek.ts +5 -1
  79. package/src/combinators/regex.ts +5 -3
  80. package/src/combinators/repeat.ts +4 -10
  81. package/src/combinators/sequence.ts +35 -16
  82. package/src/combinators/trivia-skip.ts +75 -11
  83. package/src/compiler/direct-projection.ts +43 -0
  84. package/src/compiler/token-alphabet.ts +4316 -12
  85. package/src/compiler/token-capability.ts +6 -0
  86. package/src/cst/trivia-charscan.ts +34 -0
  87. package/src/cst/trivia-css-scanner.ts +142 -0
  88. package/src/cst/trivia-kinds.ts +3 -1
  89. package/src/plugin/index.ts +4 -4
  90. package/src/table/assemble.ts +1224 -222
  91. package/src/table/child-slots.ts +4 -3
  92. package/src/table/compile-rule-map.ts +21 -3
  93. package/src/table/emit-assembly.ts +363 -109
  94. package/src/table/emit.ts +26 -1
  95. package/src/table/encode.ts +246 -54
  96. package/src/table/exec-baseline.ts +3 -7
  97. package/src/table/exec.ts +140 -18
  98. package/src/table/lex-body.ts +30 -0
  99. package/src/table/lex-program.ts +422 -0
  100. package/src/table/ops.ts +50 -4
  101. package/src/table/program.ts +67 -2
  102. package/src/table/scalar-terminal.ts +51 -0
  103. package/src/table/site-labels.ts +13 -3
  104. package/src/table/stamp.ts +3 -3
  105. package/src/types.ts +1 -1
  106. package/src/version.ts +1 -1
  107. package/dist/analysis/diagnostics.cjs +0 -13736
  108. package/dist/analysis/diagnostics.cjs.map +0 -6
  109. package/dist/cli/index.cjs +0 -14837
  110. package/dist/cli/index.cjs.map +0 -6
  111. package/dist/index.cjs +0 -16303
  112. package/dist/index.cjs.map +0 -6
  113. package/dist/language-service/index.cjs +0 -1302
  114. package/dist/language-service/index.cjs.map +0 -6
  115. package/dist/oracle/index.cjs +0 -254
  116. package/dist/oracle/index.cjs.map +0 -6
  117. package/dist/plugin/index.cjs +0 -16009
  118. package/dist/plugin/index.cjs.map +0 -6
  119. package/dist/run/index.cjs +0 -577
  120. package/dist/run/index.cjs.map +0 -6
  121. package/dist/spec/index.cjs +0 -6188
  122. package/dist/spec/index.cjs.map +0 -6
  123. package/dist/table/index.cjs +0 -11375
  124. package/dist/table/index.cjs.map +0 -6
@@ -0,0 +1,6 @@
1
+ /** Private phase-A capability/normalizer leaf used only by grammar compilers. */
2
+ export {
3
+ assertLexicalCapabilityClosure,
4
+ collectLexicalCapabilities,
5
+ winnerWrapsReference,
6
+ } from './token-alphabet.ts'
@@ -26,6 +26,7 @@
26
26
  */
27
27
  import type { Combinator } from '../types.ts'
28
28
  import { parseClassRanges } from '../regex/classes.ts'
29
+ import { commonCssTriviaVisitor, type CssTriviaVisitor } from './trivia-css-scanner.ts'
29
30
  import type { LabeledTriviaSpec } from './trivia-kinds.ts'
30
31
 
31
32
  export type TriviaArmMatcher = (input: string, pos: number) => number
@@ -220,6 +221,39 @@ function classifyParser(p: Combinator<unknown>): TriviaArmMatcher | null {
220
221
  return classifyArm(d.source)
221
222
  }
222
223
 
224
+ function plainRegexSource(p: Combinator<unknown>): string | null {
225
+ const d = p._def
226
+ return d.tag === 'regex' && d.flags === '' ? d.source : null
227
+ }
228
+
229
+ let visitSpec0: LabeledTriviaSpec | undefined
230
+ let visitSpec1: LabeledTriviaSpec | undefined
231
+ let visitSpec2: LabeledTriviaSpec | undefined
232
+ let visitSpec3: LabeledTriviaSpec | undefined
233
+ let visitValue0: CssTriviaVisitor | null | undefined
234
+ let visitValue1: CssTriviaVisitor | null | undefined
235
+ let visitValue2: CssTriviaVisitor | null | undefined
236
+ let visitValue3: CssTriviaVisitor | null | undefined
237
+
238
+ /** A direct classified scanner for the four canonical CSS/Less trivia tuples. */
239
+ export function commonLabeledTriviaVisitor(spec: LabeledTriviaSpec): CssTriviaVisitor | null {
240
+ if (spec === visitSpec0) return visitValue0!
241
+ if (spec === visitSpec1) return visitValue1!
242
+ if (spec === visitSpec2) return visitValue2!
243
+ if (spec === visitSpec3) return visitValue3!
244
+ const sources = spec.minRepeats <= 1 ? spec.arms.map(arm => plainRegexSource(arm.parser)) : []
245
+ const visitor = commonCssTriviaVisitor(sources)
246
+ visitSpec3 = visitSpec2
247
+ visitValue3 = visitValue2
248
+ visitSpec2 = visitSpec1
249
+ visitValue2 = visitValue1
250
+ visitSpec1 = visitSpec0
251
+ visitValue1 = visitValue0
252
+ visitSpec0 = spec
253
+ visitValue0 = visitor
254
+ return visitor
255
+ }
256
+
223
257
  let armSpec0: LabeledTriviaSpec | undefined
224
258
  let armSpec1: LabeledTriviaSpec | undefined
225
259
  let armSpec2: LabeledTriviaSpec | undefined
@@ -0,0 +1,142 @@
1
+ export type CssTriviaScanner = (input: string, cur: number) => number
2
+ export type CssTriviaVisitor = (
3
+ input: string,
4
+ cur: number,
5
+ visit: (start: number, end: number, kindIndex: number) => void,
6
+ ) => number
7
+
8
+ const CSS_WS_SOURCE = '[ \\t\\n\\r\\f]+'
9
+ const CSS_LINE_COMMENT_SOURCE = '\\/\\/[^\\n\\r]*'
10
+ const CSS_BLOCK_COMMENT_SOURCE = '\\/\\*(?:[^*]|\\*(?!\\/))*\\*\\/'
11
+
12
+ function scanWhitespace(input: string, cur: number): number {
13
+ let pos = cur
14
+ while (pos < input.length) {
15
+ const c = input.charCodeAt(pos)
16
+ if (c !== 32 && c !== 9 && c !== 10 && c !== 13 && c !== 12) break
17
+ pos++
18
+ }
19
+ return pos
20
+ }
21
+
22
+ function scanLineComment(input: string, cur: number): number {
23
+ if (input.charCodeAt(cur) !== 47 || input.charCodeAt(cur + 1) !== 47) return cur
24
+ let pos = cur + 2
25
+ while (pos < input.length) {
26
+ const c = input.charCodeAt(pos)
27
+ if (c === 10 || c === 13) break
28
+ pos++
29
+ }
30
+ return pos
31
+ }
32
+
33
+ function scanBlockComment(input: string, cur: number): number {
34
+ if (input.charCodeAt(cur) !== 47 || input.charCodeAt(cur + 1) !== 42) return cur
35
+ const close = input.indexOf('*/', cur + 2)
36
+ return close < 0 ? cur : close + 2
37
+ }
38
+
39
+ function scanWsLineBlockTrivia(input: string, cur: number): number {
40
+ let pos = cur
41
+ for (;;) {
42
+ const ws = scanWhitespace(input, pos)
43
+ if (ws !== pos) { pos = ws; continue }
44
+ const line = scanLineComment(input, pos)
45
+ if (line !== pos) { pos = line; continue }
46
+ const block = scanBlockComment(input, pos)
47
+ if (block !== pos) { pos = block; continue }
48
+ return pos
49
+ }
50
+ }
51
+
52
+ function scanWsBlockTrivia(input: string, cur: number): number {
53
+ let pos = cur
54
+ for (;;) {
55
+ const ws = scanWhitespace(input, pos)
56
+ if (ws !== pos) { pos = ws; continue }
57
+ const block = scanBlockComment(input, pos)
58
+ if (block !== pos) { pos = block; continue }
59
+ return pos
60
+ }
61
+ }
62
+
63
+ function scanLineBlockTrivia(input: string, cur: number): number {
64
+ let pos = cur
65
+ for (;;) {
66
+ const line = scanLineComment(input, pos)
67
+ if (line !== pos) { pos = line; continue }
68
+ const block = scanBlockComment(input, pos)
69
+ if (block !== pos) { pos = block; continue }
70
+ return pos
71
+ }
72
+ }
73
+
74
+ function scanBlockTrivia(input: string, cur: number): number {
75
+ let pos = cur
76
+ for (;;) {
77
+ const block = scanBlockComment(input, pos)
78
+ if (block === pos) return pos
79
+ pos = block
80
+ }
81
+ }
82
+
83
+ function visitWsLineBlock(input: string, cur: number, visit: (start: number, end: number, kindIndex: number) => void): number {
84
+ let pos = cur
85
+ for (;;) {
86
+ let end = scanWhitespace(input, pos)
87
+ if (end !== pos) { visit(pos, end, 0); pos = end; continue }
88
+ end = scanLineComment(input, pos)
89
+ if (end !== pos) { visit(pos, end, 1); pos = end; continue }
90
+ end = scanBlockComment(input, pos)
91
+ if (end !== pos) { visit(pos, end, 2); pos = end; continue }
92
+ return pos
93
+ }
94
+ }
95
+
96
+ function visitWsBlock(input: string, cur: number, visit: (start: number, end: number, kindIndex: number) => void): number {
97
+ let pos = cur
98
+ for (;;) {
99
+ let end = scanWhitespace(input, pos)
100
+ if (end !== pos) { visit(pos, end, 0); pos = end; continue }
101
+ end = scanBlockComment(input, pos)
102
+ if (end !== pos) { visit(pos, end, 1); pos = end; continue }
103
+ return pos
104
+ }
105
+ }
106
+
107
+ function visitLineBlock(input: string, cur: number, visit: (start: number, end: number, kindIndex: number) => void): number {
108
+ let pos = cur
109
+ for (;;) {
110
+ let end = scanLineComment(input, pos)
111
+ if (end !== pos) { visit(pos, end, 0); pos = end; continue }
112
+ end = scanBlockComment(input, pos)
113
+ if (end !== pos) { visit(pos, end, 1); pos = end; continue }
114
+ return pos
115
+ }
116
+ }
117
+
118
+ function visitBlock(input: string, cur: number, visit: (start: number, end: number, kindIndex: number) => void): number {
119
+ let pos = cur
120
+ for (;;) {
121
+ const end = scanBlockComment(input, pos)
122
+ if (end === pos) return pos
123
+ visit(pos, end, 0)
124
+ pos = end
125
+ }
126
+ }
127
+
128
+ export function commonCssTriviaScanner(sources: readonly (string | null)[]): CssTriviaScanner | null {
129
+ if (sources.length === 3 && sources[0] === CSS_WS_SOURCE && sources[1] === CSS_LINE_COMMENT_SOURCE && sources[2] === CSS_BLOCK_COMMENT_SOURCE) return scanWsLineBlockTrivia
130
+ if (sources.length === 2 && sources[0] === CSS_WS_SOURCE && sources[1] === CSS_BLOCK_COMMENT_SOURCE) return scanWsBlockTrivia
131
+ if (sources.length === 2 && sources[0] === CSS_LINE_COMMENT_SOURCE && sources[1] === CSS_BLOCK_COMMENT_SOURCE) return scanLineBlockTrivia
132
+ if (sources.length === 1 && sources[0] === CSS_BLOCK_COMMENT_SOURCE) return scanBlockTrivia
133
+ return null
134
+ }
135
+
136
+ export function commonCssTriviaVisitor(sources: readonly (string | null)[]): CssTriviaVisitor | null {
137
+ if (sources.length === 3 && sources[0] === CSS_WS_SOURCE && sources[1] === CSS_LINE_COMMENT_SOURCE && sources[2] === CSS_BLOCK_COMMENT_SOURCE) return visitWsLineBlock
138
+ if (sources.length === 2 && sources[0] === CSS_WS_SOURCE && sources[1] === CSS_BLOCK_COMMENT_SOURCE) return visitWsBlock
139
+ if (sources.length === 2 && sources[0] === CSS_LINE_COMMENT_SOURCE && sources[1] === CSS_BLOCK_COMMENT_SOURCE) return visitLineBlock
140
+ if (sources.length === 1 && sources[0] === CSS_BLOCK_COMMENT_SOURCE) return visitBlock
141
+ return null
142
+ }
@@ -2,7 +2,7 @@ import type { Combinator, ParseContext } from '../types.ts'
2
2
  import { pushCstTriviaEntry, pushTriviaLogEntry } from './capture-buffer.ts'
3
3
  import { startsFirstSet } from '../combinators/first-set.ts'
4
4
  import { createDetachedParseContext } from '../parse-context.ts'
5
- import { charArmsFor, charTriviaEnd, charTriviaKindMask, charTriviaVisit } from './trivia-charscan.ts'
5
+ import { charArmsFor, charTriviaEnd, charTriviaKindMask, charTriviaVisit, commonLabeledTriviaVisitor } from './trivia-charscan.ts'
6
6
 
7
7
  export type TriviaChunk = { start: number; end: number; kindIndex: number }
8
8
 
@@ -199,6 +199,8 @@ export function visitLabeledTrivia(
199
199
  visit: (start: number, end: number, kindIndex: number) => void,
200
200
  ): number | undefined {
201
201
  if (spec.minRepeats > 1) return undefined
202
+ const common = commonLabeledTriviaVisitor(spec)
203
+ if (common !== null) return common(input, cur, visit)
202
204
  const chars = charArmsFor(spec)
203
205
  if (chars !== null) return charTriviaVisit(input, cur, chars, visit)
204
206
 
@@ -1625,10 +1625,10 @@ function transformMacroImpl(
1625
1625
  if (compiled !== null) {
1626
1626
  usedTableRuntime = true
1627
1627
  return {
1628
- replacement: compiled.replacementWithMetadata(staticTableMetadataSource({
1629
- reflection: compiled.reflection,
1630
- leaf: true,
1631
- })),
1628
+ replacement: compiled.replacementWithMetadata(
1629
+ staticTableMetadataSource({ reflection: compiled.reflection, leaf: true }),
1630
+ { precompileDefault: true },
1631
+ ),
1632
1632
  ...(importedFactories.length ? { importedFactories } : {}),
1633
1633
  }
1634
1634
  }