@kerebron/tree-sitter 0.4.26 → 0.4.27
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/package.json +2 -1
- package/esm/deno-tree-sitter/main/extended/base_node.d.ts +0 -48
- package/esm/deno-tree-sitter/main/extended/base_node.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/extended/base_node.js +0 -154
- package/esm/deno-tree-sitter/main/extended/node_extended.d.ts +0 -237
- package/esm/deno-tree-sitter/main/extended/node_extended.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/extended/node_extended.js +0 -572
- package/esm/deno-tree-sitter/main/extended/parser.d.ts +0 -37
- package/esm/deno-tree-sitter/main/extended/parser.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/extended/parser.js +0 -86
- package/esm/deno-tree-sitter/main/extended/soft_node.d.ts +0 -15
- package/esm/deno-tree-sitter/main/extended/soft_node.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/extended/soft_node.js +0 -27
- package/esm/deno-tree-sitter/main/extended/soft_text_node.d.ts +0 -10
- package/esm/deno-tree-sitter/main/extended/soft_text_node.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/extended/soft_text_node.js +0 -10
- package/esm/deno-tree-sitter/main/extended/whitespace_node.d.ts +0 -10
- package/esm/deno-tree-sitter/main/extended/whitespace_node.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/extended/whitespace_node.js +0 -10
- package/esm/deno-tree-sitter/main/extras/misc.d.ts +0 -2
- package/esm/deno-tree-sitter/main/extras/misc.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/extras/misc.js +0 -13
- package/esm/deno-tree-sitter/main/tree_sitter/bindings.d.ts +0 -14
- package/esm/deno-tree-sitter/main/tree_sitter/bindings.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/tree_sitter/bindings.js +0 -21
- package/esm/deno-tree-sitter/main/tree_sitter/constants.d.ts +0 -60
- package/esm/deno-tree-sitter/main/tree_sitter/constants.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/tree_sitter/constants.js +0 -66
- package/esm/deno-tree-sitter/main/tree_sitter/language.d.ts +0 -137
- package/esm/deno-tree-sitter/main/tree_sitter/language.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/tree_sitter/language.js +0 -264
- package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.d.ts +0 -41
- package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.js +0 -65
- package/esm/deno-tree-sitter/main/tree_sitter/marshal.d.ts +0 -85
- package/esm/deno-tree-sitter/main/tree_sitter/marshal.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/tree_sitter/marshal.js +0 -173
- package/esm/deno-tree-sitter/main/tree_sitter/node.d.ts +0 -260
- package/esm/deno-tree-sitter/main/tree_sitter/node.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/tree_sitter/node.js +0 -557
- package/esm/deno-tree-sitter/main/tree_sitter/parser.d.ts +0 -124
- package/esm/deno-tree-sitter/main/tree_sitter/parser.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/tree_sitter/parser.js +0 -252
- package/esm/deno-tree-sitter/main/tree_sitter/query.d.ts +0 -134
- package/esm/deno-tree-sitter/main/tree_sitter/query.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/tree_sitter/query.js +0 -620
- package/esm/deno-tree-sitter/main/tree_sitter/tree.d.ts +0 -49
- package/esm/deno-tree-sitter/main/tree_sitter/tree.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/tree_sitter/tree.js +0 -130
- package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.d.ts +0 -165
- package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.js +0 -280
- package/esm/deno-tree-sitter/main/tree_sitter_wasm.d.ts +0 -3
- package/esm/deno-tree-sitter/main/tree_sitter_wasm.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/tree_sitter_wasm.js +0 -0
- package/esm/deno-tree-sitter/main/wasm_loader.d.ts +0 -29
- package/esm/deno-tree-sitter/main/wasm_loader.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/wasm_loader.js +0 -1702
- package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.d.ts +0 -3
- package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.d.ts.map +0 -1
- package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.js +0 -8
- package/esm/mod.d.ts +0 -7
- package/esm/mod.d.ts.map +0 -1
- package/esm/mod.js +0 -7
- package/esm/package.json +0 -3
|
@@ -1,557 +0,0 @@
|
|
|
1
|
-
import { INTERNAL, assertInternal, SIZE_OF_INT, SIZE_OF_NODE, SIZE_OF_POINT, ZERO_POINT, isPoint, C } from "./constants.js";
|
|
2
|
-
import { getText, Tree } from "./tree.js";
|
|
3
|
-
import { TreeCursor } from "./tree_cursor.js";
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
|
-
import { Language } from "./language.js";
|
|
6
|
-
import { marshalNode, marshalPoint, unmarshalNode, unmarshalPoint } from "./marshal.js";
|
|
7
|
-
import { TRANSFER_BUFFER } from "./parser.js";
|
|
8
|
-
/** A single node within a syntax {@link Tree}. */
|
|
9
|
-
export class Node {
|
|
10
|
-
/** @internal */
|
|
11
|
-
[0] = 0; // Internal handle for Wasm
|
|
12
|
-
/** @internal */
|
|
13
|
-
_children;
|
|
14
|
-
/** @internal */
|
|
15
|
-
_namedChildren;
|
|
16
|
-
/** @internal */
|
|
17
|
-
constructor(internal, { id, tree, startIndex, startPosition, other }) {
|
|
18
|
-
assertInternal(internal);
|
|
19
|
-
this[0] = other;
|
|
20
|
-
this.id = id;
|
|
21
|
-
this.tree = tree;
|
|
22
|
-
this.startIndex = startIndex;
|
|
23
|
-
this.startPosition = startPosition;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* The numeric id for this node that is unique.
|
|
27
|
-
*
|
|
28
|
-
* Within a given syntax tree, no two nodes have the same id. However:
|
|
29
|
-
*
|
|
30
|
-
* * If a new tree is created based on an older tree, and a node from the old tree is reused in
|
|
31
|
-
* the process, then that node will have the same id in both trees.
|
|
32
|
-
*
|
|
33
|
-
* * A node not marked as having changes does not guarantee it was reused.
|
|
34
|
-
*
|
|
35
|
-
* * If a node is marked as having changed in the old tree, it will not be reused.
|
|
36
|
-
*/
|
|
37
|
-
id;
|
|
38
|
-
/** The byte index where this node starts. */
|
|
39
|
-
startIndex;
|
|
40
|
-
/** The position where this node starts. */
|
|
41
|
-
startPosition;
|
|
42
|
-
/** The tree that this node belongs to. */
|
|
43
|
-
tree;
|
|
44
|
-
/** Get this node's type as a numerical id. */
|
|
45
|
-
get typeId() {
|
|
46
|
-
marshalNode(this);
|
|
47
|
-
return C._ts_node_symbol_wasm(this.tree[0]);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Get the node's type as a numerical id as it appears in the grammar,
|
|
51
|
-
* ignoring aliases.
|
|
52
|
-
*/
|
|
53
|
-
get grammarId() {
|
|
54
|
-
marshalNode(this);
|
|
55
|
-
return C._ts_node_grammar_symbol_wasm(this.tree[0]);
|
|
56
|
-
}
|
|
57
|
-
/** Get this node's type as a string. */
|
|
58
|
-
get type() {
|
|
59
|
-
return this.tree.language.types[this.typeId] || "ERROR";
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Get this node's symbol name as it appears in the grammar, ignoring
|
|
63
|
-
* aliases as a string.
|
|
64
|
-
*/
|
|
65
|
-
get grammarType() {
|
|
66
|
-
return this.tree.language.types[this.grammarId] || "ERROR";
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Check if this node is *named*.
|
|
70
|
-
*
|
|
71
|
-
* Named nodes correspond to named rules in the grammar, whereas
|
|
72
|
-
* *anonymous* nodes correspond to string literals in the grammar.
|
|
73
|
-
*/
|
|
74
|
-
get isNamed() {
|
|
75
|
-
marshalNode(this);
|
|
76
|
-
return C._ts_node_is_named_wasm(this.tree[0]) === 1;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Check if this node is *extra*.
|
|
80
|
-
*
|
|
81
|
-
* Extra nodes represent things like comments, which are not required
|
|
82
|
-
* by the grammar, but can appear anywhere.
|
|
83
|
-
*/
|
|
84
|
-
get isExtra() {
|
|
85
|
-
marshalNode(this);
|
|
86
|
-
return C._ts_node_is_extra_wasm(this.tree[0]) === 1;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Check if this node represents a syntax error.
|
|
90
|
-
*
|
|
91
|
-
* Syntax errors represent parts of the code that could not be incorporated
|
|
92
|
-
* into a valid syntax tree.
|
|
93
|
-
*/
|
|
94
|
-
get isError() {
|
|
95
|
-
marshalNode(this);
|
|
96
|
-
return C._ts_node_is_error_wasm(this.tree[0]) === 1;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Check if this node is *missing*.
|
|
100
|
-
*
|
|
101
|
-
* Missing nodes are inserted by the parser in order to recover from
|
|
102
|
-
* certain kinds of syntax errors.
|
|
103
|
-
*/
|
|
104
|
-
get isMissing() {
|
|
105
|
-
marshalNode(this);
|
|
106
|
-
return C._ts_node_is_missing_wasm(this.tree[0]) === 1;
|
|
107
|
-
}
|
|
108
|
-
/** Check if this node has been edited. */
|
|
109
|
-
get hasChanges() {
|
|
110
|
-
marshalNode(this);
|
|
111
|
-
return C._ts_node_has_changes_wasm(this.tree[0]) === 1;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Check if this node represents a syntax error or contains any syntax
|
|
115
|
-
* errors anywhere within it.
|
|
116
|
-
*/
|
|
117
|
-
get hasError() {
|
|
118
|
-
marshalNode(this);
|
|
119
|
-
return C._ts_node_has_error_wasm(this.tree[0]) === 1;
|
|
120
|
-
}
|
|
121
|
-
/** Get the byte index where this node ends. */
|
|
122
|
-
get endIndex() {
|
|
123
|
-
marshalNode(this);
|
|
124
|
-
return C._ts_node_end_index_wasm(this.tree[0]);
|
|
125
|
-
}
|
|
126
|
-
/** Get the position where this node ends. */
|
|
127
|
-
get endPosition() {
|
|
128
|
-
marshalNode(this);
|
|
129
|
-
C._ts_node_end_point_wasm(this.tree[0]);
|
|
130
|
-
return unmarshalPoint(TRANSFER_BUFFER);
|
|
131
|
-
}
|
|
132
|
-
/** Get the string content of this node. */
|
|
133
|
-
get text() {
|
|
134
|
-
return getText(this.tree, this.startIndex, this.endIndex, this.startPosition);
|
|
135
|
-
}
|
|
136
|
-
/** Get this node's parse state. */
|
|
137
|
-
get parseState() {
|
|
138
|
-
marshalNode(this);
|
|
139
|
-
return C._ts_node_parse_state_wasm(this.tree[0]);
|
|
140
|
-
}
|
|
141
|
-
/** Get the parse state after this node. */
|
|
142
|
-
get nextParseState() {
|
|
143
|
-
marshalNode(this);
|
|
144
|
-
return C._ts_node_next_parse_state_wasm(this.tree[0]);
|
|
145
|
-
}
|
|
146
|
-
/** Check if this node is equal to another node. */
|
|
147
|
-
equals(other) {
|
|
148
|
-
return this.tree === other.tree && this.id === other.id;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Get the node's child at the given index, where zero represents the first child.
|
|
152
|
-
*
|
|
153
|
-
* This method is fairly fast, but its cost is technically log(n), so if
|
|
154
|
-
* you might be iterating over a long list of children, you should use
|
|
155
|
-
* {@link Node#children} instead.
|
|
156
|
-
*/
|
|
157
|
-
child(index) {
|
|
158
|
-
marshalNode(this);
|
|
159
|
-
C._ts_node_child_wasm(this.tree[0], index);
|
|
160
|
-
return unmarshalNode(this.tree);
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Get this node's *named* child at the given index.
|
|
164
|
-
*
|
|
165
|
-
* See also {@link Node#isNamed}.
|
|
166
|
-
* This method is fairly fast, but its cost is technically log(n), so if
|
|
167
|
-
* you might be iterating over a long list of children, you should use
|
|
168
|
-
* {@link Node#namedChildren} instead.
|
|
169
|
-
*/
|
|
170
|
-
namedChild(index) {
|
|
171
|
-
marshalNode(this);
|
|
172
|
-
C._ts_node_named_child_wasm(this.tree[0], index);
|
|
173
|
-
return unmarshalNode(this.tree);
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Get this node's child with the given numerical field id.
|
|
177
|
-
*
|
|
178
|
-
* See also {@link Node#childForFieldName}. You can
|
|
179
|
-
* convert a field name to an id using {@link Language#fieldIdForName}.
|
|
180
|
-
*/
|
|
181
|
-
childForFieldId(fieldId) {
|
|
182
|
-
marshalNode(this);
|
|
183
|
-
C._ts_node_child_by_field_id_wasm(this.tree[0], fieldId);
|
|
184
|
-
return unmarshalNode(this.tree);
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Get the first child with the given field name.
|
|
188
|
-
*
|
|
189
|
-
* If multiple children may have the same field name, access them using
|
|
190
|
-
* {@link Node#childrenForFieldName}.
|
|
191
|
-
*/
|
|
192
|
-
childForFieldName(fieldName) {
|
|
193
|
-
const fieldId = this.tree.language.fields.indexOf(fieldName);
|
|
194
|
-
if (fieldId !== -1)
|
|
195
|
-
return this.childForFieldId(fieldId);
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
/** Get the field name of this node's child at the given index. */
|
|
199
|
-
fieldNameForChild(index) {
|
|
200
|
-
marshalNode(this);
|
|
201
|
-
const address = C._ts_node_field_name_for_child_wasm(this.tree[0], index);
|
|
202
|
-
if (!address)
|
|
203
|
-
return null;
|
|
204
|
-
return C.AsciiToString(address);
|
|
205
|
-
}
|
|
206
|
-
/** Get the field name of this node's named child at the given index. */
|
|
207
|
-
fieldNameForNamedChild(index) {
|
|
208
|
-
marshalNode(this);
|
|
209
|
-
const address = C._ts_node_field_name_for_named_child_wasm(this.tree[0], index);
|
|
210
|
-
if (!address)
|
|
211
|
-
return null;
|
|
212
|
-
return C.AsciiToString(address);
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Get an array of this node's children with a given field name.
|
|
216
|
-
*
|
|
217
|
-
* See also {@link Node#children}.
|
|
218
|
-
*/
|
|
219
|
-
childrenForFieldName(fieldName) {
|
|
220
|
-
const fieldId = this.tree.language.fields.indexOf(fieldName);
|
|
221
|
-
if (fieldId !== -1 && fieldId !== 0)
|
|
222
|
-
return this.childrenForFieldId(fieldId);
|
|
223
|
-
return [];
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Get an array of this node's children with a given field id.
|
|
227
|
-
*
|
|
228
|
-
* See also {@link Node#childrenForFieldName}.
|
|
229
|
-
*/
|
|
230
|
-
childrenForFieldId(fieldId) {
|
|
231
|
-
marshalNode(this);
|
|
232
|
-
C._ts_node_children_by_field_id_wasm(this.tree[0], fieldId);
|
|
233
|
-
const count = C.getValue(TRANSFER_BUFFER, "i32");
|
|
234
|
-
const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
235
|
-
const result = new Array(count);
|
|
236
|
-
if (count > 0) {
|
|
237
|
-
let address = buffer;
|
|
238
|
-
for (let i = 0; i < count; i++) {
|
|
239
|
-
result[i] = unmarshalNode(this.tree, address);
|
|
240
|
-
address += SIZE_OF_NODE;
|
|
241
|
-
}
|
|
242
|
-
C._free(buffer);
|
|
243
|
-
}
|
|
244
|
-
return result;
|
|
245
|
-
}
|
|
246
|
-
/** Get the node's first child that contains or starts after the given byte offset. */
|
|
247
|
-
firstChildForIndex(index) {
|
|
248
|
-
marshalNode(this);
|
|
249
|
-
const address = TRANSFER_BUFFER + SIZE_OF_NODE;
|
|
250
|
-
C.setValue(address, index, "i32");
|
|
251
|
-
C._ts_node_first_child_for_byte_wasm(this.tree[0]);
|
|
252
|
-
return unmarshalNode(this.tree);
|
|
253
|
-
}
|
|
254
|
-
/** Get the node's first named child that contains or starts after the given byte offset. */
|
|
255
|
-
firstNamedChildForIndex(index) {
|
|
256
|
-
marshalNode(this);
|
|
257
|
-
const address = TRANSFER_BUFFER + SIZE_OF_NODE;
|
|
258
|
-
C.setValue(address, index, "i32");
|
|
259
|
-
C._ts_node_first_named_child_for_byte_wasm(this.tree[0]);
|
|
260
|
-
return unmarshalNode(this.tree);
|
|
261
|
-
}
|
|
262
|
-
/** Get this node's number of children. */
|
|
263
|
-
get childCount() {
|
|
264
|
-
marshalNode(this);
|
|
265
|
-
return C._ts_node_child_count_wasm(this.tree[0]);
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Get this node's number of *named* children.
|
|
269
|
-
*
|
|
270
|
-
* See also {@link Node#isNamed}.
|
|
271
|
-
*/
|
|
272
|
-
get namedChildCount() {
|
|
273
|
-
marshalNode(this);
|
|
274
|
-
return C._ts_node_named_child_count_wasm(this.tree[0]);
|
|
275
|
-
}
|
|
276
|
-
/** Get this node's first child. */
|
|
277
|
-
get firstChild() {
|
|
278
|
-
return this.child(0);
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Get this node's first named child.
|
|
282
|
-
*
|
|
283
|
-
* See also {@link Node#isNamed}.
|
|
284
|
-
*/
|
|
285
|
-
get firstNamedChild() {
|
|
286
|
-
return this.namedChild(0);
|
|
287
|
-
}
|
|
288
|
-
/** Get this node's last child. */
|
|
289
|
-
get lastChild() {
|
|
290
|
-
return this.child(this.childCount - 1);
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Get this node's last named child.
|
|
294
|
-
*
|
|
295
|
-
* See also {@link Node#isNamed}.
|
|
296
|
-
*/
|
|
297
|
-
get lastNamedChild() {
|
|
298
|
-
return this.namedChild(this.namedChildCount - 1);
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Iterate over this node's children.
|
|
302
|
-
*
|
|
303
|
-
* If you're walking the tree recursively, you may want to use the
|
|
304
|
-
* {@link TreeCursor} APIs directly instead.
|
|
305
|
-
*/
|
|
306
|
-
get children() {
|
|
307
|
-
if (!this._children) {
|
|
308
|
-
marshalNode(this);
|
|
309
|
-
C._ts_node_children_wasm(this.tree[0]);
|
|
310
|
-
const count = C.getValue(TRANSFER_BUFFER, "i32");
|
|
311
|
-
const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
312
|
-
this._children = new Array(count);
|
|
313
|
-
if (count > 0) {
|
|
314
|
-
let address = buffer;
|
|
315
|
-
for (let i = 0; i < count; i++) {
|
|
316
|
-
this._children[i] = unmarshalNode(this.tree, address);
|
|
317
|
-
address += SIZE_OF_NODE;
|
|
318
|
-
}
|
|
319
|
-
C._free(buffer);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
return this._children;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Iterate over this node's named children.
|
|
326
|
-
*
|
|
327
|
-
* See also {@link Node#children}.
|
|
328
|
-
*/
|
|
329
|
-
get namedChildren() {
|
|
330
|
-
if (!this._namedChildren) {
|
|
331
|
-
marshalNode(this);
|
|
332
|
-
C._ts_node_named_children_wasm(this.tree[0]);
|
|
333
|
-
const count = C.getValue(TRANSFER_BUFFER, "i32");
|
|
334
|
-
const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
335
|
-
this._namedChildren = new Array(count);
|
|
336
|
-
if (count > 0) {
|
|
337
|
-
let address = buffer;
|
|
338
|
-
for (let i = 0; i < count; i++) {
|
|
339
|
-
this._namedChildren[i] = unmarshalNode(this.tree, address);
|
|
340
|
-
address += SIZE_OF_NODE;
|
|
341
|
-
}
|
|
342
|
-
C._free(buffer);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
return this._namedChildren;
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Get the descendants of this node that are the given type, or in the given types array.
|
|
349
|
-
*
|
|
350
|
-
* The types array should contain node type strings, which can be retrieved from {@link Language#types}.
|
|
351
|
-
*
|
|
352
|
-
* Additionally, a `startPosition` and `endPosition` can be passed in to restrict the search to a byte range.
|
|
353
|
-
*/
|
|
354
|
-
descendantsOfType(types, startPosition = ZERO_POINT, endPosition = ZERO_POINT) {
|
|
355
|
-
if (!Array.isArray(types))
|
|
356
|
-
types = [types];
|
|
357
|
-
// Convert the type strings to numeric type symbols
|
|
358
|
-
const symbols = [];
|
|
359
|
-
const typesBySymbol = this.tree.language.types;
|
|
360
|
-
for (const node_type of types) {
|
|
361
|
-
if (node_type == "ERROR") {
|
|
362
|
-
symbols.push(65535); // Internally, ts_builtin_sym_error is -1, which is UINT_16MAX
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
for (let i = 0, n = typesBySymbol.length; i < n; i++) {
|
|
366
|
-
if (types.includes(typesBySymbol[i])) {
|
|
367
|
-
symbols.push(i);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
// Copy the array of symbols to the Wasm heap
|
|
371
|
-
const symbolsAddress = C._malloc(SIZE_OF_INT * symbols.length);
|
|
372
|
-
for (let i = 0, n = symbols.length; i < n; i++) {
|
|
373
|
-
C.setValue(symbolsAddress + i * SIZE_OF_INT, symbols[i], "i32");
|
|
374
|
-
}
|
|
375
|
-
// Call the C API to compute the descendants
|
|
376
|
-
marshalNode(this);
|
|
377
|
-
C._ts_node_descendants_of_type_wasm(this.tree[0], symbolsAddress, symbols.length, startPosition.row, startPosition.column, endPosition.row, endPosition.column);
|
|
378
|
-
// Instantiate the nodes based on the data returned
|
|
379
|
-
const descendantCount = C.getValue(TRANSFER_BUFFER, "i32");
|
|
380
|
-
const descendantAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
381
|
-
const result = new Array(descendantCount);
|
|
382
|
-
if (descendantCount > 0) {
|
|
383
|
-
let address = descendantAddress;
|
|
384
|
-
for (let i = 0; i < descendantCount; i++) {
|
|
385
|
-
result[i] = unmarshalNode(this.tree, address);
|
|
386
|
-
address += SIZE_OF_NODE;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
// Free the intermediate buffers
|
|
390
|
-
C._free(descendantAddress);
|
|
391
|
-
C._free(symbolsAddress);
|
|
392
|
-
return result;
|
|
393
|
-
}
|
|
394
|
-
/** Get this node's next sibling. */
|
|
395
|
-
get nextSibling() {
|
|
396
|
-
marshalNode(this);
|
|
397
|
-
C._ts_node_next_sibling_wasm(this.tree[0]);
|
|
398
|
-
return unmarshalNode(this.tree);
|
|
399
|
-
}
|
|
400
|
-
/** Get this node's previous sibling. */
|
|
401
|
-
get previousSibling() {
|
|
402
|
-
marshalNode(this);
|
|
403
|
-
C._ts_node_prev_sibling_wasm(this.tree[0]);
|
|
404
|
-
return unmarshalNode(this.tree);
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Get this node's next *named* sibling.
|
|
408
|
-
*
|
|
409
|
-
* See also {@link Node#isNamed}.
|
|
410
|
-
*/
|
|
411
|
-
get nextNamedSibling() {
|
|
412
|
-
marshalNode(this);
|
|
413
|
-
C._ts_node_next_named_sibling_wasm(this.tree[0]);
|
|
414
|
-
return unmarshalNode(this.tree);
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* Get this node's previous *named* sibling.
|
|
418
|
-
*
|
|
419
|
-
* See also {@link Node#isNamed}.
|
|
420
|
-
*/
|
|
421
|
-
get previousNamedSibling() {
|
|
422
|
-
marshalNode(this);
|
|
423
|
-
C._ts_node_prev_named_sibling_wasm(this.tree[0]);
|
|
424
|
-
return unmarshalNode(this.tree);
|
|
425
|
-
}
|
|
426
|
-
/** Get the node's number of descendants, including one for the node itself. */
|
|
427
|
-
get descendantCount() {
|
|
428
|
-
marshalNode(this);
|
|
429
|
-
return C._ts_node_descendant_count_wasm(this.tree[0]);
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Get this node's immediate parent.
|
|
433
|
-
* Prefer {@link Node#childWithDescendant} for iterating over this node's ancestors.
|
|
434
|
-
*/
|
|
435
|
-
get parent() {
|
|
436
|
-
marshalNode(this);
|
|
437
|
-
C._ts_node_parent_wasm(this.tree[0]);
|
|
438
|
-
return unmarshalNode(this.tree);
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Get the node that contains `descendant`.
|
|
442
|
-
*
|
|
443
|
-
* Note that this can return `descendant` itself.
|
|
444
|
-
*/
|
|
445
|
-
childWithDescendant(descendant) {
|
|
446
|
-
marshalNode(this);
|
|
447
|
-
marshalNode(descendant, 1);
|
|
448
|
-
C._ts_node_child_with_descendant_wasm(this.tree[0]);
|
|
449
|
-
return unmarshalNode(this.tree);
|
|
450
|
-
}
|
|
451
|
-
/** Get the smallest node within this node that spans the given byte range. */
|
|
452
|
-
descendantForIndex(start, end = start) {
|
|
453
|
-
if (typeof start !== "number" || typeof end !== "number") {
|
|
454
|
-
throw new Error("Arguments must be numbers");
|
|
455
|
-
}
|
|
456
|
-
marshalNode(this);
|
|
457
|
-
const address = TRANSFER_BUFFER + SIZE_OF_NODE;
|
|
458
|
-
C.setValue(address, start, "i32");
|
|
459
|
-
C.setValue(address + SIZE_OF_INT, end, "i32");
|
|
460
|
-
C._ts_node_descendant_for_index_wasm(this.tree[0]);
|
|
461
|
-
return unmarshalNode(this.tree);
|
|
462
|
-
}
|
|
463
|
-
/** Get the smallest named node within this node that spans the given byte range. */
|
|
464
|
-
namedDescendantForIndex(start, end = start) {
|
|
465
|
-
if (typeof start !== "number" || typeof end !== "number") {
|
|
466
|
-
throw new Error("Arguments must be numbers");
|
|
467
|
-
}
|
|
468
|
-
marshalNode(this);
|
|
469
|
-
const address = TRANSFER_BUFFER + SIZE_OF_NODE;
|
|
470
|
-
C.setValue(address, start, "i32");
|
|
471
|
-
C.setValue(address + SIZE_OF_INT, end, "i32");
|
|
472
|
-
C._ts_node_named_descendant_for_index_wasm(this.tree[0]);
|
|
473
|
-
return unmarshalNode(this.tree);
|
|
474
|
-
}
|
|
475
|
-
/** Get the smallest node within this node that spans the given point range. */
|
|
476
|
-
descendantForPosition(start, end = start) {
|
|
477
|
-
if (!isPoint(start) || !isPoint(end)) {
|
|
478
|
-
throw new Error("Arguments must be {row, column} objects");
|
|
479
|
-
}
|
|
480
|
-
marshalNode(this);
|
|
481
|
-
const address = TRANSFER_BUFFER + SIZE_OF_NODE;
|
|
482
|
-
marshalPoint(address, start);
|
|
483
|
-
marshalPoint(address + SIZE_OF_POINT, end);
|
|
484
|
-
C._ts_node_descendant_for_position_wasm(this.tree[0]);
|
|
485
|
-
return unmarshalNode(this.tree);
|
|
486
|
-
}
|
|
487
|
-
/** Get the smallest named node within this node that spans the given point range. */
|
|
488
|
-
namedDescendantForPosition(start, end = start) {
|
|
489
|
-
if (!isPoint(start) || !isPoint(end)) {
|
|
490
|
-
throw new Error("Arguments must be {row, column} objects");
|
|
491
|
-
}
|
|
492
|
-
marshalNode(this);
|
|
493
|
-
const address = TRANSFER_BUFFER + SIZE_OF_NODE;
|
|
494
|
-
marshalPoint(address, start);
|
|
495
|
-
marshalPoint(address + SIZE_OF_POINT, end);
|
|
496
|
-
C._ts_node_named_descendant_for_position_wasm(this.tree[0]);
|
|
497
|
-
return unmarshalNode(this.tree);
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* Create a new {@link TreeCursor} starting from this node.
|
|
501
|
-
*
|
|
502
|
-
* Note that the given node is considered the root of the cursor,
|
|
503
|
-
* and the cursor cannot walk outside this node.
|
|
504
|
-
*/
|
|
505
|
-
walk() {
|
|
506
|
-
marshalNode(this);
|
|
507
|
-
C._ts_tree_cursor_new_wasm(this.tree[0]);
|
|
508
|
-
return new TreeCursor(INTERNAL, this.tree);
|
|
509
|
-
}
|
|
510
|
-
/**
|
|
511
|
-
* Edit this node to keep it in-sync with source code that has been edited.
|
|
512
|
-
*
|
|
513
|
-
* This function is only rarely needed. When you edit a syntax tree with
|
|
514
|
-
* the {@link Tree#edit} method, all of the nodes that you retrieve from
|
|
515
|
-
* the tree afterward will already reflect the edit. You only need to
|
|
516
|
-
* use {@link Node#edit} when you have a specific {@link Node} instance that
|
|
517
|
-
* you want to keep and continue to use after an edit.
|
|
518
|
-
*/
|
|
519
|
-
edit(edit) {
|
|
520
|
-
if (this.startIndex >= edit.oldEndIndex) {
|
|
521
|
-
this.startIndex = edit.newEndIndex + (this.startIndex - edit.oldEndIndex);
|
|
522
|
-
let subbedPointRow;
|
|
523
|
-
let subbedPointColumn;
|
|
524
|
-
if (this.startPosition.row > edit.oldEndPosition.row) {
|
|
525
|
-
subbedPointRow = this.startPosition.row - edit.oldEndPosition.row;
|
|
526
|
-
subbedPointColumn = this.startPosition.column;
|
|
527
|
-
}
|
|
528
|
-
else {
|
|
529
|
-
subbedPointRow = 0;
|
|
530
|
-
subbedPointColumn = this.startPosition.column;
|
|
531
|
-
if (this.startPosition.column >= edit.oldEndPosition.column) {
|
|
532
|
-
subbedPointColumn = this.startPosition.column - edit.oldEndPosition.column;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
if (subbedPointRow > 0) {
|
|
536
|
-
this.startPosition.row += subbedPointRow;
|
|
537
|
-
this.startPosition.column = subbedPointColumn;
|
|
538
|
-
}
|
|
539
|
-
else {
|
|
540
|
-
this.startPosition.column += subbedPointColumn;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
else if (this.startIndex > edit.startIndex) {
|
|
544
|
-
this.startIndex = edit.newEndIndex;
|
|
545
|
-
this.startPosition.row = edit.newEndPosition.row;
|
|
546
|
-
this.startPosition.column = edit.newEndPosition.column;
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
/** Get the S-expression representation of this node. */
|
|
550
|
-
toString() {
|
|
551
|
-
marshalNode(this);
|
|
552
|
-
const address = C._ts_node_to_string_wasm(this.tree[0]);
|
|
553
|
-
const result = C.AsciiToString(address);
|
|
554
|
-
C._free(address);
|
|
555
|
-
return result;
|
|
556
|
-
}
|
|
557
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Options for parsing
|
|
3
|
-
*
|
|
4
|
-
* The `includedRanges` property is an array of {@link Range} objects that
|
|
5
|
-
* represent the ranges of text that the parser should include when parsing.
|
|
6
|
-
*
|
|
7
|
-
* The `progressCallback` property is a function that is called periodically
|
|
8
|
-
* during parsing to check whether parsing should be cancelled.
|
|
9
|
-
*
|
|
10
|
-
* See {@link Parser#parse} for more information.
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* A stateful object that is passed into the progress callback {@link ParseOptions#progressCallback}
|
|
14
|
-
* to provide the current state of the parser.
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* @internal
|
|
18
|
-
*
|
|
19
|
-
* Global variable for transferring data across the FFI boundary
|
|
20
|
-
*/
|
|
21
|
-
export let TRANSFER_BUFFER: any;
|
|
22
|
-
/**
|
|
23
|
-
* The latest ABI version that is supported by the current version of the
|
|
24
|
-
* library.
|
|
25
|
-
*
|
|
26
|
-
* When Languages are generated by the Tree-sitter CLI, they are
|
|
27
|
-
* assigned an ABI version number that corresponds to the current CLI version.
|
|
28
|
-
* The Tree-sitter library is generally backwards-compatible with languages
|
|
29
|
-
* generated using older CLI versions, but is not forwards-compatible.
|
|
30
|
-
*/
|
|
31
|
-
export let LANGUAGE_VERSION: any;
|
|
32
|
-
/**
|
|
33
|
-
* The earliest ABI version that is supported by the current version of the
|
|
34
|
-
* library.
|
|
35
|
-
*/
|
|
36
|
-
export let MIN_COMPATIBLE_VERSION: any;
|
|
37
|
-
/**
|
|
38
|
-
* A stateful object that is used to produce a {@link Tree} based on some
|
|
39
|
-
* source code.
|
|
40
|
-
*/
|
|
41
|
-
export class Parser {
|
|
42
|
-
/**
|
|
43
|
-
* This must always be called before creating a Parser.
|
|
44
|
-
*
|
|
45
|
-
* You can optionally pass in options to configure the Wasm module, the most common
|
|
46
|
-
* one being `locateFile` to help the module find the `.wasm` file.
|
|
47
|
-
*/
|
|
48
|
-
static init(moduleOptions: any): Promise<void>;
|
|
49
|
-
/** @internal */
|
|
50
|
-
0: number;
|
|
51
|
-
/** @internal */
|
|
52
|
-
1: number;
|
|
53
|
-
/** @internal */
|
|
54
|
-
logCallback: null;
|
|
55
|
-
/** The parser's current language. */
|
|
56
|
-
language: null;
|
|
57
|
-
/** @internal */
|
|
58
|
-
initialize(): void;
|
|
59
|
-
/** Delete the parser, freeing its resources. */
|
|
60
|
-
delete(): void;
|
|
61
|
-
/**
|
|
62
|
-
* Set the language that the parser should use for parsing.
|
|
63
|
-
*
|
|
64
|
-
* If the language was not successfully assigned, an error will be thrown.
|
|
65
|
-
* This happens if the language was generated with an incompatible
|
|
66
|
-
* version of the Tree-sitter CLI. Check the language's version using
|
|
67
|
-
* {@link Language#version} and compare it to this library's
|
|
68
|
-
* {@link LANGUAGE_VERSION} and {@link MIN_COMPATIBLE_VERSION} constants.
|
|
69
|
-
*/
|
|
70
|
-
setLanguage(language: any): this;
|
|
71
|
-
/**
|
|
72
|
-
* Parse a slice of UTF8 text.
|
|
73
|
-
*
|
|
74
|
-
* @param {string | ParseCallback} callback - The UTF8-encoded text to parse or a callback function.
|
|
75
|
-
*
|
|
76
|
-
* @param {Tree | null} [oldTree] - A previous syntax tree parsed from the same document. If the text of the
|
|
77
|
-
* document has changed since `oldTree` was created, then you must edit `oldTree` to match
|
|
78
|
-
* the new text using {@link Tree#edit}.
|
|
79
|
-
*
|
|
80
|
-
* @param {ParseOptions} [options] - Options for parsing the text.
|
|
81
|
-
* This can be used to set the included ranges, or a progress callback.
|
|
82
|
-
*
|
|
83
|
-
* @returns {Tree | null} A {@link Tree} if parsing succeeded, or `null` if:
|
|
84
|
-
* - The parser has not yet had a language assigned with {@link Parser#setLanguage}.
|
|
85
|
-
* - The progress callback returned true.
|
|
86
|
-
*/
|
|
87
|
-
parse(callback: string | ParseCallback, oldTree?: Tree | null, options?: ParseOptions): Tree | null;
|
|
88
|
-
/**
|
|
89
|
-
* Instruct the parser to start the next parse from the beginning.
|
|
90
|
-
*
|
|
91
|
-
* If the parser previously failed because of a timeout, cancellation,
|
|
92
|
-
* or callback, then by default, it will resume where it left off on the
|
|
93
|
-
* next call to {@link Parser#parse} or other parsing functions.
|
|
94
|
-
* If you don't want to resume, and instead intend to use this parser to
|
|
95
|
-
* parse some other document, you must call `reset` first.
|
|
96
|
-
*/
|
|
97
|
-
reset(): void;
|
|
98
|
-
/** Get the ranges of text that the parser will include when parsing. */
|
|
99
|
-
getIncludedRanges(): any[];
|
|
100
|
-
/**
|
|
101
|
-
* @deprecated since version 0.25.0, prefer passing a progress callback to {@link Parser#parse}
|
|
102
|
-
*
|
|
103
|
-
* Get the duration in microseconds that parsing is allowed to take.
|
|
104
|
-
*
|
|
105
|
-
* This is set via {@link Parser#setTimeoutMicros}.
|
|
106
|
-
*/
|
|
107
|
-
getTimeoutMicros(): any;
|
|
108
|
-
/**
|
|
109
|
-
* @deprecated since version 0.25.0, prefer passing a progress callback to {@link Parser#parse}
|
|
110
|
-
*
|
|
111
|
-
* Set the maximum duration in microseconds that parsing should be allowed
|
|
112
|
-
* to take before halting.
|
|
113
|
-
*
|
|
114
|
-
* If parsing takes longer than this, it will halt early, returning `null`.
|
|
115
|
-
* See {@link Parser#parse} for more information.
|
|
116
|
-
*/
|
|
117
|
-
setTimeoutMicros(timeout: any): void;
|
|
118
|
-
/** Set the logging callback that a parser should use during parsing. */
|
|
119
|
-
setLogger(callback: any): this;
|
|
120
|
-
/** Get the parser's current logger. */
|
|
121
|
-
getLogger(): null;
|
|
122
|
-
}
|
|
123
|
-
import { Tree } from "./tree.js";
|
|
124
|
-
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/tree_sitter/parser.js"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH;;;GAGG;AACH;;;;GAIG;AACH,gCAA0B;AAE1B;;;;;;;;GAQG;AACH,iCAA2B;AAE3B;;;GAGG;AACH,uCAAiC;AAEjC;;;GAGG;AACH;IAaI;;;;;OAKG;IACH,+CAKC;IAvBD,gBAAgB;IAChB,UAAQ;IAER,gBAAgB;IAChB,UAAO;IAEP,gBAAgB;IAChB,kBAAkB;IAElB,qCAAqC;IACrC,eAAe;IAsBf,gBAAgB;IAChB,mBAOC;IAED,gDAAgD;IAChD,eAKC;IAED;;;;;;;;OAQG;IACH,iCAkBC;IAED;;;;;;;;;;;;;;;OAeG;IACH,gBAbW,MAAM,GAAG,aAAa,YAEtB,IAAI,GAAG,IAAI,YAIX,YAAY,GAGV,IAAI,GAAG,IAAI,CAyDvB;IAED;;;;;;;;OAQG;IACH,cAEC;IAED,wEAAwE;IACxE,2BAgBC;IAED;;;;;;OAMG;IACH,wBAEC;IAED;;;;;;;;OAQG;IACH,qCAEC;IAED,wEAAwE;IACxE,+BASC;IAED,uCAAuC;IACvC,kBAEC;CACJ;qBA5QoB,WAAW"}
|