@willbooster/tree-sitter-c 8.0.0 → 9.0.1
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/README.md +1 -1
- package/grammar.js +54 -29
- package/package.json +1 -1
- package/src/node-types.json +51 -0
- package/src/scanner.c +13 -14
- package/tree-sitter-c.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ fuzzed with, at version 7.0.5 or later. No other runtime loads the parser:
|
|
|
70
70
|
```toml
|
|
71
71
|
[dependencies]
|
|
72
72
|
tree-sitter = { package = "willbooster-tree-sitter", version = "7.0.5" }
|
|
73
|
-
tree-sitter-c = { package = "willbooster-tree-sitter-c", version = "
|
|
73
|
+
tree-sitter-c = { package = "willbooster-tree-sitter-c", version = "9" }
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
```rust
|
package/grammar.js
CHANGED
|
@@ -68,6 +68,19 @@ module.exports = Object.assign(
|
|
|
68
68
|
name: 'c',
|
|
69
69
|
|
|
70
70
|
conflicts: ($) => [
|
|
71
|
+
[$.preproc_include_argument],
|
|
72
|
+
[$._preproc_include_token, $.preproc_argument_list],
|
|
73
|
+
[$._preproc_include_path, $.preproc_include_argument],
|
|
74
|
+
[$.compound_statement, $.initializer_list],
|
|
75
|
+
[$.comma_expression, $._initializer_element],
|
|
76
|
+
[$.comma_expression, $.initializer_pair],
|
|
77
|
+
[$._block_item, $._initializer_directive],
|
|
78
|
+
[sym('preproc_if'), sym('preproc_if_in_initializer_list')],
|
|
79
|
+
[sym('preproc_ifdef'), sym('preproc_ifdef_in_initializer_list')],
|
|
80
|
+
[sym('preproc_else'), sym('preproc_else_in_initializer_list')],
|
|
81
|
+
[sym('preproc_elif'), sym('preproc_elif_in_initializer_list')],
|
|
82
|
+
[sym('preproc_elifdef'), sym('preproc_elifdef_in_initializer_list')],
|
|
83
|
+
|
|
71
84
|
[$.type_specifier, $.expression, $.va_arg_expression, $.macro_type_specifier],
|
|
72
85
|
[$.va_arg_expression, $.expression],
|
|
73
86
|
[$.type_definition, $._declaration_modifiers],
|
|
@@ -231,19 +244,41 @@ module.exports = Object.assign(
|
|
|
231
244
|
preproc_include: ($) =>
|
|
232
245
|
seq(
|
|
233
246
|
preprocessor('include'),
|
|
234
|
-
field(
|
|
235
|
-
'path',
|
|
236
|
-
choice(
|
|
237
|
-
$.string_literal,
|
|
238
|
-
$.system_lib_string,
|
|
239
|
-
$.identifier,
|
|
240
|
-
alias($.preproc_call_expression, $.call_expression)
|
|
241
|
-
)
|
|
242
|
-
),
|
|
247
|
+
field('path', choice($._preproc_include_path, $.preproc_include_argument)),
|
|
243
248
|
repeat(choice($.comment, $.pragma_operator)),
|
|
244
249
|
sym('_preproc_newline')
|
|
245
250
|
),
|
|
246
251
|
|
|
252
|
+
_preproc_include_path: ($) =>
|
|
253
|
+
choice(
|
|
254
|
+
$.string_literal,
|
|
255
|
+
$.system_lib_string,
|
|
256
|
+
$.identifier,
|
|
257
|
+
alias($.preproc_call_expression, $.call_expression)
|
|
258
|
+
),
|
|
259
|
+
|
|
260
|
+
preproc_include_argument: ($) => prec.dynamic(-1, seq($.identifier, repeat1($._preproc_include_segment))),
|
|
261
|
+
|
|
262
|
+
_preproc_include_segment: ($) =>
|
|
263
|
+
prec.dynamic(-1, seq(repeat(choice($.comment, $.pragma_operator)), $._preproc_include_token)),
|
|
264
|
+
|
|
265
|
+
_preproc_include_token: ($) =>
|
|
266
|
+
choice(
|
|
267
|
+
$.identifier,
|
|
268
|
+
$.number_literal,
|
|
269
|
+
$.char_literal,
|
|
270
|
+
$.string_literal,
|
|
271
|
+
$.system_lib_string,
|
|
272
|
+
...BINARY_OPERATORS.map(([operator]) => operator),
|
|
273
|
+
'!',
|
|
274
|
+
'~',
|
|
275
|
+
'(',
|
|
276
|
+
')',
|
|
277
|
+
',',
|
|
278
|
+
'defined',
|
|
279
|
+
token(prec(-3, /\S/))
|
|
280
|
+
),
|
|
281
|
+
|
|
247
282
|
preproc_def: ($) =>
|
|
248
283
|
seq(
|
|
249
284
|
preprocessor('define'),
|
|
@@ -1361,12 +1396,17 @@ module.exports = Object.assign(
|
|
|
1361
1396
|
|
|
1362
1397
|
extension_expression: ($) => seq('__extension__', $.expression),
|
|
1363
1398
|
|
|
1364
|
-
// Compound statements, designated initializers, and a trailing comma parse macro arguments, e.g.
|
|
1365
|
-
// MYFORLOOP(1, 10, i, { foo(i); bar(i); }) and PARAMS(.foo = foo, .bar = { bar, 1 },)
|
|
1366
1399
|
argument_list: ($) =>
|
|
1367
1400
|
seq(
|
|
1368
1401
|
'(',
|
|
1369
|
-
optional(
|
|
1402
|
+
optional(
|
|
1403
|
+
seq(
|
|
1404
|
+
commaSep1(
|
|
1405
|
+
choice($.expression, $.compound_statement, $.initializer_pair, prec.dynamic(-1, $.initializer_list))
|
|
1406
|
+
),
|
|
1407
|
+
optional(',')
|
|
1408
|
+
)
|
|
1409
|
+
),
|
|
1370
1410
|
')'
|
|
1371
1411
|
),
|
|
1372
1412
|
|
|
@@ -1422,29 +1462,14 @@ module.exports = Object.assign(
|
|
|
1422
1462
|
alias(sym('preproc_ifdef_in_initializer_list'), sym('preproc_ifdef')),
|
|
1423
1463
|
$.preproc_def,
|
|
1424
1464
|
$.preproc_function_def,
|
|
1425
|
-
|
|
1465
|
+
$.preproc_include,
|
|
1466
|
+
$.preproc_call
|
|
1426
1467
|
),
|
|
1427
1468
|
|
|
1428
1469
|
_initializer_element: ($) => choice($.initializer_pair, $.expression, $.initializer_list),
|
|
1429
1470
|
|
|
1430
1471
|
_initializer_branch: ($) => choice(seq(',', optional($._initializer_sequence)), $._initializer_sequence),
|
|
1431
1472
|
|
|
1432
|
-
_initializer_preproc_call: ($) =>
|
|
1433
|
-
seq(
|
|
1434
|
-
field(
|
|
1435
|
-
'directive',
|
|
1436
|
-
alias(token(/#[ \t]*(embed|include|undef|error|warning|line|pragma)/), $.preproc_directive)
|
|
1437
|
-
),
|
|
1438
|
-
repeat(choice($.comment, $.pragma_operator)),
|
|
1439
|
-
optional(
|
|
1440
|
-
seq(
|
|
1441
|
-
field('argument', alias($._preproc_directive_arg, $.preproc_arg)),
|
|
1442
|
-
repeat(choice($.comment, $.pragma_operator))
|
|
1443
|
-
)
|
|
1444
|
-
),
|
|
1445
|
-
alias(sym('_preproc_newline'), '\n')
|
|
1446
|
-
),
|
|
1447
|
-
|
|
1448
1473
|
...preprocIf('_in_initializer_list', () => sym('_initializer_branch'), 0, false),
|
|
1449
1474
|
|
|
1450
1475
|
initializer_pair: ($) =>
|
package/package.json
CHANGED
package/src/node-types.json
CHANGED
|
@@ -531,6 +531,10 @@
|
|
|
531
531
|
"type": "expression",
|
|
532
532
|
"named": true
|
|
533
533
|
},
|
|
534
|
+
{
|
|
535
|
+
"type": "initializer_list",
|
|
536
|
+
"named": true
|
|
537
|
+
},
|
|
534
538
|
{
|
|
535
539
|
"type": "initializer_pair",
|
|
536
540
|
"named": true
|
|
@@ -2384,6 +2388,10 @@
|
|
|
2384
2388
|
{
|
|
2385
2389
|
"type": "preproc_ifdef",
|
|
2386
2390
|
"named": true
|
|
2391
|
+
},
|
|
2392
|
+
{
|
|
2393
|
+
"type": "preproc_include",
|
|
2394
|
+
"named": true
|
|
2387
2395
|
}
|
|
2388
2396
|
]
|
|
2389
2397
|
}
|
|
@@ -3626,6 +3634,10 @@
|
|
|
3626
3634
|
"type": "identifier",
|
|
3627
3635
|
"named": true
|
|
3628
3636
|
},
|
|
3637
|
+
{
|
|
3638
|
+
"type": "preproc_include_argument",
|
|
3639
|
+
"named": true
|
|
3640
|
+
},
|
|
3629
3641
|
{
|
|
3630
3642
|
"type": "string_literal",
|
|
3631
3643
|
"named": true
|
|
@@ -3652,6 +3664,45 @@
|
|
|
3652
3664
|
]
|
|
3653
3665
|
}
|
|
3654
3666
|
},
|
|
3667
|
+
{
|
|
3668
|
+
"type": "preproc_include_argument",
|
|
3669
|
+
"named": true,
|
|
3670
|
+
"fields": {},
|
|
3671
|
+
"children": {
|
|
3672
|
+
"multiple": true,
|
|
3673
|
+
"required": true,
|
|
3674
|
+
"types": [
|
|
3675
|
+
{
|
|
3676
|
+
"type": "char_literal",
|
|
3677
|
+
"named": true
|
|
3678
|
+
},
|
|
3679
|
+
{
|
|
3680
|
+
"type": "comment",
|
|
3681
|
+
"named": true
|
|
3682
|
+
},
|
|
3683
|
+
{
|
|
3684
|
+
"type": "identifier",
|
|
3685
|
+
"named": true
|
|
3686
|
+
},
|
|
3687
|
+
{
|
|
3688
|
+
"type": "number_literal",
|
|
3689
|
+
"named": true
|
|
3690
|
+
},
|
|
3691
|
+
{
|
|
3692
|
+
"type": "pragma_operator",
|
|
3693
|
+
"named": true
|
|
3694
|
+
},
|
|
3695
|
+
{
|
|
3696
|
+
"type": "string_literal",
|
|
3697
|
+
"named": true
|
|
3698
|
+
},
|
|
3699
|
+
{
|
|
3700
|
+
"type": "system_lib_string",
|
|
3701
|
+
"named": true
|
|
3702
|
+
}
|
|
3703
|
+
]
|
|
3704
|
+
}
|
|
3705
|
+
},
|
|
3655
3706
|
{
|
|
3656
3707
|
"type": "preproc_params",
|
|
3657
3708
|
"named": true,
|
package/src/scanner.c
CHANGED
|
@@ -30,17 +30,16 @@ bool tree_sitter_c_external_scanner_scan(void *payload, TSLexer *lexer, const bo
|
|
|
30
30
|
}
|
|
31
31
|
bool directive_text = !valid_symbols[PREPROC_ARG] && valid_symbols[PREPROC_DIRECTIVE_ARG];
|
|
32
32
|
TSSymbol argument_symbol = directive_text ? PREPROC_DIRECTIVE_ARG : PREPROC_ARG;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
33
|
+
bool argument_valid = valid_symbols[PREPROC_ARG] || directive_text;
|
|
34
|
+
while (valid_symbols[PREPROC_LPAREN] && lexer->lookahead == '\\') {
|
|
35
|
+
lexer->advance(lexer, true);
|
|
36
|
+
if (!scan_preproc_newline(lexer, true)) return false;
|
|
37
|
+
}
|
|
38
|
+
if (valid_symbols[PREPROC_LPAREN] && lexer->lookahead == '(') {
|
|
39
|
+
lexer->advance(lexer, false);
|
|
40
|
+
lexer->mark_end(lexer);
|
|
41
|
+
lexer->result_symbol = PREPROC_LPAREN;
|
|
42
|
+
return true;
|
|
44
43
|
}
|
|
45
44
|
if (valid_symbols[PREPROC_NEWLINE]) {
|
|
46
45
|
for (;;) {
|
|
@@ -52,16 +51,16 @@ bool tree_sitter_c_external_scanner_scan(void *payload, TSLexer *lexer, const bo
|
|
|
52
51
|
lexer->mark_end(lexer);
|
|
53
52
|
if (!scan_preproc_newline(lexer, true)) {
|
|
54
53
|
lexer->result_symbol = argument_symbol;
|
|
55
|
-
return
|
|
54
|
+
return argument_valid && scan_preproc_arg(lexer, true, directive_text);
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
|
-
if (scan_preproc_newline(lexer, false)) {
|
|
57
|
+
if (lexer->eof(lexer) || scan_preproc_newline(lexer, false)) {
|
|
59
58
|
lexer->mark_end(lexer);
|
|
60
59
|
lexer->result_symbol = PREPROC_NEWLINE;
|
|
61
60
|
return true;
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
|
-
if (
|
|
63
|
+
if (argument_valid) {
|
|
65
64
|
lexer->result_symbol = argument_symbol;
|
|
66
65
|
return scan_preproc_arg(lexer, false, directive_text);
|
|
67
66
|
}
|
package/tree-sitter-c.wasm
CHANGED
|
Binary file
|