tree-sitter-topaz 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +171 -0
- package/NOTICE +1 -0
- package/binding.gyp +23 -0
- package/bindings/node/binding.cc +19 -0
- package/bindings/node/index.d.ts +8 -0
- package/bindings/node/index.js +9 -0
- package/grammar.js +1201 -0
- package/package.json +59 -0
- package/queries/highlights.scm +90 -0
- package/queries/indents.scm +24 -0
- package/queries/injections.scm +11 -0
- package/queries/locals.scm +13 -0
- package/src/grammar.json +6462 -0
- package/src/node-types.json +8728 -0
- package/src/parser.c +96271 -0
- package/src/scanner.c +571 -0
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +291 -0
- package/src/tree_sitter/parser.h +286 -0
- package/tree-sitter.json +36 -0
package/src/scanner.c
ADDED
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
#include "tree_sitter/parser.h"
|
|
2
|
+
|
|
3
|
+
#include <stdbool.h>
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
#include <string.h>
|
|
6
|
+
|
|
7
|
+
enum TokenType {
|
|
8
|
+
NOMINAL_RECORD_CONSTRUCTION,
|
|
9
|
+
RECORD_LBRACE,
|
|
10
|
+
CALL_TYPE_ARGUMENTS,
|
|
11
|
+
CASE_PATTERN,
|
|
12
|
+
STRING,
|
|
13
|
+
TAGGED_TEMPLATE,
|
|
14
|
+
COMPREHENSION_CLAUSES,
|
|
15
|
+
BINDING_CONDITION,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
void *tree_sitter_topaz_external_scanner_create(void) { return NULL; }
|
|
19
|
+
void tree_sitter_topaz_external_scanner_destroy(void *payload) {
|
|
20
|
+
(void)payload;
|
|
21
|
+
}
|
|
22
|
+
unsigned tree_sitter_topaz_external_scanner_serialize(void *payload,
|
|
23
|
+
char *buffer) {
|
|
24
|
+
(void)payload;
|
|
25
|
+
(void)buffer;
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
void tree_sitter_topaz_external_scanner_deserialize(void *payload,
|
|
29
|
+
const char *buffer,
|
|
30
|
+
unsigned length) {
|
|
31
|
+
(void)payload;
|
|
32
|
+
(void)buffer;
|
|
33
|
+
(void)length;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static bool is_space(int32_t character) {
|
|
37
|
+
return character == ' ' || character == '\t' || character == '\r' ||
|
|
38
|
+
character == '\n' || character == '\f';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static bool is_identifier_start(int32_t character) {
|
|
42
|
+
return character == '_' || character >= 0x80 ||
|
|
43
|
+
(character >= 'A' && character <= 'Z') ||
|
|
44
|
+
(character >= 'a' && character <= 'z');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static bool is_identifier_continue(int32_t character) {
|
|
48
|
+
return is_identifier_start(character) ||
|
|
49
|
+
(character >= '0' && character <= '9');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static void skip_space_and_comments(TSLexer *lexer) {
|
|
53
|
+
for (;;) {
|
|
54
|
+
while (is_space(lexer->lookahead)) {
|
|
55
|
+
lexer->advance(lexer, true);
|
|
56
|
+
}
|
|
57
|
+
if (lexer->lookahead != '/') {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
lexer->advance(lexer, true);
|
|
61
|
+
if (lexer->lookahead == '/') {
|
|
62
|
+
while (lexer->lookahead != 0 && lexer->lookahead != '\n' &&
|
|
63
|
+
lexer->lookahead != '\r') {
|
|
64
|
+
lexer->advance(lexer, true);
|
|
65
|
+
}
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (lexer->lookahead == '*') {
|
|
69
|
+
lexer->advance(lexer, true);
|
|
70
|
+
int32_t previous = 0;
|
|
71
|
+
while (lexer->lookahead != 0) {
|
|
72
|
+
int32_t current = lexer->lookahead;
|
|
73
|
+
lexer->advance(lexer, true);
|
|
74
|
+
if (previous == '*' && current == '/') {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
previous = current;
|
|
78
|
+
}
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static bool scan_nominal_record_construction(TSLexer *lexer) {
|
|
86
|
+
if (!is_identifier_start(lexer->lookahead)) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
char head[24] = {0};
|
|
90
|
+
unsigned head_length = 0;
|
|
91
|
+
do {
|
|
92
|
+
if (lexer->lookahead < 0x80 && head_length + 1 < sizeof(head)) {
|
|
93
|
+
head[head_length++] = (char)lexer->lookahead;
|
|
94
|
+
}
|
|
95
|
+
lexer->advance(lexer, false);
|
|
96
|
+
} while (is_identifier_continue(lexer->lookahead));
|
|
97
|
+
static const char *reserved[] = {
|
|
98
|
+
"break", "case", "concurrent", "const", "continue",
|
|
99
|
+
"defer", "else", "enum", "export", "false",
|
|
100
|
+
"for", "function", "if", "impl", "import",
|
|
101
|
+
"let", "loop", "map", "match", "mut",
|
|
102
|
+
"newtype", "null", "protocol", "record", "return",
|
|
103
|
+
"set", "true", "type", "using", "while",
|
|
104
|
+
};
|
|
105
|
+
for (unsigned i = 0; i < sizeof(reserved) / sizeof(reserved[0]); i++) {
|
|
106
|
+
if (strcmp(head, reserved[i]) == 0) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
while (is_space(lexer->lookahead)) {
|
|
111
|
+
lexer->advance(lexer, false);
|
|
112
|
+
}
|
|
113
|
+
if (lexer->lookahead != '{') {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
lexer->advance(lexer, false);
|
|
118
|
+
while (is_space(lexer->lookahead)) {
|
|
119
|
+
lexer->advance(lexer, false);
|
|
120
|
+
}
|
|
121
|
+
bool valid_head = lexer->lookahead == '}' || lexer->lookahead == '.';
|
|
122
|
+
if (!valid_head && is_identifier_start(lexer->lookahead)) {
|
|
123
|
+
do {
|
|
124
|
+
lexer->advance(lexer, false);
|
|
125
|
+
} while (is_identifier_continue(lexer->lookahead));
|
|
126
|
+
while (is_space(lexer->lookahead)) {
|
|
127
|
+
lexer->advance(lexer, false);
|
|
128
|
+
}
|
|
129
|
+
valid_head = lexer->lookahead == ':';
|
|
130
|
+
}
|
|
131
|
+
if (!valid_head) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
unsigned depth = 1;
|
|
136
|
+
bool string = false;
|
|
137
|
+
bool escaped = false;
|
|
138
|
+
while (lexer->lookahead != 0) {
|
|
139
|
+
int32_t character = lexer->lookahead;
|
|
140
|
+
lexer->advance(lexer, false);
|
|
141
|
+
if (string) {
|
|
142
|
+
if (escaped) {
|
|
143
|
+
escaped = false;
|
|
144
|
+
} else if (character == '\\') {
|
|
145
|
+
escaped = true;
|
|
146
|
+
} else if (character == '"') {
|
|
147
|
+
string = false;
|
|
148
|
+
}
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (character == '"') {
|
|
152
|
+
string = true;
|
|
153
|
+
} else if (character == '{') {
|
|
154
|
+
depth += 1;
|
|
155
|
+
} else if (character == '}') {
|
|
156
|
+
depth -= 1;
|
|
157
|
+
if (depth == 0) {
|
|
158
|
+
lexer->mark_end(lexer);
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
static bool scan_string_body(TSLexer *lexer) {
|
|
167
|
+
if (lexer->lookahead != '"') {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
lexer->advance(lexer, false);
|
|
172
|
+
bool triple = false;
|
|
173
|
+
if (lexer->lookahead == '"') {
|
|
174
|
+
lexer->advance(lexer, false);
|
|
175
|
+
if (lexer->lookahead == '"') {
|
|
176
|
+
lexer->advance(lexer, false);
|
|
177
|
+
triple = true;
|
|
178
|
+
} else {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
unsigned interpolation_depth = 0;
|
|
184
|
+
bool escaped = false;
|
|
185
|
+
bool nested_string = false;
|
|
186
|
+
while (lexer->lookahead != 0) {
|
|
187
|
+
int32_t character = lexer->lookahead;
|
|
188
|
+
if (escaped) {
|
|
189
|
+
lexer->advance(lexer, false);
|
|
190
|
+
escaped = false;
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (character == '\\') {
|
|
194
|
+
lexer->advance(lexer, false);
|
|
195
|
+
escaped = true;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (interpolation_depth > 0) {
|
|
200
|
+
if (nested_string) {
|
|
201
|
+
lexer->advance(lexer, false);
|
|
202
|
+
if (character == '"') {
|
|
203
|
+
nested_string = false;
|
|
204
|
+
}
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (character == '"') {
|
|
208
|
+
nested_string = true;
|
|
209
|
+
} else if (character == '{') {
|
|
210
|
+
interpolation_depth += 1;
|
|
211
|
+
} else if (character == '}') {
|
|
212
|
+
interpolation_depth -= 1;
|
|
213
|
+
}
|
|
214
|
+
lexer->advance(lexer, false);
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (character == '{') {
|
|
219
|
+
interpolation_depth = 1;
|
|
220
|
+
lexer->advance(lexer, false);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (character == '\n' || character == '\r') {
|
|
224
|
+
if (!triple) {
|
|
225
|
+
lexer->mark_end(lexer);
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
lexer->advance(lexer, false);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (character != '"') {
|
|
232
|
+
lexer->advance(lexer, false);
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
lexer->advance(lexer, false);
|
|
237
|
+
if (!triple) {
|
|
238
|
+
lexer->mark_end(lexer);
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
if (lexer->lookahead != '"') {
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
lexer->advance(lexer, false);
|
|
245
|
+
if (lexer->lookahead != '"') {
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
lexer->advance(lexer, false);
|
|
249
|
+
lexer->mark_end(lexer);
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
lexer->mark_end(lexer);
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
static bool scan_tagged_template(TSLexer *lexer) {
|
|
257
|
+
if (lexer->lookahead == 'p' || lexer->lookahead == 'r') {
|
|
258
|
+
lexer->advance(lexer, false);
|
|
259
|
+
} else if (lexer->lookahead == 's') {
|
|
260
|
+
lexer->advance(lexer, false);
|
|
261
|
+
if (lexer->lookahead == 'h') {
|
|
262
|
+
lexer->advance(lexer, false);
|
|
263
|
+
} else if (lexer->lookahead == 'q') {
|
|
264
|
+
lexer->advance(lexer, false);
|
|
265
|
+
if (lexer->lookahead != 'l') {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
lexer->advance(lexer, false);
|
|
269
|
+
} else {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
return scan_string_body(lexer);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
static bool scan_until_arrow(TSLexer *lexer, enum TokenType symbol) {
|
|
279
|
+
unsigned parentheses = 0;
|
|
280
|
+
unsigned brackets = 0;
|
|
281
|
+
unsigned braces = 0;
|
|
282
|
+
bool consumed = false;
|
|
283
|
+
bool string = false;
|
|
284
|
+
bool escaped = false;
|
|
285
|
+
while (lexer->lookahead != 0) {
|
|
286
|
+
int32_t character = lexer->lookahead;
|
|
287
|
+
if (string) {
|
|
288
|
+
lexer->advance(lexer, false);
|
|
289
|
+
consumed = true;
|
|
290
|
+
if (escaped) {
|
|
291
|
+
escaped = false;
|
|
292
|
+
} else if (character == '\\') {
|
|
293
|
+
escaped = true;
|
|
294
|
+
} else if (character == '"') {
|
|
295
|
+
string = false;
|
|
296
|
+
}
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
if (character == '"') {
|
|
300
|
+
string = true;
|
|
301
|
+
lexer->advance(lexer, false);
|
|
302
|
+
consumed = true;
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (character == '(') {
|
|
306
|
+
parentheses += 1;
|
|
307
|
+
} else if (character == ')' && parentheses > 0) {
|
|
308
|
+
parentheses -= 1;
|
|
309
|
+
} else if (character == '[') {
|
|
310
|
+
brackets += 1;
|
|
311
|
+
} else if (character == ']' && brackets > 0) {
|
|
312
|
+
brackets -= 1;
|
|
313
|
+
} else if (character == '{') {
|
|
314
|
+
braces += 1;
|
|
315
|
+
} else if (character == '}' && braces > 0) {
|
|
316
|
+
braces -= 1;
|
|
317
|
+
} else if (character == '=' && parentheses == 0 && brackets == 0 &&
|
|
318
|
+
braces == 0) {
|
|
319
|
+
lexer->mark_end(lexer);
|
|
320
|
+
lexer->advance(lexer, false);
|
|
321
|
+
if (lexer->lookahead == '>' && consumed) {
|
|
322
|
+
lexer->result_symbol = symbol;
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
consumed = true;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
lexer->advance(lexer, false);
|
|
329
|
+
consumed = true;
|
|
330
|
+
}
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
static bool scan_comprehension_clauses(TSLexer *lexer) {
|
|
335
|
+
if (lexer->lookahead != 'f') {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
lexer->advance(lexer, false);
|
|
339
|
+
if (lexer->lookahead != 'o') {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
lexer->advance(lexer, false);
|
|
343
|
+
if (lexer->lookahead != 'r') {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
lexer->advance(lexer, false);
|
|
347
|
+
if (!is_space(lexer->lookahead)) {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
return scan_until_arrow(lexer, COMPREHENSION_CLAUSES);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
static bool scan_binding_condition(TSLexer *lexer) {
|
|
354
|
+
const char *head = "let";
|
|
355
|
+
for (unsigned i = 0; head[i] != 0; i++) {
|
|
356
|
+
if (lexer->lookahead != head[i]) {
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
lexer->advance(lexer, false);
|
|
360
|
+
}
|
|
361
|
+
if (!is_space(lexer->lookahead)) {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
unsigned parentheses = 0;
|
|
366
|
+
unsigned brackets = 0;
|
|
367
|
+
unsigned braces = 0;
|
|
368
|
+
bool seen_equals = false;
|
|
369
|
+
bool string = false;
|
|
370
|
+
bool escaped = false;
|
|
371
|
+
while (lexer->lookahead != 0) {
|
|
372
|
+
int32_t character = lexer->lookahead;
|
|
373
|
+
if (string) {
|
|
374
|
+
lexer->advance(lexer, false);
|
|
375
|
+
if (escaped) {
|
|
376
|
+
escaped = false;
|
|
377
|
+
} else if (character == '\\') {
|
|
378
|
+
escaped = true;
|
|
379
|
+
} else if (character == '"') {
|
|
380
|
+
string = false;
|
|
381
|
+
}
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (character == '"') {
|
|
385
|
+
string = true;
|
|
386
|
+
lexer->advance(lexer, false);
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
if (character == '(') {
|
|
390
|
+
parentheses += 1;
|
|
391
|
+
} else if (character == ')' && parentheses > 0) {
|
|
392
|
+
parentheses -= 1;
|
|
393
|
+
} else if (character == '[') {
|
|
394
|
+
brackets += 1;
|
|
395
|
+
} else if (character == ']' && brackets > 0) {
|
|
396
|
+
brackets -= 1;
|
|
397
|
+
} else if (character == '{') {
|
|
398
|
+
if (seen_equals && parentheses == 0 && brackets == 0 && braces == 0) {
|
|
399
|
+
lexer->mark_end(lexer);
|
|
400
|
+
lexer->result_symbol = BINDING_CONDITION;
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
braces += 1;
|
|
404
|
+
} else if (character == '}' && braces > 0) {
|
|
405
|
+
braces -= 1;
|
|
406
|
+
} else if (character == '=' && parentheses == 0 && brackets == 0 &&
|
|
407
|
+
braces == 0) {
|
|
408
|
+
seen_equals = true;
|
|
409
|
+
}
|
|
410
|
+
lexer->advance(lexer, false);
|
|
411
|
+
}
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
bool tree_sitter_topaz_external_scanner_scan(void *payload, TSLexer *lexer,
|
|
416
|
+
const bool *valid_symbols) {
|
|
417
|
+
(void)payload;
|
|
418
|
+
while (is_space(lexer->lookahead)) {
|
|
419
|
+
lexer->advance(lexer, true);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (valid_symbols[COMPREHENSION_CLAUSES] && lexer->lookahead == 'f') {
|
|
423
|
+
return scan_comprehension_clauses(lexer);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (valid_symbols[BINDING_CONDITION] && lexer->lookahead == 'l') {
|
|
427
|
+
return scan_binding_condition(lexer);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (valid_symbols[CASE_PATTERN]) {
|
|
431
|
+
unsigned parentheses = 0;
|
|
432
|
+
unsigned brackets = 0;
|
|
433
|
+
unsigned braces = 0;
|
|
434
|
+
bool consumed = false;
|
|
435
|
+
bool string = false;
|
|
436
|
+
bool escaped = false;
|
|
437
|
+
while (lexer->lookahead != 0) {
|
|
438
|
+
int32_t character = lexer->lookahead;
|
|
439
|
+
if (string) {
|
|
440
|
+
lexer->advance(lexer, false);
|
|
441
|
+
consumed = true;
|
|
442
|
+
if (escaped) {
|
|
443
|
+
escaped = false;
|
|
444
|
+
} else if (character == '\\') {
|
|
445
|
+
escaped = true;
|
|
446
|
+
} else if (character == '"') {
|
|
447
|
+
string = false;
|
|
448
|
+
}
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
if (character == '"') {
|
|
452
|
+
string = true;
|
|
453
|
+
lexer->advance(lexer, false);
|
|
454
|
+
consumed = true;
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
if (character == '(') {
|
|
458
|
+
parentheses += 1;
|
|
459
|
+
} else if (character == ')' && parentheses > 0) {
|
|
460
|
+
parentheses -= 1;
|
|
461
|
+
} else if (character == '[') {
|
|
462
|
+
brackets += 1;
|
|
463
|
+
} else if (character == ']' && brackets > 0) {
|
|
464
|
+
brackets -= 1;
|
|
465
|
+
} else if (character == '{') {
|
|
466
|
+
braces += 1;
|
|
467
|
+
} else if (character == '}' && braces > 0) {
|
|
468
|
+
braces -= 1;
|
|
469
|
+
} else if (character == '=' && parentheses == 0 && brackets == 0 &&
|
|
470
|
+
braces == 0) {
|
|
471
|
+
lexer->mark_end(lexer);
|
|
472
|
+
lexer->advance(lexer, false);
|
|
473
|
+
if (lexer->lookahead == '>' && consumed) {
|
|
474
|
+
lexer->result_symbol = CASE_PATTERN;
|
|
475
|
+
return true;
|
|
476
|
+
}
|
|
477
|
+
consumed = true;
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
lexer->advance(lexer, false);
|
|
481
|
+
consumed = true;
|
|
482
|
+
}
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
if (valid_symbols[STRING] && lexer->lookahead == '"') {
|
|
487
|
+
if (scan_string_body(lexer)) {
|
|
488
|
+
lexer->result_symbol = STRING;
|
|
489
|
+
return true;
|
|
490
|
+
}
|
|
491
|
+
return false;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
if (valid_symbols[TAGGED_TEMPLATE] &&
|
|
495
|
+
(lexer->lookahead == 'p' || lexer->lookahead == 'r' ||
|
|
496
|
+
lexer->lookahead == 's')) {
|
|
497
|
+
if (scan_tagged_template(lexer)) {
|
|
498
|
+
lexer->result_symbol = TAGGED_TEMPLATE;
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
501
|
+
return false;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if (valid_symbols[CALL_TYPE_ARGUMENTS] && lexer->lookahead == '<') {
|
|
505
|
+
unsigned depth = 0;
|
|
506
|
+
do {
|
|
507
|
+
if (lexer->lookahead == '<') {
|
|
508
|
+
depth += 1;
|
|
509
|
+
} else if (lexer->lookahead == '>') {
|
|
510
|
+
depth -= 1;
|
|
511
|
+
}
|
|
512
|
+
lexer->advance(lexer, false);
|
|
513
|
+
if (depth == 0) {
|
|
514
|
+
lexer->mark_end(lexer);
|
|
515
|
+
if (lexer->lookahead == '(') {
|
|
516
|
+
lexer->result_symbol = CALL_TYPE_ARGUMENTS;
|
|
517
|
+
return true;
|
|
518
|
+
}
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
} while (lexer->lookahead != 0);
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
if (valid_symbols[RECORD_LBRACE] && lexer->lookahead == '{') {
|
|
526
|
+
lexer->advance(lexer, false);
|
|
527
|
+
lexer->mark_end(lexer);
|
|
528
|
+
skip_space_and_comments(lexer);
|
|
529
|
+
|
|
530
|
+
if (lexer->lookahead == '}') {
|
|
531
|
+
lexer->result_symbol = RECORD_LBRACE;
|
|
532
|
+
return true;
|
|
533
|
+
}
|
|
534
|
+
if (lexer->lookahead == '.') {
|
|
535
|
+
lexer->advance(lexer, true);
|
|
536
|
+
if (lexer->lookahead != '.') {
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
lexer->advance(lexer, true);
|
|
540
|
+
if (lexer->lookahead != '.') {
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
lexer->result_symbol = RECORD_LBRACE;
|
|
544
|
+
return true;
|
|
545
|
+
}
|
|
546
|
+
if (!is_identifier_start(lexer->lookahead)) {
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
do {
|
|
550
|
+
lexer->advance(lexer, true);
|
|
551
|
+
} while (is_identifier_continue(lexer->lookahead));
|
|
552
|
+
skip_space_and_comments(lexer);
|
|
553
|
+
if (lexer->lookahead != ':') {
|
|
554
|
+
return false;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
lexer->result_symbol = RECORD_LBRACE;
|
|
558
|
+
return true;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (valid_symbols[NOMINAL_RECORD_CONSTRUCTION] &&
|
|
562
|
+
is_identifier_start(lexer->lookahead)) {
|
|
563
|
+
if (scan_nominal_record_construction(lexer)) {
|
|
564
|
+
lexer->result_symbol = NOMINAL_RECORD_CONSTRUCTION;
|
|
565
|
+
return true;
|
|
566
|
+
}
|
|
567
|
+
return false;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#ifndef TREE_SITTER_ALLOC_H_
|
|
2
|
+
#define TREE_SITTER_ALLOC_H_
|
|
3
|
+
|
|
4
|
+
#ifdef __cplusplus
|
|
5
|
+
extern "C" {
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
#include <stdbool.h>
|
|
9
|
+
#include <stdio.h>
|
|
10
|
+
#include <stdlib.h>
|
|
11
|
+
|
|
12
|
+
// Allow clients to override allocation functions
|
|
13
|
+
#ifdef TREE_SITTER_REUSE_ALLOCATOR
|
|
14
|
+
|
|
15
|
+
extern void *(*ts_current_malloc)(size_t size);
|
|
16
|
+
extern void *(*ts_current_calloc)(size_t count, size_t size);
|
|
17
|
+
extern void *(*ts_current_realloc)(void *ptr, size_t size);
|
|
18
|
+
extern void (*ts_current_free)(void *ptr);
|
|
19
|
+
|
|
20
|
+
#ifndef ts_malloc
|
|
21
|
+
#define ts_malloc ts_current_malloc
|
|
22
|
+
#endif
|
|
23
|
+
#ifndef ts_calloc
|
|
24
|
+
#define ts_calloc ts_current_calloc
|
|
25
|
+
#endif
|
|
26
|
+
#ifndef ts_realloc
|
|
27
|
+
#define ts_realloc ts_current_realloc
|
|
28
|
+
#endif
|
|
29
|
+
#ifndef ts_free
|
|
30
|
+
#define ts_free ts_current_free
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
#else
|
|
34
|
+
|
|
35
|
+
#ifndef ts_malloc
|
|
36
|
+
#define ts_malloc malloc
|
|
37
|
+
#endif
|
|
38
|
+
#ifndef ts_calloc
|
|
39
|
+
#define ts_calloc calloc
|
|
40
|
+
#endif
|
|
41
|
+
#ifndef ts_realloc
|
|
42
|
+
#define ts_realloc realloc
|
|
43
|
+
#endif
|
|
44
|
+
#ifndef ts_free
|
|
45
|
+
#define ts_free free
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
#endif
|
|
49
|
+
|
|
50
|
+
#ifdef __cplusplus
|
|
51
|
+
}
|
|
52
|
+
#endif
|
|
53
|
+
|
|
54
|
+
#endif // TREE_SITTER_ALLOC_H_
|