@willbooster/tree-sitter-c 11.0.0 → 12.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/grammar.js CHANGED
@@ -71,11 +71,27 @@ module.exports = Object.assign(
71
71
  name: 'c',
72
72
 
73
73
  conflicts: ($) => [
74
- [$._macro_declaration_specifiers],
74
+ [$._statement_declaration, $._statement_declaration_modifiers],
75
+ [$.declaration, $._declaration_modifiers],
76
+ [$._statement_declaration, $._statement_type_definition, $._statement_declaration_modifiers],
77
+ [$.declaration, $.type_definition, $._macro_declaration_specifiers, $._declaration_modifiers],
78
+ [$.type_definition, $.type_specifier],
79
+ [$.type_definition, $._macro_declaration_specifiers],
80
+ [$._macro_declaration_specifiers, $._declaration_modifiers, $.attributed_statement, $.case_statement],
81
+ [$._macro_declaration_specifiers, $.type_specifier, $.expression, $.macro_specifier],
82
+ [$._macro_declaration_specifiers, $.type_specifier, $.macro_specifier],
83
+ [$.macro_specifier, $._type_declarator],
84
+ [$.macro_specifier, $._field_declarator],
85
+ [$.macro_specifier, $._declarator],
86
+ [$.macro_specifier, $._declarator, $.attributed_declarator, $.type_specifier],
87
+ [$.macro_specifier, $._declarator, $.attributed_declarator],
88
+ [$.macro_specifier, $.sized_type_specifier],
89
+ [$.macro_specifier, $.type_specifier, $.sized_type_specifier],
90
+ [$.macro_specifier, $.expression],
91
+ [$.macro_specifier, $.type_specifier],
75
92
  [$._macro_declaration_specifiers, $.type_definition, $.type_specifier],
76
93
  [$._macro_declaration_specifiers, $.type_specifier, $.expression],
77
94
  [$._macro_declaration_specifiers, $.type_specifier],
78
- [$._macro_declaration_specifiers, $.type_definition, $._declaration_modifiers],
79
95
  [$._macro_declaration_specifiers, $._declaration_modifiers, $._empty_declaration],
80
96
  [$._macro_declaration_specifiers, $._declaration_modifiers],
81
97
  [$.preproc_include_argument],
@@ -85,20 +101,25 @@ module.exports = Object.assign(
85
101
  [$.comma_expression, $._initializer_element],
86
102
  [$.comma_expression, $.initializer_pair],
87
103
  [$._block_item, $._initializer_directive],
88
- [sym('preproc_if'), sym('preproc_if_in_initializer_list')],
89
- [sym('preproc_ifdef'), sym('preproc_ifdef_in_initializer_list')],
90
- [sym('preproc_else'), sym('preproc_else_in_initializer_list')],
91
- [sym('preproc_elif'), sym('preproc_elif_in_initializer_list')],
92
- [sym('preproc_elifdef'), sym('preproc_elifdef_in_initializer_list')],
104
+ [sym('preproc_if_in_statement'), sym('preproc_if_in_initializer_list')],
105
+ [sym('preproc_ifdef_in_statement'), sym('preproc_ifdef_in_initializer_list')],
106
+ [sym('preproc_else_in_statement'), sym('preproc_else_in_initializer_list')],
107
+ [sym('preproc_elif_in_statement'), sym('preproc_elif_in_initializer_list')],
108
+ [sym('preproc_elifdef_in_statement'), sym('preproc_elifdef_in_initializer_list')],
93
109
 
94
110
  [$.type_specifier, $.expression, $.va_arg_expression, $.macro_type_specifier],
95
111
  [$.va_arg_expression, $.expression],
96
112
  [$.type_definition, $._declaration_modifiers],
97
- [$.type_definition, $.type_specifier],
113
+ [$._statement_type_definition, $._statement_declaration_modifiers],
114
+ [$.type_definition, $._declaration_modifiers, $._empty_declaration],
115
+ [$._statement_type_definition, $.type_specifier],
98
116
  [$.type_definition, $.type_qualifier, $.extension_expression],
117
+ [$._statement_type_definition, $.type_qualifier, $.extension_expression],
99
118
  [$.type_definition, $.type_qualifier],
100
- [$._declaration_modifiers, $._empty_declaration],
119
+ [$._statement_type_definition, $.type_qualifier],
120
+ [$._statement_declaration_modifiers, $._statement_empty_declaration],
101
121
  [$.declaration, $.storage_class_specifier],
122
+ [$._statement_declaration, $.storage_class_specifier],
102
123
  [$.sized_type_specifier, $.enum_specifier],
103
124
  [$.type_specifier, $._declarator],
104
125
  [$.type_specifier, $._declarator, $.macro_type_specifier],
@@ -118,8 +139,8 @@ module.exports = Object.assign(
118
139
  [$.attributed_statement],
119
140
  [$.case_statement],
120
141
  [$._single_attributed_statement],
121
- [$._declaration_modifiers, $._case_body_attributed_statement, $._case_label_attributes],
122
- [$._declaration_modifiers, $.attributed_statement, $.case_statement],
142
+ [$._statement_declaration_modifiers, $._case_body_attributed_statement, $._case_label_attributes],
143
+ [$._statement_declaration_modifiers, $.attributed_statement, $.case_statement],
123
144
  [$.enum_specifier],
124
145
  [sym('preproc_if_in_enumerator_list'), sym('preproc_if_in_enumerator_list_no_comma')],
125
146
  [sym('preproc_ifdef_in_enumerator_list'), sym('preproc_ifdef_in_enumerator_list_no_comma')],
@@ -130,6 +151,7 @@ module.exports = Object.assign(
130
151
  [$.parameter_list, $._old_style_parameter_list],
131
152
  [$.function_declarator, $._function_declaration_declarator],
132
153
  [$.pointer_declarator],
154
+ [$.pointer_declarator, $.abstract_pointer_declarator],
133
155
  [$.pointer_field_declarator],
134
156
  [$.pointer_type_declarator],
135
157
  [$.abstract_pointer_declarator],
@@ -146,6 +168,7 @@ module.exports = Object.assign(
146
168
  [$.attributed_field_declarator, $._field_declarator],
147
169
  [$.attributed_type_declarator],
148
170
  [$.attributed_type_declarator, $._type_declarator],
171
+ [$._declaration_modifiers, $._field_declaration_list_item],
149
172
  [$._declaration_specifiers],
150
173
  [$._compound_literal_storage_class_specifier, $.type_specifier],
151
174
  [$._compound_literal_constexpr_specifier, $.type_qualifier],
@@ -169,6 +192,7 @@ module.exports = Object.assign(
169
192
 
170
193
  inline: ($) => [
171
194
  $._non_identifier_type_specifier,
195
+ $._non_macro_declaration_modifiers,
172
196
  $._unattributed_declarator,
173
197
  $._unattributed_field_declarator,
174
198
  $._unattributed_type_declarator,
@@ -223,9 +247,41 @@ module.exports = Object.assign(
223
247
  $.preproc_call
224
248
  ),
225
249
 
226
- _block_item: ($) => blockItemRule($, false),
250
+ _block_item: ($) =>
251
+ choice(
252
+ alias($._statement_function_definition, $.function_definition),
253
+ alias($._statement_old_style_function_definition, $.function_definition),
254
+ $.linkage_specification,
255
+ alias($._statement_declaration, $.declaration),
256
+ $.statement,
257
+ alias($._statement_type_definition, $.type_definition),
258
+ $._statement_empty_declaration,
259
+ alias(sym('preproc_if_in_statement'), sym('preproc_if')),
260
+ alias(sym('preproc_ifdef_in_statement'), sym('preproc_ifdef')),
261
+ $.preproc_include,
262
+ $.preproc_def,
263
+ $.preproc_function_def,
264
+ $.preproc_call
265
+ ),
227
266
 
228
- _header_preproc_item: ($) => blockItemRule($, true),
267
+ _header_preproc_item: ($) =>
268
+ choice(
269
+ $.function_definition,
270
+ alias($._old_style_function_definition, $.function_definition),
271
+ $.linkage_specification,
272
+ $.declaration,
273
+ alias(sym('_macro_modified_declaration'), $.declaration),
274
+ alias(sym('_trailing_macro_modified_declaration'), $.declaration),
275
+ $.statement,
276
+ $.type_definition,
277
+ $._empty_declaration,
278
+ alias(sym('preproc_if_in_header'), sym('preproc_if')),
279
+ alias(sym('preproc_ifdef_in_header'), sym('preproc_ifdef')),
280
+ $.preproc_include,
281
+ $.preproc_def,
282
+ $.preproc_function_def,
283
+ $.preproc_call
284
+ ),
229
285
 
230
286
  // Derived grammars that replace externals still need this lexical fallback. Comment-rich spacing makes the
231
287
  // lexer too large for the pinned Node Wasm optimizer; the external scanner handles those forms.
@@ -318,8 +374,8 @@ module.exports = Object.assign(
318
374
  ),
319
375
 
320
376
  ...preprocIf('_in_header', () => sym('_header_preproc_item')),
321
-
322
377
  ...preprocIf('', () => sym('_block_item')),
378
+ ...preprocIf('_in_statement', () => sym('_block_item')),
323
379
  ...preprocIf('_in_single_case', () => sym('_single_case_body'), 0, true),
324
380
  ...preprocIf('_in_field_declaration_list', () => sym('_field_declaration_list_item')),
325
381
  ...preprocIf('_in_enumerator_list', () => choice(seq(sym('enumerator'), ','), sym('_enumerator_directives'))),
@@ -392,23 +448,11 @@ module.exports = Object.assign(
392
448
  );
393
449
  },
394
450
 
395
- function_definition: ($) =>
396
- seq(
397
- optional($.ms_call_modifier),
398
- $._declaration_specifiers,
399
- optional($.ms_call_modifier),
400
- field('declarator', $._declarator),
401
- field('body', $.compound_statement)
402
- ),
403
-
404
- _old_style_function_definition: ($) =>
405
- seq(
406
- optional($.ms_call_modifier),
407
- $._declaration_specifiers,
408
- field('declarator', alias($._old_style_declarator, $._declarator)),
409
- repeat1($.declaration),
410
- field('body', $.compound_statement)
411
- ),
451
+ function_definition: ($) => functionDefinitionRule($, $._declaration_specifiers, false),
452
+ _statement_function_definition: ($) => functionDefinitionRule($, $._statement_declaration_specifiers, false),
453
+ _old_style_function_definition: ($) => functionDefinitionRule($, $._declaration_specifiers, true),
454
+ _statement_old_style_function_definition: ($) =>
455
+ functionDefinitionRule($, $._statement_declaration_specifiers, true),
412
456
 
413
457
  _old_style_declarator: ($) =>
414
458
  choice(
@@ -426,16 +470,27 @@ module.exports = Object.assign(
426
470
  '*',
427
471
  repeat($.attribute_declaration),
428
472
  repeat($.ms_pointer_modifier),
429
- repeat(choice($.type_qualifier, $.attribute_specifier)),
473
+ repeat(choice($.type_qualifier, $.attribute_specifier, $.macro_specifier)),
430
474
  field('declarator', alias($._old_style_declarator, $._declarator))
431
475
  )
432
476
  )
433
477
  ),
434
478
 
435
- declaration: ($) => declarationRule($, $._declaration_specifiers, true),
479
+ declaration: ($) => declarationRule($, $._declaration_specifiers, $._declaration_modifiers),
480
+ _statement_declaration: ($) =>
481
+ declarationRule($, $._statement_declaration_specifiers, $._statement_declaration_modifiers),
482
+
483
+ type_definition: ($) => typeDefinitionRule($, $._declaration_modifiers, true),
484
+ _statement_type_definition: ($) => typeDefinitionRule($, $._statement_declaration_modifiers, false),
436
485
 
437
486
  _macro_modified_declaration: ($) =>
438
- declarationRule($, $._macro_declaration_specifiers, false, $._macro_declaration_declarator),
487
+ declarationRule(
488
+ $,
489
+ $._macro_declaration_specifiers,
490
+ $._non_macro_declaration_modifiers,
491
+ false,
492
+ $._macro_declaration_declarator
493
+ ),
439
494
 
440
495
  _trailing_macro_modified_declaration: ($) =>
441
496
  seq(
@@ -452,52 +507,46 @@ module.exports = Object.assign(
452
507
  _trailing_macro_pointer_declarator: ($) => pointerDeclaratorRule($, $._trailing_macro_object_declarator),
453
508
 
454
509
  _macro_declaration_specifiers: ($) => {
455
- const modifier = choice($._declaration_modifiers, alias($._macro_attribute_suffix, $.attribute_specifier));
510
+ const modifier = choice(
511
+ $._non_macro_declaration_modifiers,
512
+ alias($._macro_attribute_suffix, $.attribute_specifier)
513
+ );
456
514
  const postModifier = choice(
457
- $._declaration_modifiers,
515
+ $._non_macro_declaration_modifiers,
458
516
  alias($._post_type_macro_attribute_suffix, $.attribute_specifier)
459
517
  );
460
518
  return choice(
461
519
  seq(
462
520
  choice($.storage_class_specifier, $.type_qualifier, $.ms_declspec_modifier),
463
- repeat($._declaration_modifiers),
521
+ repeat($._non_macro_declaration_modifiers),
464
522
  alias($._macro_attribute_specifier, $.attribute_specifier),
465
523
  repeat(modifier),
466
524
  field('type', $._non_identifier_type_specifier),
467
525
  repeat(postModifier)
468
526
  ),
469
527
  seq(
470
- repeat($._declaration_modifiers),
528
+ repeat($._non_macro_declaration_modifiers),
471
529
  field('type', choice($._non_identifier_type_specifier, $._type_identifier)),
472
- repeat($._declaration_modifiers),
530
+ repeat($._non_macro_declaration_modifiers),
473
531
  alias($._post_type_macro_attribute_specifier, $.attribute_specifier),
474
532
  repeat(postModifier)
475
533
  )
476
534
  );
477
535
  },
478
536
 
479
- type_definition: ($) =>
537
+ _type_definition_type: ($) =>
480
538
  seq(
481
- optional(prec.dynamic(1, '__extension__')),
482
- choice(
483
- seq(repeat($.type_qualifier), 'typedef', $._type_definition_type),
484
- seq(
485
- repeat($._declaration_modifiers),
486
- field('type', $._non_identifier_type_specifier),
487
- repeat($.type_qualifier),
488
- 'typedef',
489
- repeat(choice($.type_qualifier, $._non_identifier_type_specifier))
490
- )
491
- ),
492
- $._type_definition_declarators,
493
- repeat($.attribute_specifier),
494
- ';'
539
+ repeat(choice($.type_qualifier, $.macro_specifier)),
540
+ field('type', $.type_specifier),
541
+ repeat($.type_qualifier)
495
542
  ),
496
- _type_definition_type: ($) =>
497
- seq(repeat($.type_qualifier), field('type', $.type_specifier), repeat($.type_qualifier)),
498
543
  _type_definition_declarators: ($) => commaSep1(field('declarator', $._type_declarator)),
499
544
 
500
- _declaration_modifiers: ($) =>
545
+ _declaration_modifiers: ($) => choice($._non_macro_declaration_modifiers, $.macro_specifier),
546
+
547
+ _statement_declaration_modifiers: ($) => $._non_macro_declaration_modifiers,
548
+
549
+ _non_macro_declaration_modifiers: ($) =>
501
550
  choice(
502
551
  $.storage_class_specifier,
503
552
  $.type_qualifier,
@@ -507,7 +556,18 @@ module.exports = Object.assign(
507
556
  ),
508
557
 
509
558
  _declaration_specifiers: ($) =>
510
- seq(repeat($._declaration_modifiers), field('type', $.type_specifier), repeat($._declaration_modifiers)),
559
+ seq(
560
+ repeat($._declaration_modifiers),
561
+ field('type', $.type_specifier),
562
+ repeat($._non_macro_declaration_modifiers)
563
+ ),
564
+
565
+ _statement_declaration_specifiers: ($) =>
566
+ seq(
567
+ repeat($._statement_declaration_modifiers),
568
+ field('type', $.type_specifier),
569
+ repeat($._statement_declaration_modifiers)
570
+ ),
511
571
 
512
572
  linkage_specification: ($) =>
513
573
  seq(
@@ -563,7 +623,7 @@ module.exports = Object.assign(
563
623
  $.ms_pointer_size_modifier
564
624
  ),
565
625
 
566
- declaration_list: ($) => seq('{', repeat($._block_item), '}'),
626
+ declaration_list: ($) => seq('{', repeat($._top_level_item), '}'),
567
627
 
568
628
  _declarator: ($) => choice($.attributed_declarator, $._unattributed_declarator),
569
629
 
@@ -640,7 +700,7 @@ module.exports = Object.assign(
640
700
  '*',
641
701
  repeat($.attribute_declaration),
642
702
  repeat($.ms_pointer_modifier),
643
- repeat(choice($.type_qualifier, $.attribute_specifier)),
703
+ repeat(choice($.type_qualifier, $.attribute_specifier, $.macro_specifier)),
644
704
  field('declarator', $._field_declarator)
645
705
  )
646
706
  )
@@ -655,7 +715,7 @@ module.exports = Object.assign(
655
715
  '*',
656
716
  repeat($.attribute_declaration),
657
717
  repeat($.ms_pointer_modifier),
658
- repeat(choice($.type_qualifier, $.attribute_specifier)),
718
+ repeat(choice($.type_qualifier, $.attribute_specifier, $.macro_specifier)),
659
719
  field('declarator', $._type_declarator)
660
720
  )
661
721
  )
@@ -825,7 +885,7 @@ module.exports = Object.assign(
825
885
  bit_int_specifier: ($) => seq('_BitInt', '(', $.expression, ')'),
826
886
 
827
887
  sized_type_specifier: ($) =>
828
- sizedTypeSpecifier(optional(choice(prec.dynamic(-1, $._type_identifier), $.primitive_type))),
888
+ sizedTypeSpecifier(optional(choice(prec.dynamic(-3, $._type_identifier), $.primitive_type))),
829
889
 
830
890
  _sized_bit_int_specifier: ($) => sizedTypeSpecifier($.bit_int_specifier),
831
891
 
@@ -937,6 +997,7 @@ module.exports = Object.assign(
937
997
  _field_declaration_list_item: ($) =>
938
998
  choice(
939
999
  $.field_declaration,
1000
+ prec.dynamic(-1, $.macro_specifier),
940
1001
  $.preproc_def,
941
1002
  $.preproc_function_def,
942
1003
  $.preproc_call,
@@ -1010,7 +1071,12 @@ module.exports = Object.assign(
1010
1071
  $.goto_statement
1011
1072
  ),
1012
1073
 
1013
- labeled_statement: ($) => seq(field('label', $._statement_identifier), ':', choice($.declaration, $.statement)),
1074
+ labeled_statement: ($) =>
1075
+ seq(
1076
+ field('label', $._statement_identifier),
1077
+ ':',
1078
+ choice(alias($._statement_declaration, $.declaration), $.statement)
1079
+ ),
1014
1080
 
1015
1081
  // This is missing binary expressions, others were kept so that macro code can be parsed better and code examples
1016
1082
  _top_level_expression_statement: ($) => seq(optional($._expression_not_binary), ';'),
@@ -1075,14 +1141,18 @@ module.exports = Object.assign(
1075
1141
  1,
1076
1142
  choice(
1077
1143
  $._single_statement,
1078
- $.declaration,
1079
- $.type_definition,
1144
+ alias($._statement_declaration, $.declaration),
1145
+ alias($._statement_type_definition, $.type_definition),
1080
1146
  alias(sym('preproc_if_in_single_case'), sym('preproc_if')),
1081
1147
  alias(sym('preproc_ifdef_in_single_case'), sym('preproc_ifdef'))
1082
1148
  )
1083
1149
  ),
1084
1150
  _single_labeled_statement: ($) =>
1085
- seq(field('label', $._statement_identifier), ':', choice($._single_statement, $.declaration)),
1151
+ seq(
1152
+ field('label', $._statement_identifier),
1153
+ ':',
1154
+ choice($._single_statement, alias($._statement_declaration, $.declaration))
1155
+ ),
1086
1156
  _single_attributed_statement: ($) =>
1087
1157
  seq(
1088
1158
  repeat1($.attribute_declaration),
@@ -1105,7 +1175,14 @@ module.exports = Object.assign(
1105
1175
  ),
1106
1176
 
1107
1177
  _case_statement_item: ($) =>
1108
- prec.dynamic(1, choice(alias($._case_body_statement, $.statement), $.declaration, $.type_definition)),
1178
+ prec.dynamic(
1179
+ 1,
1180
+ choice(
1181
+ alias($._case_body_statement, $.statement),
1182
+ alias($._statement_declaration, $.declaration),
1183
+ alias($._statement_type_definition, $.type_definition)
1184
+ )
1185
+ ),
1109
1186
 
1110
1187
  _case_body_statement: ($) =>
1111
1188
  choice(
@@ -1118,7 +1195,7 @@ module.exports = Object.assign(
1118
1195
  seq(
1119
1196
  field('label', $._statement_identifier),
1120
1197
  ':',
1121
- choice($.declaration, alias($._case_body_statement, $.statement))
1198
+ choice(alias($._statement_declaration, $.declaration), alias($._case_body_statement, $.statement))
1122
1199
  ),
1123
1200
  _case_body_attributed_statement: ($) =>
1124
1201
  prec(1, seq(repeat1($.attribute_declaration), alias($._case_body_unattributed_statement, $.statement))),
@@ -1147,7 +1224,7 @@ module.exports = Object.assign(
1147
1224
  _for_statement_body: ($) =>
1148
1225
  seq(
1149
1226
  choice(
1150
- field('initializer', $.declaration),
1227
+ field('initializer', alias($._statement_declaration, $.declaration)),
1151
1228
  seq(field('initializer', optional(choice($.expression, $.comma_expression))), ';')
1152
1229
  ),
1153
1230
  field('condition', optional(choice($.expression, $.comma_expression))),
@@ -1603,7 +1680,10 @@ module.exports = Object.assign(
1603
1680
  _field_identifier: ($) => alias(choice($.identifier, VA_ARG_KEYWORDS), sym('field_identifier')),
1604
1681
  _statement_identifier: ($) => alias(choice($.identifier, VA_ARG_KEYWORDS), sym('statement_identifier')),
1605
1682
 
1606
- _empty_declaration: ($) => seq(repeat($.ms_declspec_modifier), $.type_specifier, ';'),
1683
+ _empty_declaration: ($) => seq(repeat(choice($.ms_declspec_modifier, $.macro_specifier)), $.type_specifier, ';'),
1684
+ _statement_empty_declaration: ($) => seq(repeat($.ms_declspec_modifier), $.type_specifier, ';'),
1685
+
1686
+ macro_specifier: ($) => prec.dynamic(-2, field('name', $.identifier)),
1607
1687
 
1608
1688
  macro_type_specifier: ($) =>
1609
1689
  prec.dynamic(
@@ -1626,53 +1706,96 @@ module.exports = Object.assign(
1626
1706
  );
1627
1707
 
1628
1708
  /**
1629
- * @param {import('./types/treeSitterDsl').GrammarSymbols<'ms_based_modifier' | 'ms_call_modifier' | 'attribute_declaration' | 'ms_pointer_modifier' | 'type_qualifier' | 'attribute_specifier'>} $
1709
+ * @param {import('./types/treeSitterDsl').GrammarSymbols<'ms_based_modifier' | 'ms_call_modifier' | 'attribute_declaration' | 'ms_pointer_modifier' | 'type_qualifier' | 'attribute_specifier' | 'macro_specifier'>} $
1630
1710
  * @param {import('./types/treeSitterDsl').Rule} declarator
1631
1711
  */
1632
1712
  function pointerDeclaratorRule($, declarator) {
1633
- return prec.dynamic(
1634
- 1,
1635
- prec.right(
1636
- seq(
1637
- optional($.ms_based_modifier),
1638
- optional(prec.dynamic(2, $.ms_call_modifier)),
1639
- '*',
1640
- repeat($.attribute_declaration),
1641
- repeat($.ms_pointer_modifier),
1642
- repeat(choice($.type_qualifier, $.attribute_specifier)),
1643
- field('declarator', declarator)
1644
- )
1713
+ return prec.right(
1714
+ seq(
1715
+ optional($.ms_based_modifier),
1716
+ optional(prec.dynamic(2, $.ms_call_modifier)),
1717
+ '*',
1718
+ repeat($.attribute_declaration),
1719
+ repeat($.ms_pointer_modifier),
1720
+ repeat(choice($.type_qualifier, $.attribute_specifier, $.macro_specifier)),
1721
+ field('declarator', declarator)
1645
1722
  )
1646
1723
  );
1647
1724
  }
1648
1725
 
1649
1726
  /**
1650
- * @param {import('./types/treeSitterDsl').GrammarSymbols<'storage_class_specifier' | 'ms_call_modifier' | '_declaration_declarator' | 'gnu_asm_expression' | 'init_declarator' | '_declaration_modifiers'>} $
1727
+ * @param {import('./types/treeSitterDsl').GrammarSymbols<'ms_call_modifier' | '_old_style_declarator' | '_declarator' | 'declaration' | 'compound_statement'>} $
1651
1728
  * @param {import('./types/treeSitterDsl').Rule} specifiers
1652
- * @param {boolean} allowAuto
1653
- * @param {import('./types/treeSitterDsl').Rule} declarator
1729
+ * @param {boolean} oldStyle
1654
1730
  */
1655
- function declarationRule($, specifiers, allowAuto, declarator = $._declaration_declarator) {
1731
+ function functionDefinitionRule($, specifiers, oldStyle) {
1656
1732
  return seq(
1657
- allowAuto
1658
- ? choice(
1659
- specifiers,
1660
- prec.dynamic(
1661
- PREC.PAREN_DECLARATOR - 1,
1662
- seq(
1663
- repeat($._declaration_modifiers),
1664
- alias('auto', $.storage_class_specifier),
1665
- repeat($._declaration_modifiers)
1733
+ optional($.ms_call_modifier),
1734
+ specifiers,
1735
+ ...(oldStyle ? [] : [optional($.ms_call_modifier)]),
1736
+ field('declarator', oldStyle ? alias($._old_style_declarator, $._declarator) : $._declarator),
1737
+ ...(oldStyle ? [repeat1($.declaration)] : []),
1738
+ field('body', $.compound_statement)
1739
+ );
1740
+ }
1741
+
1742
+ /**
1743
+ * @param {import('./types/treeSitterDsl').GrammarSymbols<'storage_class_specifier' | 'ms_call_modifier' | '_declaration_declarator' | 'gnu_asm_expression' | 'init_declarator' | 'type_qualifier' | 'identifier'>} $
1744
+ * @param {import('./types/treeSitterDsl').Rule} specifiers
1745
+ * @param {import('./types/treeSitterDsl').Rule} modifiers
1746
+ * @param {boolean} allowInferredType
1747
+ * @param {import('./types/treeSitterDsl').Rule} declarator
1748
+ */
1749
+ function declarationRule($, specifiers, modifiers, allowInferredType = true, declarator = $._declaration_declarator) {
1750
+ return choice(
1751
+ seq(
1752
+ prec.dynamic(
1753
+ 1,
1754
+ allowInferredType
1755
+ ? choice(
1756
+ specifiers,
1757
+ prec.dynamic(
1758
+ PREC.PAREN_DECLARATOR - 1,
1759
+ seq(repeat(modifiers), alias('auto', $.storage_class_specifier), repeat(modifiers))
1760
+ )
1666
1761
  )
1667
- )
1762
+ : specifiers
1763
+ ),
1764
+ commaSep1(
1765
+ field(
1766
+ 'declarator',
1767
+ choice(seq(optional($.ms_call_modifier), declarator, optional($.gnu_asm_expression)), $.init_declarator)
1668
1768
  )
1669
- : specifiers,
1670
- commaSep1(
1671
- field(
1672
- 'declarator',
1673
- choice(seq(optional($.ms_call_modifier), declarator, optional($.gnu_asm_expression)), $.init_declarator)
1769
+ ),
1770
+ ';'
1771
+ ),
1772
+ ...(allowInferredType
1773
+ ? [seq(repeat1($.type_qualifier), commaSep1(field('declarator', choice($.identifier, $.init_declarator))), ';')]
1774
+ : [])
1775
+ );
1776
+ }
1777
+
1778
+ /**
1779
+ * @param {import('./types/treeSitterDsl').GrammarSymbols<'macro_specifier' | 'type_qualifier' | '_type_definition_type' | '_non_identifier_type_specifier' | '_type_definition_declarators' | 'attribute_specifier'>} $
1780
+ * @param {import('./types/treeSitterDsl').Rule} modifiers
1781
+ * @param {boolean} allowPrefixMarkers
1782
+ */
1783
+ function typeDefinitionRule($, modifiers, allowPrefixMarkers) {
1784
+ return seq(
1785
+ optional(prec.dynamic(1, '__extension__')),
1786
+ ...(allowPrefixMarkers ? [repeat($.macro_specifier)] : []),
1787
+ choice(
1788
+ seq(repeat($.type_qualifier), 'typedef', $._type_definition_type),
1789
+ seq(
1790
+ repeat(modifiers),
1791
+ field('type', $._non_identifier_type_specifier),
1792
+ repeat($.type_qualifier),
1793
+ 'typedef',
1794
+ repeat(choice($.type_qualifier, $._non_identifier_type_specifier))
1674
1795
  )
1675
1796
  ),
1797
+ $._type_definition_declarators,
1798
+ repeat($.attribute_specifier),
1676
1799
  ';'
1677
1800
  );
1678
1801
  }
@@ -1693,34 +1816,6 @@ function declarationDeclaratorRule($, functionDeclarator) {
1693
1816
  );
1694
1817
  }
1695
1818
 
1696
- /**
1697
- * @param {import('./types/treeSitterDsl').GrammarSymbols<'function_definition' | '_old_style_function_definition' | 'linkage_specification' | 'declaration' | '_macro_modified_declaration' | 'statement' | 'type_definition' | '_empty_declaration' | 'preproc_include' | 'preproc_def' | 'preproc_function_def' | 'preproc_call'>} $
1698
- * @param {boolean} header
1699
- */
1700
- function blockItemRule($, header) {
1701
- return choice(
1702
- $.function_definition,
1703
- alias($._old_style_function_definition, $.function_definition),
1704
- $.linkage_specification,
1705
- $.declaration,
1706
- ...(header
1707
- ? [
1708
- alias($._macro_modified_declaration, $.declaration),
1709
- alias(sym('_trailing_macro_modified_declaration'), $.declaration),
1710
- ]
1711
- : []),
1712
- $.statement,
1713
- $.type_definition,
1714
- $._empty_declaration,
1715
- header ? alias(sym('preproc_if_in_header'), sym('preproc_if')) : sym('preproc_if'),
1716
- header ? alias(sym('preproc_ifdef_in_header'), sym('preproc_ifdef')) : sym('preproc_ifdef'),
1717
- $.preproc_include,
1718
- $.preproc_def,
1719
- $.preproc_function_def,
1720
- $.preproc_call
1721
- );
1722
- }
1723
-
1724
1819
  /**
1725
1820
  * @param {import('./types/treeSitterDsl').GrammarSymbols<'identifier' | 'argument_list' | '_macro_attribute_argument_list'>} $
1726
1821
  * @param {'leading' | 'post-type' | 'continuation' | 'post-type-continuation' | 'trailing'} context
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c",
3
- "version": "11.0.0",
3
+ "version": "12.0.0",
4
4
  "description": "C grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -1448,6 +1448,10 @@
1448
1448
  "type": "attribute_specifier",
1449
1449
  "named": true
1450
1450
  },
1451
+ {
1452
+ "type": "macro_specifier",
1453
+ "named": true
1454
+ },
1451
1455
  {
1452
1456
  "type": "ms_declspec_modifier",
1453
1457
  "named": true
@@ -1471,18 +1475,66 @@
1471
1475
  "multiple": true,
1472
1476
  "required": false,
1473
1477
  "types": [
1478
+ {
1479
+ "type": "attributed_statement",
1480
+ "named": true
1481
+ },
1482
+ {
1483
+ "type": "break_statement",
1484
+ "named": true
1485
+ },
1486
+ {
1487
+ "type": "case_statement",
1488
+ "named": true
1489
+ },
1490
+ {
1491
+ "type": "compound_statement",
1492
+ "named": true
1493
+ },
1494
+ {
1495
+ "type": "continue_statement",
1496
+ "named": true
1497
+ },
1474
1498
  {
1475
1499
  "type": "declaration",
1476
1500
  "named": true
1477
1501
  },
1502
+ {
1503
+ "type": "do_statement",
1504
+ "named": true
1505
+ },
1506
+ {
1507
+ "type": "expression_statement",
1508
+ "named": true
1509
+ },
1510
+ {
1511
+ "type": "for_statement",
1512
+ "named": true
1513
+ },
1478
1514
  {
1479
1515
  "type": "function_definition",
1480
1516
  "named": true
1481
1517
  },
1518
+ {
1519
+ "type": "goto_statement",
1520
+ "named": true
1521
+ },
1522
+ {
1523
+ "type": "if_statement",
1524
+ "named": true
1525
+ },
1526
+ {
1527
+ "type": "labeled_statement",
1528
+ "named": true
1529
+ },
1482
1530
  {
1483
1531
  "type": "linkage_specification",
1484
1532
  "named": true
1485
1533
  },
1534
+ {
1535
+ "type": "macro_specifier",
1536
+ "named": true
1537
+ },
1486
1538
  {
1487
1539
  "type": "ms_declspec_modifier",
1488
1540
  "named": true
@@ -1512,7 +1564,11 @@
1512
1564
  "named": true
1513
1565
  },
1514
1566
  {
1515
- "type": "statement",
1567
+ "type": "return_statement",
1568
+ "named": true
1569
+ },
1570
+ {
1571
+ "type": "switch_statement",
1516
1572
  "named": true
1517
1573
  },
1518
1574
  {
@@ -1522,6 +1578,10 @@
1522
1578
  {
1523
1579
  "type": "type_specifier",
1524
1580
  "named": true
1581
+ },
1582
+ {
1583
+ "type": "while_statement",
1584
+ "named": true
1525
1585
  }
1526
1586
  ]
1527
1587
  }
@@ -1757,6 +1817,10 @@
1757
1817
  "type": "bitfield_clause",
1758
1818
  "named": true
1759
1819
  },
1820
+ {
1821
+ "type": "macro_specifier",
1822
+ "named": true
1823
+ },
1760
1824
  {
1761
1825
  "type": "ms_declspec_modifier",
1762
1826
  "named": true
@@ -1784,6 +1848,10 @@
1784
1848
  "type": "field_declaration",
1785
1849
  "named": true
1786
1850
  },
1851
+ {
1852
+ "type": "macro_specifier",
1853
+ "named": true
1854
+ },
1787
1855
  {
1788
1856
  "type": "preproc_call",
1789
1857
  "named": true
@@ -2031,6 +2099,10 @@
2031
2099
  "type": "declaration",
2032
2100
  "named": true
2033
2101
  },
2102
+ {
2103
+ "type": "macro_specifier",
2104
+ "named": true
2105
+ },
2034
2106
  {
2035
2107
  "type": "ms_call_modifier",
2036
2108
  "named": true
@@ -2527,6 +2599,22 @@
2527
2599
  }
2528
2600
  }
2529
2601
  },
2602
+ {
2603
+ "type": "macro_specifier",
2604
+ "named": true,
2605
+ "fields": {
2606
+ "name": {
2607
+ "multiple": false,
2608
+ "required": true,
2609
+ "types": [
2610
+ {
2611
+ "type": "identifier",
2612
+ "named": true
2613
+ }
2614
+ ]
2615
+ }
2616
+ }
2617
+ },
2530
2618
  {
2531
2619
  "type": "macro_type_specifier",
2532
2620
  "named": true,
@@ -2705,6 +2793,10 @@
2705
2793
  "type": "attribute_specifier",
2706
2794
  "named": true
2707
2795
  },
2796
+ {
2797
+ "type": "macro_specifier",
2798
+ "named": true
2799
+ },
2708
2800
  {
2709
2801
  "type": "ms_declspec_modifier",
2710
2802
  "named": true
@@ -2862,6 +2954,10 @@
2862
2954
  "type": "attribute_specifier",
2863
2955
  "named": true
2864
2956
  },
2957
+ {
2958
+ "type": "macro_specifier",
2959
+ "named": true
2960
+ },
2865
2961
  {
2866
2962
  "type": "ms_based_modifier",
2867
2963
  "named": true
@@ -3103,6 +3199,10 @@
3103
3199
  "type": "linkage_specification",
3104
3200
  "named": true
3105
3201
  },
3202
+ {
3203
+ "type": "macro_specifier",
3204
+ "named": true
3205
+ },
3106
3206
  {
3107
3207
  "type": "ms_declspec_modifier",
3108
3208
  "named": true
@@ -3215,6 +3315,10 @@
3215
3315
  "type": "linkage_specification",
3216
3316
  "named": true
3217
3317
  },
3318
+ {
3319
+ "type": "macro_specifier",
3320
+ "named": true
3321
+ },
3218
3322
  {
3219
3323
  "type": "ms_declspec_modifier",
3220
3324
  "named": true
@@ -3298,6 +3402,10 @@
3298
3402
  "type": "linkage_specification",
3299
3403
  "named": true
3300
3404
  },
3405
+ {
3406
+ "type": "macro_specifier",
3407
+ "named": true
3408
+ },
3301
3409
  {
3302
3410
  "type": "ms_declspec_modifier",
3303
3411
  "named": true
@@ -3488,6 +3596,10 @@
3488
3596
  "type": "linkage_specification",
3489
3597
  "named": true
3490
3598
  },
3599
+ {
3600
+ "type": "macro_specifier",
3601
+ "named": true
3602
+ },
3491
3603
  {
3492
3604
  "type": "ms_declspec_modifier",
3493
3605
  "named": true
@@ -3600,6 +3712,10 @@
3600
3712
  "type": "linkage_specification",
3601
3713
  "named": true
3602
3714
  },
3715
+ {
3716
+ "type": "macro_specifier",
3717
+ "named": true
3718
+ },
3603
3719
  {
3604
3720
  "type": "ms_declspec_modifier",
3605
3721
  "named": true
@@ -4129,6 +4245,10 @@
4129
4245
  "type": "linkage_specification",
4130
4246
  "named": true
4131
4247
  },
4248
+ {
4249
+ "type": "macro_specifier",
4250
+ "named": true
4251
+ },
4132
4252
  {
4133
4253
  "type": "ms_declspec_modifier",
4134
4254
  "named": true
@@ -4229,6 +4349,10 @@
4229
4349
  "type": "enum_specifier",
4230
4350
  "named": true
4231
4351
  },
4352
+ {
4353
+ "type": "macro_specifier",
4354
+ "named": true
4355
+ },
4232
4356
  {
4233
4357
  "type": "ms_declspec_modifier",
4234
4358
  "named": true
Binary file
package/tree-sitter.json CHANGED
@@ -16,7 +16,7 @@
16
16
  }
17
17
  ],
18
18
  "metadata": {
19
- "version": "11.0.0",
19
+ "version": "12.0.0",
20
20
  "license": "MIT",
21
21
  "description": "C grammar for tree-sitter",
22
22
  "authors": [