@kerebron/tree-sitter 0.4.6
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 +23 -0
- package/README.md +4 -0
- package/esm/_dnt.polyfills.d.ts +101 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +127 -0
- package/esm/deno-tree-sitter/main/extended/base_node.d.ts +48 -0
- package/esm/deno-tree-sitter/main/extended/base_node.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/extended/base_node.js +154 -0
- package/esm/deno-tree-sitter/main/extended/node_extended.d.ts +237 -0
- package/esm/deno-tree-sitter/main/extended/node_extended.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/extended/node_extended.js +665 -0
- package/esm/deno-tree-sitter/main/extended/parser.d.ts +37 -0
- package/esm/deno-tree-sitter/main/extended/parser.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/extended/parser.js +86 -0
- package/esm/deno-tree-sitter/main/extended/soft_node.d.ts +15 -0
- package/esm/deno-tree-sitter/main/extended/soft_node.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/extended/soft_node.js +32 -0
- package/esm/deno-tree-sitter/main/extended/soft_text_node.d.ts +10 -0
- package/esm/deno-tree-sitter/main/extended/soft_text_node.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/extended/soft_text_node.js +10 -0
- package/esm/deno-tree-sitter/main/extended/whitespace_node.d.ts +10 -0
- package/esm/deno-tree-sitter/main/extended/whitespace_node.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/extended/whitespace_node.js +10 -0
- package/esm/deno-tree-sitter/main/extras/misc.d.ts +2 -0
- package/esm/deno-tree-sitter/main/extras/misc.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/extras/misc.js +13 -0
- package/esm/deno-tree-sitter/main/tree_sitter/bindings.d.ts +14 -0
- package/esm/deno-tree-sitter/main/tree_sitter/bindings.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/bindings.js +21 -0
- package/esm/deno-tree-sitter/main/tree_sitter/constants.d.ts +60 -0
- package/esm/deno-tree-sitter/main/tree_sitter/constants.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/constants.js +66 -0
- package/esm/deno-tree-sitter/main/tree_sitter/language.d.ts +137 -0
- package/esm/deno-tree-sitter/main/tree_sitter/language.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/language.js +296 -0
- package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.d.ts +41 -0
- package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/lookahead_iterator.js +75 -0
- package/esm/deno-tree-sitter/main/tree_sitter/marshal.d.ts +85 -0
- package/esm/deno-tree-sitter/main/tree_sitter/marshal.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/marshal.js +173 -0
- package/esm/deno-tree-sitter/main/tree_sitter/node.d.ts +260 -0
- package/esm/deno-tree-sitter/main/tree_sitter/node.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/node.js +592 -0
- package/esm/deno-tree-sitter/main/tree_sitter/parser.d.ts +124 -0
- package/esm/deno-tree-sitter/main/tree_sitter/parser.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/parser.js +272 -0
- package/esm/deno-tree-sitter/main/tree_sitter/query.d.ts +134 -0
- package/esm/deno-tree-sitter/main/tree_sitter/query.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/query.js +670 -0
- package/esm/deno-tree-sitter/main/tree_sitter/tree.d.ts +49 -0
- package/esm/deno-tree-sitter/main/tree_sitter/tree.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/tree.js +145 -0
- package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.d.ts +165 -0
- package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter/tree_cursor.js +305 -0
- package/esm/deno-tree-sitter/main/tree_sitter_wasm.d.ts +3 -0
- package/esm/deno-tree-sitter/main/tree_sitter_wasm.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/tree_sitter_wasm.js +0 -0
- package/esm/deno-tree-sitter/main/wasm_loader.d.ts +29 -0
- package/esm/deno-tree-sitter/main/wasm_loader.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/wasm_loader.js +1709 -0
- package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.d.ts +3 -0
- package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.d.ts.map +1 -0
- package/esm/deno-tree-sitter/main/wasm_loader_with_defaults.js +8 -0
- package/esm/mod.d.ts +8 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +8 -0
- package/esm/package.json +3 -0
- package/package.json +16 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { C, INTERNAL, assertInternal, SIZE_OF_INT, SIZE_OF_SHORT } from "./constants.js";
|
|
2
|
+
import { LookaheadIterator } from "./lookahead_iterator.js";
|
|
3
|
+
import { unmarshalLanguageMetadata } from "./marshal.js";
|
|
4
|
+
import { TRANSFER_BUFFER } from "./parser.js";
|
|
5
|
+
import { Query } from "./query.js";
|
|
6
|
+
const LANGUAGE_FUNCTION_REGEX = /^tree_sitter_\w+$/;
|
|
7
|
+
export class LanguageMetadata {
|
|
8
|
+
constructor() {
|
|
9
|
+
Object.defineProperty(this, "major_version", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: void 0
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(this, "minor_version", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: void 0
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "patch_version", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: void 0
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* An opaque object that defines how to parse a particular language.
|
|
31
|
+
* The code for each `Language` is generated by the Tree-sitter CLI.
|
|
32
|
+
*/
|
|
33
|
+
export class Language {
|
|
34
|
+
/** @internal */
|
|
35
|
+
constructor(internal, address) {
|
|
36
|
+
/** @internal */
|
|
37
|
+
Object.defineProperty(this, 0, {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: 0
|
|
42
|
+
}); // Internal handle for Wasm
|
|
43
|
+
/**
|
|
44
|
+
* A list of all node types in the language. The index of each type in this
|
|
45
|
+
* array is its node type id.
|
|
46
|
+
*/
|
|
47
|
+
Object.defineProperty(this, "types", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: void 0
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* A list of all field names in the language. The index of each field name in
|
|
55
|
+
* this array is its field id.
|
|
56
|
+
*/
|
|
57
|
+
Object.defineProperty(this, "fields", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true,
|
|
60
|
+
writable: true,
|
|
61
|
+
value: void 0
|
|
62
|
+
});
|
|
63
|
+
assertInternal(internal);
|
|
64
|
+
this[0] = address;
|
|
65
|
+
this.types = new Array(C._ts_language_symbol_count(this[0]));
|
|
66
|
+
for (let i = 0, n = this.types.length; i < n; i++) {
|
|
67
|
+
if (C._ts_language_symbol_type(this[0], i) < 2) {
|
|
68
|
+
this.types[i] = C.UTF8ToString(C._ts_language_symbol_name(this[0], i));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
this.fields = new Array(C._ts_language_field_count(this[0]) + 1);
|
|
72
|
+
for (let i = 0, n = this.fields.length; i < n; i++) {
|
|
73
|
+
const fieldName = C._ts_language_field_name_for_id(this[0], i);
|
|
74
|
+
if (fieldName !== 0) {
|
|
75
|
+
this.fields[i] = C.UTF8ToString(fieldName);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.fields[i] = null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Gets the name of the language.
|
|
84
|
+
*/
|
|
85
|
+
get name() {
|
|
86
|
+
const ptr = C._ts_language_name(this[0]);
|
|
87
|
+
if (ptr === 0)
|
|
88
|
+
return null;
|
|
89
|
+
return C.UTF8ToString(ptr);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* @deprecated since version 0.25.0, use {@link Language#abiVersion} instead
|
|
93
|
+
* Gets the version of the language.
|
|
94
|
+
*/
|
|
95
|
+
get version() {
|
|
96
|
+
return C._ts_language_version(this[0]);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Gets the ABI version of the language.
|
|
100
|
+
*/
|
|
101
|
+
get abiVersion() {
|
|
102
|
+
return C._ts_language_abi_version(this[0]);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get the metadata for this language. This information is generated by the
|
|
106
|
+
* CLI, and relies on the language author providing the correct metadata in
|
|
107
|
+
* the language's `tree-sitter.json` file.
|
|
108
|
+
*/
|
|
109
|
+
get metadata() {
|
|
110
|
+
C._ts_language_metadata(this[0]);
|
|
111
|
+
const length = C.getValue(TRANSFER_BUFFER, "i32");
|
|
112
|
+
const address = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
113
|
+
if (length === 0)
|
|
114
|
+
return null;
|
|
115
|
+
return unmarshalLanguageMetadata(address);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Gets the number of fields in the language.
|
|
119
|
+
*/
|
|
120
|
+
get fieldCount() {
|
|
121
|
+
return this.fields.length - 1;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Gets the number of states in the language.
|
|
125
|
+
*/
|
|
126
|
+
get stateCount() {
|
|
127
|
+
return C._ts_language_state_count(this[0]);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get the field id for a field name.
|
|
131
|
+
*/
|
|
132
|
+
fieldIdForName(fieldName) {
|
|
133
|
+
const result = this.fields.indexOf(fieldName);
|
|
134
|
+
return result !== -1 ? result : null;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get the field name for a field id.
|
|
138
|
+
*/
|
|
139
|
+
fieldNameForId(fieldId) {
|
|
140
|
+
return this.fields[fieldId] ?? null;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get the node type id for a node type name.
|
|
144
|
+
*/
|
|
145
|
+
idForNodeType(type, named) {
|
|
146
|
+
const typeLength = C.lengthBytesUTF8(type);
|
|
147
|
+
const typeAddress = C._malloc(typeLength + 1);
|
|
148
|
+
C.stringToUTF8(type, typeAddress, typeLength + 1);
|
|
149
|
+
const result = C._ts_language_symbol_for_name(this[0], typeAddress, typeLength, named ? 1 : 0);
|
|
150
|
+
C._free(typeAddress);
|
|
151
|
+
return result || null;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Gets the number of node types in the language.
|
|
155
|
+
*/
|
|
156
|
+
get nodeTypeCount() {
|
|
157
|
+
return C._ts_language_symbol_count(this[0]);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Get the node type name for a node type id.
|
|
161
|
+
*/
|
|
162
|
+
nodeTypeForId(typeId) {
|
|
163
|
+
const name = C._ts_language_symbol_name(this[0], typeId);
|
|
164
|
+
return name ? C.UTF8ToString(name) : null;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Check if a node type is named.
|
|
168
|
+
*
|
|
169
|
+
* @see {@link https://tree-sitter.github.io/tree-sitter/using-parsers/2-basic-parsing.html#named-vs-anonymous-nodes}
|
|
170
|
+
*/
|
|
171
|
+
nodeTypeIsNamed(typeId) {
|
|
172
|
+
return C._ts_language_type_is_named_wasm(this[0], typeId) ? true : false;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Check if a node type is visible.
|
|
176
|
+
*/
|
|
177
|
+
nodeTypeIsVisible(typeId) {
|
|
178
|
+
return C._ts_language_type_is_visible_wasm(this[0], typeId) ? true : false;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Get the supertypes ids of this language.
|
|
182
|
+
*
|
|
183
|
+
* @see {@link https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types.html?highlight=supertype#supertype-nodes}
|
|
184
|
+
*/
|
|
185
|
+
get supertypes() {
|
|
186
|
+
C._ts_language_supertypes_wasm(this[0]);
|
|
187
|
+
const count = C.getValue(TRANSFER_BUFFER, "i32");
|
|
188
|
+
const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
189
|
+
const result = new Array(count);
|
|
190
|
+
if (count > 0) {
|
|
191
|
+
let address = buffer;
|
|
192
|
+
for (let i = 0; i < count; i++) {
|
|
193
|
+
result[i] = C.getValue(address, "i16");
|
|
194
|
+
address += SIZE_OF_SHORT;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get the subtype ids for a given supertype node id.
|
|
201
|
+
*/
|
|
202
|
+
subtypes(supertype) {
|
|
203
|
+
C._ts_language_subtypes_wasm(this[0], supertype);
|
|
204
|
+
const count = C.getValue(TRANSFER_BUFFER, "i32");
|
|
205
|
+
const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
|
|
206
|
+
const result = new Array(count);
|
|
207
|
+
if (count > 0) {
|
|
208
|
+
let address = buffer;
|
|
209
|
+
for (let i = 0; i < count; i++) {
|
|
210
|
+
result[i] = C.getValue(address, "i16");
|
|
211
|
+
address += SIZE_OF_SHORT;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get the next state id for a given state id and node type id.
|
|
218
|
+
*/
|
|
219
|
+
nextState(stateId, typeId) {
|
|
220
|
+
return C._ts_language_next_state(this[0], stateId, typeId);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Create a new lookahead iterator for this language and parse state.
|
|
224
|
+
*
|
|
225
|
+
* This returns `null` if state is invalid for this language.
|
|
226
|
+
*
|
|
227
|
+
* Iterating {@link LookaheadIterator} will yield valid symbols in the given
|
|
228
|
+
* parse state. Newly created lookahead iterators will return the `ERROR`
|
|
229
|
+
* symbol from {@link LookaheadIterator#currentType}.
|
|
230
|
+
*
|
|
231
|
+
* Lookahead iterators can be useful for generating suggestions and improving
|
|
232
|
+
* syntax error diagnostics. To get symbols valid in an `ERROR` node, use the
|
|
233
|
+
* lookahead iterator on its first leaf node state. For `MISSING` nodes, a
|
|
234
|
+
* lookahead iterator created on the previous non-extra leaf node may be
|
|
235
|
+
* appropriate.
|
|
236
|
+
*/
|
|
237
|
+
lookaheadIterator(stateId) {
|
|
238
|
+
const address = C._ts_lookahead_iterator_new(this[0], stateId);
|
|
239
|
+
if (address)
|
|
240
|
+
return new LookaheadIterator(INTERNAL, address, this);
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* @deprecated since version 0.25.0, call `new` on a {@link Query} instead
|
|
245
|
+
*
|
|
246
|
+
* Create a new query from a string containing one or more S-expression
|
|
247
|
+
* patterns.
|
|
248
|
+
*
|
|
249
|
+
* The query is associated with a particular language, and can only be run
|
|
250
|
+
* on syntax nodes parsed with that language. References to Queries can be
|
|
251
|
+
* shared between multiple threads.
|
|
252
|
+
*
|
|
253
|
+
* @link {@see https://tree-sitter.github.io/tree-sitter/using-parsers/queries}
|
|
254
|
+
*/
|
|
255
|
+
query(source) {
|
|
256
|
+
console.warn("Language.query is deprecated. Use new Query(language, source) instead.");
|
|
257
|
+
return new Query(this, source);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Load a language from a WebAssembly module.
|
|
261
|
+
* The module can be provided as a path to a file or as a buffer.
|
|
262
|
+
*/
|
|
263
|
+
static async load(input) {
|
|
264
|
+
let bytes;
|
|
265
|
+
if (input instanceof Uint8Array) {
|
|
266
|
+
bytes = Promise.resolve(input);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
270
|
+
if (globalThis.process?.versions.node) {
|
|
271
|
+
const fs = await import("node:fs/promises");
|
|
272
|
+
bytes = fs.readFile(input);
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
bytes = fetch(input).then((response) => response.arrayBuffer().then((buffer) => {
|
|
276
|
+
if (response.ok) {
|
|
277
|
+
return new Uint8Array(buffer);
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
const body = new TextDecoder("utf-8").decode(buffer);
|
|
281
|
+
throw new Error(`Language.load failed with status ${response.status}.\n\n${body}`);
|
|
282
|
+
}
|
|
283
|
+
}));
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const mod = await C.loadWebAssemblyModule(await bytes, { loadAsync: true });
|
|
287
|
+
const symbolNames = Object.keys(mod);
|
|
288
|
+
const functionName = symbolNames.find((key) => LANGUAGE_FUNCTION_REGEX.test(key) && !key.includes("external_scanner_"));
|
|
289
|
+
if (!functionName) {
|
|
290
|
+
console.log(`Couldn't find language function in Wasm file. Symbols:\n${JSON.stringify(symbolNames, null, 2)}`);
|
|
291
|
+
throw new Error("Language.load failed: no language function found in Wasm file");
|
|
292
|
+
}
|
|
293
|
+
const languageAddress = mod[functionName]();
|
|
294
|
+
return new Language(INTERNAL, languageAddress);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export class LookaheadIterator {
|
|
2
|
+
/** @internal */
|
|
3
|
+
constructor(internal: any, address: any, language: any);
|
|
4
|
+
/** @internal */
|
|
5
|
+
0: number;
|
|
6
|
+
/** @internal */
|
|
7
|
+
language: any;
|
|
8
|
+
/** Get the current symbol of the lookahead iterator. */
|
|
9
|
+
get currentTypeId(): any;
|
|
10
|
+
/** Get the current symbol name of the lookahead iterator. */
|
|
11
|
+
get currentType(): any;
|
|
12
|
+
/** Delete the lookahead iterator, freeing its resources. */
|
|
13
|
+
delete(): void;
|
|
14
|
+
/**
|
|
15
|
+
* Reset the lookahead iterator.
|
|
16
|
+
*
|
|
17
|
+
* This returns `true` if the language was set successfully and `false`
|
|
18
|
+
* otherwise.
|
|
19
|
+
*/
|
|
20
|
+
reset(language: any, stateId: any): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Reset the lookahead iterator to another state.
|
|
23
|
+
*
|
|
24
|
+
* This returns `true` if the iterator was reset to the given state and
|
|
25
|
+
* `false` otherwise.
|
|
26
|
+
*/
|
|
27
|
+
resetState(stateId: any): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Returns an iterator that iterates over the symbols of the lookahead iterator.
|
|
30
|
+
*
|
|
31
|
+
* The iterator will yield the current symbol name as a string for each step
|
|
32
|
+
* until there are no more symbols to iterate over.
|
|
33
|
+
*/
|
|
34
|
+
[Symbol.iterator](): {
|
|
35
|
+
next: () => {
|
|
36
|
+
done: boolean;
|
|
37
|
+
value: any;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=lookahead_iterator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookahead_iterator.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/tree_sitter/lookahead_iterator.js"],"names":[],"mappings":"AAGA;IAOI,gBAAgB;IAChB,wDAIC;IAXD,gBAAgB;IAChB,UAAO;IAEP,gBAAgB;IAChB,cAAQ;IASR,wDAAwD;IACxD,yBAEC;IAED,6DAA6D;IAC7D,uBAEC;IAED,4DAA4D;IAC5D,eAGC;IAED;;;;;OAKG;IACH,4CAMC;IAED;;;;;OAKG;IACH,kCAEC;IAED;;;;;OAKG;IACH;;;;;MASC;CACJ"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { C, assertInternal } from "./constants.js";
|
|
2
|
+
import { Language } from "./language.js";
|
|
3
|
+
export class LookaheadIterator {
|
|
4
|
+
/** @internal */
|
|
5
|
+
constructor(internal, address, language) {
|
|
6
|
+
/** @internal */
|
|
7
|
+
Object.defineProperty(this, 0, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: 0
|
|
12
|
+
}); // Internal handle for Wasm
|
|
13
|
+
/** @internal */
|
|
14
|
+
Object.defineProperty(this, "language", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: void 0
|
|
19
|
+
});
|
|
20
|
+
assertInternal(internal);
|
|
21
|
+
this[0] = address;
|
|
22
|
+
this.language = language;
|
|
23
|
+
}
|
|
24
|
+
/** Get the current symbol of the lookahead iterator. */
|
|
25
|
+
get currentTypeId() {
|
|
26
|
+
return C._ts_lookahead_iterator_current_symbol(this[0]);
|
|
27
|
+
}
|
|
28
|
+
/** Get the current symbol name of the lookahead iterator. */
|
|
29
|
+
get currentType() {
|
|
30
|
+
return this.language.types[this.currentTypeId] || "ERROR";
|
|
31
|
+
}
|
|
32
|
+
/** Delete the lookahead iterator, freeing its resources. */
|
|
33
|
+
delete() {
|
|
34
|
+
C._ts_lookahead_iterator_delete(this[0]);
|
|
35
|
+
this[0] = 0;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Reset the lookahead iterator.
|
|
39
|
+
*
|
|
40
|
+
* This returns `true` if the language was set successfully and `false`
|
|
41
|
+
* otherwise.
|
|
42
|
+
*/
|
|
43
|
+
reset(language, stateId) {
|
|
44
|
+
if (C._ts_lookahead_iterator_reset(this[0], language[0], stateId)) {
|
|
45
|
+
this.language = language;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Reset the lookahead iterator to another state.
|
|
52
|
+
*
|
|
53
|
+
* This returns `true` if the iterator was reset to the given state and
|
|
54
|
+
* `false` otherwise.
|
|
55
|
+
*/
|
|
56
|
+
resetState(stateId) {
|
|
57
|
+
return Boolean(C._ts_lookahead_iterator_reset_state(this[0], stateId));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns an iterator that iterates over the symbols of the lookahead iterator.
|
|
61
|
+
*
|
|
62
|
+
* The iterator will yield the current symbol name as a string for each step
|
|
63
|
+
* until there are no more symbols to iterate over.
|
|
64
|
+
*/
|
|
65
|
+
[Symbol.iterator]() {
|
|
66
|
+
return {
|
|
67
|
+
next: () => {
|
|
68
|
+
if (C._ts_lookahead_iterator_next(this[0])) {
|
|
69
|
+
return { done: false, value: this.currentType };
|
|
70
|
+
}
|
|
71
|
+
return { done: true, value: "" };
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*
|
|
4
|
+
* Unmarshals a {@link QueryMatch} to the transfer buffer.
|
|
5
|
+
*/
|
|
6
|
+
export function unmarshalCaptures(query: any, tree: any, address: any, patternIndex: any, result: any): any;
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*
|
|
10
|
+
* Marshals a {@link Node} to the transfer buffer.
|
|
11
|
+
*/
|
|
12
|
+
export function marshalNode(node: any, index?: number): void;
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*
|
|
16
|
+
* Unmarshals a {@link Node} from the transfer buffer.
|
|
17
|
+
*/
|
|
18
|
+
export function unmarshalNode(tree: any, address?: any): any;
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*
|
|
22
|
+
* Marshals a {@link TreeCursor} to the transfer buffer.
|
|
23
|
+
*/
|
|
24
|
+
export function marshalTreeCursor(cursor: any, address?: any): void;
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*
|
|
28
|
+
* Unmarshals a {@link TreeCursor} from the transfer buffer.
|
|
29
|
+
*/
|
|
30
|
+
export function unmarshalTreeCursor(cursor: any): void;
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*
|
|
34
|
+
* Marshals a {@link Point} to the transfer buffer.
|
|
35
|
+
*/
|
|
36
|
+
export function marshalPoint(address: any, point: any): void;
|
|
37
|
+
/**
|
|
38
|
+
* @internal
|
|
39
|
+
*
|
|
40
|
+
* Unmarshals a {@link Point} from the transfer buffer.
|
|
41
|
+
*/
|
|
42
|
+
export function unmarshalPoint(address: any): {
|
|
43
|
+
row: number;
|
|
44
|
+
column: number;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* @internal
|
|
48
|
+
*
|
|
49
|
+
* Marshals a {@link Range} to the transfer buffer.
|
|
50
|
+
*/
|
|
51
|
+
export function marshalRange(address: any, range: any): void;
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*
|
|
55
|
+
* Unmarshals a {@link Range} from the transfer buffer.
|
|
56
|
+
*/
|
|
57
|
+
export function unmarshalRange(address: any): {
|
|
58
|
+
startPosition: {
|
|
59
|
+
row: number;
|
|
60
|
+
column: number;
|
|
61
|
+
};
|
|
62
|
+
endPosition: {
|
|
63
|
+
row: number;
|
|
64
|
+
column: number;
|
|
65
|
+
};
|
|
66
|
+
startIndex: number;
|
|
67
|
+
endIndex: number;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* @internal
|
|
71
|
+
*
|
|
72
|
+
* Marshals an {@link Edit} to the transfer buffer.
|
|
73
|
+
*/
|
|
74
|
+
export function marshalEdit(edit: any, address?: any): void;
|
|
75
|
+
/**
|
|
76
|
+
* @internal
|
|
77
|
+
*
|
|
78
|
+
* Unmarshals a {@link LanguageMetadata} from the transfer buffer.
|
|
79
|
+
*/
|
|
80
|
+
export function unmarshalLanguageMetadata(address: any): {
|
|
81
|
+
major_version: any;
|
|
82
|
+
minor_version: any;
|
|
83
|
+
field_count: any;
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=marshal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marshal.d.ts","sourceRoot":"","sources":["../../../../src/deno-tree-sitter/main/tree_sitter/marshal.js"],"names":[],"mappings":"AASA;;;;GAIG;AACH,4GASC;AAED;;;;GAIG;AACH,6DAWC;AAED;;;;GAIG;AACH,6DAsBC;AAED;;;;GAIG;AACH,oEAKC;AAED;;;;GAIG;AACH,uDAKC;AAED;;;;GAIG;AACH,6DAGC;AAED;;;;GAIG;AACH;;;EAMC;AAED;;;;GAIG;AACH,6DASC;AAED;;;;GAIG;AACH;;;;;;;;;;;EAUC;AAED;;;;GAIG;AACH,4DAaC;AAED;;;;GAIG;AACH;;;;EAQC"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { INTERNAL, SIZE_OF_INT, SIZE_OF_NODE, SIZE_OF_POINT, C } from "./constants.js";
|
|
2
|
+
import { Node } from "./node.js";
|
|
3
|
+
import { Tree } from "./tree.js";
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
|
+
import { Query } from "./query.js";
|
|
6
|
+
import { TreeCursor } from "./tree_cursor.js";
|
|
7
|
+
import { TRANSFER_BUFFER } from "./parser.js";
|
|
8
|
+
import { LanguageMetadata } from "./language.js";
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*
|
|
12
|
+
* Unmarshals a {@link QueryMatch} to the transfer buffer.
|
|
13
|
+
*/
|
|
14
|
+
export function unmarshalCaptures(query, tree, address, patternIndex, result) {
|
|
15
|
+
for (let i = 0, n = result.length; i < n; i++) {
|
|
16
|
+
const captureIndex = C.getValue(address, "i32");
|
|
17
|
+
address += SIZE_OF_INT;
|
|
18
|
+
const node = unmarshalNode(tree, address);
|
|
19
|
+
address += SIZE_OF_NODE;
|
|
20
|
+
result[i] = { patternIndex, name: query.captureNames[captureIndex], node };
|
|
21
|
+
}
|
|
22
|
+
return address;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*
|
|
27
|
+
* Marshals a {@link Node} to the transfer buffer.
|
|
28
|
+
*/
|
|
29
|
+
export function marshalNode(node, index = 0) {
|
|
30
|
+
let address = TRANSFER_BUFFER + index * SIZE_OF_NODE;
|
|
31
|
+
C.setValue(address, node.id, "i32");
|
|
32
|
+
address += SIZE_OF_INT;
|
|
33
|
+
C.setValue(address, node.startIndex, "i32");
|
|
34
|
+
address += SIZE_OF_INT;
|
|
35
|
+
C.setValue(address, node.startPosition.row, "i32");
|
|
36
|
+
address += SIZE_OF_INT;
|
|
37
|
+
C.setValue(address, node.startPosition.column, "i32");
|
|
38
|
+
address += SIZE_OF_INT;
|
|
39
|
+
C.setValue(address, node[0], "i32");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
*
|
|
44
|
+
* Unmarshals a {@link Node} from the transfer buffer.
|
|
45
|
+
*/
|
|
46
|
+
export function unmarshalNode(tree, address = TRANSFER_BUFFER) {
|
|
47
|
+
const id = C.getValue(address, "i32");
|
|
48
|
+
address += SIZE_OF_INT;
|
|
49
|
+
if (id === 0)
|
|
50
|
+
return null;
|
|
51
|
+
const index = C.getValue(address, "i32");
|
|
52
|
+
address += SIZE_OF_INT;
|
|
53
|
+
const row = C.getValue(address, "i32");
|
|
54
|
+
address += SIZE_OF_INT;
|
|
55
|
+
const column = C.getValue(address, "i32");
|
|
56
|
+
address += SIZE_OF_INT;
|
|
57
|
+
const other = C.getValue(address, "i32");
|
|
58
|
+
const result = new Node(INTERNAL, {
|
|
59
|
+
id,
|
|
60
|
+
tree,
|
|
61
|
+
startIndex: index,
|
|
62
|
+
startPosition: { row, column },
|
|
63
|
+
other,
|
|
64
|
+
});
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @internal
|
|
69
|
+
*
|
|
70
|
+
* Marshals a {@link TreeCursor} to the transfer buffer.
|
|
71
|
+
*/
|
|
72
|
+
export function marshalTreeCursor(cursor, address = TRANSFER_BUFFER) {
|
|
73
|
+
C.setValue(address + 0 * SIZE_OF_INT, cursor[0], "i32");
|
|
74
|
+
C.setValue(address + 1 * SIZE_OF_INT, cursor[1], "i32");
|
|
75
|
+
C.setValue(address + 2 * SIZE_OF_INT, cursor[2], "i32");
|
|
76
|
+
C.setValue(address + 3 * SIZE_OF_INT, cursor[3], "i32");
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @internal
|
|
80
|
+
*
|
|
81
|
+
* Unmarshals a {@link TreeCursor} from the transfer buffer.
|
|
82
|
+
*/
|
|
83
|
+
export function unmarshalTreeCursor(cursor) {
|
|
84
|
+
cursor[0] = C.getValue(TRANSFER_BUFFER + 0 * SIZE_OF_INT, "i32");
|
|
85
|
+
cursor[1] = C.getValue(TRANSFER_BUFFER + 1 * SIZE_OF_INT, "i32");
|
|
86
|
+
cursor[2] = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32");
|
|
87
|
+
cursor[3] = C.getValue(TRANSFER_BUFFER + 3 * SIZE_OF_INT, "i32");
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* @internal
|
|
91
|
+
*
|
|
92
|
+
* Marshals a {@link Point} to the transfer buffer.
|
|
93
|
+
*/
|
|
94
|
+
export function marshalPoint(address, point) {
|
|
95
|
+
C.setValue(address, point.row, "i32");
|
|
96
|
+
C.setValue(address + SIZE_OF_INT, point.column, "i32");
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @internal
|
|
100
|
+
*
|
|
101
|
+
* Unmarshals a {@link Point} from the transfer buffer.
|
|
102
|
+
*/
|
|
103
|
+
export function unmarshalPoint(address) {
|
|
104
|
+
const result = {
|
|
105
|
+
row: C.getValue(address, "i32") >>> 0,
|
|
106
|
+
column: C.getValue(address + SIZE_OF_INT, "i32") >>> 0,
|
|
107
|
+
};
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* @internal
|
|
112
|
+
*
|
|
113
|
+
* Marshals a {@link Range} to the transfer buffer.
|
|
114
|
+
*/
|
|
115
|
+
export function marshalRange(address, range) {
|
|
116
|
+
marshalPoint(address, range.startPosition);
|
|
117
|
+
address += SIZE_OF_POINT;
|
|
118
|
+
marshalPoint(address, range.endPosition);
|
|
119
|
+
address += SIZE_OF_POINT;
|
|
120
|
+
C.setValue(address, range.startIndex, "i32");
|
|
121
|
+
address += SIZE_OF_INT;
|
|
122
|
+
C.setValue(address, range.endIndex, "i32");
|
|
123
|
+
address += SIZE_OF_INT;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* @internal
|
|
127
|
+
*
|
|
128
|
+
* Unmarshals a {@link Range} from the transfer buffer.
|
|
129
|
+
*/
|
|
130
|
+
export function unmarshalRange(address) {
|
|
131
|
+
const result = {};
|
|
132
|
+
result.startPosition = unmarshalPoint(address);
|
|
133
|
+
address += SIZE_OF_POINT;
|
|
134
|
+
result.endPosition = unmarshalPoint(address);
|
|
135
|
+
address += SIZE_OF_POINT;
|
|
136
|
+
result.startIndex = C.getValue(address, "i32") >>> 0;
|
|
137
|
+
address += SIZE_OF_INT;
|
|
138
|
+
result.endIndex = C.getValue(address, "i32") >>> 0;
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* @internal
|
|
143
|
+
*
|
|
144
|
+
* Marshals an {@link Edit} to the transfer buffer.
|
|
145
|
+
*/
|
|
146
|
+
export function marshalEdit(edit, address = TRANSFER_BUFFER) {
|
|
147
|
+
marshalPoint(address, edit.startPosition);
|
|
148
|
+
address += SIZE_OF_POINT;
|
|
149
|
+
marshalPoint(address, edit.oldEndPosition);
|
|
150
|
+
address += SIZE_OF_POINT;
|
|
151
|
+
marshalPoint(address, edit.newEndPosition);
|
|
152
|
+
address += SIZE_OF_POINT;
|
|
153
|
+
C.setValue(address, edit.startIndex, "i32");
|
|
154
|
+
address += SIZE_OF_INT;
|
|
155
|
+
C.setValue(address, edit.oldEndIndex, "i32");
|
|
156
|
+
address += SIZE_OF_INT;
|
|
157
|
+
C.setValue(address, edit.newEndIndex, "i32");
|
|
158
|
+
address += SIZE_OF_INT;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* @internal
|
|
162
|
+
*
|
|
163
|
+
* Unmarshals a {@link LanguageMetadata} from the transfer buffer.
|
|
164
|
+
*/
|
|
165
|
+
export function unmarshalLanguageMetadata(address) {
|
|
166
|
+
const result = {};
|
|
167
|
+
result.major_version = C.getValue(address, "i32");
|
|
168
|
+
address += SIZE_OF_INT;
|
|
169
|
+
result.minor_version = C.getValue(address, "i32");
|
|
170
|
+
address += SIZE_OF_INT;
|
|
171
|
+
result.field_count = C.getValue(address, "i32");
|
|
172
|
+
return result;
|
|
173
|
+
}
|