@willbooster/web-tree-sitter 1.0.41 → 1.1.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 +34 -8
- package/debug/web-tree-sitter.wasm +0 -0
- package/debug/web-tree-sitter.wasm.map +2 -2
- package/dsl.d.ts +445 -0
- package/package.json +11 -4
- package/web-tree-sitter.wasm +0 -0
- package/web-tree-sitter.wasm.map +2 -2
package/dsl.d.ts
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
/*
|
|
2
|
+
The MIT License (MIT)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2018 Max Brunsfeld
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// Based on tree-sitter-cli 0.27.0, with receiver-free signatures for destructured CLI globals.
|
|
26
|
+
export type AliasRule = { type: 'ALIAS'; named: boolean; content: Rule; value: string };
|
|
27
|
+
export type BlankRule = { type: 'BLANK' };
|
|
28
|
+
export type ChoiceRule = { type: 'CHOICE'; members: Rule[] };
|
|
29
|
+
export type FieldRule = { type: 'FIELD'; name: string; content: Rule };
|
|
30
|
+
export type ImmediateTokenRule = { type: 'IMMEDIATE_TOKEN'; content: Rule };
|
|
31
|
+
export type PatternRule = { type: 'PATTERN'; value: string; flags?: string };
|
|
32
|
+
export type PrecedenceValue = string | number;
|
|
33
|
+
export type PrecDynamicRule = { type: 'PREC_DYNAMIC'; content: Rule; value: number };
|
|
34
|
+
export type PrecLeftRule = { type: 'PREC_LEFT'; content: Rule; value: PrecedenceValue };
|
|
35
|
+
export type PrecRightRule = { type: 'PREC_RIGHT'; content: Rule; value: PrecedenceValue };
|
|
36
|
+
export type PrecRule = { type: 'PREC'; content: Rule; value: PrecedenceValue };
|
|
37
|
+
export type Repeat1Rule = { type: 'REPEAT1'; content: Rule };
|
|
38
|
+
export type RepeatRule = { type: 'REPEAT'; content: Rule };
|
|
39
|
+
export type ReservedRule = { type: 'RESERVED'; content: Rule; context_name: string };
|
|
40
|
+
export type SeqRule = { type: 'SEQ'; members: Rule[] };
|
|
41
|
+
export type StringRule = { type: 'STRING'; value: string };
|
|
42
|
+
export type SymbolRule<Name extends string> = { type: 'SYMBOL'; name: Name };
|
|
43
|
+
export type PrecedenceEntry = StringRule | SymbolRule<string>;
|
|
44
|
+
export type TokenRule = { type: 'TOKEN'; content: Rule };
|
|
45
|
+
export type EOFRule = { type: 'EOF' };
|
|
46
|
+
|
|
47
|
+
export type Rule =
|
|
48
|
+
| AliasRule
|
|
49
|
+
| BlankRule
|
|
50
|
+
| ChoiceRule
|
|
51
|
+
| FieldRule
|
|
52
|
+
| ImmediateTokenRule
|
|
53
|
+
| PatternRule
|
|
54
|
+
| PrecDynamicRule
|
|
55
|
+
| PrecLeftRule
|
|
56
|
+
| PrecRightRule
|
|
57
|
+
| PrecRule
|
|
58
|
+
| Repeat1Rule
|
|
59
|
+
| RepeatRule
|
|
60
|
+
| ReservedRule
|
|
61
|
+
| SeqRule
|
|
62
|
+
| StringRule
|
|
63
|
+
| SymbolRule<string>
|
|
64
|
+
| TokenRule
|
|
65
|
+
| EOFRule;
|
|
66
|
+
|
|
67
|
+
export interface RustRegex {
|
|
68
|
+
value: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type RuleOrLiteral = Rule | RegExp | RustRegex | string;
|
|
72
|
+
|
|
73
|
+
export type GrammarSymbols<RuleName extends string> = {
|
|
74
|
+
[name in RuleName]: SymbolRule<name>;
|
|
75
|
+
} & Record<string, SymbolRule<string>>;
|
|
76
|
+
|
|
77
|
+
export type RuleBuilder<RuleName extends string> = ($: GrammarSymbols<RuleName>, previous?: Rule) => RuleOrLiteral;
|
|
78
|
+
|
|
79
|
+
export type RuleBuilders<RuleName extends string, BaseGrammarRuleName extends string> = {
|
|
80
|
+
[name in RuleName]: RuleBuilder<RuleName | BaseGrammarRuleName>;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export interface Grammar<
|
|
84
|
+
RuleName extends string,
|
|
85
|
+
BaseGrammarRuleName extends string = never,
|
|
86
|
+
Rules extends RuleBuilders<RuleName, BaseGrammarRuleName> = RuleBuilders<RuleName, BaseGrammarRuleName>,
|
|
87
|
+
> {
|
|
88
|
+
/**
|
|
89
|
+
* Name of the grammar language.
|
|
90
|
+
*/
|
|
91
|
+
name: string;
|
|
92
|
+
|
|
93
|
+
/** Mapping of grammar rule names to rule builder functions. */
|
|
94
|
+
rules: Rules;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* An array of arrays of precedence names or rules. Each inner array represents
|
|
98
|
+
* a *descending* ordering. Names/rules listed earlier in one of these arrays
|
|
99
|
+
* have higher precedence than any names/rules listed later in the same array.
|
|
100
|
+
*
|
|
101
|
+
* Using rules is just a shorthand way for using a name then calling prec()
|
|
102
|
+
* with that name. It is just a convenience.
|
|
103
|
+
*/
|
|
104
|
+
precedences?: (
|
|
105
|
+
$: GrammarSymbols<RuleName | BaseGrammarRuleName>,
|
|
106
|
+
previous: PrecedenceEntry[][]
|
|
107
|
+
) => (string | PrecedenceEntry)[][];
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* An array of arrays of rule names. Each inner array represents a set of
|
|
111
|
+
* rules that's involved in an _LR(1) conflict_ that is _intended to exist_
|
|
112
|
+
* in the grammar. When these conflicts occur at runtime, Tree-sitter will
|
|
113
|
+
* use the GLR algorithm to explore all of the possible interpretations. If
|
|
114
|
+
* _multiple_ parses end up succeeding, Tree-sitter will pick the subtree
|
|
115
|
+
* whose corresponding rule has the highest total _dynamic precedence_.
|
|
116
|
+
*
|
|
117
|
+
* @param $ grammar rules
|
|
118
|
+
*/
|
|
119
|
+
conflicts?: (
|
|
120
|
+
$: GrammarSymbols<RuleName | BaseGrammarRuleName>,
|
|
121
|
+
previous: SymbolRule<string>[][]
|
|
122
|
+
) => SymbolRule<string>[][];
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* An array of token names which can be returned by an _external scanner_.
|
|
126
|
+
* External scanners allow you to write custom C code which runs during the
|
|
127
|
+
* lexing process in order to handle lexical rules (e.g. Python's indentation
|
|
128
|
+
* tokens) that cannot be described by regular expressions.
|
|
129
|
+
*
|
|
130
|
+
* @param $ grammar rules
|
|
131
|
+
* @param previous array of externals from the base schema, if any
|
|
132
|
+
*
|
|
133
|
+
* @see https://tree-sitter.github.io/tree-sitter/creating-parsers/4-external-scanners
|
|
134
|
+
*/
|
|
135
|
+
externals?: ($: Record<string, SymbolRule<string>>, previous: Rule[]) => RuleOrLiteral[];
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* An array of tokens that may appear anywhere in the language. This
|
|
139
|
+
* is often used for whitespace and comments. The default value of
|
|
140
|
+
* extras is to accept whitespace. To control whitespace explicitly,
|
|
141
|
+
* specify extras: `$ => []` in your grammar.
|
|
142
|
+
*
|
|
143
|
+
* @param $ grammar rules
|
|
144
|
+
* @param previous array of extras from the base grammar
|
|
145
|
+
*/
|
|
146
|
+
extras?: ($: GrammarSymbols<RuleName | BaseGrammarRuleName>, previous: Rule[]) => RuleOrLiteral[];
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* An array of rules that should be automatically removed from the
|
|
150
|
+
* grammar by replacing all of their usages with a copy of their definition.
|
|
151
|
+
* This is useful for rules that are used in multiple places but for which
|
|
152
|
+
* you don't want to create syntax tree nodes at runtime.
|
|
153
|
+
*
|
|
154
|
+
* @param $ grammar rules
|
|
155
|
+
*/
|
|
156
|
+
inline?: ($: GrammarSymbols<RuleName | BaseGrammarRuleName>, previous: SymbolRule<string>[]) => SymbolRule<string>[];
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* A list of hidden rule names that should be considered supertypes in the
|
|
160
|
+
* generated node types file.
|
|
161
|
+
*
|
|
162
|
+
* @param $ grammar rules
|
|
163
|
+
*
|
|
164
|
+
* @see https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types
|
|
165
|
+
*/
|
|
166
|
+
supertypes?: (
|
|
167
|
+
$: GrammarSymbols<RuleName | BaseGrammarRuleName>,
|
|
168
|
+
previous: SymbolRule<string>[]
|
|
169
|
+
) => SymbolRule<string>[];
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* The name of a token that will match keywords for the purpose of the
|
|
173
|
+
* keyword extraction optimization.
|
|
174
|
+
*
|
|
175
|
+
* @param $ grammar rules
|
|
176
|
+
*
|
|
177
|
+
* @see https://tree-sitter.github.io/tree-sitter/creating-parsers/3-writing-the-grammar#keyword-extraction
|
|
178
|
+
*/
|
|
179
|
+
word?: ($: GrammarSymbols<RuleName | BaseGrammarRuleName>) => SymbolRule<string>;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Mapping of names to reserved word sets. The first reserved word set is the
|
|
183
|
+
* global word set, meaning it applies to every rule in every parse state.
|
|
184
|
+
* The other word sets can be used with the `reserved` function. Each callback
|
|
185
|
+
* receives the base grammar's reserved word set of the same name as its second
|
|
186
|
+
* argument, or `undefined` if no matching set exists.
|
|
187
|
+
*/
|
|
188
|
+
reserved?: Record<
|
|
189
|
+
string,
|
|
190
|
+
($: GrammarSymbols<RuleName | BaseGrammarRuleName>, previous: Rule[] | undefined) => RuleOrLiteral[]
|
|
191
|
+
>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Return type of grammar(). The runtime evaluates and normalizes the grammar
|
|
196
|
+
* beneath a "grammar" key. Optional input fields become required output fields
|
|
197
|
+
* with default values when not provided.
|
|
198
|
+
*/
|
|
199
|
+
export type GrammarSchema<RuleName extends string> = {
|
|
200
|
+
grammar: {
|
|
201
|
+
name: string;
|
|
202
|
+
/** Base grammar name when extending; undefined for root grammars. */
|
|
203
|
+
inherits: string | undefined;
|
|
204
|
+
rules: Record<RuleName, Rule>;
|
|
205
|
+
precedences: PrecedenceEntry[][];
|
|
206
|
+
conflicts: string[][];
|
|
207
|
+
externals: Rule[];
|
|
208
|
+
extras: Rule[];
|
|
209
|
+
inline: string[];
|
|
210
|
+
supertypes: string[];
|
|
211
|
+
word: string | undefined;
|
|
212
|
+
reserved: Record<string, Rule[]>;
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/** Globals injected into grammar modules by the Tree-sitter CLI. */
|
|
217
|
+
export interface DSL {
|
|
218
|
+
RustRegex: new (pattern: string) => RustRegex;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Causes the given rule to appear with an alternative name in the syntax tree.
|
|
222
|
+
* For instance with `alias($.foo, 'bar')`, the aliased rule will appear as an
|
|
223
|
+
* anonymous node, as if the rule had been written as the simple string.
|
|
224
|
+
*
|
|
225
|
+
* @param rule rule that will be aliased
|
|
226
|
+
* @param name target name for the alias
|
|
227
|
+
*/
|
|
228
|
+
alias(this: void, rule: RuleOrLiteral, name: string): AliasRule;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Causes the given rule to appear as an alternative named node, for instance
|
|
232
|
+
* with `alias($.foo, $.bar)`, the aliased rule `foo` will appear as a named
|
|
233
|
+
* node called `bar`.
|
|
234
|
+
*
|
|
235
|
+
* @param rule rule that will be aliased
|
|
236
|
+
* @param symbol target symbol for the alias
|
|
237
|
+
*/
|
|
238
|
+
alias(this: void, rule: RuleOrLiteral, symbol: SymbolRule<string>): AliasRule;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Creates a blank rule, matching nothing.
|
|
242
|
+
*/
|
|
243
|
+
blank(this: void): BlankRule;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Assigns a field name to the child node(s) matched by the given rule.
|
|
247
|
+
* In the resulting syntax tree, you can then use that field name to
|
|
248
|
+
* access specific children.
|
|
249
|
+
*
|
|
250
|
+
* @param name name of the field
|
|
251
|
+
* @param rule rule the field should match
|
|
252
|
+
*/
|
|
253
|
+
field(this: void, name: string, rule: RuleOrLiteral): FieldRule;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Creates a rule that matches one of a set of possible rules. The order
|
|
257
|
+
* of the arguments does not matter. This is analogous to the `|` (pipe)
|
|
258
|
+
* operator in EBNF notation.
|
|
259
|
+
*
|
|
260
|
+
* @param options possible rule choices
|
|
261
|
+
*/
|
|
262
|
+
choice(this: void, ...options: RuleOrLiteral[]): ChoiceRule;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Creates a rule that matches zero or one occurrence of a given rule.
|
|
266
|
+
* It is analogous to the `[x]` (square bracket) syntax in EBNF notation.
|
|
267
|
+
*
|
|
268
|
+
* @param rule rule to be made optional
|
|
269
|
+
*/
|
|
270
|
+
optional(this: void, rule: RuleOrLiteral): ChoiceRule;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Marks the given rule with a precedence which will be used to resolve LR(1)
|
|
274
|
+
* conflicts at parser-generation time. When two rules overlap in a way that
|
|
275
|
+
* represents either a true ambiguity or a _local_ ambiguity given one token
|
|
276
|
+
* of lookahead, Tree-sitter will try to resolve the conflict by matching the
|
|
277
|
+
* rule with the higher precedence.
|
|
278
|
+
*
|
|
279
|
+
* Precedence values can either be strings or numbers. When comparing rules
|
|
280
|
+
* with numerical precedence, higher numbers indicate higher precedences. To
|
|
281
|
+
* compare rules with string precedence, Tree-sitter uses the grammar's `precedences`
|
|
282
|
+
* field.
|
|
283
|
+
*
|
|
284
|
+
* The default precedence of all rules is zero. This works similarly to the precedence directives in Yacc grammars.
|
|
285
|
+
*
|
|
286
|
+
* @param value precedence weight
|
|
287
|
+
* @param rule rule being weighted
|
|
288
|
+
*
|
|
289
|
+
* @see https://en.wikipedia.org/wiki/LR_parser#Conflicts_in_the_constructed_tables
|
|
290
|
+
* @see https://docs.oracle.com/cd/E19504-01/802-5880/6i9k05dh3/index.html
|
|
291
|
+
*/
|
|
292
|
+
prec: {
|
|
293
|
+
(this: void, value: string | number, rule: RuleOrLiteral): PrecRule;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Marks the given rule as left-associative (and optionally applies a
|
|
297
|
+
* numerical precedence). When an LR(1) conflict arises in which all of the
|
|
298
|
+
* rules have the same numerical precedence, Tree-sitter will consult the
|
|
299
|
+
* rules' associativity. If there is a left-associative rule, Tree-sitter
|
|
300
|
+
* will prefer matching a rule that ends _earlier_. This works similarly to
|
|
301
|
+
* associativity directives in Yacc grammars.
|
|
302
|
+
*
|
|
303
|
+
* @param value (optional) precedence weight
|
|
304
|
+
* @param rule rule to mark as left-associative
|
|
305
|
+
*
|
|
306
|
+
* @see https://docs.oracle.com/cd/E19504-01/802-5880/6i9k05dh3/index.html
|
|
307
|
+
*/
|
|
308
|
+
left(this: void, rule: RuleOrLiteral): PrecLeftRule;
|
|
309
|
+
left(this: void, value: string | number, rule: RuleOrLiteral): PrecLeftRule;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Marks the given rule as right-associative (and optionally applies a
|
|
313
|
+
* numerical precedence). When an LR(1) conflict arises in which all of the
|
|
314
|
+
* rules have the same numerical precedence, Tree-sitter will consult the
|
|
315
|
+
* rules' associativity. If there is a right-associative rule, Tree-sitter
|
|
316
|
+
* will prefer matching a rule that ends _later_. This works similarly to
|
|
317
|
+
* associativity directives in Yacc grammars.
|
|
318
|
+
*
|
|
319
|
+
* @param value (optional) precedence weight
|
|
320
|
+
* @param rule rule to mark as right-associative
|
|
321
|
+
*
|
|
322
|
+
* @see https://docs.oracle.com/cd/E19504-01/802-5880/6i9k05dh3/index.html
|
|
323
|
+
*/
|
|
324
|
+
right(this: void, rule: RuleOrLiteral): PrecRightRule;
|
|
325
|
+
right(this: void, value: string | number, rule: RuleOrLiteral): PrecRightRule;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Marks the given rule with a numerical precedence which will be used to
|
|
329
|
+
* resolve LR(1) conflicts at _runtime_ instead of parser-generation time.
|
|
330
|
+
* This is only necessary when handling a conflict dynamically using the
|
|
331
|
+
* `conflicts` field in the grammar, and when there is a genuine _ambiguity_:
|
|
332
|
+
* multiple rules correctly match a given piece of code. In that event,
|
|
333
|
+
* Tree-sitter compares the total dynamic precedence associated with each
|
|
334
|
+
* rule, and selects the one with the highest total. This is similar to
|
|
335
|
+
* dynamic precedence directives in Bison grammars.
|
|
336
|
+
*
|
|
337
|
+
* @param value precedence weight
|
|
338
|
+
* @param rule rule being weighted
|
|
339
|
+
*
|
|
340
|
+
* @see https://www.gnu.org/software/bison/manual/html_node/Generalized-LR-Parsing.html
|
|
341
|
+
*/
|
|
342
|
+
dynamic(this: void, value: number, rule: RuleOrLiteral): PrecDynamicRule;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Creates a rule that matches _zero-or-more_ occurrences of a given rule.
|
|
347
|
+
* It is analogous to the `{x}` (curly brace) syntax in EBNF notation. This
|
|
348
|
+
* rule is implemented in terms of `repeat1` but is included because it
|
|
349
|
+
* is very commonly used.
|
|
350
|
+
*
|
|
351
|
+
* @param rule rule to repeat, zero or more times
|
|
352
|
+
*/
|
|
353
|
+
repeat(this: void, rule: RuleOrLiteral): RepeatRule;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Creates a rule that matches one-or-more occurrences of a given rule.
|
|
357
|
+
*
|
|
358
|
+
* @param rule rule to repeat, one or more times
|
|
359
|
+
*/
|
|
360
|
+
repeat1(this: void, rule: RuleOrLiteral): Repeat1Rule;
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Overrides the global reserved word set for a given rule. The word set name
|
|
364
|
+
* should be defined in the `reserved` field in the grammar.
|
|
365
|
+
*
|
|
366
|
+
* @param wordset name of the reserved word set
|
|
367
|
+
* @param rule rule that will use the reserved word set
|
|
368
|
+
*/
|
|
369
|
+
reserved(this: void, wordset: string, rule: RuleOrLiteral): ReservedRule;
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Creates a rule that matches any number of other rules, one after another.
|
|
373
|
+
* It is analogous to simply writing multiple symbols next to each other
|
|
374
|
+
* in EBNF notation.
|
|
375
|
+
*
|
|
376
|
+
* @param rules ordered rules that comprise the sequence
|
|
377
|
+
*/
|
|
378
|
+
seq(this: void, ...rules: RuleOrLiteral[]): SeqRule;
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Creates a symbol rule, representing another rule in the grammar by name.
|
|
382
|
+
*
|
|
383
|
+
* @param name name of the target rule
|
|
384
|
+
*/
|
|
385
|
+
sym<Name extends string>(this: void, name: Name): SymbolRule<Name>;
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Marks the given rule as producing only a single token. Tree-sitter's
|
|
389
|
+
* default is to treat each string or RegExp literal in the grammar as a
|
|
390
|
+
* separate token. Each token is matched separately by the lexer and
|
|
391
|
+
* returned as its own leaf node in the tree. The token function allows
|
|
392
|
+
* you to express a complex rule using the DSL functions (rather
|
|
393
|
+
* than as a single regular expression) but still have Tree-sitter treat
|
|
394
|
+
* it as a single token.
|
|
395
|
+
*
|
|
396
|
+
* @param rule rule to represent as a single token
|
|
397
|
+
*/
|
|
398
|
+
token: {
|
|
399
|
+
(this: void, rule: RuleOrLiteral): TokenRule;
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Marks the given rule as producing an immediate token. This allows
|
|
403
|
+
* the parser to produce a different token based on whether or not
|
|
404
|
+
* there are `extras` preceding the token's main content. When there
|
|
405
|
+
* are _no_ leading `extras`, an immediate token is preferred over a
|
|
406
|
+
* normal token which would otherwise match.
|
|
407
|
+
*
|
|
408
|
+
* @param rule rule to represent as an immediate token
|
|
409
|
+
*/
|
|
410
|
+
immediate(this: void, rule: RuleOrLiteral): ImmediateTokenRule;
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Matches the end of input. May only appear as the final symbol of a
|
|
415
|
+
* (possibly nested) sequence; a production ending in `eof()` reduces only
|
|
416
|
+
* when the lookahead is end-of-input, rather than shifting a token.
|
|
417
|
+
*
|
|
418
|
+
* Choice branches that continue past `eof()` are dropped as unreachable,
|
|
419
|
+
* and `eof()` is not allowed inside `token()`.
|
|
420
|
+
*
|
|
421
|
+
* Useful when a rule should match either an explicit terminator (e.g. a
|
|
422
|
+
* newline) or the end of the file.
|
|
423
|
+
*/
|
|
424
|
+
eof(this: void): EOFRule;
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Creates a new language grammar with the provided schema.
|
|
428
|
+
*
|
|
429
|
+
* @param options grammar options
|
|
430
|
+
*/
|
|
431
|
+
grammar<RuleName extends string>(this: void, options: Grammar<RuleName>): GrammarSchema<RuleName>;
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Extends an existing language grammar with the provided options,
|
|
435
|
+
* creating a new language.
|
|
436
|
+
*
|
|
437
|
+
* @param baseGrammar base grammar schema to extend from
|
|
438
|
+
* @param options grammar options for the new extended language
|
|
439
|
+
*/
|
|
440
|
+
grammar<BaseGrammarRuleName extends string, RuleName extends string>(
|
|
441
|
+
this: void,
|
|
442
|
+
baseGrammar: GrammarSchema<BaseGrammarRuleName>,
|
|
443
|
+
options: Grammar<RuleName, BaseGrammarRuleName>
|
|
444
|
+
): GrammarSchema<RuleName | BaseGrammarRuleName>;
|
|
445
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/web-tree-sitter",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Tree-sitter bindings for the web",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -50,7 +50,10 @@
|
|
|
50
50
|
"default": "./debug/web-tree-sitter.cjs"
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
|
-
"./debug/web-tree-sitter.wasm": "./debug/web-tree-sitter.wasm"
|
|
53
|
+
"./debug/web-tree-sitter.wasm": "./debug/web-tree-sitter.wasm",
|
|
54
|
+
"./dsl": {
|
|
55
|
+
"types": "./dsl.d.ts"
|
|
56
|
+
}
|
|
54
57
|
},
|
|
55
58
|
"browser": {
|
|
56
59
|
"fs": false,
|
|
@@ -62,6 +65,9 @@
|
|
|
62
65
|
"*": {
|
|
63
66
|
"debug": [
|
|
64
67
|
"web-tree-sitter.d.ts"
|
|
68
|
+
],
|
|
69
|
+
"dsl": [
|
|
70
|
+
"dsl.d.ts"
|
|
65
71
|
]
|
|
66
72
|
}
|
|
67
73
|
},
|
|
@@ -89,7 +95,8 @@
|
|
|
89
95
|
"web-tree-sitter.d.ts",
|
|
90
96
|
"web-tree-sitter.d.ts.map",
|
|
91
97
|
"web-tree-sitter.d.cts",
|
|
92
|
-
"web-tree-sitter.d.cts.map"
|
|
98
|
+
"web-tree-sitter.d.cts.map",
|
|
99
|
+
"dsl.d.ts"
|
|
93
100
|
],
|
|
94
101
|
"dependencies": {
|
|
95
102
|
"@types/emscripten": "^1.41.5"
|
|
@@ -124,7 +131,7 @@
|
|
|
124
131
|
"test:watch": "vitest",
|
|
125
132
|
"prepack": "cp ../../LICENSE .",
|
|
126
133
|
"postpack": "rm LICENSE",
|
|
127
|
-
"prepublishOnly": "tsx script/check-artifacts-fresh.ts"
|
|
134
|
+
"prepublishOnly": "node script/checkDslTypes.js && tsx script/check-artifacts-fresh.ts"
|
|
128
135
|
},
|
|
129
136
|
"publishConfig": {
|
|
130
137
|
"access": "public",
|
package/web-tree-sitter.wasm
CHANGED
|
Binary file
|