@willbooster/tree-sitter-c 7.0.3 → 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],
@@ -114,6 +126,16 @@ module.exports = Object.assign(
114
126
  [$.type_specifier, $._top_level_expression_statement],
115
127
  [$.type_qualifier, $.extension_expression],
116
128
  [$.storage_class_specifier, $.type_specifier],
129
+ [$.storage_class_specifier, $.type_specifier, $.expression],
130
+ [$.storage_class_specifier, $.expression],
131
+ [$.attributed_declarator],
132
+ [$.attributed_declarator, $._declarator],
133
+ [$.attributed_declarator, $._declarator, $.type_specifier],
134
+ [$.attributed_field_declarator],
135
+ [$.attributed_field_declarator, $._field_declarator],
136
+ [$.attributed_type_declarator],
137
+ [$.attributed_type_declarator, $._type_declarator],
138
+ [$._declaration_specifiers],
117
139
  [$._compound_literal_storage_class_specifier, $.type_specifier],
118
140
  [$._compound_literal_constexpr_specifier, $.type_qualifier],
119
141
  ],
@@ -131,6 +153,9 @@ module.exports = Object.assign(
131
153
 
132
154
  inline: ($) => [
133
155
  $._non_identifier_type_specifier,
156
+ $._unattributed_declarator,
157
+ $._unattributed_field_declarator,
158
+ $._unattributed_type_declarator,
134
159
  $._type_identifier,
135
160
  $._field_identifier,
136
161
  $._statement_identifier,
@@ -218,19 +243,41 @@ module.exports = Object.assign(
218
243
  preproc_include: ($) =>
219
244
  seq(
220
245
  preprocessor('include'),
221
- field(
222
- 'path',
223
- choice(
224
- $.string_literal,
225
- $.system_lib_string,
226
- $.identifier,
227
- alias($.preproc_call_expression, $.call_expression)
228
- )
229
- ),
246
+ field('path', choice($._preproc_include_path, $.preproc_include_argument)),
230
247
  repeat(choice($.comment, $.pragma_operator)),
231
248
  sym('_preproc_newline')
232
249
  ),
233
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
+
234
281
  preproc_def: ($) =>
235
282
  seq(
236
283
  preprocessor('define'),
@@ -434,9 +481,7 @@ module.exports = Object.assign(
434
481
  ),
435
482
 
436
483
  _declaration_specifiers: ($) =>
437
- prec.right(
438
- seq(repeat($._declaration_modifiers), field('type', $.type_specifier), repeat($._declaration_modifiers))
439
- ),
484
+ seq(repeat($._declaration_modifiers), field('type', $.type_specifier), repeat($._declaration_modifiers)),
440
485
 
441
486
  linkage_specification: ($) =>
442
487
  seq(
@@ -450,7 +495,7 @@ module.exports = Object.assign(
450
495
  attribute: ($) =>
451
496
  seq(optional(seq(field('prefix', $.identifier), '::')), field('name', $.identifier), optional($.argument_list)),
452
497
 
453
- attribute_declaration: ($) => seq('[[', commaSep1($.attribute), ']]'),
498
+ attribute_declaration: ($) => seq('[', '[', commaSep1($.attribute), ']', ']'),
454
499
 
455
500
  ms_declspec_modifier: ($) => seq('__declspec', '(', repeat(seq($.identifier, optional($.argument_list))), ')'),
456
501
 
@@ -479,9 +524,10 @@ module.exports = Object.assign(
479
524
 
480
525
  declaration_list: ($) => seq('{', repeat($._block_item), '}'),
481
526
 
482
- _declarator: ($) =>
527
+ _declarator: ($) => choice($.attributed_declarator, $._unattributed_declarator),
528
+
529
+ _unattributed_declarator: ($) =>
483
530
  choice(
484
- $.attributed_declarator,
485
531
  $.pointer_declarator,
486
532
  $.function_declarator,
487
533
  $.array_declarator,
@@ -502,8 +548,10 @@ module.exports = Object.assign(
502
548
  ),
503
549
 
504
550
  _field_declarator: ($) =>
551
+ choice(alias($.attributed_field_declarator, $.attributed_declarator), $._unattributed_field_declarator),
552
+
553
+ _unattributed_field_declarator: ($) =>
505
554
  choice(
506
- alias($.attributed_field_declarator, $.attributed_declarator),
507
555
  alias($.pointer_field_declarator, $.pointer_declarator),
508
556
  alias($.function_field_declarator, $.function_declarator),
509
557
  alias($.array_field_declarator, $.array_declarator),
@@ -512,8 +560,10 @@ module.exports = Object.assign(
512
560
  ),
513
561
 
514
562
  _type_declarator: ($) =>
563
+ choice(alias($.attributed_type_declarator, $.attributed_declarator), $._unattributed_type_declarator),
564
+
565
+ _unattributed_type_declarator: ($) =>
515
566
  choice(
516
- alias($.attributed_type_declarator, $.attributed_declarator),
517
567
  alias($.pointer_type_declarator, $.pointer_declarator),
518
568
  alias($.function_type_declarator, $.function_declarator),
519
569
  alias($.array_type_declarator, $.array_declarator),
@@ -540,9 +590,9 @@ module.exports = Object.assign(
540
590
  abstract_parenthesized_declarator: ($) =>
541
591
  prec(1, seq('(', optional($.ms_call_modifier), $._abstract_declarator, ')')),
542
592
 
543
- attributed_declarator: ($) => prec.right(seq($._declarator, repeat1($.attribute_declaration))),
544
- attributed_field_declarator: ($) => prec.right(seq($._field_declarator, repeat1($.attribute_declaration))),
545
- attributed_type_declarator: ($) => prec.right(seq($._type_declarator, repeat1($.attribute_declaration))),
593
+ attributed_declarator: ($) => seq($._unattributed_declarator, repeat1($.attribute_declaration)),
594
+ attributed_field_declarator: ($) => seq($._unattributed_field_declarator, repeat1($.attribute_declaration)),
595
+ attributed_type_declarator: ($) => seq($._unattributed_type_declarator, repeat1($.attribute_declaration)),
546
596
 
547
597
  pointer_declarator: ($) =>
548
598
  prec.dynamic(
@@ -1345,12 +1395,17 @@ module.exports = Object.assign(
1345
1395
 
1346
1396
  extension_expression: ($) => seq('__extension__', $.expression),
1347
1397
 
1348
- // Compound statements, designated initializers, and a trailing comma parse macro arguments, e.g.
1349
- // MYFORLOOP(1, 10, i, { foo(i); bar(i); }) and PARAMS(.foo = foo, .bar = { bar, 1 },)
1350
1398
  argument_list: ($) =>
1351
1399
  seq(
1352
1400
  '(',
1353
- 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
+ ),
1354
1409
  ')'
1355
1410
  ),
1356
1411
 
@@ -1406,29 +1461,14 @@ module.exports = Object.assign(
1406
1461
  alias(sym('preproc_ifdef_in_initializer_list'), sym('preproc_ifdef')),
1407
1462
  $.preproc_def,
1408
1463
  $.preproc_function_def,
1409
- alias($._initializer_preproc_call, $.preproc_call)
1464
+ $.preproc_include,
1465
+ $.preproc_call
1410
1466
  ),
1411
1467
 
1412
1468
  _initializer_element: ($) => choice($.initializer_pair, $.expression, $.initializer_list),
1413
1469
 
1414
1470
  _initializer_branch: ($) => choice(seq(',', optional($._initializer_sequence)), $._initializer_sequence),
1415
1471
 
1416
- _initializer_preproc_call: ($) =>
1417
- seq(
1418
- field(
1419
- 'directive',
1420
- alias(token(/#[ \t]*(embed|include|undef|error|warning|line|pragma)/), $.preproc_directive)
1421
- ),
1422
- repeat(choice($.comment, $.pragma_operator)),
1423
- optional(
1424
- seq(
1425
- field('argument', alias($._preproc_directive_arg, $.preproc_arg)),
1426
- repeat(choice($.comment, $.pragma_operator))
1427
- )
1428
- ),
1429
- alias(sym('_preproc_newline'), '\n')
1430
- ),
1431
-
1432
1472
  ...preprocIf('_in_initializer_list', () => sym('_initializer_branch'), 0, false),
1433
1473
 
1434
1474
  initializer_pair: ($) =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c",
3
- "version": "7.0.3",
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
@@ -781,19 +785,39 @@
781
785
  "required": true,
782
786
  "types": [
783
787
  {
784
- "type": "_declarator",
788
+ "type": "array_declarator",
785
789
  "named": true
786
790
  },
787
791
  {
788
- "type": "_field_declarator",
792
+ "type": "attribute_declaration",
789
793
  "named": true
790
794
  },
791
795
  {
792
- "type": "_type_declarator",
796
+ "type": "field_identifier",
793
797
  "named": true
794
798
  },
795
799
  {
796
- "type": "attribute_declaration",
800
+ "type": "function_declarator",
801
+ "named": true
802
+ },
803
+ {
804
+ "type": "identifier",
805
+ "named": true
806
+ },
807
+ {
808
+ "type": "parenthesized_declarator",
809
+ "named": true
810
+ },
811
+ {
812
+ "type": "pointer_declarator",
813
+ "named": true
814
+ },
815
+ {
816
+ "type": "primitive_type",
817
+ "named": true
818
+ },
819
+ {
820
+ "type": "type_identifier",
797
821
  "named": true
798
822
  }
799
823
  ]
@@ -2364,6 +2388,10 @@
2364
2388
  {
2365
2389
  "type": "preproc_ifdef",
2366
2390
  "named": true
2391
+ },
2392
+ {
2393
+ "type": "preproc_include",
2394
+ "named": true
2367
2395
  }
2368
2396
  ]
2369
2397
  }
@@ -3606,6 +3634,10 @@
3606
3634
  "type": "identifier",
3607
3635
  "named": true
3608
3636
  },
3637
+ {
3638
+ "type": "preproc_include_argument",
3639
+ "named": true
3640
+ },
3609
3641
  {
3610
3642
  "type": "string_literal",
3611
3643
  "named": true
@@ -3632,6 +3664,45 @@
3632
3664
  ]
3633
3665
  }
3634
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
+ },
3635
3706
  {
3636
3707
  "type": "preproc_params",
3637
3708
  "named": true,
@@ -4639,18 +4710,10 @@
4639
4710
  "type": "[",
4640
4711
  "named": false
4641
4712
  },
4642
- {
4643
- "type": "[[",
4644
- "named": false
4645
- },
4646
4713
  {
4647
4714
  "type": "]",
4648
4715
  "named": false
4649
4716
  },
4650
- {
4651
- "type": "]]",
4652
- "named": false
4653
- },
4654
4717
  {
4655
4718
  "type": "^",
4656
4719
  "named": false
Binary file
package/tree-sitter.json CHANGED
@@ -16,7 +16,7 @@
16
16
  }
17
17
  ],
18
18
  "metadata": {
19
- "version": "7.0.3",
19
+ "version": "9.0.0",
20
20
  "license": "MIT",
21
21
  "description": "C grammar for tree-sitter",
22
22
  "authors": [