@prosdevlab/dev-agent 0.8.5
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 +138 -0
- package/dist/cli.js +74721 -0
- package/dist/cli.js.map +1 -0
- package/dist/mcp.js +61445 -0
- package/dist/mcp.js.map +1 -0
- package/dist/vendor/web-tree-sitter/lib/alloc.c +48 -0
- package/dist/vendor/web-tree-sitter/lib/alloc.h +41 -0
- package/dist/vendor/web-tree-sitter/lib/array.h +291 -0
- package/dist/vendor/web-tree-sitter/lib/atomic.h +68 -0
- package/dist/vendor/web-tree-sitter/lib/clock.h +146 -0
- package/dist/vendor/web-tree-sitter/lib/error_costs.h +11 -0
- package/dist/vendor/web-tree-sitter/lib/get_changed_ranges.c +523 -0
- package/dist/vendor/web-tree-sitter/lib/get_changed_ranges.h +36 -0
- package/dist/vendor/web-tree-sitter/lib/host.h +21 -0
- package/dist/vendor/web-tree-sitter/lib/language.c +293 -0
- package/dist/vendor/web-tree-sitter/lib/language.h +293 -0
- package/dist/vendor/web-tree-sitter/lib/length.h +52 -0
- package/dist/vendor/web-tree-sitter/lib/lexer.c +483 -0
- package/dist/vendor/web-tree-sitter/lib/lexer.h +54 -0
- package/dist/vendor/web-tree-sitter/lib/lib.c +12 -0
- package/dist/vendor/web-tree-sitter/lib/node.c +875 -0
- package/dist/vendor/web-tree-sitter/lib/parser.c +2297 -0
- package/dist/vendor/web-tree-sitter/lib/parser.h +286 -0
- package/dist/vendor/web-tree-sitter/lib/point.h +48 -0
- package/dist/vendor/web-tree-sitter/lib/query.c +4347 -0
- package/dist/vendor/web-tree-sitter/lib/reduce_action.h +34 -0
- package/dist/vendor/web-tree-sitter/lib/reusable_node.h +95 -0
- package/dist/vendor/web-tree-sitter/lib/stack.c +912 -0
- package/dist/vendor/web-tree-sitter/lib/stack.h +133 -0
- package/dist/vendor/web-tree-sitter/lib/subtree.c +1034 -0
- package/dist/vendor/web-tree-sitter/lib/subtree.h +399 -0
- package/dist/vendor/web-tree-sitter/lib/tree-sitter.c +987 -0
- package/dist/vendor/web-tree-sitter/lib/tree-sitter.cjs +2988 -0
- package/dist/vendor/web-tree-sitter/lib/tree-sitter.wasm +0 -0
- package/dist/vendor/web-tree-sitter/lib/tree-sitter.wasm.map +1 -0
- package/dist/vendor/web-tree-sitter/lib/tree.c +170 -0
- package/dist/vendor/web-tree-sitter/lib/tree.h +31 -0
- package/dist/vendor/web-tree-sitter/lib/tree_cursor.c +716 -0
- package/dist/vendor/web-tree-sitter/lib/tree_cursor.h +48 -0
- package/dist/vendor/web-tree-sitter/lib/ts_assert.h +11 -0
- package/dist/vendor/web-tree-sitter/lib/unicode.h +75 -0
- package/dist/vendor/web-tree-sitter/lib/wasm_store.c +1937 -0
- package/dist/vendor/web-tree-sitter/lib/wasm_store.h +31 -0
- package/dist/vendor/web-tree-sitter/package.json +98 -0
- package/dist/vendor/web-tree-sitter/tree-sitter.cjs +4031 -0
- package/dist/vendor/web-tree-sitter/tree-sitter.wasm +0 -0
- package/dist/wasm/tree-sitter-go.wasm +0 -0
- package/dist/wasm/tree-sitter.wasm +0 -0
- package/package.json +65 -0
|
@@ -0,0 +1,987 @@
|
|
|
1
|
+
#include "array.h"
|
|
2
|
+
#include "point.h"
|
|
3
|
+
|
|
4
|
+
#include <emscripten.h>
|
|
5
|
+
#include <tree_sitter/api.h>
|
|
6
|
+
|
|
7
|
+
/*****************************/
|
|
8
|
+
/* Section - Data marshaling */
|
|
9
|
+
/*****************************/
|
|
10
|
+
|
|
11
|
+
static const uint32_t INPUT_BUFFER_SIZE = 10 * 1024;
|
|
12
|
+
|
|
13
|
+
const void *TRANSFER_BUFFER[12] = {
|
|
14
|
+
NULL, NULL, NULL, NULL,
|
|
15
|
+
NULL, NULL, NULL, NULL,
|
|
16
|
+
NULL, NULL, NULL, NULL,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
static const int SIZE_OF_CURSOR = 4;
|
|
20
|
+
static const int SIZE_OF_NODE = 5;
|
|
21
|
+
static const int SIZE_OF_POINT = 2;
|
|
22
|
+
static const int SIZE_OF_RANGE = 2 + (2 * SIZE_OF_POINT);
|
|
23
|
+
static const int SIZE_OF_CAPTURE = 1 + SIZE_OF_NODE;
|
|
24
|
+
|
|
25
|
+
void *ts_init() {
|
|
26
|
+
TRANSFER_BUFFER[0] = (const void *)TREE_SITTER_LANGUAGE_VERSION;
|
|
27
|
+
TRANSFER_BUFFER[1] = (const void *)TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION;
|
|
28
|
+
return (void*)TRANSFER_BUFFER;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static uint32_t code_unit_to_byte(uint32_t unit) {
|
|
32
|
+
return unit << 1;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static uint32_t byte_to_code_unit(uint32_t byte) {
|
|
36
|
+
return byte >> 1;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static inline void marshal_node(const void **buffer, TSNode node) {
|
|
40
|
+
buffer[0] = node.id;
|
|
41
|
+
buffer[1] = (const void *)byte_to_code_unit(node.context[0]);
|
|
42
|
+
buffer[2] = (const void *)node.context[1];
|
|
43
|
+
buffer[3] = (const void *)byte_to_code_unit(node.context[2]);
|
|
44
|
+
buffer[4] = (const void *)node.context[3];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static inline TSNode unmarshal_node_at(const TSTree *tree, uint32_t index) {
|
|
48
|
+
TSNode node;
|
|
49
|
+
const void **buffer = TRANSFER_BUFFER + index * SIZE_OF_NODE;
|
|
50
|
+
node.id = buffer[0];
|
|
51
|
+
node.context[0] = code_unit_to_byte((uint32_t)buffer[1]);
|
|
52
|
+
node.context[1] = (uint32_t)buffer[2];
|
|
53
|
+
node.context[2] = code_unit_to_byte((uint32_t)buffer[3]);
|
|
54
|
+
node.context[3] = (uint32_t)buffer[4];
|
|
55
|
+
node.tree = tree;
|
|
56
|
+
return node;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static inline TSNode unmarshal_node(const TSTree *tree) {
|
|
60
|
+
return unmarshal_node_at(tree, 0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static inline void marshal_cursor(const TSTreeCursor *cursor) {
|
|
64
|
+
TRANSFER_BUFFER[0] = cursor->id;
|
|
65
|
+
TRANSFER_BUFFER[1] = (const void *)cursor->context[0];
|
|
66
|
+
TRANSFER_BUFFER[2] = (const void *)cursor->context[1];
|
|
67
|
+
TRANSFER_BUFFER[3] = (const void *)cursor->context[2];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static inline TSTreeCursor unmarshal_cursor(const void **buffer, const TSTree *tree) {
|
|
71
|
+
TSTreeCursor cursor;
|
|
72
|
+
cursor.id = buffer[0];
|
|
73
|
+
cursor.context[0] = (uint32_t)buffer[1];
|
|
74
|
+
cursor.context[1] = (uint32_t)buffer[2];
|
|
75
|
+
cursor.context[2] = (uint32_t)buffer[3];
|
|
76
|
+
cursor.tree = tree;
|
|
77
|
+
return cursor;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static void marshal_point(TSPoint point) {
|
|
81
|
+
TRANSFER_BUFFER[0] = (const void *)point.row;
|
|
82
|
+
TRANSFER_BUFFER[1] = (const void *)byte_to_code_unit(point.column);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static TSPoint unmarshal_point(const void **address) {
|
|
86
|
+
TSPoint point;
|
|
87
|
+
point.row = (uint32_t)address[0];
|
|
88
|
+
point.column = code_unit_to_byte((uint32_t)address[1]);
|
|
89
|
+
return point;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static void marshal_range(TSRange *range) {
|
|
93
|
+
range->start_byte = byte_to_code_unit(range->start_byte);
|
|
94
|
+
range->end_byte = byte_to_code_unit(range->end_byte);
|
|
95
|
+
range->start_point.column = byte_to_code_unit(range->start_point.column);
|
|
96
|
+
range->end_point.column = byte_to_code_unit(range->end_point.column);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static void unmarshal_range(TSRange *range) {
|
|
100
|
+
range->start_byte = code_unit_to_byte(range->start_byte);
|
|
101
|
+
range->end_byte = code_unit_to_byte(range->end_byte);
|
|
102
|
+
range->start_point.column = code_unit_to_byte(range->start_point.column);
|
|
103
|
+
range->end_point.column = code_unit_to_byte(range->end_point.column);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static TSInputEdit unmarshal_edit() {
|
|
107
|
+
TSInputEdit edit;
|
|
108
|
+
const void **address = TRANSFER_BUFFER;
|
|
109
|
+
edit.start_point = unmarshal_point(address); address += SIZE_OF_POINT;
|
|
110
|
+
edit.old_end_point = unmarshal_point(address); address += SIZE_OF_POINT;
|
|
111
|
+
edit.new_end_point = unmarshal_point(address); address += SIZE_OF_POINT;
|
|
112
|
+
edit.start_byte = code_unit_to_byte((uint32_t)*address); address += 1;
|
|
113
|
+
edit.old_end_byte = code_unit_to_byte((uint32_t)*address); address += 1;
|
|
114
|
+
edit.new_end_byte = code_unit_to_byte((uint32_t)*address); address += 1;
|
|
115
|
+
return edit;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static void marshal_language_metadata(const TSLanguageMetadata *metadata) {
|
|
119
|
+
if (metadata == NULL) {
|
|
120
|
+
TRANSFER_BUFFER[0] = 0;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
TRANSFER_BUFFER[0] = (const void*)3;
|
|
124
|
+
TRANSFER_BUFFER[1] = (const void*)(uint32_t)metadata->major_version;
|
|
125
|
+
TRANSFER_BUFFER[2] = (const void*)(uint32_t)metadata->minor_version;
|
|
126
|
+
TRANSFER_BUFFER[3] = (const void*)(uint32_t)metadata->patch_version;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/********************/
|
|
130
|
+
/* Section - Parser */
|
|
131
|
+
/********************/
|
|
132
|
+
|
|
133
|
+
extern void tree_sitter_parse_callback(
|
|
134
|
+
char *input_buffer,
|
|
135
|
+
uint32_t index,
|
|
136
|
+
uint32_t row,
|
|
137
|
+
uint32_t column,
|
|
138
|
+
uint32_t *length_read
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
extern void tree_sitter_log_callback(
|
|
142
|
+
bool is_lex_message,
|
|
143
|
+
const char *message
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
extern bool tree_sitter_progress_callback(
|
|
147
|
+
uint32_t current_offset,
|
|
148
|
+
bool has_error
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
extern bool tree_sitter_query_progress_callback(
|
|
152
|
+
uint32_t current_offset
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
static const char *call_parse_callback(
|
|
156
|
+
void *payload,
|
|
157
|
+
uint32_t byte,
|
|
158
|
+
TSPoint position,
|
|
159
|
+
uint32_t *bytes_read
|
|
160
|
+
) {
|
|
161
|
+
char *buffer = (char *)payload;
|
|
162
|
+
tree_sitter_parse_callback(
|
|
163
|
+
buffer,
|
|
164
|
+
byte_to_code_unit(byte),
|
|
165
|
+
position.row,
|
|
166
|
+
byte_to_code_unit(position.column),
|
|
167
|
+
bytes_read
|
|
168
|
+
);
|
|
169
|
+
*bytes_read = code_unit_to_byte(*bytes_read);
|
|
170
|
+
if (*bytes_read >= INPUT_BUFFER_SIZE) {
|
|
171
|
+
*bytes_read = INPUT_BUFFER_SIZE - 2;
|
|
172
|
+
}
|
|
173
|
+
return buffer;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
static void call_log_callback(
|
|
177
|
+
void *payload,
|
|
178
|
+
TSLogType log_type,
|
|
179
|
+
const char *message
|
|
180
|
+
) {
|
|
181
|
+
tree_sitter_log_callback(log_type == TSLogTypeLex, message);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
static bool progress_callback(
|
|
185
|
+
TSParseState *state
|
|
186
|
+
) {
|
|
187
|
+
return tree_sitter_progress_callback(state->current_byte_offset, state->has_error);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
static bool query_progress_callback(
|
|
191
|
+
TSQueryCursorState *state
|
|
192
|
+
) {
|
|
193
|
+
return tree_sitter_query_progress_callback(state->current_byte_offset);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
void ts_parser_new_wasm() {
|
|
197
|
+
TSParser *parser = ts_parser_new();
|
|
198
|
+
char *input_buffer = calloc(INPUT_BUFFER_SIZE, sizeof(char));
|
|
199
|
+
TRANSFER_BUFFER[0] = parser;
|
|
200
|
+
TRANSFER_BUFFER[1] = input_buffer;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
void ts_parser_enable_logger_wasm(TSParser *self, bool should_log) {
|
|
204
|
+
TSLogger logger = {self, should_log ? call_log_callback : NULL};
|
|
205
|
+
ts_parser_set_logger(self, logger);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
TSTree *ts_parser_parse_wasm(
|
|
209
|
+
TSParser *self,
|
|
210
|
+
char *input_buffer,
|
|
211
|
+
const TSTree *old_tree,
|
|
212
|
+
TSRange *ranges,
|
|
213
|
+
uint32_t range_count
|
|
214
|
+
) {
|
|
215
|
+
TSInput input = {
|
|
216
|
+
input_buffer,
|
|
217
|
+
call_parse_callback,
|
|
218
|
+
TSInputEncodingUTF16LE,
|
|
219
|
+
NULL,
|
|
220
|
+
};
|
|
221
|
+
if (range_count) {
|
|
222
|
+
for (unsigned i = 0; i < range_count; i++) {
|
|
223
|
+
unmarshal_range(&ranges[i]);
|
|
224
|
+
}
|
|
225
|
+
ts_parser_set_included_ranges(self, ranges, range_count);
|
|
226
|
+
free(ranges);
|
|
227
|
+
} else {
|
|
228
|
+
ts_parser_set_included_ranges(self, NULL, 0);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
TSParseOptions options = {.payload = NULL, .progress_callback = progress_callback};
|
|
232
|
+
|
|
233
|
+
return ts_parser_parse_with_options(self, old_tree, input, options);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
void ts_parser_included_ranges_wasm(TSParser *self) {
|
|
237
|
+
uint32_t range_count = 0;
|
|
238
|
+
const TSRange *ranges = ts_parser_included_ranges(self, &range_count);
|
|
239
|
+
TSRange *copied_ranges = malloc(sizeof(TSRange) * range_count);
|
|
240
|
+
memcpy(copied_ranges, ranges, sizeof(TSRange) * range_count);
|
|
241
|
+
for (unsigned i = 0; i < range_count; i++) {
|
|
242
|
+
marshal_range(&copied_ranges[i]);
|
|
243
|
+
}
|
|
244
|
+
TRANSFER_BUFFER[0] = range_count ? (const void *)range_count : NULL;
|
|
245
|
+
TRANSFER_BUFFER[1] = copied_ranges;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**********************/
|
|
249
|
+
/* Section - Language */
|
|
250
|
+
/**********************/
|
|
251
|
+
|
|
252
|
+
int ts_language_type_is_named_wasm(const TSLanguage *self, TSSymbol typeId) {
|
|
253
|
+
const TSSymbolType symbolType = ts_language_symbol_type(self, typeId);
|
|
254
|
+
return symbolType == TSSymbolTypeRegular;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
int ts_language_type_is_visible_wasm(const TSLanguage *self, TSSymbol typeId) {
|
|
258
|
+
const TSSymbolType symbolType = ts_language_symbol_type(self, typeId);
|
|
259
|
+
return symbolType <= TSSymbolTypeAnonymous;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
void ts_language_metadata_wasm(const TSLanguage *self) {
|
|
263
|
+
const TSLanguageMetadata *metadata = ts_language_metadata(self);
|
|
264
|
+
marshal_language_metadata(metadata);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
void ts_language_supertypes_wasm(const TSLanguage *self) {
|
|
268
|
+
uint32_t length;
|
|
269
|
+
const TSSymbol *supertypes = ts_language_supertypes(self, &length);
|
|
270
|
+
TRANSFER_BUFFER[0] = (const void *)length;
|
|
271
|
+
TRANSFER_BUFFER[1] = supertypes;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
void ts_language_subtypes_wasm(const TSLanguage *self, TSSymbol supertype) {
|
|
275
|
+
uint32_t length;
|
|
276
|
+
const TSSymbol *subtypes = ts_language_subtypes(self, supertype, &length);
|
|
277
|
+
TRANSFER_BUFFER[0] = (const void *)length;
|
|
278
|
+
TRANSFER_BUFFER[1] = subtypes;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/******************/
|
|
282
|
+
/* Section - Tree */
|
|
283
|
+
/******************/
|
|
284
|
+
|
|
285
|
+
void ts_tree_root_node_wasm(const TSTree *tree) {
|
|
286
|
+
marshal_node(TRANSFER_BUFFER, ts_tree_root_node(tree));
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
void ts_tree_root_node_with_offset_wasm(const TSTree *tree) {
|
|
290
|
+
// read int and point from transfer buffer
|
|
291
|
+
const void **address = TRANSFER_BUFFER + SIZE_OF_NODE;
|
|
292
|
+
uint32_t offset = code_unit_to_byte((uint32_t)address[0]);
|
|
293
|
+
TSPoint extent = unmarshal_point(address + 1);
|
|
294
|
+
TSNode node = ts_tree_root_node_with_offset(tree, offset, extent);
|
|
295
|
+
marshal_node(TRANSFER_BUFFER, node);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
void ts_tree_edit_wasm(TSTree *tree) {
|
|
299
|
+
TSInputEdit edit = unmarshal_edit();
|
|
300
|
+
ts_tree_edit(tree, &edit);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
void ts_tree_included_ranges_wasm(const TSTree *tree) {
|
|
304
|
+
uint32_t range_count;
|
|
305
|
+
TSRange *ranges = ts_tree_included_ranges(tree, &range_count);
|
|
306
|
+
for (unsigned i = 0; i < range_count; i++) {
|
|
307
|
+
marshal_range(&ranges[i]);
|
|
308
|
+
}
|
|
309
|
+
TRANSFER_BUFFER[0] = (range_count ? (const void *)range_count : NULL);
|
|
310
|
+
TRANSFER_BUFFER[1] = (const void *)ranges;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
void ts_tree_get_changed_ranges_wasm(TSTree *tree, TSTree *other) {
|
|
314
|
+
unsigned range_count;
|
|
315
|
+
TSRange *ranges = ts_tree_get_changed_ranges(tree, other, &range_count);
|
|
316
|
+
for (unsigned i = 0; i < range_count; i++) {
|
|
317
|
+
marshal_range(&ranges[i]);
|
|
318
|
+
}
|
|
319
|
+
TRANSFER_BUFFER[0] = (const void *)range_count;
|
|
320
|
+
TRANSFER_BUFFER[1] = (const void *)ranges;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/************************/
|
|
324
|
+
/* Section - TreeCursor */
|
|
325
|
+
/************************/
|
|
326
|
+
|
|
327
|
+
void ts_tree_cursor_new_wasm(const TSTree *tree) {
|
|
328
|
+
TSNode node = unmarshal_node(tree);
|
|
329
|
+
TSTreeCursor cursor = ts_tree_cursor_new(node);
|
|
330
|
+
marshal_cursor(&cursor);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
void ts_tree_cursor_copy_wasm(const TSTree *tree) {
|
|
334
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
335
|
+
TSTreeCursor copy = ts_tree_cursor_copy(&cursor);
|
|
336
|
+
marshal_cursor(©);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
void ts_tree_cursor_delete_wasm(const TSTree *tree) {
|
|
340
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
341
|
+
ts_tree_cursor_delete(&cursor);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
void ts_tree_cursor_reset_wasm(const TSTree *tree) {
|
|
345
|
+
TSNode node = unmarshal_node(tree);
|
|
346
|
+
TSTreeCursor cursor = unmarshal_cursor(&TRANSFER_BUFFER[SIZE_OF_NODE], tree);
|
|
347
|
+
ts_tree_cursor_reset(&cursor, node);
|
|
348
|
+
marshal_cursor(&cursor);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
void ts_tree_cursor_reset_to_wasm(const TSTree *_dst, const TSTree *_src) {
|
|
352
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, _dst);
|
|
353
|
+
TSTreeCursor src = unmarshal_cursor(&TRANSFER_BUFFER[SIZE_OF_CURSOR], _src);
|
|
354
|
+
ts_tree_cursor_reset_to(&cursor, &src);
|
|
355
|
+
marshal_cursor(&cursor);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
bool ts_tree_cursor_goto_first_child_wasm(const TSTree *tree) {
|
|
359
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
360
|
+
bool result = ts_tree_cursor_goto_first_child(&cursor);
|
|
361
|
+
marshal_cursor(&cursor);
|
|
362
|
+
return result;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
bool ts_tree_cursor_goto_last_child_wasm(const TSTree *tree) {
|
|
366
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
367
|
+
bool result = ts_tree_cursor_goto_last_child(&cursor);
|
|
368
|
+
marshal_cursor(&cursor);
|
|
369
|
+
return result;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
bool ts_tree_cursor_goto_first_child_for_index_wasm(const TSTree *tree) {
|
|
373
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
374
|
+
const void **address = TRANSFER_BUFFER + 3;
|
|
375
|
+
uint32_t index = code_unit_to_byte((uint32_t)address[0]);
|
|
376
|
+
bool result = ts_tree_cursor_goto_first_child_for_byte(&cursor, index);
|
|
377
|
+
marshal_cursor(&cursor);
|
|
378
|
+
return result;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
bool ts_tree_cursor_goto_first_child_for_position_wasm(const TSTree *tree) {
|
|
382
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
383
|
+
const void **address = TRANSFER_BUFFER + 3;
|
|
384
|
+
TSPoint point = unmarshal_point(address);
|
|
385
|
+
bool result = ts_tree_cursor_goto_first_child_for_point(&cursor, point);
|
|
386
|
+
marshal_cursor(&cursor);
|
|
387
|
+
return result;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
bool ts_tree_cursor_goto_next_sibling_wasm(const TSTree *tree) {
|
|
391
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
392
|
+
bool result = ts_tree_cursor_goto_next_sibling(&cursor);
|
|
393
|
+
marshal_cursor(&cursor);
|
|
394
|
+
return result;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
bool ts_tree_cursor_goto_previous_sibling_wasm(const TSTree *tree) {
|
|
398
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
399
|
+
bool result = ts_tree_cursor_goto_previous_sibling(&cursor);
|
|
400
|
+
marshal_cursor(&cursor);
|
|
401
|
+
return result;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
void ts_tree_cursor_goto_descendant_wasm(const TSTree *tree, uint32_t goal_descendant_index) {
|
|
405
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
406
|
+
ts_tree_cursor_goto_descendant(&cursor, goal_descendant_index);
|
|
407
|
+
marshal_cursor(&cursor);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
bool ts_tree_cursor_goto_parent_wasm(const TSTree *tree) {
|
|
411
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
412
|
+
bool result = ts_tree_cursor_goto_parent(&cursor);
|
|
413
|
+
marshal_cursor(&cursor);
|
|
414
|
+
return result;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
uint16_t ts_tree_cursor_current_node_type_id_wasm(const TSTree *tree) {
|
|
418
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
419
|
+
TSNode node = ts_tree_cursor_current_node(&cursor);
|
|
420
|
+
return ts_node_symbol(node);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
uint16_t ts_tree_cursor_current_node_state_id_wasm(const TSTree *tree) {
|
|
424
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
425
|
+
TSNode node = ts_tree_cursor_current_node(&cursor);
|
|
426
|
+
return ts_node_parse_state(node);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
bool ts_tree_cursor_current_node_is_named_wasm(const TSTree *tree) {
|
|
430
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
431
|
+
TSNode node = ts_tree_cursor_current_node(&cursor);
|
|
432
|
+
return ts_node_is_named(node);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
bool ts_tree_cursor_current_node_is_missing_wasm(const TSTree *tree) {
|
|
436
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
437
|
+
TSNode node = ts_tree_cursor_current_node(&cursor);
|
|
438
|
+
return ts_node_is_missing(node);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
uint32_t ts_tree_cursor_current_node_id_wasm(const TSTree *tree) {
|
|
442
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
443
|
+
TSNode node = ts_tree_cursor_current_node(&cursor);
|
|
444
|
+
return (uint32_t)node.id;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
void ts_tree_cursor_start_position_wasm(const TSTree *tree) {
|
|
448
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
449
|
+
TSNode node = ts_tree_cursor_current_node(&cursor);
|
|
450
|
+
marshal_point(ts_node_start_point(node));
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
void ts_tree_cursor_end_position_wasm(const TSTree *tree) {
|
|
454
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
455
|
+
TSNode node = ts_tree_cursor_current_node(&cursor);
|
|
456
|
+
marshal_point(ts_node_end_point(node));
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
uint32_t ts_tree_cursor_start_index_wasm(const TSTree *tree) {
|
|
460
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
461
|
+
TSNode node = ts_tree_cursor_current_node(&cursor);
|
|
462
|
+
return byte_to_code_unit(ts_node_start_byte(node));
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
uint32_t ts_tree_cursor_end_index_wasm(const TSTree *tree) {
|
|
466
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
467
|
+
TSNode node = ts_tree_cursor_current_node(&cursor);
|
|
468
|
+
return byte_to_code_unit(ts_node_end_byte(node));
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
uint32_t ts_tree_cursor_current_field_id_wasm(const TSTree *tree) {
|
|
472
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
473
|
+
return ts_tree_cursor_current_field_id(&cursor);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
uint32_t ts_tree_cursor_current_depth_wasm(const TSTree *tree) {
|
|
477
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
478
|
+
return ts_tree_cursor_current_depth(&cursor);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
uint32_t ts_tree_cursor_current_descendant_index_wasm(const TSTree *tree) {
|
|
482
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
483
|
+
return ts_tree_cursor_current_descendant_index(&cursor);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
void ts_tree_cursor_current_node_wasm(const TSTree *tree) {
|
|
487
|
+
TSTreeCursor cursor = unmarshal_cursor(TRANSFER_BUFFER, tree);
|
|
488
|
+
marshal_node(TRANSFER_BUFFER, ts_tree_cursor_current_node(&cursor));
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/******************/
|
|
492
|
+
/* Section - Node */
|
|
493
|
+
/******************/
|
|
494
|
+
|
|
495
|
+
static TSTreeCursor scratch_cursor = {0};
|
|
496
|
+
static TSQueryCursor *scratch_query_cursor = NULL;
|
|
497
|
+
|
|
498
|
+
uint16_t ts_node_symbol_wasm(const TSTree *tree) {
|
|
499
|
+
TSNode node = unmarshal_node(tree);
|
|
500
|
+
return ts_node_symbol(node);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
const char *ts_node_field_name_for_child_wasm(const TSTree *tree, uint32_t index) {
|
|
504
|
+
TSNode node = unmarshal_node(tree);
|
|
505
|
+
return ts_node_field_name_for_child(node, index);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const char *ts_node_field_name_for_named_child_wasm(const TSTree *tree, uint32_t index) {
|
|
509
|
+
TSNode node = unmarshal_node(tree);
|
|
510
|
+
return ts_node_field_name_for_named_child(node, index);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
void ts_node_children_by_field_id_wasm(const TSTree *tree, uint32_t field_id) {
|
|
514
|
+
TSNode node = unmarshal_node(tree);
|
|
515
|
+
TSTreeCursor cursor = ts_tree_cursor_new(node);
|
|
516
|
+
|
|
517
|
+
bool done = field_id == 0;
|
|
518
|
+
if (!done) {
|
|
519
|
+
ts_tree_cursor_reset(&cursor, node);
|
|
520
|
+
ts_tree_cursor_goto_first_child(&cursor);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
Array(const void*) result = array_new();
|
|
524
|
+
|
|
525
|
+
while (!done) {
|
|
526
|
+
while (ts_tree_cursor_current_field_id(&cursor) != field_id) {
|
|
527
|
+
if (!ts_tree_cursor_goto_next_sibling(&cursor)) {
|
|
528
|
+
done = true;
|
|
529
|
+
break;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
if (done) {
|
|
533
|
+
break;
|
|
534
|
+
}
|
|
535
|
+
TSNode result_node = ts_tree_cursor_current_node(&cursor);
|
|
536
|
+
if (!ts_tree_cursor_goto_next_sibling(&cursor)) {
|
|
537
|
+
done = true;
|
|
538
|
+
}
|
|
539
|
+
array_grow_by(&result, SIZE_OF_NODE);
|
|
540
|
+
marshal_node(result.contents + result.size - SIZE_OF_NODE, result_node);
|
|
541
|
+
}
|
|
542
|
+
ts_tree_cursor_delete(&cursor);
|
|
543
|
+
|
|
544
|
+
TRANSFER_BUFFER[0] = (const void*)(result.size / SIZE_OF_NODE);
|
|
545
|
+
TRANSFER_BUFFER[1] = (const void*)result.contents;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
void ts_node_first_child_for_byte_wasm(const TSTree *tree) {
|
|
549
|
+
TSNode node = unmarshal_node(tree);
|
|
550
|
+
const void** address = TRANSFER_BUFFER + SIZE_OF_NODE;
|
|
551
|
+
uint32_t byte = code_unit_to_byte((uint32_t)address[0]);
|
|
552
|
+
marshal_node(TRANSFER_BUFFER, ts_node_first_child_for_byte(node, byte));
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
void ts_node_first_named_child_for_byte_wasm(const TSTree *tree) {
|
|
556
|
+
TSNode node = unmarshal_node(tree);
|
|
557
|
+
const void** address = TRANSFER_BUFFER + SIZE_OF_NODE;
|
|
558
|
+
uint32_t byte = code_unit_to_byte((uint32_t)address[0]);
|
|
559
|
+
marshal_node(TRANSFER_BUFFER, ts_node_first_named_child_for_byte(node, byte));
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
uint16_t ts_node_grammar_symbol_wasm(const TSTree *tree) {
|
|
563
|
+
TSNode node = unmarshal_node(tree);
|
|
564
|
+
return ts_node_grammar_symbol(node);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
uint32_t ts_node_child_count_wasm(const TSTree *tree) {
|
|
568
|
+
TSNode node = unmarshal_node(tree);
|
|
569
|
+
return ts_node_child_count(node);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
uint32_t ts_node_named_child_count_wasm(const TSTree *tree) {
|
|
573
|
+
TSNode node = unmarshal_node(tree);
|
|
574
|
+
return ts_node_named_child_count(node);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
void ts_node_child_wasm(const TSTree *tree, uint32_t index) {
|
|
578
|
+
TSNode node = unmarshal_node(tree);
|
|
579
|
+
marshal_node(TRANSFER_BUFFER, ts_node_child(node, index));
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
void ts_node_named_child_wasm(const TSTree *tree, uint32_t index) {
|
|
583
|
+
TSNode node = unmarshal_node(tree);
|
|
584
|
+
marshal_node(TRANSFER_BUFFER, ts_node_named_child(node, index));
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
void ts_node_child_by_field_id_wasm(const TSTree *tree, uint32_t field_id) {
|
|
588
|
+
TSNode node = unmarshal_node(tree);
|
|
589
|
+
marshal_node(TRANSFER_BUFFER, ts_node_child_by_field_id(node, field_id));
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
void ts_node_next_sibling_wasm(const TSTree *tree) {
|
|
593
|
+
TSNode node = unmarshal_node(tree);
|
|
594
|
+
marshal_node(TRANSFER_BUFFER, ts_node_next_sibling(node));
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
void ts_node_prev_sibling_wasm(const TSTree *tree) {
|
|
598
|
+
TSNode node = unmarshal_node(tree);
|
|
599
|
+
marshal_node(TRANSFER_BUFFER, ts_node_prev_sibling(node));
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
void ts_node_next_named_sibling_wasm(const TSTree *tree) {
|
|
603
|
+
TSNode node = unmarshal_node(tree);
|
|
604
|
+
marshal_node(TRANSFER_BUFFER, ts_node_next_named_sibling(node));
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
void ts_node_prev_named_sibling_wasm(const TSTree *tree) {
|
|
608
|
+
TSNode node = unmarshal_node(tree);
|
|
609
|
+
marshal_node(TRANSFER_BUFFER, ts_node_prev_named_sibling(node));
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
uint32_t ts_node_descendant_count_wasm(const TSTree *tree) {
|
|
613
|
+
TSNode node = unmarshal_node(tree);
|
|
614
|
+
return ts_node_descendant_count(node);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
void ts_node_parent_wasm(const TSTree *tree) {
|
|
618
|
+
TSNode node = unmarshal_node(tree);
|
|
619
|
+
marshal_node(TRANSFER_BUFFER, ts_node_parent(node));
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
void ts_node_child_with_descendant_wasm(const TSTree *tree) {
|
|
623
|
+
TSNode node = unmarshal_node(tree);
|
|
624
|
+
TSNode descendant = unmarshal_node_at(tree, 1);
|
|
625
|
+
marshal_node(TRANSFER_BUFFER, ts_node_child_with_descendant(node, descendant));
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
void ts_node_descendant_for_index_wasm(const TSTree *tree) {
|
|
629
|
+
TSNode node = unmarshal_node(tree);
|
|
630
|
+
const void **address = TRANSFER_BUFFER + SIZE_OF_NODE;
|
|
631
|
+
uint32_t start = code_unit_to_byte((uint32_t)address[0]);
|
|
632
|
+
uint32_t end = code_unit_to_byte((uint32_t)address[1]);
|
|
633
|
+
marshal_node(TRANSFER_BUFFER, ts_node_descendant_for_byte_range(node, start, end));
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
void ts_node_named_descendant_for_index_wasm(const TSTree *tree) {
|
|
637
|
+
TSNode node = unmarshal_node(tree);
|
|
638
|
+
const void **address = TRANSFER_BUFFER + SIZE_OF_NODE;
|
|
639
|
+
uint32_t start = code_unit_to_byte((uint32_t)address[0]);
|
|
640
|
+
uint32_t end = code_unit_to_byte((uint32_t)address[1]);
|
|
641
|
+
marshal_node(TRANSFER_BUFFER, ts_node_named_descendant_for_byte_range(node, start, end));
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
void ts_node_descendant_for_position_wasm(const TSTree *tree) {
|
|
645
|
+
TSNode node = unmarshal_node(tree);
|
|
646
|
+
const void **address = TRANSFER_BUFFER + SIZE_OF_NODE;
|
|
647
|
+
TSPoint start = unmarshal_point(address); address += SIZE_OF_POINT;
|
|
648
|
+
TSPoint end = unmarshal_point(address);
|
|
649
|
+
marshal_node(TRANSFER_BUFFER, ts_node_descendant_for_point_range(node, start, end));
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
void ts_node_named_descendant_for_position_wasm(const TSTree *tree) {
|
|
653
|
+
TSNode node = unmarshal_node(tree);
|
|
654
|
+
const void **address = TRANSFER_BUFFER + SIZE_OF_NODE;
|
|
655
|
+
TSPoint start = unmarshal_point(address); address += SIZE_OF_POINT;
|
|
656
|
+
TSPoint end = unmarshal_point(address);
|
|
657
|
+
marshal_node(TRANSFER_BUFFER, ts_node_named_descendant_for_point_range(node, start, end));
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
void ts_node_start_point_wasm(const TSTree *tree) {
|
|
661
|
+
TSNode node = unmarshal_node(tree);
|
|
662
|
+
marshal_point(ts_node_start_point(node));
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
void ts_node_end_point_wasm(const TSTree *tree) {
|
|
666
|
+
TSNode node = unmarshal_node(tree);
|
|
667
|
+
marshal_point(ts_node_end_point(node));
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
uint32_t ts_node_start_index_wasm(const TSTree *tree) {
|
|
671
|
+
TSNode node = unmarshal_node(tree);
|
|
672
|
+
return byte_to_code_unit(ts_node_start_byte(node));
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
uint32_t ts_node_end_index_wasm(const TSTree *tree) {
|
|
676
|
+
TSNode node = unmarshal_node(tree);
|
|
677
|
+
return byte_to_code_unit(ts_node_end_byte(node));
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
char *ts_node_to_string_wasm(const TSTree *tree) {
|
|
681
|
+
TSNode node = unmarshal_node(tree);
|
|
682
|
+
return ts_node_string(node);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
void ts_node_children_wasm(const TSTree *tree) {
|
|
686
|
+
TSNode node = unmarshal_node(tree);
|
|
687
|
+
uint32_t count = ts_node_child_count(node);
|
|
688
|
+
const void **result = NULL;
|
|
689
|
+
if (count > 0) {
|
|
690
|
+
result = (const void**)calloc(sizeof(void *), SIZE_OF_NODE * count);
|
|
691
|
+
const void **address = result;
|
|
692
|
+
ts_tree_cursor_reset(&scratch_cursor, node);
|
|
693
|
+
ts_tree_cursor_goto_first_child(&scratch_cursor);
|
|
694
|
+
marshal_node(address, ts_tree_cursor_current_node(&scratch_cursor));
|
|
695
|
+
for (uint32_t i = 1; i < count; i++) {
|
|
696
|
+
address += SIZE_OF_NODE;
|
|
697
|
+
ts_tree_cursor_goto_next_sibling(&scratch_cursor);
|
|
698
|
+
TSNode child = ts_tree_cursor_current_node(&scratch_cursor);
|
|
699
|
+
marshal_node(address, child);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
TRANSFER_BUFFER[0] = (const void *)count;
|
|
703
|
+
TRANSFER_BUFFER[1] = (const void *)result;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
void ts_node_named_children_wasm(const TSTree *tree) {
|
|
707
|
+
TSNode node = unmarshal_node(tree);
|
|
708
|
+
uint32_t count = ts_node_named_child_count(node);
|
|
709
|
+
const void **result = NULL;
|
|
710
|
+
if (count > 0) {
|
|
711
|
+
result = (const void**)calloc(sizeof(void *), SIZE_OF_NODE * count);
|
|
712
|
+
const void **address = result;
|
|
713
|
+
ts_tree_cursor_reset(&scratch_cursor, node);
|
|
714
|
+
ts_tree_cursor_goto_first_child(&scratch_cursor);
|
|
715
|
+
uint32_t i = 0;
|
|
716
|
+
for (;;) {
|
|
717
|
+
TSNode child = ts_tree_cursor_current_node(&scratch_cursor);
|
|
718
|
+
if (ts_node_is_named(child)) {
|
|
719
|
+
marshal_node(address, child);
|
|
720
|
+
address += SIZE_OF_NODE;
|
|
721
|
+
i++;
|
|
722
|
+
if (i == count) {
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
if (!ts_tree_cursor_goto_next_sibling(&scratch_cursor)) {
|
|
727
|
+
break;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
TRANSFER_BUFFER[0] = (const void *)count;
|
|
732
|
+
TRANSFER_BUFFER[1] = (const void *)result;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
bool symbols_contain(const uint32_t *set, uint32_t length, uint32_t value) {
|
|
736
|
+
for (unsigned i = 0; i < length; i++) {
|
|
737
|
+
if (set[i] == value) {
|
|
738
|
+
return true;
|
|
739
|
+
}
|
|
740
|
+
if (set[i] > value) {
|
|
741
|
+
break;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
return false;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
void ts_node_descendants_of_type_wasm(
|
|
748
|
+
const TSTree *tree,
|
|
749
|
+
const uint32_t *symbols,
|
|
750
|
+
uint32_t symbol_count,
|
|
751
|
+
uint32_t start_row,
|
|
752
|
+
uint32_t start_column,
|
|
753
|
+
uint32_t end_row,
|
|
754
|
+
uint32_t end_column
|
|
755
|
+
) {
|
|
756
|
+
TSNode node = unmarshal_node(tree);
|
|
757
|
+
TSPoint start_point = {start_row, code_unit_to_byte(start_column)};
|
|
758
|
+
TSPoint end_point = {end_row, code_unit_to_byte(end_column)};
|
|
759
|
+
if (end_point.row == 0 && end_point.column == 0) {
|
|
760
|
+
end_point = (TSPoint) {UINT32_MAX, UINT32_MAX};
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
Array(const void *) result = array_new();
|
|
764
|
+
|
|
765
|
+
// Walk the tree depth first looking for matching nodes.
|
|
766
|
+
ts_tree_cursor_reset(&scratch_cursor, node);
|
|
767
|
+
bool already_visited_children = false;
|
|
768
|
+
while (true) {
|
|
769
|
+
TSNode descendant = ts_tree_cursor_current_node(&scratch_cursor);
|
|
770
|
+
|
|
771
|
+
if (!already_visited_children) {
|
|
772
|
+
// If this node is before the selected range, then avoid
|
|
773
|
+
// descending into it.
|
|
774
|
+
if (point_lte(ts_node_end_point(descendant), start_point)) {
|
|
775
|
+
if (ts_tree_cursor_goto_next_sibling(&scratch_cursor)) {
|
|
776
|
+
already_visited_children = false;
|
|
777
|
+
} else {
|
|
778
|
+
if (!ts_tree_cursor_goto_parent(&scratch_cursor)) {
|
|
779
|
+
break;
|
|
780
|
+
}
|
|
781
|
+
already_visited_children = true;
|
|
782
|
+
}
|
|
783
|
+
continue;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// If this node is after the selected range, then stop walking.
|
|
787
|
+
if (point_lte(end_point, ts_node_start_point(descendant))) {
|
|
788
|
+
break;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
// Add the node to the result if its type matches one of the given
|
|
792
|
+
// node types.
|
|
793
|
+
if (symbols_contain(symbols, symbol_count, ts_node_symbol(descendant))) {
|
|
794
|
+
array_grow_by(&result, SIZE_OF_NODE);
|
|
795
|
+
marshal_node(result.contents + result.size - SIZE_OF_NODE, descendant);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// Continue walking.
|
|
799
|
+
if (ts_tree_cursor_goto_first_child(&scratch_cursor)) {
|
|
800
|
+
already_visited_children = false;
|
|
801
|
+
} else if (ts_tree_cursor_goto_next_sibling(&scratch_cursor)) {
|
|
802
|
+
already_visited_children = false;
|
|
803
|
+
} else {
|
|
804
|
+
if (!ts_tree_cursor_goto_parent(&scratch_cursor)) {
|
|
805
|
+
break;
|
|
806
|
+
}
|
|
807
|
+
already_visited_children = true;
|
|
808
|
+
}
|
|
809
|
+
} else {
|
|
810
|
+
if (ts_tree_cursor_goto_next_sibling(&scratch_cursor)) {
|
|
811
|
+
already_visited_children = false;
|
|
812
|
+
} else {
|
|
813
|
+
if (!ts_tree_cursor_goto_parent(&scratch_cursor)) {
|
|
814
|
+
break;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
TRANSFER_BUFFER[0] = (const void *)(result.size / SIZE_OF_NODE);
|
|
821
|
+
TRANSFER_BUFFER[1] = (const void *)result.contents;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
int ts_node_is_named_wasm(const TSTree *tree) {
|
|
825
|
+
TSNode node = unmarshal_node(tree);
|
|
826
|
+
return ts_node_is_named(node);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
int ts_node_has_changes_wasm(const TSTree *tree) {
|
|
830
|
+
TSNode node = unmarshal_node(tree);
|
|
831
|
+
return ts_node_has_changes(node);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
int ts_node_has_error_wasm(const TSTree *tree) {
|
|
835
|
+
TSNode node = unmarshal_node(tree);
|
|
836
|
+
return ts_node_has_error(node);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
int ts_node_is_error_wasm(const TSTree *tree) {
|
|
840
|
+
TSNode node = unmarshal_node(tree);
|
|
841
|
+
return ts_node_is_error(node);
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
int ts_node_is_missing_wasm(const TSTree *tree) {
|
|
845
|
+
TSNode node = unmarshal_node(tree);
|
|
846
|
+
return ts_node_is_missing(node);
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
int ts_node_is_extra_wasm(const TSTree *tree) {
|
|
850
|
+
TSNode node = unmarshal_node(tree);
|
|
851
|
+
return ts_node_is_extra(node);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
uint16_t ts_node_parse_state_wasm(const TSTree *tree) {
|
|
855
|
+
TSNode node = unmarshal_node(tree);
|
|
856
|
+
return ts_node_parse_state(node);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
uint16_t ts_node_next_parse_state_wasm(const TSTree *tree) {
|
|
860
|
+
TSNode node = unmarshal_node(tree);
|
|
861
|
+
return ts_node_next_parse_state(node);
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
/******************/
|
|
865
|
+
/* Section - Query */
|
|
866
|
+
/******************/
|
|
867
|
+
|
|
868
|
+
void ts_query_matches_wasm(
|
|
869
|
+
const TSQuery *self,
|
|
870
|
+
const TSTree *tree,
|
|
871
|
+
uint32_t start_row,
|
|
872
|
+
uint32_t start_column,
|
|
873
|
+
uint32_t end_row,
|
|
874
|
+
uint32_t end_column,
|
|
875
|
+
uint32_t start_index,
|
|
876
|
+
uint32_t end_index,
|
|
877
|
+
uint32_t match_limit,
|
|
878
|
+
uint32_t max_start_depth,
|
|
879
|
+
uint32_t timeout_micros
|
|
880
|
+
) {
|
|
881
|
+
if (!scratch_query_cursor) {
|
|
882
|
+
scratch_query_cursor = ts_query_cursor_new();
|
|
883
|
+
}
|
|
884
|
+
if (match_limit == 0) {
|
|
885
|
+
ts_query_cursor_set_match_limit(scratch_query_cursor, UINT32_MAX);
|
|
886
|
+
} else {
|
|
887
|
+
ts_query_cursor_set_match_limit(scratch_query_cursor, match_limit);
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
TSNode node = unmarshal_node(tree);
|
|
891
|
+
TSPoint start_point = {start_row, code_unit_to_byte(start_column)};
|
|
892
|
+
TSPoint end_point = {end_row, code_unit_to_byte(end_column)};
|
|
893
|
+
ts_query_cursor_set_point_range(scratch_query_cursor, start_point, end_point);
|
|
894
|
+
ts_query_cursor_set_byte_range(scratch_query_cursor, start_index, end_index);
|
|
895
|
+
ts_query_cursor_set_match_limit(scratch_query_cursor, match_limit);
|
|
896
|
+
ts_query_cursor_set_max_start_depth(scratch_query_cursor, max_start_depth);
|
|
897
|
+
ts_query_cursor_set_timeout_micros(scratch_query_cursor, timeout_micros);
|
|
898
|
+
|
|
899
|
+
TSQueryCursorOptions options = {.payload = NULL, .progress_callback = query_progress_callback};
|
|
900
|
+
|
|
901
|
+
ts_query_cursor_exec_with_options(scratch_query_cursor, self, node, &options);
|
|
902
|
+
|
|
903
|
+
uint32_t index = 0;
|
|
904
|
+
uint32_t match_count = 0;
|
|
905
|
+
Array(const void *) result = array_new();
|
|
906
|
+
|
|
907
|
+
TSQueryMatch match;
|
|
908
|
+
while (ts_query_cursor_next_match(scratch_query_cursor, &match)) {
|
|
909
|
+
match_count++;
|
|
910
|
+
array_grow_by(&result, 2 + (SIZE_OF_CAPTURE * match.capture_count));
|
|
911
|
+
result.contents[index++] = (const void *)(uint32_t)match.pattern_index;
|
|
912
|
+
result.contents[index++] = (const void *)(uint32_t)match.capture_count;
|
|
913
|
+
for (unsigned i = 0; i < match.capture_count; i++) {
|
|
914
|
+
const TSQueryCapture *capture = &match.captures[i];
|
|
915
|
+
result.contents[index++] = (const void *)capture->index;
|
|
916
|
+
marshal_node(result.contents + index, capture->node);
|
|
917
|
+
index += SIZE_OF_NODE;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
bool did_exceed_match_limit =
|
|
922
|
+
ts_query_cursor_did_exceed_match_limit(scratch_query_cursor);
|
|
923
|
+
TRANSFER_BUFFER[0] = (const void *)(match_count);
|
|
924
|
+
TRANSFER_BUFFER[1] = (const void *)result.contents;
|
|
925
|
+
TRANSFER_BUFFER[2] = (const void *)(did_exceed_match_limit);
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
void ts_query_captures_wasm(
|
|
929
|
+
const TSQuery *self,
|
|
930
|
+
const TSTree *tree,
|
|
931
|
+
uint32_t start_row,
|
|
932
|
+
uint32_t start_column,
|
|
933
|
+
uint32_t end_row,
|
|
934
|
+
uint32_t end_column,
|
|
935
|
+
uint32_t start_index,
|
|
936
|
+
uint32_t end_index,
|
|
937
|
+
uint32_t match_limit,
|
|
938
|
+
uint32_t max_start_depth,
|
|
939
|
+
uint32_t timeout_micros
|
|
940
|
+
) {
|
|
941
|
+
if (!scratch_query_cursor) {
|
|
942
|
+
scratch_query_cursor = ts_query_cursor_new();
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
ts_query_cursor_set_match_limit(scratch_query_cursor, match_limit);
|
|
946
|
+
|
|
947
|
+
TSNode node = unmarshal_node(tree);
|
|
948
|
+
TSPoint start_point = {start_row, code_unit_to_byte(start_column)};
|
|
949
|
+
TSPoint end_point = {end_row, code_unit_to_byte(end_column)};
|
|
950
|
+
ts_query_cursor_set_point_range(scratch_query_cursor, start_point, end_point);
|
|
951
|
+
ts_query_cursor_set_byte_range(scratch_query_cursor, start_index, end_index);
|
|
952
|
+
ts_query_cursor_set_match_limit(scratch_query_cursor, match_limit);
|
|
953
|
+
ts_query_cursor_set_max_start_depth(scratch_query_cursor, max_start_depth);
|
|
954
|
+
ts_query_cursor_set_timeout_micros(scratch_query_cursor, timeout_micros);
|
|
955
|
+
ts_query_cursor_exec(scratch_query_cursor, self, node);
|
|
956
|
+
|
|
957
|
+
unsigned index = 0;
|
|
958
|
+
unsigned capture_count = 0;
|
|
959
|
+
Array(const void *) result = array_new();
|
|
960
|
+
|
|
961
|
+
TSQueryMatch match;
|
|
962
|
+
uint32_t capture_index;
|
|
963
|
+
while (ts_query_cursor_next_capture(
|
|
964
|
+
scratch_query_cursor,
|
|
965
|
+
&match,
|
|
966
|
+
&capture_index
|
|
967
|
+
)) {
|
|
968
|
+
capture_count++;
|
|
969
|
+
|
|
970
|
+
array_grow_by(&result, 3 + (SIZE_OF_CAPTURE * match.capture_count));
|
|
971
|
+
result.contents[index++] = (const void *)(uint32_t)match.pattern_index;
|
|
972
|
+
result.contents[index++] = (const void *)(uint32_t)match.capture_count;
|
|
973
|
+
result.contents[index++] = (const void *)capture_index;
|
|
974
|
+
for (unsigned i = 0; i < match.capture_count; i++) {
|
|
975
|
+
const TSQueryCapture *capture = &match.captures[i];
|
|
976
|
+
result.contents[index++] = (const void *)capture->index;
|
|
977
|
+
marshal_node(result.contents + index, capture->node);
|
|
978
|
+
index += SIZE_OF_NODE;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
bool did_exceed_match_limit =
|
|
983
|
+
ts_query_cursor_did_exceed_match_limit(scratch_query_cursor);
|
|
984
|
+
TRANSFER_BUFFER[0] = (const void *)(capture_count);
|
|
985
|
+
TRANSFER_BUFFER[1] = (const void *)result.contents;
|
|
986
|
+
TRANSFER_BUFFER[2] = (const void *)(did_exceed_match_limit);
|
|
987
|
+
}
|