parseman 0.48.0 → 0.49.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/dist/analysis/diagnostics.js +158 -51
- package/dist/analysis/diagnostics.js.map +2 -2
- package/dist/cli/index.js +160 -52
- package/dist/cli/index.js.map +2 -2
- package/dist/combinators/choice.d.ts.map +1 -1
- package/dist/compiler/ir-serialize.d.ts.map +1 -1
- package/dist/compiler/linker.d.ts.map +1 -1
- package/dist/index.js +169 -55
- package/dist/index.js.map +2 -2
- package/dist/language-service/index.js.map +1 -1
- package/dist/plugin/direct-builder-static.d.ts +20 -0
- package/dist/plugin/direct-builder-static.d.ts.map +1 -1
- package/dist/plugin/evaluator.d.ts +13 -0
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +365 -71
- package/dist/plugin/index.js.map +2 -2
- package/dist/spec/index.js +12 -2
- package/dist/spec/index.js.map +2 -2
- package/dist/table/assemble.d.ts.map +1 -1
- package/dist/table/emit-assembly.d.ts.map +1 -1
- package/dist/table/encode.d.ts.map +1 -1
- package/dist/table/exec.d.ts.map +1 -1
- package/dist/table/index.js +158 -51
- package/dist/table/index.js.map +1 -1
- package/dist/table/lex-program.d.ts.map +1 -1
- package/dist/table/ops.d.ts +4 -4
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/combinators/choice.ts +10 -1
- package/src/compiler/ir-serialize.ts +15 -3
- package/src/compiler/linker.ts +14 -1
- package/src/plugin/direct-builder-static.ts +116 -12
- package/src/plugin/evaluator.ts +50 -2
- package/src/plugin/index.ts +140 -1
- package/src/table/assemble.ts +82 -59
- package/src/table/emit-assembly.ts +10 -5
- package/src/table/encode.ts +6 -10
- package/src/table/exec.ts +13 -18
- package/src/table/lex-program.ts +15 -6
- package/src/table/ops.ts +4 -4
- package/src/types.ts +1 -1
- package/src/version.ts +1 -1
package/src/table/lex-program.ts
CHANGED
|
@@ -150,7 +150,8 @@ function sequence5(
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
type ChoiceTail = (
|
|
153
|
-
input: string, pos: number, ctx: ParseContext, lead: number,
|
|
153
|
+
input: string, pos: number, ctx: ParseContext, lead: number,
|
|
154
|
+
acc: string[] | undefined, best: number,
|
|
154
155
|
) => number
|
|
155
156
|
|
|
156
157
|
function appendExpected(acc: string[] | undefined, values: readonly string[] | undefined): string[] | undefined {
|
|
@@ -181,24 +182,32 @@ function choiceNode(
|
|
|
181
182
|
}
|
|
182
183
|
for (let i = arms.length - 1; i >= 0; i--) {
|
|
183
184
|
const arm = arms[i]!, cls = classes[i], staticExpected = armExpected[i]!, next = tail
|
|
184
|
-
tail = (input, pos, ctx, lead, acc) => {
|
|
185
|
+
tail = (input, pos, ctx, lead, acc, best) => {
|
|
185
186
|
if (cls !== undefined && !classHas(cls, lead)) {
|
|
186
|
-
return next(
|
|
187
|
+
return next(
|
|
188
|
+
input, pos, ctx, lead,
|
|
189
|
+
best === pos ? appendExpected(acc, staticExpected) : acc,
|
|
190
|
+
best,
|
|
191
|
+
)
|
|
187
192
|
}
|
|
188
193
|
ctx._fc = false
|
|
189
194
|
const end = arm.run(input, pos, ctx)
|
|
190
195
|
if (end >= 0) return end
|
|
191
|
-
const
|
|
196
|
+
const at = ctx._fe ?? pos
|
|
197
|
+
if (at > best) { best = at; acc = undefined }
|
|
198
|
+
const nextAcc = at === best ? appendExpected(acc, ctx._fx) : acc
|
|
192
199
|
if (committed(ctx)) {
|
|
193
200
|
if (nextAcc !== undefined) ctx._fx = nextAcc
|
|
194
201
|
return -1
|
|
195
202
|
}
|
|
196
|
-
return next(input, pos, ctx, lead, nextAcc)
|
|
203
|
+
return next(input, pos, ctx, lead, nextAcc, best)
|
|
197
204
|
}
|
|
198
205
|
}
|
|
199
206
|
return {
|
|
200
207
|
match: matchTail,
|
|
201
|
-
run: (input, pos, ctx) => tail(
|
|
208
|
+
run: (input, pos, ctx) => tail(
|
|
209
|
+
input, pos, ctx, pos < input.length ? input.codePointAt(pos)! : -1, undefined, pos,
|
|
210
|
+
),
|
|
202
211
|
}
|
|
203
212
|
}
|
|
204
213
|
|
package/src/table/ops.ts
CHANGED
|
@@ -30,10 +30,10 @@ export const OP_SEQV = 4
|
|
|
30
30
|
* `CHOICE d n fx c1 … cn` — `d` indexes a dispatch table (or −1 for ordered
|
|
31
31
|
* try); `fx` indexes the choice's OWN expected set.
|
|
32
32
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
33
|
+
* Ordered failure keeps the expected sets at the deepest arm offset, merging
|
|
34
|
+
* exact ties in source order. Exclusive dispatch propagates its sole selected
|
|
35
|
+
* arm. A pure dispatch miss uses `fx`, the static union of every arm opener, so
|
|
36
|
+
* the result never names nothing merely because no arm claimed the lead.
|
|
37
37
|
*/
|
|
38
38
|
export const OP_CHOICE = 5
|
|
39
39
|
/**
|
package/src/types.ts
CHANGED
|
@@ -89,7 +89,7 @@ export type ParserDef =
|
|
|
89
89
|
// it requires, so it carries `parser`'s first-set and a leading `peek()` gates
|
|
90
90
|
// its choice arm (see `isPositiveLookahead` / `sequenceFirstSet`).
|
|
91
91
|
| { tag: 'peek'; parser: Combinator<unknown> }
|
|
92
|
-
| { tag: 'node'; type?: string; parser: Combinator<unknown>; build?: ((children: ReadonlyArray<unknown>, fields: FieldMap | undefined, span: { start: number; end: number }, rawChildren: ReadonlyArray<unknown>, triviaLog: readonly number[], state: unknown) => unknown) | undefined; buildSrc?: string; /** The IDENTIFIER the type argument was written as at the `node()` call site, when it was a plain identifier rather than a literal — ANALYSIS ONLY, never emitted. Lets the inline-`mk` matcher recognise `node(t, …, (…) => mk(t, …))` from a factory, where the two `t`s are provably one binding. */ typeSrc?: string; /** Resolved source of a NAMED `buildSrc` — ANALYSIS ONLY, never emitted. See `buildAnalysisSrc`. */ buildSigSrc?: string; /** Declared positional arity of `build`: author-declared via `node(..., { buildArity })`, or resolved from the reducer's declaration. Wins over source inspection. */ buildArity?: number; /** Why arity could not be resolved, for the diagnostic. */ buildArityUnresolved?: string; buildStaticError?: readonly string[]; unwrap?: boolean; collapse?: boolean; project?: number; captureTrivia?: boolean; trailingTrivia?: boolean; tags?: readonly string[] }
|
|
92
|
+
| { tag: 'node'; type?: string; parser: Combinator<unknown>; build?: ((children: ReadonlyArray<unknown>, fields: FieldMap | undefined, span: { start: number; end: number }, rawChildren: ReadonlyArray<unknown>, triviaLog: readonly number[], state: unknown) => unknown) | undefined; buildSrc?: string; /** The IDENTIFIER the type argument was written as at the `node()` call site, when it was a plain identifier rather than a literal — ANALYSIS ONLY, never emitted. Lets the inline-`mk` matcher recognise `node(t, …, (…) => mk(t, …))` from a factory, where the two `t`s are provably one binding. */ typeSrc?: string; /** Resolved source of a NAMED `buildSrc` — ANALYSIS ONLY, never emitted. See `buildAnalysisSrc`. */ buildSigSrc?: string; /** Declared positional arity of `build`: author-declared via `node(..., { buildArity })`, or resolved from the reducer's declaration. Wins over source inspection. */ buildArity?: number; /** Why arity could not be resolved, for the diagnostic. */ buildArityUnresolved?: string; buildStaticError?: readonly string[]; /** Import provenance for a direct builder's free names — each `{ local, source, imported }` lets a downstream compose() re-emit `import { imported as local } from source` so the inlined builder source can bind. Carried through the IR round-trip. */ buildImports?: ReadonlyArray<{ local: string; source: string; imported: string }>; unwrap?: boolean; collapse?: boolean; project?: number; captureTrivia?: boolean; trailingTrivia?: boolean; tags?: readonly string[] }
|
|
93
93
|
// `predSrc`/`extraSrc` (set by the macro evaluator): SOURCE TEXT of the guard
|
|
94
94
|
// predicate / the withCtx `extra` value, so codegen inlines them into `_mf`
|
|
95
95
|
// rather than pushing a `null` source. Absent under runtime compile() (the real
|
package/src/version.ts
CHANGED