-
Notifications
You must be signed in to change notification settings - Fork 2
/
shim.c
527 lines (443 loc) · 10.8 KB
/
shim.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
#include <stdint.h>
#include <stdlib.h>
#include <tree_sitter/api.h>
/*******************/
/* Section - Point */
/*******************/
TSPoint *ts_point_new(uint32_t row, uint32_t column)
{
TSPoint *point = malloc(sizeof(TSPoint));
if (point)
*point = (TSPoint){ .row = row, .column = column };
return point;
}
uint32_t ts_point_row(TSPoint *self)
{
return self->row;
}
uint32_t ts_point_column(TSPoint *self)
{
return self->column;
}
void ts_point_delete(TSPoint *self)
{
free(self);
}
/******************/
/* Section - Tree */
/******************/
TSNode *ts_tree_root_node_(const TSTree *self)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_tree_root_node(self);
return node;
}
TSNode *ts_tree_root_node_with_offset_(const TSTree *self,
uint32_t offset_bytes,
TSPoint *offset_extent)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_tree_root_node_with_offset(self, offset_bytes,
*offset_extent);
return node;
}
/******************/
/* Section - Node */
/******************/
const char *ts_node_type_(TSNode *self)
{
return ts_node_type(*self);
}
TSSymbol ts_node_symbol_(TSNode *self)
{
return ts_node_symbol(*self);
}
const TSLanguage *ts_node_language_(TSNode *self)
{
return ts_node_language(*self);
}
const char *ts_node_grammar_type_(TSNode *self)
{
return ts_node_grammar_type(*self);
}
TSSymbol ts_node_grammar_symbol_(TSNode *self)
{
return ts_node_grammar_symbol(*self);
}
uint32_t ts_node_start_byte_(TSNode *self)
{
return ts_node_start_byte(*self);
}
TSPoint *ts_node_start_point_(TSNode *self)
{
TSPoint *point = malloc(sizeof(TSPoint));
if (point)
*point = ts_node_start_point(*self);
return point;
}
uint32_t ts_node_end_byte_(TSNode *self)
{
return ts_node_end_byte(*self);
}
TSPoint *ts_node_end_point_(TSNode *self)
{
TSPoint *point = malloc(sizeof(TSPoint));
if (point)
*point = ts_node_end_point(*self);
return point;
}
char *ts_node_string_(TSNode *self)
{
return ts_node_string(*self);
}
bool ts_node_is_null_(TSNode *self)
{
return ts_node_is_null(*self);
}
bool ts_node_is_named_(TSNode *self)
{
return ts_node_is_named(*self);
}
bool ts_node_is_missing_(TSNode *self)
{
return ts_node_is_missing(*self);
}
bool ts_node_is_extra_(TSNode *self)
{
return ts_node_is_extra(*self);
}
bool ts_node_has_changes_(TSNode *self)
{
return ts_node_has_changes(*self);
}
bool ts_node_has_error_(TSNode *self)
{
return ts_node_has_error(*self);
}
bool ts_node_is_error_(TSNode *self)
{
return ts_node_is_error(*self);
}
TSStateId ts_node_parse_state_(TSNode *self)
{
return ts_node_parse_state(*self);
}
TSStateId ts_node_next_parse_state_(TSNode *self)
{
return ts_node_next_parse_state(*self);
}
TSNode *ts_node_parent_(TSNode *self)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_node_parent(*self);
return node;
}
TSNode *ts_node_child_containing_descendant_(TSNode *self, TSNode *descendant)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_node_child_containing_descendant(*self, *descendant);
return node;
}
TSNode *ts_node_child_(TSNode *self, uint32_t child_index)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_node_child(*self, child_index);
return node;
}
const char *ts_node_field_name_for_child_(TSNode *self, uint32_t child_index)
{
return ts_node_field_name_for_child(*self, child_index);
}
uint32_t ts_node_child_count_(TSNode *self)
{
return ts_node_child_count(*self);
}
TSNode *ts_node_named_child_(TSNode *self, uint32_t child_index)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_node_named_child(*self, child_index);
return node;
}
uint32_t ts_node_named_child_count_(TSNode *self)
{
return ts_node_named_child_count(*self);
}
TSNode *ts_node_child_by_field_id_(TSNode *self, TSFieldId field_id)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_node_child_by_field_id(*self, field_id);
return node;
}
TSNode *ts_node_next_sibling_(TSNode *self)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_node_next_sibling(*self);
return node;
}
TSNode *ts_node_prev_sibling_(TSNode *self)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_node_prev_sibling(*self);
return node;
}
TSNode *ts_node_next_named_sibling_(TSNode *self)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_node_next_named_sibling(*self);
return node;
}
TSNode *ts_node_prev_named_sibling_(TSNode *self)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_node_prev_named_sibling(*self);
return node;
}
TSNode *ts_node_first_child_for_byte_(TSNode *self, uint32_t byte)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_node_first_child_for_byte(*self, byte);
return node;
}
TSNode *ts_node_first_named_child_for_byte_(TSNode *self, uint32_t byte)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_node_first_named_child_for_byte(*self, byte);
return node;
}
uint32_t ts_node_descendant_count_(TSNode *self)
{
return ts_node_descendant_count(*self);
}
TSNode *ts_node_descendant_for_byte_range_(TSNode *self, uint32_t start,
uint32_t end)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_node_descendant_for_byte_range(*self, start, end);
return node;
}
TSNode *ts_node_descendant_for_point_range_(TSNode *self, TSPoint *start,
TSPoint *end)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_node_descendant_for_point_range(*self, *start, *end);
return node;
}
TSNode *ts_node_named_descendant_for_byte_range_(TSNode *self, uint32_t start,
uint32_t end)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_node_named_descendant_for_byte_range(*self, start,
end);
return node;
}
TSNode *ts_node_named_descendant_for_point_range_(TSNode *self, TSPoint *start,
TSPoint *end)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_node_named_descendant_for_point_range(*self, *start,
*end);
return node;
}
bool ts_node_eq_(TSNode *self, TSNode *other)
{
return ts_node_eq(*self, *other);
}
void ts_node_delete(TSNode *self)
{
free(self);
}
/************************/
/* Section - TreeCursor */
/************************/
TSTreeCursor *ts_tree_cursor_new_(TSNode *node)
{
TSTreeCursor *cursor = malloc(sizeof(TSTreeCursor));
if (cursor)
*cursor = ts_tree_cursor_new(*node);
return cursor;
}
void ts_tree_cursor_reset_(TSTreeCursor *self, TSNode *node)
{
ts_tree_cursor_reset(self, *node);
}
TSNode *ts_tree_cursor_current_node_(const TSTreeCursor *self)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = ts_tree_cursor_current_node(self);
return node;
}
uint64_t ts_tree_cursor_goto_first_child_for_point_(TSTreeCursor *self,
TSPoint *goal_point)
{
return ts_tree_cursor_goto_first_child_for_point(self, *goal_point);
}
/*******************/
/* Section - Query */
/*******************/
typedef struct {
TSQuery *query;
uint32_t error_offset;
TSQueryError error_type;
} TSQuery_;
uint32_t ts_query_error_offset(TSQuery_ *self)
{
return self->error_offset;
}
TSQueryError ts_query_error_type(TSQuery_ *self)
{
return self->error_type;
}
TSQuery_ *ts_query_new_(const TSLanguage *language, const char *source,
uint32_t source_len)
{
TSQuery_ *query_ = malloc(sizeof(TSQuery_));
if (query_) {
query_->error_offset = 0;
query_->error_type = 0;
query_->query = ts_query_new(language, source, source_len,
&query_->error_offset,
&query_->error_type);
}
return query_;
}
void ts_query_delete_(TSQuery_ *self)
{
ts_query_delete(self->query);
free(self);
}
uint32_t ts_query_pattern_count_(TSQuery_ *self)
{
return ts_query_pattern_count(self->query);
}
uint32_t ts_query_capture_count_(TSQuery_ *self)
{
return ts_query_capture_count(self->query);
}
uint32_t ts_query_string_count_(TSQuery_ *self)
{
return ts_query_string_count(self->query);
}
uint32_t ts_query_start_byte_for_pattern_(TSQuery_ *self,
uint32_t pattern_index)
{
return ts_query_start_byte_for_pattern(self->query, pattern_index);
}
const TSQueryPredicateStep *
ts_query_predicates_for_pattern_(TSQuery_ *self, uint32_t pattern_index,
uint32_t *step_count)
{
return ts_query_predicates_for_pattern(self->query, pattern_index,
step_count);
}
bool ts_query_is_pattern_rooted_(TSQuery_ *self, uint32_t pattern_index)
{
return ts_query_is_pattern_rooted(self->query, pattern_index);
}
bool ts_query_is_pattern_non_local_(TSQuery_ *self, uint32_t pattern_index)
{
return ts_query_is_pattern_non_local(self->query, pattern_index);
}
bool ts_query_is_pattern_guaranteed_at_step_(TSQuery_ *self,
uint32_t byte_offset)
{
return ts_query_is_pattern_guaranteed_at_step(self->query, byte_offset);
}
const char *ts_query_capture_name_for_id_(TSQuery_ *self, uint32_t index,
uint32_t *length)
{
return ts_query_capture_name_for_id(self->query, index, length);
}
TSQuantifier ts_query_capture_quantifier_for_id_(TSQuery_ *self,
uint32_t pattern_index,
uint32_t capture_index)
{
return ts_query_capture_quantifier_for_id(self->query, pattern_index,
capture_index);
}
const char *ts_query_string_value_for_id_(TSQuery_ *self, uint32_t index,
uint32_t *length)
{
return ts_query_string_value_for_id(self->query, index, length);
}
void ts_query_disable_capture_(TSQuery_ *self, const char *name,
uint32_t length)
{
ts_query_disable_capture(self->query, name, length);
}
void ts_query_disable_pattern_(TSQuery_ *self, uint32_t pattern_index)
{
ts_query_disable_pattern(self->query, pattern_index);
}
void ts_query_cursor_exec_(TSQueryCursor *self, const TSQuery_ *query,
TSNode *node)
{
ts_query_cursor_exec(self, query->query, *node);
}
void ts_query_cursor_set_point_range_(TSQueryCursor *self, TSPoint *start_point,
TSPoint *end_point)
{
ts_query_cursor_set_point_range(self, *start_point, *end_point);
}
TSNode *ts_query_capture_node(TSQueryCapture *query_capture)
{
TSNode *node = malloc(sizeof(TSNode));
if (node)
*node = query_capture->node;
return node;
}
uint32_t ts_query_capture_index(TSQueryCapture *query_capture)
{
return query_capture->index;
}
TSQueryMatch *ts_query_match_new()
{
TSQueryMatch *self = malloc(sizeof(TSQueryMatch));
if (self)
*self = (TSQueryMatch){};
return self;
}
void ts_query_match_delete(TSQueryMatch *self)
{
free(self);
}
uint32_t ts_query_match_id(TSQueryMatch *self)
{
return self->id;
}
uint16_t ts_query_match_pattern_index(TSQueryMatch *self)
{
return self->pattern_index;
}
uint16_t ts_query_match_capture_count(TSQueryMatch *self)
{
return self->capture_count;
}
TSQueryCapture *ts_query_match_capture(TSQueryMatch *self, uint16_t index)
{
TSQueryCapture *capture = malloc(sizeof(TSQueryCapture));
if (capture)
*capture = self->captures[index];
return capture;
}
void ts_query_capture_delete(TSQueryCapture *self)
{
free(self);
}