parseman 0.5.0 → 0.6.1
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 +19 -15
- package/dist/combinators/choice.d.ts.map +1 -1
- package/dist/combinators/completions.d.ts +1 -1
- package/dist/combinators/completions.d.ts.map +1 -1
- package/dist/combinators/grammar.d.ts.map +1 -1
- package/dist/combinators/keywords.d.ts +22 -0
- package/dist/combinators/keywords.d.ts.map +1 -1
- package/dist/combinators/literal.d.ts.map +1 -1
- package/dist/combinators/map.d.ts +8 -2
- package/dist/combinators/map.d.ts.map +1 -1
- package/dist/combinators/node.d.ts +10 -11
- package/dist/combinators/node.d.ts.map +1 -1
- package/dist/combinators/not.d.ts +3 -3
- package/dist/combinators/not.d.ts.map +1 -1
- package/dist/combinators/recover.d.ts +2 -2
- package/dist/combinators/recover.d.ts.map +1 -1
- package/dist/combinators/regex.d.ts.map +1 -1
- package/dist/combinators/repeat.d.ts +4 -4
- 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 +16 -10
- package/dist/combinators/trivia-skip.d.ts.map +1 -1
- package/dist/combinators/withCtx.d.ts +2 -2
- package/dist/combinators/withCtx.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts +4 -2
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/inline-build.d.ts +11 -0
- package/dist/compiler/inline-build.d.ts.map +1 -0
- package/dist/compiler/inline-callback.d.ts +12 -0
- package/dist/compiler/inline-callback.d.ts.map +1 -0
- package/dist/compiler/trivia-fast-path.d.ts +24 -0
- package/dist/compiler/trivia-fast-path.d.ts.map +1 -0
- package/dist/cst/capture-buffer.d.ts +46 -0
- package/dist/cst/capture-buffer.d.ts.map +1 -0
- package/dist/cst/trivia-entries.d.ts +20 -0
- package/dist/cst/trivia-entries.d.ts.map +1 -0
- package/dist/cst/trivia-index.d.ts +11 -11
- package/dist/cst/trivia-index.d.ts.map +1 -1
- package/dist/cst/trivia-kinds.d.ts +47 -0
- package/dist/cst/trivia-kinds.d.ts.map +1 -0
- package/dist/cst/types.d.ts +9 -13
- package/dist/cst/types.d.ts.map +1 -1
- package/dist/functional/doc.d.ts +2 -20
- package/dist/functional/doc.d.ts.map +1 -1
- package/dist/index.cjs +1238 -662
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1256 -6241
- package/dist/index.js.map +4 -4
- package/dist/plugin/evaluator.d.ts +7 -0
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.cjs +1249 -369
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +1249 -369
- package/dist/plugin/index.js.map +4 -4
- package/dist/types.d.ts +32 -9
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
- package/dist/cst/grammar.d.ts +0 -115
- package/dist/cst/grammar.d.ts.map +0 -1
- package/dist/cst/incremental.d.ts +0 -40
- package/dist/cst/incremental.d.ts.map +0 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Combinator, ParseContext } from '../types.ts';
|
|
2
|
+
export type TriviaChunk = {
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
5
|
+
kindIndex: number;
|
|
6
|
+
};
|
|
7
|
+
export type LabeledTriviaSpec = {
|
|
8
|
+
readonly labels: readonly string[];
|
|
9
|
+
readonly arms: ReadonlyArray<{
|
|
10
|
+
label: string;
|
|
11
|
+
kindIndex: number;
|
|
12
|
+
parser: Combinator<unknown>;
|
|
13
|
+
}>;
|
|
14
|
+
readonly minRepeats: number;
|
|
15
|
+
};
|
|
16
|
+
/** Strip `label()` wrapper; returns inner parser for matching. */
|
|
17
|
+
export declare function peelLabel(p: Combinator<unknown>): {
|
|
18
|
+
label: string;
|
|
19
|
+
parser: Combinator<unknown>;
|
|
20
|
+
} | null;
|
|
21
|
+
/**
|
|
22
|
+
* When every trivia arm is `label(name, parser)` inside `oneOrMore(choice(…))`
|
|
23
|
+
* (or a single labeled arm), return the label table and matchers.
|
|
24
|
+
*/
|
|
25
|
+
export declare function analyzeLabeledTrivia(trivia: Combinator<unknown>): LabeledTriviaSpec | null;
|
|
26
|
+
/** Label table on a `trivia()` combinator, if all arms are labeled. */
|
|
27
|
+
export declare function triviaKindLabels(trivia: Combinator<unknown> | undefined): readonly string[] | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Scan maximal labeled trivia chunks (PEG `oneOrMore(choice(…))` semantics).
|
|
30
|
+
* Each successful arm match becomes one entry with that arm's kind index.
|
|
31
|
+
*/
|
|
32
|
+
export declare function scanLabeledTriviaChunks(input: string, cur: number, spec: LabeledTriviaSpec): {
|
|
33
|
+
end: number;
|
|
34
|
+
chunks: TriviaChunk[];
|
|
35
|
+
};
|
|
36
|
+
/** Hand-rolled ws / block-comment scan with per-chunk kind indices (interpreter). */
|
|
37
|
+
export declare function scanFastWsCommentsChunks(input: string, cur: number, wsKind: number, commentKind: number): {
|
|
38
|
+
end: number;
|
|
39
|
+
chunks: TriviaChunk[];
|
|
40
|
+
};
|
|
41
|
+
/** Fast scan when trivia is labeled ws + block-comment (CSS `rw`). */
|
|
42
|
+
export declare function tryFastLabeledScan(input: string, cur: number, trivia: Combinator<unknown>): {
|
|
43
|
+
end: number;
|
|
44
|
+
chunks: TriviaChunk[];
|
|
45
|
+
} | null;
|
|
46
|
+
export declare function recordTriviaChunks(ctx: ParseContext, chunks: readonly TriviaChunk[]): void;
|
|
47
|
+
//# sourceMappingURL=trivia-kinds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trivia-kinds.d.ts","sourceRoot":"","sources":["../../src/cst/trivia-kinds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,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AAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,EAAE,CAAA;CAAE,CA6BxC;AAED,sEAAsE;AACtE,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,GAC1B;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,EAAE,CAAA;CAAE,GAAG,IAAI,CAiB/C;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI,CAQ1F"}
|
package/dist/cst/types.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { Span } from '../types.ts';
|
|
2
2
|
/**
|
|
3
|
-
* Minimal interface a node must satisfy for
|
|
4
|
-
* re-parse the tree.
|
|
5
|
-
*
|
|
3
|
+
* Minimal interface a node must satisfy for incremental re-parse to navigate and
|
|
4
|
+
* re-parse the tree. Any object with `_tag: 'node'`, `type`, `span`, `state`,
|
|
5
|
+
* and `children` works — whether from `node()` build callbacks or custom ASTs.
|
|
6
6
|
*
|
|
7
|
-
* `children` only needs
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* object-spreading, so overriding `buildNode` handles class instances correctly.
|
|
7
|
+
* `children` only needs items with `_tag` so traversal can distinguish sub-nodes
|
|
8
|
+
* from leaves. `makeFunctionalDoc` uses an optional `rebuild` callback (or a
|
|
9
|
+
* shallow spread) when grafting a re-parsed subtree.
|
|
11
10
|
*/
|
|
12
11
|
export type NodeLike = {
|
|
13
12
|
readonly _tag: 'node';
|
|
@@ -19,9 +18,8 @@ export type NodeLike = {
|
|
|
19
18
|
}>;
|
|
20
19
|
};
|
|
21
20
|
/**
|
|
22
|
-
* A named CST node
|
|
23
|
-
* Children are in parse order:
|
|
24
|
-
* with CSTLeaf terminals from literal() / regex() calls inside lowercase helpers.
|
|
21
|
+
* A named CST node from a `node()` rule (or equivalent build callback).
|
|
22
|
+
* Children are in parse order: sub-nodes interspersed with CSTLeaf terminals.
|
|
25
23
|
*/
|
|
26
24
|
export type CSTNode = {
|
|
27
25
|
readonly _tag: 'node';
|
|
@@ -37,9 +35,7 @@ export type CSTNode = {
|
|
|
37
35
|
readonly state: unknown;
|
|
38
36
|
};
|
|
39
37
|
/**
|
|
40
|
-
* A terminal token — the result of a literal() or regex() match inside a
|
|
41
|
-
* Lowercase helpers are transparent: their terminals surface as leaves of the
|
|
42
|
-
* nearest enclosing capital-letter rule.
|
|
38
|
+
* A terminal token — the result of a literal() or regex() match inside a node rule.
|
|
43
39
|
*/
|
|
44
40
|
export type CSTLeaf = {
|
|
45
41
|
readonly _tag: 'leaf';
|
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
|
|
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;;;;;;;;GAQG;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,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC5D,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,2DAA2D;IAC3D,Q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* 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.
|
|
2
|
+
* Functional incremental document — incremental re-parse over a rules() registry.
|
|
20
3
|
*/
|
|
21
4
|
import type { ParseContext, ParseFail, ParseResult } from '../types.ts';
|
|
22
5
|
import type { NodeLike, CSTLeaf, CSTError } from '../cst/types.ts';
|
|
@@ -40,8 +23,7 @@ export interface FunctionalDoc<N extends NodeLike> {
|
|
|
40
23
|
readonly input: string;
|
|
41
24
|
/**
|
|
42
25
|
* Incrementally re-parse after a text change. `from`/`to` are byte offsets in
|
|
43
|
-
* the OLD input; `replacement` fills that range
|
|
44
|
-
* (see ParseDoc.edit for the mapping).
|
|
26
|
+
* the OLD input; `replacement` fills that range (editor change-event shape).
|
|
45
27
|
*/
|
|
46
28
|
edit(from: number, to: number, replacement: string): FunctionalDoc<N>;
|
|
47
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["../../src/functional/doc.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["../../src/functional/doc.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,E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