parseman 0.47.1 → 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.
- package/README.md +27 -21
- package/dist/analysis/diagnostics.js +2863 -353
- package/dist/analysis/diagnostics.js.map +3 -3
- package/dist/cli/index.js +2854 -344
- package/dist/cli/index.js.map +3 -3
- package/dist/combinators/expect.d.ts +1 -0
- package/dist/combinators/expect.d.ts.map +1 -1
- package/dist/combinators/expected.d.ts +8 -0
- package/dist/combinators/expected.d.ts.map +1 -0
- package/dist/combinators/first-set.d.ts +8 -0
- package/dist/combinators/first-set.d.ts.map +1 -1
- package/dist/combinators/grammar.d.ts.map +1 -1
- package/dist/combinators/keywords.d.ts +4 -0
- package/dist/combinators/keywords.d.ts.map +1 -1
- package/dist/combinators/literal.d.ts.map +1 -1
- package/dist/combinators/not.d.ts.map +1 -1
- package/dist/combinators/peek.d.ts.map +1 -1
- package/dist/combinators/regex.d.ts.map +1 -1
- package/dist/combinators/repeat.d.ts.map +1 -1
- package/dist/combinators/sequence.d.ts.map +1 -1
- package/dist/combinators/trivia-skip.d.ts +16 -3
- package/dist/combinators/trivia-skip.d.ts.map +1 -1
- package/dist/compiler/direct-projection.d.ts +12 -0
- package/dist/compiler/direct-projection.d.ts.map +1 -0
- package/dist/compiler/token-alphabet.d.ts +845 -5
- package/dist/compiler/token-alphabet.d.ts.map +1 -1
- package/dist/compiler/token-capability.d.ts +3 -0
- package/dist/compiler/token-capability.d.ts.map +1 -0
- package/dist/compiler/token-capability.js +3192 -0
- package/dist/compiler/token-capability.js.map +6 -0
- package/dist/cst/trivia-charscan.d.ts +3 -0
- package/dist/cst/trivia-charscan.d.ts.map +1 -1
- package/dist/cst/trivia-css-scanner.d.ts +5 -0
- package/dist/cst/trivia-css-scanner.d.ts.map +1 -0
- package/dist/cst/trivia-kinds.d.ts.map +1 -1
- package/dist/index.js +2862 -339
- package/dist/index.js.map +3 -3
- package/dist/language-service/index.js +5 -1
- package/dist/language-service/index.js.map +1 -1
- package/dist/plugin/index.js +2870 -347
- package/dist/plugin/index.js.map +3 -3
- package/dist/spec/index.js +315 -46
- package/dist/spec/index.js.map +2 -2
- package/dist/table/assemble.d.ts.map +1 -1
- package/dist/table/child-slots.d.ts.map +1 -1
- package/dist/table/compile-rule-map.d.ts +3 -1
- package/dist/table/compile-rule-map.d.ts.map +1 -1
- package/dist/table/emit-assembly.d.ts +12 -13
- package/dist/table/emit-assembly.d.ts.map +1 -1
- package/dist/table/emit.d.ts.map +1 -1
- package/dist/table/encode.d.ts.map +1 -1
- package/dist/table/exec-baseline.d.ts.map +1 -1
- package/dist/table/exec.d.ts.map +1 -1
- package/dist/table/index.js +2819 -300
- package/dist/table/index.js.map +3 -3
- package/dist/table/lex-body.d.ts +9 -0
- package/dist/table/lex-body.d.ts.map +1 -0
- package/dist/table/lex-program.d.ts +25 -0
- package/dist/table/lex-program.d.ts.map +1 -0
- package/dist/table/ops.d.ts +43 -7
- package/dist/table/ops.d.ts.map +1 -1
- package/dist/table/program.d.ts +50 -2
- package/dist/table/program.d.ts.map +1 -1
- package/dist/table/scalar-terminal.d.ts +13 -0
- package/dist/table/scalar-terminal.d.ts.map +1 -0
- package/dist/table/site-labels.d.ts.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +11 -11
- package/src/combinators/expect.ts +1 -0
- package/src/combinators/expected.ts +17 -0
- package/src/combinators/first-set.ts +58 -5
- package/src/combinators/grammar.ts +8 -3
- package/src/combinators/keywords.ts +22 -6
- package/src/combinators/literal.ts +2 -1
- package/src/combinators/not.ts +5 -1
- package/src/combinators/peek.ts +5 -1
- package/src/combinators/regex.ts +5 -3
- package/src/combinators/repeat.ts +4 -10
- package/src/combinators/sequence.ts +17 -14
- package/src/combinators/trivia-skip.ts +46 -13
- package/src/compiler/direct-projection.ts +43 -0
- package/src/compiler/token-alphabet.ts +4316 -12
- package/src/compiler/token-capability.ts +6 -0
- package/src/cst/trivia-charscan.ts +34 -0
- package/src/cst/trivia-css-scanner.ts +142 -0
- package/src/cst/trivia-kinds.ts +3 -1
- package/src/plugin/index.ts +4 -4
- package/src/table/assemble.ts +1211 -221
- package/src/table/child-slots.ts +2 -1
- package/src/table/compile-rule-map.ts +21 -3
- package/src/table/emit-assembly.ts +328 -85
- package/src/table/emit.ts +16 -2
- package/src/table/encode.ts +242 -50
- package/src/table/exec-baseline.ts +3 -7
- package/src/table/exec.ts +121 -7
- package/src/table/lex-body.ts +30 -0
- package/src/table/lex-program.ts +422 -0
- package/src/table/ops.ts +45 -7
- package/src/table/program.ts +46 -2
- package/src/table/scalar-terminal.ts +51 -0
- package/src/table/site-labels.ts +11 -1
- package/src/table/stamp.ts +1 -1
- package/src/types.ts +1 -1
- package/src/version.ts +1 -1
- package/dist/analysis/diagnostics.cjs +0 -13824
- package/dist/analysis/diagnostics.cjs.map +0 -6
- package/dist/cli/index.cjs +0 -14925
- package/dist/cli/index.cjs.map +0 -6
- package/dist/index.cjs +0 -16391
- package/dist/index.cjs.map +0 -6
- package/dist/language-service/index.cjs +0 -1304
- package/dist/language-service/index.cjs.map +0 -6
- package/dist/oracle/index.cjs +0 -254
- package/dist/oracle/index.cjs.map +0 -6
- package/dist/plugin/index.cjs +0 -16097
- package/dist/plugin/index.cjs.map +0 -6
- package/dist/run/index.cjs +0 -577
- package/dist/run/index.cjs.map +0 -6
- package/dist/spec/index.cjs +0 -6236
- package/dist/spec/index.cjs.map +0 -6
- package/dist/table/index.cjs +0 -11463
- package/dist/table/index.cjs.map +0 -6
|
@@ -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
|
+
}
|
package/src/cst/trivia-kinds.ts
CHANGED
|
@@ -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
|
|
package/src/plugin/index.ts
CHANGED
|
@@ -1625,10 +1625,10 @@ function transformMacroImpl(
|
|
|
1625
1625
|
if (compiled !== null) {
|
|
1626
1626
|
usedTableRuntime = true
|
|
1627
1627
|
return {
|
|
1628
|
-
replacement: compiled.replacementWithMetadata(
|
|
1629
|
-
reflection: compiled.reflection,
|
|
1630
|
-
|
|
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
|
}
|