parseman 0.2.0 → 0.3.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 +167 -126
- package/dist/combinators/choice.d.ts.map +1 -1
- package/dist/combinators/completions.d.ts +17 -0
- package/dist/combinators/completions.d.ts.map +1 -0
- package/dist/combinators/grammar.d.ts +20 -4
- package/dist/combinators/grammar.d.ts.map +1 -1
- package/dist/combinators/guard.d.ts +2 -2
- package/dist/combinators/guard.d.ts.map +1 -1
- package/dist/combinators/keywords.d.ts +22 -0
- package/dist/combinators/keywords.d.ts.map +1 -0
- package/dist/combinators/literal.d.ts.map +1 -1
- package/dist/combinators/node.d.ts +24 -0
- package/dist/combinators/node.d.ts.map +1 -0
- package/dist/combinators/parser.d.ts +7 -7
- package/dist/combinators/parser.d.ts.map +1 -1
- package/dist/combinators/probe.d.ts +13 -0
- package/dist/combinators/probe.d.ts.map +1 -0
- package/dist/combinators/recover.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/scanTo.d.ts.map +1 -1
- package/dist/combinators/sequence.d.ts.map +1 -1
- package/dist/combinators/trivia-skip.d.ts +33 -0
- package/dist/combinators/trivia-skip.d.ts.map +1 -0
- package/dist/combinators/withCtx.d.ts +1 -1
- package/dist/compiler/codegen.d.ts +13 -4
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/cst/grammar.d.ts +33 -2
- package/dist/cst/grammar.d.ts.map +1 -1
- package/dist/cst/incremental.d.ts +4 -2
- package/dist/cst/incremental.d.ts.map +1 -1
- package/dist/cst/trivia-index.d.ts +50 -0
- package/dist/cst/trivia-index.d.ts.map +1 -0
- package/dist/cst/types.d.ts +7 -7
- package/dist/cst/types.d.ts.map +1 -1
- package/dist/functional/doc.d.ts +53 -0
- package/dist/functional/doc.d.ts.map +1 -0
- package/dist/index.cjs +953 -221
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6519 -226
- package/dist/index.js.map +4 -4
- package/dist/plugin/evaluator.d.ts +26 -6
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.cjs +1164 -215
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.d.ts +5 -2
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +1164 -215
- package/dist/plugin/index.js.map +4 -4
- package/dist/types.d.ts +51 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ParseContext, ParseFail } from '../types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a ParseFail and, if a completions probe is active, records it.
|
|
4
|
+
*
|
|
5
|
+
* Rules:
|
|
6
|
+
* - Only failures at or before the probe's target offset are eligible.
|
|
7
|
+
* - A deeper failure (higher pos) replaces the current best.
|
|
8
|
+
* - A tie (same pos) merges expected arrays — this is what makes choice arms
|
|
9
|
+
* aggregate their alternatives rather than each overwriting the last.
|
|
10
|
+
* - Shallower failures are ignored.
|
|
11
|
+
*/
|
|
12
|
+
export declare function failAt(ctx: ParseContext, expected: string[], pos: number): ParseFail;
|
|
13
|
+
//# sourceMappingURL=probe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"probe.d.ts","sourceRoot":"","sources":["../../src/combinators/probe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE1D;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAYpF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recover.d.ts","sourceRoot":"","sources":["../../src/combinators/recover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,UAAU,EAAE,MAAM,aAAa,CAAA;AAEhG,YAAY,EAAE,UAAU,EAAE,CAAA;AAE1B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EACrB,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,GAC5B,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"recover.d.ts","sourceRoot":"","sources":["../../src/combinators/recover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,UAAU,EAAE,MAAM,aAAa,CAAA;AAEhG,YAAY,EAAE,UAAU,EAAE,CAAA;AAE1B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EACrB,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,GAC5B,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CA6B5B;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../src/combinators/regex.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAmD,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../src/combinators/regex.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAmD,MAAM,aAAa,CAAA;AA4H9F,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,SAAK,GAAG,UAAU,CAAC,MAAM,CAAC,CA2B9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repeat.d.ts","sourceRoot":"","sources":["../../src/combinators/repeat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"repeat.d.ts","sourceRoot":"","sources":["../../src/combinators/repeat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AA+CpF,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAuB9D;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CA2BnE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,CAiBvE;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CA6B5F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanTo.d.ts","sourceRoot":"","sources":["../../src/combinators/scanTo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAMpF,MAAM,MAAM,aAAa,GAAG;IAC1B,uGAAuG;IACvG,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,CAAA;IAC5B;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,EAC7B,EAAE,IAAS,EAAE,KAAa,EAAE,GAAE,aAAkB,GAC/C,UAAU,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"scanTo.d.ts","sourceRoot":"","sources":["../../src/combinators/scanTo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAMpF,MAAM,MAAM,aAAa,GAAG;IAC1B,uGAAuG;IACvG,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,CAAA;IAC5B;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,EAC7B,EAAE,IAAS,EAAE,KAAa,EAAE,GAAE,aAAkB,GAC/C,UAAU,CAAC,MAAM,CAAC,CA+DpB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,aAAkB,GAC1B,UAAU,CAAC,MAAM,CAAC,CAYpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../../src/combinators/sequence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAoD,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../../src/combinators/sequence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAoD,MAAM,aAAa,CAAA;AAI/F,KAAK,aAAa,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI;KACnD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAC7D,CAAA;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,EAChF,GAAG,OAAO,EAAE,CAAC,GACZ,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAqD9B"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ParseContext } from '../types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Result of scanning trivia: the position after it, plus a `commit()` that
|
|
4
|
+
* records the matched trivia tokens into the active rawChildren collector.
|
|
5
|
+
* Recording is deferred so callers that may reject the following item (e.g.
|
|
6
|
+
* many()/oneOrMore() retries) can advance speculatively without recording
|
|
7
|
+
* trivia that doesn't actually sit between two accepted items.
|
|
8
|
+
*/
|
|
9
|
+
export type TriviaScan = {
|
|
10
|
+
end: number;
|
|
11
|
+
commit: () => void;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Scan trivia at `cur` using `ctx.trivia`, WITHOUT recording it. Returns the
|
|
15
|
+
* position after the trivia (or `cur` if none) and a `commit()` to record it.
|
|
16
|
+
*
|
|
17
|
+
* Recording is gated on `ctx.captureTrivia`:
|
|
18
|
+
* - capture off (default): commit() is a no-op; trivia is skipped silently.
|
|
19
|
+
* - capture on (and a rawChildren collector is active): commit() records each
|
|
20
|
+
* maximal trivia sub-match (a whitespace run or a comment) as a separate
|
|
21
|
+
* CSTTrivia token. Relies on the trivia parser being structured so each
|
|
22
|
+
* token is a distinct leaf match.
|
|
23
|
+
*
|
|
24
|
+
* The trivia parser always runs with `trivia` unset in its sub-context so it
|
|
25
|
+
* cannot recurse into itself.
|
|
26
|
+
*/
|
|
27
|
+
export declare function scanTrivia(input: string, cur: number, ctx: ParseContext): TriviaScan;
|
|
28
|
+
/**
|
|
29
|
+
* Consume trivia at `cur`, recording it immediately. For callers that always
|
|
30
|
+
* accept the trivia between two committed terms (e.g. sequence/sepBy).
|
|
31
|
+
*/
|
|
32
|
+
export declare function consumeTrivia(input: string, cur: number, ctx: ParseContext): number;
|
|
33
|
+
//# sourceMappingURL=trivia-skip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trivia-skip.d.ts","sourceRoot":"","sources":["../../src/combinators/trivia-skip.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI/C;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,CAAA;AAI5D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,UAAU,CA0CpF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,MAAM,CAInF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Combinator } from '../types.ts';
|
|
2
2
|
/**
|
|
3
|
-
* Runs `parser` with `ctx.
|
|
3
|
+
* Runs `parser` with `ctx.state` set to `extra` for the duration of the parse.
|
|
4
4
|
* The outer user context is restored on exit (lexical scoping).
|
|
5
5
|
*
|
|
6
6
|
* const functionBody = withCtx({ inFn: true },
|
|
@@ -2,12 +2,21 @@
|
|
|
2
2
|
* Compile a Combinator<T> definition tree into an optimized JavaScript function.
|
|
3
3
|
*
|
|
4
4
|
* Design: every sub-emitter uses early-return on failure. Fallible contexts
|
|
5
|
-
* (
|
|
6
|
-
*
|
|
5
|
+
* (optional, sepBy loops, many loops) use labeled blocks so early-exit is a
|
|
6
|
+
* `break <label>` rather than an IIFE return — no function call, no result
|
|
7
|
+
* object allocation per node.
|
|
7
8
|
*/
|
|
8
|
-
import type { Combinator, ParseResult } from '../types.ts';
|
|
9
|
+
import type { Combinator, ParseResult, ParseError } from '../types.ts';
|
|
9
10
|
export type CompiledParser<T> = {
|
|
10
11
|
parse(input: string, pos?: number): ParseResult<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Like parse(), but activates error recovery. recover() nodes collect their
|
|
14
|
+
* ParseErrors into result.errors instead of (only) embedding them as values.
|
|
15
|
+
* Always returns ParseOk — top-level failures are still ParseFail.
|
|
16
|
+
*/
|
|
17
|
+
parseWithErrors(input: string, pos?: number): ParseResult<T> & {
|
|
18
|
+
errors: ParseError[];
|
|
19
|
+
};
|
|
11
20
|
/** The generated source (for inspection / future source maps) */
|
|
12
21
|
source: string;
|
|
13
22
|
/**
|
|
@@ -19,5 +28,5 @@ export type CompiledParser<T> = {
|
|
|
19
28
|
*/
|
|
20
29
|
inlineExpression: string | null;
|
|
21
30
|
};
|
|
22
|
-
export declare function compile<T>(parser: Combinator<T
|
|
31
|
+
export declare function compile<T>(parser: Combinator<T>, mapFnSources?: string[]): CompiledParser<T>;
|
|
23
32
|
//# sourceMappingURL=codegen.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/compiler/codegen.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/compiler/codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAuB,WAAW,EAAgB,UAAU,EAAkB,MAAM,aAAa,CAAA;AA6lCzH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAC9B,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;IAClD;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG;QAAE,MAAM,EAAE,UAAU,EAAE,CAAA;KAAE,CAAA;IACvF,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAA;IACd;;;;;;OAMG;IACH,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;CAChC,CAAA;AAgCD,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC,CAqF5F"}
|
package/dist/cst/grammar.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export type Refs<T> = {
|
|
|
28
28
|
* Expr = (g: Refs<this>) => choice(g.Atom, sequence(g.Expr, literal('+')))
|
|
29
29
|
*
|
|
30
30
|
* Convention:
|
|
31
|
-
* Capital letter → CSTNode-producing rule (span +
|
|
31
|
+
* Capital letter → CSTNode-producing rule (span + state + children)
|
|
32
32
|
* lowercase → transparent helper (terminals bubble up as CSTLeaf in the
|
|
33
33
|
* nearest enclosing capital rule)
|
|
34
34
|
*
|
|
@@ -46,6 +46,33 @@ export type Refs<T> = {
|
|
|
46
46
|
*/
|
|
47
47
|
export declare class Parser<N extends NodeLike = CSTNode> {
|
|
48
48
|
private _built;
|
|
49
|
+
/** Set in a subclass to enable automatic trivia skipping between sequence terms. */
|
|
50
|
+
protected _trivia?: Combinator<unknown>;
|
|
51
|
+
/**
|
|
52
|
+
* Set in a subclass to make the rule name optional in `parse()`.
|
|
53
|
+
* When defined, `parse(input)` is equivalent to `parse(defaultRule, input)`.
|
|
54
|
+
*/
|
|
55
|
+
protected _defaultRule?: RuleKeys<this>;
|
|
56
|
+
/**
|
|
57
|
+
* Set `true` in a subclass to record trivia (whitespace/comments) consumed
|
|
58
|
+
* between terms into each node's rawChildren as separate CSTTrivia tokens.
|
|
59
|
+
* Requires `_trivia` to be set. Default: trivia is skipped without recording.
|
|
60
|
+
*/
|
|
61
|
+
protected _captureTrivia?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* When set, makeParseDoc injects this array as ctx._triviaLog so each
|
|
64
|
+
* scanTrivia.commit() pushes [runStart, runEnd] pairs into it.
|
|
65
|
+
* Reset to [] before each parse() call in any subclass that uses it.
|
|
66
|
+
*/
|
|
67
|
+
protected _triviaLog?: number[];
|
|
68
|
+
/**
|
|
69
|
+
* Optional map of public entry-point aliases → actual rule names. Lets callers
|
|
70
|
+
* `parse('value', src)` when the grammar's rule is `ValueList`, removing
|
|
71
|
+
* per-adapter name-translation tables.
|
|
72
|
+
*/
|
|
73
|
+
protected _aliases?: Record<string, string>;
|
|
74
|
+
/** Resolve an alias to its target rule name (identity if not aliased). */
|
|
75
|
+
protected _resolveRule(name: string): string;
|
|
49
76
|
private _build;
|
|
50
77
|
/**
|
|
51
78
|
* Override to produce a custom AST node instead of a plain CSTNode.
|
|
@@ -56,7 +83,7 @@ export declare class Parser<N extends NodeLike = CSTNode> {
|
|
|
56
83
|
* grammar is whitespace-sensitive (e.g. CSS descendant vs adjacent combinators).
|
|
57
84
|
* The default implementation ignores `rawChildren`.
|
|
58
85
|
*/
|
|
59
|
-
protected buildNode(type: string, span: Span, children: ReadonlyArray<N | CSTLeaf | CSTError>,
|
|
86
|
+
protected buildNode(type: string, span: Span, children: ReadonlyArray<N | CSTLeaf | CSTError>, state: unknown, _rawChildren: ReadonlyArray<CSTRawChild>): N;
|
|
60
87
|
/** Wrap an inner combinator so it produces a CSTNode on each match. */
|
|
61
88
|
private _makeNodeParser;
|
|
62
89
|
/** Reconstruct a node with a new children array (used by IncrementalParser). */
|
|
@@ -72,8 +99,12 @@ export declare class Parser<N extends NodeLike = CSTNode> {
|
|
|
72
99
|
*
|
|
73
100
|
* // In an editor — just keep calling edit():
|
|
74
101
|
* const doc2 = doc.edit(newSrc, changeStart, changeEnd)
|
|
102
|
+
*
|
|
103
|
+
* If the grammar defines `_defaultRule`, the rule name may be omitted:
|
|
104
|
+
* const doc = css.parse(src) // uses _defaultRule
|
|
75
105
|
*/
|
|
76
106
|
parse(ruleName: RuleKeys<this>, input: string): ParseDoc<N>;
|
|
107
|
+
parse(input: string): ParseDoc<N>;
|
|
77
108
|
/**
|
|
78
109
|
* Get the compiled Combinator for a named rule.
|
|
79
110
|
* Triggers lazy initialization on first call.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grammar.d.ts","sourceRoot":"","sources":["../../src/cst/grammar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,IAAI,EAAE,MAAM,aAAa,CAAA;AAE1F,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAa,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE9F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAMhD,KAAK,OAAO,GAAG,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GACvD,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,GAAC,GAAG,CAAA;AAE9D,sEAAsE;AACtE,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KACvB,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,SAAS,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,KAAK;CACrE,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAA;AAEnB;;;;;;;GAOG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI;KACnB,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,IAAI,MAAM,EAAE,GAAG,KAAK,GAC3C,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,GAChC,CAAC,CAAC,CAAC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CAAA;IAElC;;;;OAIG;IACH,SAAS,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IAE/B;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAE3C,0EAA0E;IAC1E,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3C;IAED,OAAO,CAAC,MAAM;IA2Cd;;;;;;;;OAQG;IACH,SAAS,CAAC,SAAS,CACjB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,aAAa,CAAC,CAAC,GAAG,OAAO,GAAG,QAAQ,CAAC,EAC/C,KAAK,EAAE,OAAO,EACd,YAAY,EAAE,aAAa,CAAC,WAAW,CAAC,GACvC,CAAC,CAEH;IAED,uEAAuE;IACvE,OAAO,CAAC,eAAe;IA2CvB,gFAAgF;IAChF,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC,GAAG,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,CAEtE;IAED;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC3D,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAiBjC;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAMxC;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ParseFail } from '../types.ts';
|
|
1
|
+
import type { Combinator, ParseFail } from '../types.ts';
|
|
2
2
|
import type { Parser } from './grammar.ts';
|
|
3
3
|
import type { NodeLike } from './types.ts';
|
|
4
4
|
/**
|
|
@@ -16,6 +16,8 @@ export interface ParseDoc<N extends NodeLike = NodeLike> {
|
|
|
16
16
|
readonly tree: N | null;
|
|
17
17
|
readonly errors: ParseFail[];
|
|
18
18
|
readonly input: string;
|
|
19
|
+
/** Offset reached by the top-level rule. < input.length means input was left unconsumed. */
|
|
20
|
+
readonly consumedEnd: number;
|
|
19
21
|
/**
|
|
20
22
|
* Incrementally re-parse after a text change.
|
|
21
23
|
*
|
|
@@ -34,5 +36,5 @@ export interface ParseDoc<N extends NodeLike = NodeLike> {
|
|
|
34
36
|
*/
|
|
35
37
|
edit(from: number, to: number, replacement: string): ParseDoc<N>;
|
|
36
38
|
}
|
|
37
|
-
export declare function makeParseDoc<N extends NodeLike>(parser: Parser<N>, ruleName: string, input: string): ParseDoc<N>;
|
|
39
|
+
export declare function makeParseDoc<N extends NodeLike>(parser: Parser<N>, ruleName: string, input: string, trivia?: Combinator<unknown>, captureTrivia?: boolean, triviaLog?: number[]): ParseDoc<N>;
|
|
38
40
|
//# sourceMappingURL=incremental.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"incremental.d.ts","sourceRoot":"","sources":["../../src/cst/incremental.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,SAAS,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"incremental.d.ts","sourceRoot":"","sources":["../../src/cst/incremental.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAgB,SAAS,EAAE,MAAM,aAAa,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,EAAY,MAAM,cAAc,CAAA;AACpD,OAAO,KAAK,EAAqB,QAAQ,EAAE,MAAM,YAAY,CAAA;AAM7D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ;IACrD,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,CAAA;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,4FAA4F;IAC5F,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B;;;;;;;;;;;;;;;OAeG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;CACjE;AAsHD,wBAAgB,YAAY,CAAC,CAAC,SAAS,QAAQ,EAC7C,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAC5B,aAAa,CAAC,EAAE,OAAO,EACvB,SAAS,CAAC,EAAE,MAAM,EAAE,GACnB,QAAQ,CAAC,CAAC,CAAC,CAYb"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Span } from '../types.ts';
|
|
2
|
+
/** One captured trivia token (a whitespace run or a comment) with its source span. */
|
|
3
|
+
export type TriviaToken = {
|
|
4
|
+
readonly value: string;
|
|
5
|
+
readonly span: Span;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Before/after offset index of captured trivia. Built from a tree's rawChildren
|
|
9
|
+
* (trivia is only present there when the grammar enables `_captureTrivia`).
|
|
10
|
+
*
|
|
11
|
+
* index.before.get(node.span.start) // trivia immediately before a node
|
|
12
|
+
* index.after.get(node.span.end) // trivia immediately after a node
|
|
13
|
+
*
|
|
14
|
+
* A given trivia run is registered under BOTH the following item's start
|
|
15
|
+
* (`before`) and the preceding item's end (`after`), so either lookup finds it.
|
|
16
|
+
*/
|
|
17
|
+
export type TriviaIndex = {
|
|
18
|
+
readonly before: Map<number, TriviaToken[]>;
|
|
19
|
+
readonly after: Map<number, TriviaToken[]>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Options for trailing/leading trivia at the document boundary. A repeating root
|
|
23
|
+
* (e.g. `many()`) rolls back the trivia after its last item — it's "trailing" and
|
|
24
|
+
* belongs to the enclosing context, which at the document root is the document
|
|
25
|
+
* itself. Pass `{ input, trivia }` to re-scan and register that boundary trivia,
|
|
26
|
+
* so a round-trippable trivia map isn't missing the run before EOF.
|
|
27
|
+
*/
|
|
28
|
+
export type TriviaIndexOptions = {
|
|
29
|
+
/** The full source string. */
|
|
30
|
+
input: string;
|
|
31
|
+
/**
|
|
32
|
+
* A regex matching ONE trivia token (a whitespace run or a comment). Applied
|
|
33
|
+
* repeatedly to tokenize the boundary trivia. Each match becomes one token, so
|
|
34
|
+
* write it to match a maximal run, e.g.
|
|
35
|
+
* `/[ \t\n\r\f]+|\/\*(?:[^*]|\*(?!\/))*\*\//`.
|
|
36
|
+
*/
|
|
37
|
+
trivia: RegExp;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Walk a CST/AST node tree (anything exposing `children` whose items carry
|
|
41
|
+
* `_tag`/`span`, with trivia items tagged `'trivia'`) and build a before/after
|
|
42
|
+
* trivia index. Generic over the node type — formatters, LSPs, and codemods all
|
|
43
|
+
* need this, and Parseman already owns trivia capture.
|
|
44
|
+
*
|
|
45
|
+
* With `opts`, also captures leading trivia (before the root's content) and
|
|
46
|
+
* trailing trivia (after it, up to EOF) — the document boundaries a repeating
|
|
47
|
+
* root rolls back.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildTriviaIndex(root: unknown, opts?: TriviaIndexOptions): TriviaIndex;
|
|
50
|
+
//# sourceMappingURL=trivia-index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trivia-index.d.ts","sourceRoot":"","sources":["../../src/cst/trivia-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEvC,sFAAsF;AACtF,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAA;AAEzE;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAAA;IAC3C,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAAA;CAC3C,CAAA;AAiBD;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAA;IACb;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,kBAAkB,GAAG,WAAW,CAqEtF"}
|
package/dist/cst/types.d.ts
CHANGED
|
@@ -6,14 +6,14 @@ import type { Span } from '../types.ts';
|
|
|
6
6
|
*
|
|
7
7
|
* `children` only needs to be iterable with items that have `_tag` so the
|
|
8
8
|
* traversal code can distinguish sub-nodes from leaves. For incremental
|
|
9
|
-
* replacement,
|
|
10
|
-
*
|
|
9
|
+
* replacement, `rebuild()` on the Parser calls `buildNode()` rather than
|
|
10
|
+
* object-spreading, so overriding `buildNode` handles class instances correctly.
|
|
11
11
|
*/
|
|
12
12
|
export type NodeLike = {
|
|
13
13
|
readonly _tag: 'node';
|
|
14
14
|
readonly type: string;
|
|
15
15
|
readonly span: Span;
|
|
16
|
-
readonly
|
|
16
|
+
readonly state: unknown;
|
|
17
17
|
readonly children: ReadonlyArray<{
|
|
18
18
|
readonly _tag: string;
|
|
19
19
|
}>;
|
|
@@ -30,11 +30,11 @@ export type CSTNode = {
|
|
|
30
30
|
readonly span: Span;
|
|
31
31
|
readonly children: CSTChild[];
|
|
32
32
|
/**
|
|
33
|
-
* Shallow clone of ctx.
|
|
33
|
+
* Shallow clone of ctx.state at the moment this node's parse began.
|
|
34
34
|
* Used as the re-entry point for incremental re-parsing.
|
|
35
|
-
* Only meaningful when ctx.
|
|
35
|
+
* Only meaningful when ctx.state is primitives-only (no mutable objects).
|
|
36
36
|
*/
|
|
37
|
-
readonly
|
|
37
|
+
readonly state: unknown;
|
|
38
38
|
};
|
|
39
39
|
/**
|
|
40
40
|
* A terminal token — the result of a literal() or regex() match inside a CST rule.
|
|
@@ -57,7 +57,7 @@ export type CSTError = {
|
|
|
57
57
|
readonly span: Span;
|
|
58
58
|
readonly expected: string[];
|
|
59
59
|
readonly children: CSTChild[];
|
|
60
|
-
readonly
|
|
60
|
+
readonly state: unknown;
|
|
61
61
|
};
|
|
62
62
|
export type CSTChild = CSTNode | CSTLeaf | CSTError;
|
|
63
63
|
/**
|
package/dist/cst/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/cst/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEvC;;;;;;;;;GASG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;IACnB,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/cst/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEvC;;;;;;;;;GASG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;IACnB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;IACvB,QAA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,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Functional incremental document — a class-free counterpart to ParseDoc.
|
|
3
|
+
*
|
|
4
|
+
* The class-based Parser bakes a rule registry (method name → combinator) and
|
|
5
|
+
* a `rebuild()` hook into the grammar object. A *functional* grammar produces
|
|
6
|
+
* the same two ingredients without a class:
|
|
7
|
+
*
|
|
8
|
+
* - the registry is the object returned by `rules()` (rule name → parser fn),
|
|
9
|
+
* which the macro compiles to a map of independently-callable functions;
|
|
10
|
+
* - `rebuild` is supplied by the caller (or defaults to a shallow spread),
|
|
11
|
+
* since functional nodes are whatever the `transform()` callbacks produced.
|
|
12
|
+
*
|
|
13
|
+
* Given those, incremental re-parsing is identical in spirit to the class path:
|
|
14
|
+
* locate the smallest node containing the edit, re-parse that single rule from
|
|
15
|
+
* its start offset, and graft the result back into the tree if its end lands
|
|
16
|
+
* where the edit's delta predicts.
|
|
17
|
+
*
|
|
18
|
+
* This module has no dependency on the `Parser` class — it is what lets the
|
|
19
|
+
* class be removed once grammars move to the functional shape.
|
|
20
|
+
*/
|
|
21
|
+
import type { ParseContext, ParseFail, ParseResult } from '../types.ts';
|
|
22
|
+
import type { NodeLike, CSTLeaf, CSTError } from '../cst/types.ts';
|
|
23
|
+
/** A single compiled (or interpreted) rule: parse from `pos`, producing node `N`. */
|
|
24
|
+
export type RuleFn<N> = (input: string, pos: number, ctx: ParseContext) => ParseResult<N>;
|
|
25
|
+
/** Rule name → parser function. This is exactly the shape `rules()` returns. */
|
|
26
|
+
export type Registry<N> = Record<string, RuleFn<N>>;
|
|
27
|
+
export type FunctionalDocOptions<N extends NodeLike> = {
|
|
28
|
+
/** Initial grammar state threaded into ctx.state for the root parse. */
|
|
29
|
+
state?: unknown;
|
|
30
|
+
/**
|
|
31
|
+
* Reconstruct a parent node with one child replaced (used when grafting a
|
|
32
|
+
* re-parsed subtree into its ancestors). Defaults to a shallow spread, which
|
|
33
|
+
* works for plain-object nodes; class-instance ASTs should supply their own.
|
|
34
|
+
*/
|
|
35
|
+
rebuild?: (node: N, children: ReadonlyArray<N | CSTLeaf | CSTError>) => N;
|
|
36
|
+
};
|
|
37
|
+
export interface FunctionalDoc<N extends NodeLike> {
|
|
38
|
+
readonly tree: N | null;
|
|
39
|
+
readonly errors: ParseFail[];
|
|
40
|
+
readonly input: string;
|
|
41
|
+
/**
|
|
42
|
+
* Incrementally re-parse after a text change. `from`/`to` are byte offsets in
|
|
43
|
+
* the OLD input; `replacement` fills that range. Mirrors editor change events
|
|
44
|
+
* (see ParseDoc.edit for the mapping).
|
|
45
|
+
*/
|
|
46
|
+
edit(from: number, to: number, replacement: string): FunctionalDoc<N>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Parse `input` from `rootRule` and wrap the result in a FunctionalDoc that can
|
|
50
|
+
* be incrementally re-parsed via `.edit()`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function makeFunctionalDoc<N extends NodeLike>(registry: Registry<N>, rootRule: string, input: string, opts?: FunctionalDocOptions<N>): FunctionalDoc<N>;
|
|
53
|
+
//# sourceMappingURL=doc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["../../src/functional/doc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAElE,qFAAqF;AACrF,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,CAAA;AAEzF,gFAAgF;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