@tenzir/codemirror-lang-tql 0.4.8 → 0.5.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/LICENSE +21 -0
- package/README.md +342 -8
- package/dist/index.cjs +630 -103
- package/dist/index.d.cts +141 -4
- package/dist/index.d.ts +141 -4
- package/dist/index.js +627 -102
- package/package.json +31 -18
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,141 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { defineLanguageFacet, LanguageSupport } from '@codemirror/language';
|
|
2
|
+
import { Parser, ParseWrapper, Input, TreeFragment, PartialParse } from '@lezer/common';
|
|
3
|
+
import * as TreeSitter from 'web-tree-sitter';
|
|
4
|
+
import { Tag, Highlighter } from '@lezer/highlight';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The style tags that the highlight query's captures map to by default.
|
|
8
|
+
*
|
|
9
|
+
* A capture without an entry of its own falls back to its parent capture by
|
|
10
|
+
* dropping trailing components, so `@function.builtin` resolves like
|
|
11
|
+
* `@function`. Captures that resolve to no tag do not color anything.
|
|
12
|
+
*/
|
|
13
|
+
declare const tqlCaptureTags: Readonly<Record<string, Tag>>;
|
|
14
|
+
/**
|
|
15
|
+
* Style tags by capture name that replace the defaults of `tqlCaptureTags`.
|
|
16
|
+
* An entry covers the captures that refine it unless they have entries of
|
|
17
|
+
* their own, so `punctuation` covers `punctuation.bracket`. `null` leaves a
|
|
18
|
+
* capture out: its node then shows the color of the node around it, as
|
|
19
|
+
* tree-sitter themes do for captures they do not style.
|
|
20
|
+
*/
|
|
21
|
+
type TqlCaptureTags = Readonly<Record<string, Tag | null>>;
|
|
22
|
+
/**
|
|
23
|
+
* A highlighter that styles TQL by capture name, the way tree-sitter themes
|
|
24
|
+
* do: `classes` maps capture names to CSS classes, and a capture without an
|
|
25
|
+
* entry takes the class of the nearest capture it refines, so a `function`
|
|
26
|
+
* entry covers `function.call` and `function.method`. Unlike `tagHighlighter`,
|
|
27
|
+
* this does not fall back to a tag's parents, so `function.call` never takes
|
|
28
|
+
* the class of `variable`.
|
|
29
|
+
*/
|
|
30
|
+
declare const tqlHighlighter: (classes: Readonly<Record<string, string>>) => Highlighter;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The parts of web-tree-sitter that TQL's language support needs: the
|
|
34
|
+
* classes of the instance that loaded the grammar, after `Parser.init()`, and
|
|
35
|
+
* the grammar itself from `Language.load()`.
|
|
36
|
+
*/
|
|
37
|
+
interface TqlTreeSitter {
|
|
38
|
+
readonly Parser: typeof TreeSitter.Parser;
|
|
39
|
+
readonly Query: typeof TreeSitter.Query;
|
|
40
|
+
readonly language: TreeSitter.Language;
|
|
41
|
+
}
|
|
42
|
+
/** The query sources and capture mapping that a TQL parser runs with. */
|
|
43
|
+
interface TqlQueries {
|
|
44
|
+
readonly highlights: string;
|
|
45
|
+
readonly indents: string;
|
|
46
|
+
readonly folds: string;
|
|
47
|
+
readonly brackets: string;
|
|
48
|
+
readonly injections: string;
|
|
49
|
+
readonly tags: TqlCaptureTags;
|
|
50
|
+
}
|
|
51
|
+
type LanguageData = ReturnType<typeof defineLanguageFacet>;
|
|
52
|
+
/**
|
|
53
|
+
* A Lezer parser that parses TQL with tree-sitter-tql and converts the result
|
|
54
|
+
* into a Lezer tree, so that CodeMirror's highlighting, bracket matching,
|
|
55
|
+
* indentation, folding, and commands work from TQL's tree-sitter grammar.
|
|
56
|
+
*
|
|
57
|
+
* Every parse parses the whole document, or the part before where CodeMirror
|
|
58
|
+
* asks it to stop, in steps targeting a few milliseconds. Native parsers and
|
|
59
|
+
* trees are freed when their work finishes. `delete()` frees the combined
|
|
60
|
+
* query and any unfinished parses; afterwards, this parser must not be used.
|
|
61
|
+
*/
|
|
62
|
+
declare class TqlParser extends Parser {
|
|
63
|
+
#private;
|
|
64
|
+
/** @internal */
|
|
65
|
+
constructor(treeSitter: TqlTreeSitter, queries: TqlQueries, data: LanguageData, wrapper?: ParseWrapper);
|
|
66
|
+
createParse(input: Input, fragments: readonly TreeFragment[], ranges: readonly {
|
|
67
|
+
from: number;
|
|
68
|
+
to: number;
|
|
69
|
+
}[]): PartialParse;
|
|
70
|
+
/** Frees the combined query and the native handles of unfinished parses. */
|
|
71
|
+
delete(): void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The queries of tree-sitter-tql that `tql` uses unless given others. */
|
|
75
|
+
declare const tqlQueries: {
|
|
76
|
+
readonly highlights: string;
|
|
77
|
+
readonly indents: string;
|
|
78
|
+
readonly folds: string;
|
|
79
|
+
readonly brackets: string;
|
|
80
|
+
readonly injections: string;
|
|
81
|
+
};
|
|
82
|
+
/** How `tql` sets up the language. */
|
|
83
|
+
interface TqlOptions {
|
|
84
|
+
/** The highlight query; tree-sitter-tql's `highlights.scm` by default. */
|
|
85
|
+
readonly highlights?: string;
|
|
86
|
+
/** The indent query; tree-sitter-tql's `indents.scm` by default. */
|
|
87
|
+
readonly indents?: string;
|
|
88
|
+
/** The fold query; tree-sitter-tql's `folds.scm` by default. */
|
|
89
|
+
readonly folds?: string;
|
|
90
|
+
/** The bracket query; tree-sitter-tql's `brackets.scm` by default. */
|
|
91
|
+
readonly brackets?: string;
|
|
92
|
+
/** The injection query; tree-sitter-tql's `injections.scm` by default. */
|
|
93
|
+
readonly injections?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Style tags by capture name over the defaults of `tqlCaptureTags`, where
|
|
96
|
+
* `null` leaves a capture out so that the node around it shows through.
|
|
97
|
+
*/
|
|
98
|
+
readonly tags?: TqlCaptureTags;
|
|
99
|
+
/**
|
|
100
|
+
* Parsers for the nodes that the injection query injects a language into,
|
|
101
|
+
* by the language's name. tree-sitter-tql injects `yaml` into the body of
|
|
102
|
+
* front matter: `yamlLanguage.parser` from `@codemirror/lang-yaml`
|
|
103
|
+
* highlights and edits it as YAML; the bare parser of `@lezer/yaml` only
|
|
104
|
+
* highlights it.
|
|
105
|
+
*/
|
|
106
|
+
readonly nested?: Readonly<Record<string, Parser>>;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* TQL language support for CodeMirror from tree-sitter-tql: highlighting,
|
|
110
|
+
* bracket matching, quote pairing, indentation, folding, and comment
|
|
111
|
+
* toggling.
|
|
112
|
+
*
|
|
113
|
+
* Takes web-tree-sitter's classes and the grammar the host loaded, after
|
|
114
|
+
* `Parser.init()` and `Language.load()`, so the host decides where the
|
|
115
|
+
* WebAssembly comes from and when it loads. Each parse owns a native parser
|
|
116
|
+
* and tree and frees them when its work finishes. The language owns the
|
|
117
|
+
* combined query, which lives in WebAssembly memory until
|
|
118
|
+
* `(support.language.parser as TqlParser).delete()` frees it along with any
|
|
119
|
+
* unfinished parses, so create the language once and share it between
|
|
120
|
+
* editors.
|
|
121
|
+
*/
|
|
122
|
+
declare function tql(treeSitter: TqlTreeSitter, options?: TqlOptions): LanguageSupport;
|
|
123
|
+
/** Where `loadTql` loads web-tree-sitter and the grammar from. */
|
|
124
|
+
interface LoadTqlOptions extends TqlOptions {
|
|
125
|
+
/**
|
|
126
|
+
* The URL of web-tree-sitter's `web-tree-sitter.wasm`. Without it,
|
|
127
|
+
* web-tree-sitter looks next to its script. Ignored when web-tree-sitter
|
|
128
|
+
* was initialized already.
|
|
129
|
+
*/
|
|
130
|
+
readonly runtimeWasmUrl?: string;
|
|
131
|
+
/** The URL of tree-sitter-tql's `tree-sitter-tql.wasm`. */
|
|
132
|
+
readonly grammarWasmUrl: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Imports web-tree-sitter on demand, initializes it unless that happened
|
|
136
|
+
* already, loads the grammar, and returns `tql()` for it.
|
|
137
|
+
*/
|
|
138
|
+
declare function loadTql(options: LoadTqlOptions): Promise<LanguageSupport>;
|
|
139
|
+
|
|
140
|
+
export { TqlParser, loadTql, tql, tqlCaptureTags, tqlHighlighter, tqlQueries };
|
|
141
|
+
export type { LoadTqlOptions, TqlCaptureTags, TqlOptions, TqlTreeSitter };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,141 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { defineLanguageFacet, LanguageSupport } from '@codemirror/language';
|
|
2
|
+
import { Parser, ParseWrapper, Input, TreeFragment, PartialParse } from '@lezer/common';
|
|
3
|
+
import * as TreeSitter from 'web-tree-sitter';
|
|
4
|
+
import { Tag, Highlighter } from '@lezer/highlight';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The style tags that the highlight query's captures map to by default.
|
|
8
|
+
*
|
|
9
|
+
* A capture without an entry of its own falls back to its parent capture by
|
|
10
|
+
* dropping trailing components, so `@function.builtin` resolves like
|
|
11
|
+
* `@function`. Captures that resolve to no tag do not color anything.
|
|
12
|
+
*/
|
|
13
|
+
declare const tqlCaptureTags: Readonly<Record<string, Tag>>;
|
|
14
|
+
/**
|
|
15
|
+
* Style tags by capture name that replace the defaults of `tqlCaptureTags`.
|
|
16
|
+
* An entry covers the captures that refine it unless they have entries of
|
|
17
|
+
* their own, so `punctuation` covers `punctuation.bracket`. `null` leaves a
|
|
18
|
+
* capture out: its node then shows the color of the node around it, as
|
|
19
|
+
* tree-sitter themes do for captures they do not style.
|
|
20
|
+
*/
|
|
21
|
+
type TqlCaptureTags = Readonly<Record<string, Tag | null>>;
|
|
22
|
+
/**
|
|
23
|
+
* A highlighter that styles TQL by capture name, the way tree-sitter themes
|
|
24
|
+
* do: `classes` maps capture names to CSS classes, and a capture without an
|
|
25
|
+
* entry takes the class of the nearest capture it refines, so a `function`
|
|
26
|
+
* entry covers `function.call` and `function.method`. Unlike `tagHighlighter`,
|
|
27
|
+
* this does not fall back to a tag's parents, so `function.call` never takes
|
|
28
|
+
* the class of `variable`.
|
|
29
|
+
*/
|
|
30
|
+
declare const tqlHighlighter: (classes: Readonly<Record<string, string>>) => Highlighter;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The parts of web-tree-sitter that TQL's language support needs: the
|
|
34
|
+
* classes of the instance that loaded the grammar, after `Parser.init()`, and
|
|
35
|
+
* the grammar itself from `Language.load()`.
|
|
36
|
+
*/
|
|
37
|
+
interface TqlTreeSitter {
|
|
38
|
+
readonly Parser: typeof TreeSitter.Parser;
|
|
39
|
+
readonly Query: typeof TreeSitter.Query;
|
|
40
|
+
readonly language: TreeSitter.Language;
|
|
41
|
+
}
|
|
42
|
+
/** The query sources and capture mapping that a TQL parser runs with. */
|
|
43
|
+
interface TqlQueries {
|
|
44
|
+
readonly highlights: string;
|
|
45
|
+
readonly indents: string;
|
|
46
|
+
readonly folds: string;
|
|
47
|
+
readonly brackets: string;
|
|
48
|
+
readonly injections: string;
|
|
49
|
+
readonly tags: TqlCaptureTags;
|
|
50
|
+
}
|
|
51
|
+
type LanguageData = ReturnType<typeof defineLanguageFacet>;
|
|
52
|
+
/**
|
|
53
|
+
* A Lezer parser that parses TQL with tree-sitter-tql and converts the result
|
|
54
|
+
* into a Lezer tree, so that CodeMirror's highlighting, bracket matching,
|
|
55
|
+
* indentation, folding, and commands work from TQL's tree-sitter grammar.
|
|
56
|
+
*
|
|
57
|
+
* Every parse parses the whole document, or the part before where CodeMirror
|
|
58
|
+
* asks it to stop, in steps targeting a few milliseconds. Native parsers and
|
|
59
|
+
* trees are freed when their work finishes. `delete()` frees the combined
|
|
60
|
+
* query and any unfinished parses; afterwards, this parser must not be used.
|
|
61
|
+
*/
|
|
62
|
+
declare class TqlParser extends Parser {
|
|
63
|
+
#private;
|
|
64
|
+
/** @internal */
|
|
65
|
+
constructor(treeSitter: TqlTreeSitter, queries: TqlQueries, data: LanguageData, wrapper?: ParseWrapper);
|
|
66
|
+
createParse(input: Input, fragments: readonly TreeFragment[], ranges: readonly {
|
|
67
|
+
from: number;
|
|
68
|
+
to: number;
|
|
69
|
+
}[]): PartialParse;
|
|
70
|
+
/** Frees the combined query and the native handles of unfinished parses. */
|
|
71
|
+
delete(): void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The queries of tree-sitter-tql that `tql` uses unless given others. */
|
|
75
|
+
declare const tqlQueries: {
|
|
76
|
+
readonly highlights: string;
|
|
77
|
+
readonly indents: string;
|
|
78
|
+
readonly folds: string;
|
|
79
|
+
readonly brackets: string;
|
|
80
|
+
readonly injections: string;
|
|
81
|
+
};
|
|
82
|
+
/** How `tql` sets up the language. */
|
|
83
|
+
interface TqlOptions {
|
|
84
|
+
/** The highlight query; tree-sitter-tql's `highlights.scm` by default. */
|
|
85
|
+
readonly highlights?: string;
|
|
86
|
+
/** The indent query; tree-sitter-tql's `indents.scm` by default. */
|
|
87
|
+
readonly indents?: string;
|
|
88
|
+
/** The fold query; tree-sitter-tql's `folds.scm` by default. */
|
|
89
|
+
readonly folds?: string;
|
|
90
|
+
/** The bracket query; tree-sitter-tql's `brackets.scm` by default. */
|
|
91
|
+
readonly brackets?: string;
|
|
92
|
+
/** The injection query; tree-sitter-tql's `injections.scm` by default. */
|
|
93
|
+
readonly injections?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Style tags by capture name over the defaults of `tqlCaptureTags`, where
|
|
96
|
+
* `null` leaves a capture out so that the node around it shows through.
|
|
97
|
+
*/
|
|
98
|
+
readonly tags?: TqlCaptureTags;
|
|
99
|
+
/**
|
|
100
|
+
* Parsers for the nodes that the injection query injects a language into,
|
|
101
|
+
* by the language's name. tree-sitter-tql injects `yaml` into the body of
|
|
102
|
+
* front matter: `yamlLanguage.parser` from `@codemirror/lang-yaml`
|
|
103
|
+
* highlights and edits it as YAML; the bare parser of `@lezer/yaml` only
|
|
104
|
+
* highlights it.
|
|
105
|
+
*/
|
|
106
|
+
readonly nested?: Readonly<Record<string, Parser>>;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* TQL language support for CodeMirror from tree-sitter-tql: highlighting,
|
|
110
|
+
* bracket matching, quote pairing, indentation, folding, and comment
|
|
111
|
+
* toggling.
|
|
112
|
+
*
|
|
113
|
+
* Takes web-tree-sitter's classes and the grammar the host loaded, after
|
|
114
|
+
* `Parser.init()` and `Language.load()`, so the host decides where the
|
|
115
|
+
* WebAssembly comes from and when it loads. Each parse owns a native parser
|
|
116
|
+
* and tree and frees them when its work finishes. The language owns the
|
|
117
|
+
* combined query, which lives in WebAssembly memory until
|
|
118
|
+
* `(support.language.parser as TqlParser).delete()` frees it along with any
|
|
119
|
+
* unfinished parses, so create the language once and share it between
|
|
120
|
+
* editors.
|
|
121
|
+
*/
|
|
122
|
+
declare function tql(treeSitter: TqlTreeSitter, options?: TqlOptions): LanguageSupport;
|
|
123
|
+
/** Where `loadTql` loads web-tree-sitter and the grammar from. */
|
|
124
|
+
interface LoadTqlOptions extends TqlOptions {
|
|
125
|
+
/**
|
|
126
|
+
* The URL of web-tree-sitter's `web-tree-sitter.wasm`. Without it,
|
|
127
|
+
* web-tree-sitter looks next to its script. Ignored when web-tree-sitter
|
|
128
|
+
* was initialized already.
|
|
129
|
+
*/
|
|
130
|
+
readonly runtimeWasmUrl?: string;
|
|
131
|
+
/** The URL of tree-sitter-tql's `tree-sitter-tql.wasm`. */
|
|
132
|
+
readonly grammarWasmUrl: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Imports web-tree-sitter on demand, initializes it unless that happened
|
|
136
|
+
* already, loads the grammar, and returns `tql()` for it.
|
|
137
|
+
*/
|
|
138
|
+
declare function loadTql(options: LoadTqlOptions): Promise<LanguageSupport>;
|
|
139
|
+
|
|
140
|
+
export { TqlParser, loadTql, tql, tqlCaptureTags, tqlHighlighter, tqlQueries };
|
|
141
|
+
export type { LoadTqlOptions, TqlCaptureTags, TqlOptions, TqlTreeSitter };
|