@willbooster/tree-sitter-c 8.0.0 → 9.0.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/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 = "7" }
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,18 @@ module.exports = Object.assign(
68
68
  name: 'c',
69
69
 
70
70
  conflicts: ($) => [
71
+ [$._preproc_include_token, $.preproc_argument_list],
72
+ [$._preproc_include_path, $.preproc_include_argument],
73
+ [$.compound_statement, $.initializer_list],
74
+ [$.comma_expression, $._initializer_element],
75
+ [$.comma_expression, $.initializer_pair],
76
+ [$._block_item, $._initializer_directive],
77
+ [sym('preproc_if'), sym('preproc_if_in_initializer_list')],
78
+ [sym('preproc_ifdef'), sym('preproc_ifdef_in_initializer_list')],
79
+ [sym('preproc_else'), sym('preproc_else_in_initializer_list')],
80
+ [sym('preproc_elif'), sym('preproc_elif_in_initializer_list')],
81
+ [sym('preproc_elifdef'), sym('preproc_elifdef_in_initializer_list')],
82
+
71
83
  [$.type_specifier, $.expression, $.va_arg_expression, $.macro_type_specifier],
72
84
  [$.va_arg_expression, $.expression],
73
85
  [$.type_definition, $._declaration_modifiers],
@@ -231,19 +243,41 @@ module.exports = Object.assign(
231
243
  preproc_include: ($) =>
232
244
  seq(
233
245
  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
- ),
246
+ field('path', choice($._preproc_include_path, $.preproc_include_argument)),
243
247
  repeat(choice($.comment, $.pragma_operator)),
244
248
  sym('_preproc_newline')
245
249
  ),
246
250
 
251
+ _preproc_include_path: ($) =>
252
+ choice(
253
+ $.string_literal,
254
+ $.system_lib_string,
255
+ $.identifier,
256
+ alias($.preproc_call_expression, $.call_expression)
257
+ ),
258
+
259
+ preproc_include_argument: ($) =>
260
+ prec.dynamic(-1, prec.right(seq($.identifier, repeat1($._preproc_include_token)))),
261
+
262
+ _preproc_include_token: ($) =>
263
+ choice(
264
+ $.identifier,
265
+ $.number_literal,
266
+ $.char_literal,
267
+ $.string_literal,
268
+ $.system_lib_string,
269
+ $.comment,
270
+ $.pragma_operator,
271
+ ...BINARY_OPERATORS.map(([operator]) => operator),
272
+ '!',
273
+ '~',
274
+ '(',
275
+ ')',
276
+ ',',
277
+ 'defined',
278
+ token(prec(-3, /\S/))
279
+ ),
280
+
247
281
  preproc_def: ($) =>
248
282
  seq(
249
283
  preprocessor('define'),
@@ -1361,12 +1395,17 @@ module.exports = Object.assign(
1361
1395
 
1362
1396
  extension_expression: ($) => seq('__extension__', $.expression),
1363
1397
 
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
1398
  argument_list: ($) =>
1367
1399
  seq(
1368
1400
  '(',
1369
- optional(seq(commaSep1(choice($.expression, $.compound_statement, $.initializer_pair)), optional(','))),
1401
+ optional(
1402
+ seq(
1403
+ commaSep1(
1404
+ choice($.expression, $.compound_statement, $.initializer_pair, prec.dynamic(-1, $.initializer_list))
1405
+ ),
1406
+ optional(',')
1407
+ )
1408
+ ),
1370
1409
  ')'
1371
1410
  ),
1372
1411
 
@@ -1422,29 +1461,14 @@ module.exports = Object.assign(
1422
1461
  alias(sym('preproc_ifdef_in_initializer_list'), sym('preproc_ifdef')),
1423
1462
  $.preproc_def,
1424
1463
  $.preproc_function_def,
1425
- alias($._initializer_preproc_call, $.preproc_call)
1464
+ $.preproc_include,
1465
+ $.preproc_call
1426
1466
  ),
1427
1467
 
1428
1468
  _initializer_element: ($) => choice($.initializer_pair, $.expression, $.initializer_list),
1429
1469
 
1430
1470
  _initializer_branch: ($) => choice(seq(',', optional($._initializer_sequence)), $._initializer_sequence),
1431
1471
 
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
1472
  ...preprocIf('_in_initializer_list', () => sym('_initializer_branch'), 0, false),
1449
1473
 
1450
1474
  initializer_pair: ($) =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c",
3
- "version": "8.0.0",
3
+ "version": "9.0.0",
4
4
  "description": "C grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -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,
Binary file
package/tree-sitter.json CHANGED
@@ -16,7 +16,7 @@
16
16
  }
17
17
  ],
18
18
  "metadata": {
19
- "version": "8.0.0",
19
+ "version": "9.0.0",
20
20
  "license": "MIT",
21
21
  "description": "C grammar for tree-sitter",
22
22
  "authors": [