parseman 0.25.0 → 0.26.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/dist/combinators/choice.d.ts.map +1 -1
- package/dist/combinators/completions.d.ts +14 -4
- package/dist/combinators/completions.d.ts.map +1 -1
- package/dist/combinators/expect.d.ts +2 -0
- package/dist/combinators/expect.d.ts.map +1 -1
- package/dist/combinators/grammar.d.ts +5 -5
- package/dist/combinators/not.d.ts.map +1 -1
- package/dist/combinators/parser.d.ts +3 -2
- package/dist/combinators/parser.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 +1 -0
- package/dist/combinators/trivia-skip.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts +9 -4
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/scannable-run.d.ts +2 -2
- package/dist/compiler/scannable-run.d.ts.map +1 -1
- package/dist/cst/capture-buffer.d.ts +1 -0
- package/dist/cst/capture-buffer.d.ts.map +1 -1
- package/dist/cst/types.d.ts +7 -7
- package/dist/cst/types.d.ts.map +1 -1
- package/dist/functional/doc.d.ts +37 -2
- package/dist/functional/doc.d.ts.map +1 -1
- package/dist/functional/run.d.ts +12 -1
- package/dist/functional/run.d.ts.map +1 -1
- package/dist/index.cjs +540 -211
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +540 -211
- package/dist/index.js.map +4 -4
- package/dist/language-service/index.cjs +776 -0
- package/dist/language-service/index.cjs.map +7 -0
- package/dist/language-service/index.d.ts +94 -0
- package/dist/language-service/index.d.ts.map +1 -0
- package/dist/language-service/index.js +753 -0
- package/dist/language-service/index.js.map +7 -0
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.cjs +603 -145
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.d.ts +11 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +603 -145
- package/dist/plugin/index.js.map +4 -4
- package/dist/recovery/scan.d.ts +54 -0
- package/dist/recovery/scan.d.ts.map +1 -0
- package/dist/spec/index.cjs.map +1 -1
- package/dist/spec/index.js.map +1 -1
- package/dist/types.d.ts +60 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -1
- package/dist/combinators/recover-list.d.ts +0 -41
- package/dist/combinators/recover-list.d.ts.map +0 -1
- package/dist/combinators/recover.d.ts +0 -20
- package/dist/combinators/recover.d.ts.map +0 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `parseman/language-service` — the external, grammar-agnostic IDE layer.
|
|
3
|
+
*
|
|
4
|
+
* A grammar is pure structure (it carries no recovery/completion/lint config).
|
|
5
|
+
* `languageService(grammar, config)` layers editor behaviour ON TOP, keyed by rule
|
|
6
|
+
* name = node type, without ever modifying the grammar:
|
|
7
|
+
*
|
|
8
|
+
* - `parse(src, { tolerant })` → CST + `ParseError[]` (recovers on the compiled
|
|
9
|
+
* fast path when `grammar` is a `compile(g, { recovery: true })` grammar).
|
|
10
|
+
* - `diagnostics(src)` → structural parse errors + your per-node-type lint rules.
|
|
11
|
+
* - `completionsAt(src, offset)` → the grammar's expected-token set at the cursor,
|
|
12
|
+
* mapped through your per-rule semantic completion handlers.
|
|
13
|
+
*
|
|
14
|
+
* The grammar can be the interpreter combinator OR a compiled grammar — the domain
|
|
15
|
+
* knowledge (what to suggest after `color:`, which nodes to lint) lives here, in the
|
|
16
|
+
* consumer's config, never in the grammar.
|
|
17
|
+
*/
|
|
18
|
+
import type { Combinator, ParseContext, ParseResult, Span, ParseError } from '../types.ts';
|
|
19
|
+
import { type Walkable } from '../cst/walk.ts';
|
|
20
|
+
import { type Registry } from '../functional/doc.ts';
|
|
21
|
+
import type { NodeLike } from '../cst/types.ts';
|
|
22
|
+
export type Severity = 'error' | 'warning' | 'info';
|
|
23
|
+
export type Diagnostic = {
|
|
24
|
+
severity: Severity;
|
|
25
|
+
message: string;
|
|
26
|
+
span: Span;
|
|
27
|
+
};
|
|
28
|
+
export type CompletionItem = {
|
|
29
|
+
label: string;
|
|
30
|
+
detail?: string;
|
|
31
|
+
};
|
|
32
|
+
/** A CST node/leaf as a diagnostics handler sees it: the walk shape plus span/value. */
|
|
33
|
+
export type LsNode = Walkable & {
|
|
34
|
+
readonly span: Span;
|
|
35
|
+
readonly value?: string;
|
|
36
|
+
};
|
|
37
|
+
/** Context handed to a completion handler: which rule the cursor sits in and the
|
|
38
|
+
* grammar's raw expected-token labels there. */
|
|
39
|
+
export type CompletionContext = {
|
|
40
|
+
rule: string | null;
|
|
41
|
+
expected: string[];
|
|
42
|
+
offset: number;
|
|
43
|
+
};
|
|
44
|
+
export type LanguageServiceConfig = {
|
|
45
|
+
/** Lint/diagnostic rules keyed by node type (rule name). Return zero or more
|
|
46
|
+
* Diagnostics for each matching node. */
|
|
47
|
+
diagnostics?: Record<string, (node: LsNode) => Diagnostic | Diagnostic[] | null | undefined | void>;
|
|
48
|
+
/** Semantic completion handlers keyed by the rule the cursor is in. Turn the
|
|
49
|
+
* grammar's structural expectation into domain suggestions. */
|
|
50
|
+
complete?: Record<string, (ctx: CompletionContext) => CompletionItem[]>;
|
|
51
|
+
};
|
|
52
|
+
/** Grammar the service drives: an interpreter combinator or a compiled entry fn. */
|
|
53
|
+
type Grammar = Combinator<unknown> | ((input: string, pos: number, ctx: ParseContext) => ParseResult<unknown>);
|
|
54
|
+
/**
|
|
55
|
+
* What you hand `languageService`:
|
|
56
|
+
* - a single entry (combinator or `compile()`d fn) — stateless methods only, or
|
|
57
|
+
* - `{ rules, root }` (a `rules()` registry + its root rule name) — also unlocks
|
|
58
|
+
* `openDocument`, the live incremental editor document.
|
|
59
|
+
*/
|
|
60
|
+
export type GrammarInput = Grammar | {
|
|
61
|
+
rules: Registry<NodeLike>;
|
|
62
|
+
root: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* A live incremental document — the fused editor backend. Holds a tolerant
|
|
66
|
+
* `parseDoc` whose tree survives broken input (recovery) and re-parses only the
|
|
67
|
+
* edited span on `edit()`. Diagnostics walk the maintained tree (recovered errors
|
|
68
|
+
* ride inside it as `parseError` nodes), so they stay complete across edits without
|
|
69
|
+
* re-parsing the whole document.
|
|
70
|
+
*/
|
|
71
|
+
export type LsDocument = {
|
|
72
|
+
/** The current CST with ABSOLUTE spans (recovered errors embedded as parseError nodes). */
|
|
73
|
+
readonly tree: LsNode | null;
|
|
74
|
+
/** Apply an editor change (byte offsets in the CURRENT text); returns the next document. */
|
|
75
|
+
edit(from: number, to: number, replacement: string): LsDocument;
|
|
76
|
+
/** Structural parse errors (from the tree) + your per-node-type lint rules. */
|
|
77
|
+
diagnostics(): Diagnostic[];
|
|
78
|
+
/** Completions at a cursor offset in the current text. */
|
|
79
|
+
completionsAt(offset: number): CompletionItem[];
|
|
80
|
+
};
|
|
81
|
+
export type LanguageService = {
|
|
82
|
+
parse(src: string, opts?: {
|
|
83
|
+
tolerant?: boolean;
|
|
84
|
+
}): ParseResult<unknown> & {
|
|
85
|
+
errors: ParseError[];
|
|
86
|
+
};
|
|
87
|
+
diagnostics(src: string): Diagnostic[];
|
|
88
|
+
completionsAt(src: string, offset: number): CompletionItem[];
|
|
89
|
+
/** Open a live incremental document. Requires `languageService({ rules, root }, …)`. */
|
|
90
|
+
openDocument(src: string): LsDocument;
|
|
91
|
+
};
|
|
92
|
+
export declare function languageService(grammar: GrammarInput, config?: LanguageServiceConfig): LanguageService;
|
|
93
|
+
export {};
|
|
94
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/language-service/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,I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