@willbooster/tree-sitter-c 32.0.0 → 33.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
@@ -95,896 +95,981 @@ const PRAGMA_SPACING = repeat(choice(/\s/, /\\(?:\r\n?|\n\r?)/));
95
95
  const PREPROC_ARGUMENT = /\S([^/\n]|\/[^*]|\\\r?\n)*/;
96
96
  const VA_ARG_KEYWORDS = choice('va_arg', '__builtin_va_arg');
97
97
 
98
+ // Every keyword of the grammar that `MACRO_CASE_IDENTIFIER` would otherwise spell.
99
+ const MACRO_CASE_KEYWORDS = [
100
+ 'NULL',
101
+ '__alignof',
102
+ '__alignof__',
103
+ '__asm',
104
+ '__asm__',
105
+ '__attribute',
106
+ '__attribute__',
107
+ '__based',
108
+ '__builtin_available',
109
+ '__builtin_va_arg',
110
+ '__cdecl',
111
+ '__clrcall',
112
+ '__complex__',
113
+ '__declspec',
114
+ '__except',
115
+ '__extension__',
116
+ '__fastcall',
117
+ '__finally',
118
+ '__forceinline',
119
+ '__inline',
120
+ '__inline__',
121
+ '__leave',
122
+ '__ptr32',
123
+ '__ptr64',
124
+ '__restrict',
125
+ '__restrict__',
126
+ '__sptr',
127
+ '__stdcall',
128
+ '__thiscall',
129
+ '__thread',
130
+ '__try',
131
+ '__typeof',
132
+ '__typeof__',
133
+ '__typeof_unqual',
134
+ '__typeof_unqual__',
135
+ '__unaligned',
136
+ '__uptr',
137
+ '__vectorcall',
138
+ '__volatile__',
139
+ ];
140
+ const UPPER_CASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
141
+ const IDENTIFIER_CHARACTERS = `${UPPER_CASE}abcdefghijklmnopqrstuvwxyz0123456789_`;
142
+ const MACRO_CASE_IDENTIFIER = new RegExp(
143
+ `${identifierExcept(
144
+ ['', ...MACRO_CASE_KEYWORDS.filter((keyword) => !keyword.startsWith('__'))],
145
+ `${UPPER_CASE}_`,
146
+ `${UPPER_CASE}0123456789_`
147
+ )}|__${identifierExcept(
148
+ MACRO_CASE_KEYWORDS.filter((keyword) => keyword.startsWith('__')).map((keyword) => keyword.slice(2)),
149
+ IDENTIFIER_CHARACTERS,
150
+ IDENTIFIER_CHARACTERS
151
+ )}`
152
+ );
153
+
98
154
  // oxlint-disable-next-line unicorn/prefer-module -- This package is CommonJS, so tree-sitter loads grammar.js as CommonJS.
99
155
  module.exports = Object.assign(
100
- grammar({
101
- name: 'c',
102
-
103
- conflicts: ($) => [
104
- [$._declaration_modifiers, $._empty_declaration],
105
- [$.type_definition, $._declaration_modifiers, $._empty_declaration],
106
- [
107
- $._statement_declaration,
108
- $._statement_type_definition,
109
- $._macro_only_declaration,
110
- $._macro_declaration_specifiers,
111
- $._statement_declaration_modifiers,
112
- $._guarded_type_specifiers,
113
- ],
114
- [
115
- $._macro_declaration_specifiers,
116
- $._statement_declaration_modifiers,
117
- $._guarded_type_specifiers,
118
- $._case_body_attributed_statement,
119
- $._case_label_attributes,
120
- ],
121
- [
122
- $._statement_declaration,
123
- $._macro_only_declaration,
124
- $._macro_declaration_specifiers,
125
- $._statement_declaration_modifiers,
126
- $._guarded_type_specifiers,
127
- ],
128
- [
129
- $._statement_declaration,
130
- $._statement_type_definition,
131
- $._macro_only_declaration,
132
- $._macro_declaration_specifiers,
133
- $._statement_declaration_modifiers,
134
- $._guarded_type_specifiers,
135
- $._statement_empty_declaration,
136
- ],
137
- [
138
- $._macro_only_declaration,
139
- $._macro_declaration_specifiers,
140
- $._statement_declaration_modifiers,
141
- $._guarded_type_specifiers,
142
- ],
143
- [
144
- $._macro_only_declaration,
145
- $._macro_declaration_specifiers,
146
- $._statement_declaration_modifiers,
147
- $._guarded_type_specifiers,
148
- $._statement_empty_declaration,
149
- ],
150
- [
151
- $._macro_declaration_specifiers,
152
- $._statement_declaration_modifiers,
153
- $._guarded_type_specifiers,
154
- $.attributed_statement,
155
- $.case_statement,
156
- ],
157
- [$._macro_declaration_specifiers, $._statement_declaration_modifiers, $._guarded_type_specifiers],
158
- [$._declarator, sym('_braced_macro_function_declarator')],
159
- [
160
- $._macro_declaration_specifiers,
161
- $._declaration_modifiers,
162
- $._guarded_type_specifiers,
163
- $.attributed_statement,
164
- $.case_statement,
165
- ],
166
- [$._sized_bit_int_type_name, $._sized_bit_int_specifier],
167
- [$.type_specifier, $._type_name_specifier, $._sized_bit_int_type_name, $._sized_bit_int_specifier],
168
- [$._declaration_modifiers, $.type_descriptor],
169
- [$.type_specifier, $._type_name_specifier, $.macro_specifier],
170
- [$.type_specifier, $._type_name_specifier, $.expression, $.macro_specifier],
171
- [$.type_specifier, $._type_name_specifier, $.expression, $.macro_type_specifier],
172
- [$.type_specifier, $._type_name_specifier, $._sized_type_name, $.sized_type_specifier],
173
- [$._sized_type_name, $._sized_bit_int_type_name, $.sized_type_specifier, $._sized_bit_int_specifier],
174
- [$._sized_type_name, $.sized_type_specifier],
175
- [$.storage_class_specifier, $.type_specifier, $._type_name_specifier, $.expression],
176
- [$.storage_class_specifier, $.type_specifier, $._type_name_specifier],
177
- [$.type_specifier, $._type_name_specifier, $.expression, $.va_arg_expression, $.macro_type_specifier],
178
- [$.type_specifier, $._type_name_specifier],
179
- [$.type_specifier, $._type_name_specifier, $.expression],
180
- [$._known_annotation_type_specifier, $.sized_type_specifier],
181
- [$._known_annotation_type_specifier, $._sized_bit_int_specifier],
182
- [$._braced_macro_attribute_argument_list, $._variadic_macro_type_specifier],
183
- [$._braced_macro_attribute_argument_list, $.macro_type_specifier],
184
- [$._annotation_type_specifier, $.macro_specifier],
185
- [$._macro_attribute_specifier, $._braced_leading_macro_attribute_specifier],
186
- [$._annotation_type_specifier, $.sized_type_specifier],
187
- [$._annotation_type_specifier, $._sized_bit_int_specifier],
188
- [$._bare_initializer_type, $._annotation_type_specifier, $.type_specifier],
189
- [$._bare_initializer_type, $._annotation_type_specifier, $.type_specifier, $.macro_specifier],
190
- [$._annotation_type_specifier, $.type_specifier, $.macro_specifier],
191
- [$._annotation_type_specifier, $.type_specifier, $.expression, $.macro_specifier],
192
- [$.type_definition, $._annotation_type_specifier, $.type_specifier, $.sized_type_specifier],
193
- [$.type_definition, $._annotation_type_specifier, $.type_specifier, $._sized_bit_int_specifier],
194
- [$.type_definition, $._annotation_type_specifier, $.type_specifier],
195
- [$._statement_type_definition, $._annotation_type_specifier, $.type_specifier, $.sized_type_specifier],
196
- [$._statement_type_definition, $._annotation_type_specifier, $.type_specifier, $._sized_bit_int_specifier],
197
- [$._statement_type_definition, $._annotation_type_specifier, $.type_specifier],
198
- [$._annotation_type_specifier, $.type_specifier, $.sized_type_specifier],
199
- [$._annotation_type_specifier, $.type_specifier, $._sized_bit_int_specifier],
200
- [$._annotation_type_specifier, $.type_specifier, $.expression],
201
- [$._annotation_type_specifier, $.type_specifier],
202
- [
203
- $._macro_declaration_specifiers,
204
- $._statement_declaration_modifiers,
205
- $._case_body_attributed_statement,
206
- $._case_label_attributes,
207
- ],
208
- [$._statement_declaration, $._macro_declaration_specifiers, $._statement_declaration_modifiers],
209
- [
210
- $._statement_declaration,
211
- $._statement_type_definition,
212
- $._macro_declaration_specifiers,
213
- $._statement_declaration_modifiers,
214
- $._statement_empty_declaration,
215
- ],
216
- [
217
- $._statement_declaration,
218
- $._statement_type_definition,
219
- $._macro_declaration_specifiers,
220
- $._statement_declaration_modifiers,
221
- ],
222
- [$._macro_declaration_specifiers, $._statement_declaration_modifiers, $._statement_empty_declaration],
223
- [$._macro_declaration_specifiers, $._statement_declaration_modifiers],
224
- [$._macro_declaration_specifiers, $._statement_declaration_modifiers, $.attributed_statement, $.case_statement],
225
- [$._bare_initializer_type, $.macro_specifier],
226
- [$.declaration, $._declaration_modifiers, $._marked_macro_type_specifiers],
227
- [$._bare_initializer_type, $.type_specifier, $.macro_specifier],
228
- [$._bare_initializer_type, $.type_specifier, $.macro_type_specifier],
229
- [$._bare_initializer_type, $.type_specifier],
230
- [$._guarded_macro_type_specifier, $.type_specifier],
231
- [$._macro_declaration_specifiers, $._guarded_type_specifiers],
232
- [$._macro_declaration_specifiers, $._guarded_type_specifiers, $._marked_macro_type_specifiers],
233
- [$._macro_only_declaration, $._macro_declaration_specifiers, $._guarded_type_specifiers],
234
- [$._macro_declaration_specifiers, $._declaration_modifiers, $._marked_macro_type_specifiers],
235
- [
236
- $._macro_declaration_specifiers,
237
- $._declaration_modifiers,
238
- $._guarded_type_specifiers,
239
- $._marked_macro_type_specifiers,
240
- ],
241
- [$._declaration_modifiers, $._marked_macro_type_specifiers],
242
- [$.declaration, $._macro_declaration_specifiers, $._declaration_modifiers],
243
- [$.declaration, $._macro_declaration_specifiers, $._declaration_modifiers, $._guarded_type_specifiers],
244
- [
245
- $.declaration,
246
- $.type_definition,
247
- $._macro_only_declaration,
248
- $._macro_declaration_specifiers,
249
- $._declaration_modifiers,
250
- $._guarded_type_specifiers,
251
- $._statement_empty_declaration,
252
- ],
253
- [
254
- $._macro_only_declaration,
255
- $._macro_declaration_specifiers,
256
- $._declaration_modifiers,
257
- $._guarded_type_specifiers,
258
- $._empty_declaration,
259
- $._statement_empty_declaration,
260
- ],
261
- [
262
- $._macro_only_declaration,
263
- $._macro_declaration_specifiers,
264
- $._declaration_modifiers,
265
- $._guarded_type_specifiers,
266
- ],
267
- [
268
- $._macro_only_declaration,
269
- $._macro_declaration_specifiers,
270
- $._declaration_modifiers,
271
- $._guarded_type_specifiers,
272
- $._statement_empty_declaration,
273
- ],
274
- [$._macro_attribute_specifier, $.type_specifier, $.macro_type_specifier],
275
- [$.type_specifier, $.macro_type_specifier, $._variadic_macro_type_specifier],
276
- [$._macro_declaration_specifiers],
277
- [$._macro_attribute_argument_list, $.macro_type_specifier],
278
- [
279
- $._macro_attribute_specifier,
280
- $._braced_leading_macro_attribute_specifier,
281
- $.type_specifier,
282
- $.macro_type_specifier,
283
- $._variadic_macro_type_specifier,
284
- ],
285
- [$.declaration, $._declaration_modifiers, $._guarded_type_specifiers],
286
- [$._declaration_modifiers, $._guarded_type_specifiers],
287
- // Required by derived C++ declarations although unnecessary in C alone.
288
- [
289
- $._macro_declaration_specifiers,
290
- $._declaration_modifiers,
291
- $._guarded_type_specifiers,
292
- $._empty_declaration,
293
- $._statement_empty_declaration,
294
- ],
295
- [$._macro_declaration_specifiers, $._declaration_modifiers, $._guarded_type_specifiers],
296
- // Required by derived C++ declarations although unnecessary in C alone.
297
- [
298
- $._macro_declaration_specifiers,
299
- $._declaration_modifiers,
300
- $._guarded_type_specifiers,
301
- $._statement_empty_declaration,
302
- ],
303
- [$._string, $._raw_string_type_argument],
304
- [
305
- $._conditional_function_specifiers,
306
- $._declaration_specifiers,
307
- $._empty_declaration,
308
- $._statement_empty_declaration,
309
- ],
310
- [$._empty_declaration, $._statement_empty_declaration],
311
- [
312
- $.declaration,
313
- $.type_definition,
314
- $._macro_declaration_specifiers,
315
- $._declaration_modifiers,
316
- $._statement_empty_declaration,
317
- ],
318
- [$._macro_declaration_specifiers, $._declaration_modifiers, $._empty_declaration, $._statement_empty_declaration],
319
- [$._conditional_function_specifiers, $._declaration_specifiers, $._statement_empty_declaration],
320
- [$._macro_declaration_specifiers, $._declaration_modifiers, $._statement_empty_declaration],
321
- [$.macro_specifier, $._type_name_specifier],
322
- [$._type_name_specifier, $.expression, $.va_arg_expression, $.macro_type_specifier],
323
- [$._type_name_specifier, $.expression],
324
- [$._type_name_specifier, $.expression, $.macro_type_specifier],
325
- [$._type_name_specifier, $.macro_type_specifier],
326
- [$._type_name_specifier, $._sized_type_name],
327
- [$._type_name_specifier, $._sized_bit_int_type_name],
328
- [$._sized_type_name],
329
- [$._sized_bit_int_type_name],
330
- [$._sized_type_name, $._sized_bit_int_type_name],
331
- [$.storage_class_specifier, $._type_name_specifier],
332
- [$._compound_literal_storage_class_specifier, $._type_name_specifier],
333
- [$._field_declaration_specifiers],
334
- [$._sized_type_identifier, $._enum_underlying_type],
335
- [$.type_specifier, $._sized_type_identifier, $.macro_specifier],
336
- [$.type_specifier, $._sized_type_identifier],
337
- [$._sized_type_identifier, $.macro_specifier],
338
- [$.declaration, $._declaration_modifiers],
339
- [$.type_definition, $.type_specifier],
340
- [$._macro_declaration_specifiers, $._declaration_modifiers, $.attributed_statement, $.case_statement],
341
- [$.macro_specifier, $._type_declarator],
342
- [$.macro_specifier, $._field_declarator],
343
- [$.macro_specifier, $._declarator],
344
- [$.macro_specifier, $._declarator, $.attributed_declarator, $.type_specifier],
345
- [$.macro_specifier, $._declarator, $.attributed_declarator],
346
- [$._statement_type_definition, $.type_specifier, $.sized_type_specifier],
347
- [$._statement_type_definition, $.type_specifier, $._sized_bit_int_specifier],
348
- [$.type_definition, $.type_specifier, $.sized_type_specifier],
349
- [$.type_definition, $.type_specifier, $._sized_bit_int_specifier],
350
- [$._type_declarator, $.sized_type_specifier],
351
- [$.macro_specifier, $.expression],
352
- [$.macro_specifier, $.type_specifier],
353
- [$._macro_declaration_specifiers, $._declaration_modifiers],
354
- [$.preproc_include_argument],
355
- [$._preproc_include_token, $.preproc_argument_list],
356
- [$._preproc_include_path, $.preproc_include_argument],
357
- [$.compound_statement, $.initializer_list],
358
- [$.comma_expression, $._initializer_element],
359
- [$.comma_expression, $.initializer_pair],
360
- [$._block_item, $._initializer_directive],
361
- [sym('preproc_if_in_statement'), sym('preproc_if_in_initializer_list')],
362
- [sym('preproc_ifdef_in_statement'), sym('preproc_ifdef_in_initializer_list')],
363
- [sym('preproc_else_in_statement'), sym('preproc_else_in_initializer_list')],
364
- [sym('preproc_elif_in_statement'), sym('preproc_elif_in_initializer_list')],
365
- [sym('preproc_elifdef_in_statement'), sym('preproc_elifdef_in_initializer_list')],
366
- [$.type_specifier, $.expression, $.va_arg_expression, $.macro_type_specifier],
367
- [$.va_arg_expression, $.expression],
368
- [$.type_definition, $._declaration_modifiers],
369
- [$._statement_type_definition, $._statement_declaration_modifiers],
370
- [$._statement_type_definition, $.type_specifier],
371
- [$.type_definition, $.type_qualifier, $.extension_expression],
372
- [$._statement_type_definition, $.type_qualifier, $.extension_expression],
373
- [$.type_definition, $.type_qualifier],
374
- [$._statement_type_definition, $.type_qualifier],
375
- [$._statement_declaration_modifiers, $._statement_empty_declaration],
376
- [$.declaration, $.storage_class_specifier],
377
- [$._statement_declaration, $.storage_class_specifier],
378
- [$.type_specifier, $._declarator],
379
- [$.type_specifier, $._declarator, $.macro_type_specifier],
380
- [$.type_specifier, $.expression],
381
- [$.type_specifier, $.expression, $.macro_type_specifier],
382
- [$.type_specifier, $.macro_type_specifier],
383
- [$.type_specifier, $.sized_type_specifier],
384
- [$.type_specifier, $._sized_bit_int_specifier],
385
- [$.sized_type_specifier],
386
- [$._sized_bit_int_specifier],
387
- [$.sized_type_specifier, $._sized_bit_int_specifier],
388
- [$.type_qualifier, $.atomic_type_specifier],
389
- [$.type_definition, $._type_declarator],
390
- [$.type_definition, $.sized_type_specifier],
391
- [$.type_definition, $._sized_bit_int_specifier],
392
- [$.case_statement],
393
- [$.enum_specifier],
394
- [sym('preproc_if_in_enumerator_list'), sym('preproc_if_in_enumerator_list_no_comma')],
395
- [sym('preproc_ifdef_in_enumerator_list'), sym('preproc_ifdef_in_enumerator_list_no_comma')],
396
- [sym('preproc_else_in_enumerator_list'), sym('preproc_else_in_enumerator_list_no_comma')],
397
- [sym('preproc_elif_in_enumerator_list'), sym('preproc_elif_in_enumerator_list_no_comma')],
398
- [sym('preproc_elifdef_in_enumerator_list'), sym('preproc_elifdef_in_enumerator_list_no_comma')],
399
- [$.type_specifier, $._old_style_parameter_list],
400
- [$.parameter_list, $._old_style_parameter_list],
401
- [$.function_declarator, $._function_declaration_declarator],
402
- [$.pointer_declarator],
403
- [$.pointer_declarator, $._initialized_declarator],
404
- [$._initialized_pointer_declarator],
405
- [$.pointer_declarator, $.abstract_pointer_declarator],
406
- [$.pointer_field_declarator],
407
- [$.pointer_type_declarator],
408
- [$.abstract_pointer_declarator],
409
- [$._top_level_item, $._top_level_statement],
410
- [$.type_specifier, $._top_level_expression_statement],
411
- [$.type_qualifier, $.extension_expression],
412
- [$.storage_class_specifier, $.type_specifier],
413
- [$.storage_class_specifier, $.type_specifier, $.expression],
414
- [$.storage_class_specifier, $.expression],
415
- [$.attributed_declarator],
416
- [$.attributed_declarator, $._declarator],
417
- [$.attributed_declarator, $._declarator, $.type_specifier],
418
- [$.attributed_field_declarator],
419
- [$.attributed_field_declarator, $._field_declarator],
420
- [$.attributed_type_declarator],
421
- [$.attributed_type_declarator, $._type_declarator],
422
- [$._declaration_modifiers, $._field_declaration_list_item],
423
- [$._declaration_specifiers],
424
- [$._compound_literal_constexpr_specifier, $.type_qualifier],
425
- [$._marked_macro_type_specifiers],
426
- [$._braced_leading_macro_attribute_specifier, $._post_type_macro_attribute_specifier],
427
- [$._annotation_type_specifier, $._known_annotation_type_specifier, $.type_specifier, $._sized_bit_int_specifier],
428
- [$._annotation_type_specifier, $._known_annotation_type_specifier, $.type_specifier],
429
- [$._annotation_type_specifier, $._known_annotation_type_specifier, $.type_specifier, $.sized_type_specifier],
430
- [$._annotation_type_specifier, $._macro_attribute_suffix, $.macro_type_specifier],
431
- [$._annotation_type_specifier, $.macro_type_specifier],
432
- [$._known_annotation_type_specifier, $.type_specifier, $.sized_type_specifier],
433
- [$._known_annotation_type_specifier, $.type_specifier, $._sized_bit_int_specifier],
434
- [$._known_annotation_type_specifier, $.type_specifier],
435
- ],
436
-
437
- externals: () => [
438
- sym('pragma_operator'),
439
- sym('preproc_arg'),
440
- sym('_preproc_newline'),
441
- sym('_preproc_lparen'),
442
- sym('_preproc_directive_arg'),
443
- sym('_preproc_function_name'),
444
- sym('_function_attribute_start'),
445
- sym('_post_type_function_attribute_start'),
446
- sym('_post_type_function_attribute_suffix'),
447
- sym('_trailing_macro_attribute_name'),
448
- sym('_trailing_object_declaration_start'),
449
- sym('_conditional_marker_ifdef'),
450
- sym('_conditional_marker_ifndef'),
451
- sym('_leading_conditional_marker_ifdef'),
452
- sym('_leading_conditional_marker_ifndef'),
453
- sym('_gnu_raw_string_body'),
454
- sym('_raw_macro_type_tail'),
455
- sym('_braced_function_attribute_start'),
456
- sym('_braced_macro_type_start'),
457
- sym('_directive_context'),
458
- sym('preproc_empty'),
459
- sym('_preproc_directive_start'),
460
- ],
461
-
462
- extras: ($) => [
463
- sym('_directive_context'),
464
- sym('preproc_empty'),
465
- $.pragma_operator,
466
- /\s|\\(?:\r\n?|\n\r?)/,
467
- $.comment,
468
- ],
469
-
470
- inline: ($) => [
471
- $._bare_marker_initializer_declaration,
472
- $._unattributed_non_case_statement,
473
- $._single_unattributed_non_case_statement,
474
- $._unlabeled_non_case_statement,
475
- $._non_identifier_type_specifier,
476
- $._non_macro_declaration_modifiers,
477
- $._unattributed_declarator,
478
- $._unattributed_field_declarator,
479
- $._unattributed_type_declarator,
480
- $._type_identifier,
481
- $._field_identifier,
482
- $._statement_identifier,
483
- $._assignment_left_expression,
484
- $._expression_not_binary,
485
- ],
486
-
487
- supertypes: ($) => [
488
- $.expression,
489
- $.statement,
490
- $._single_noncompound_statement,
491
- $._non_case_statement,
492
- $._attributed_body_statement,
493
- $._single_non_case_statement,
494
- $._single_attributed_body_statement,
495
- $._case_body_statement,
496
- $._case_body_unattributed_statement,
497
- $._case_label_tail,
498
- $._case_label_statement,
499
- $._case_label_chain_statement,
500
- $.type_specifier,
501
- $._type_name_specifier,
502
- $._guarded_type_specifier,
503
- sym('_annotation_type_specifier'),
504
- sym('_known_annotation_type_specifier'),
505
- $._guarded_macro_type_specifier,
506
- sym('_bare_initializer_type'),
507
- $._declarator,
508
- $._old_style_declarator,
509
- $._initialized_declarator,
510
- sym('_guarded_initialized_declarator'),
511
- sym('_braced_macro_declarator'),
512
- $._initialized_parenthesized_content,
513
- $._field_declarator,
514
- $._type_declarator,
515
- $._abstract_declarator,
516
- ],
517
-
518
- reserved: { global: () => [], marker: ($) => [$.primitive_type] },
519
-
520
- word: ($) => $.identifier,
521
-
522
- rules: {
523
- translation_unit: ($) => repeat($._top_level_item),
524
-
525
- _top_level_item: ($) =>
526
- choice(
527
- $.function_definition,
528
- alias($._old_style_function_definition, $.function_definition),
529
- alias(sym('_conditional_function_definition'), $.function_definition),
530
- alias(sym('_conditional_old_style_function_definition'), $.function_definition),
531
- $.linkage_specification,
532
- $.declaration,
533
- alias(sym('_macro_modified_declaration'), $.declaration),
534
- alias(sym('_macro_only_declaration'), $.declaration),
535
- alias(sym('_trailing_macro_modified_declaration'), $.declaration),
536
- alias(sym('_conditional_declaration'), $.declaration),
537
- $._top_level_statement,
156
+ assertMacroCaseIdentifierSpellsNoKeyword(
157
+ grammar({
158
+ name: 'c',
159
+
160
+ conflicts: ($) => [
161
+ [$._declaration_modifiers, $._empty_declaration],
162
+ [$.type_definition, $._declaration_modifiers, $._empty_declaration],
163
+ [
164
+ $._statement_declaration,
165
+ $._statement_type_definition,
166
+ $._macro_only_declaration,
167
+ $._macro_declaration_specifiers,
168
+ $._statement_declaration_modifiers,
169
+ $._guarded_type_specifiers,
170
+ ],
171
+ [
172
+ $._macro_declaration_specifiers,
173
+ $._statement_declaration_modifiers,
174
+ $._guarded_type_specifiers,
175
+ $._case_body_attributed_statement,
176
+ $._case_label_attributes,
177
+ ],
178
+ [
179
+ $._statement_declaration,
180
+ $._macro_only_declaration,
181
+ $._macro_declaration_specifiers,
182
+ $._statement_declaration_modifiers,
183
+ $._guarded_type_specifiers,
184
+ ],
185
+ [
186
+ $._statement_declaration,
187
+ $._statement_type_definition,
188
+ $._macro_only_declaration,
189
+ $._macro_declaration_specifiers,
190
+ $._statement_declaration_modifiers,
191
+ $._guarded_type_specifiers,
192
+ $._statement_empty_declaration,
193
+ ],
194
+ [
195
+ $._macro_only_declaration,
196
+ $._macro_declaration_specifiers,
197
+ $._statement_declaration_modifiers,
198
+ $._guarded_type_specifiers,
199
+ ],
200
+ [
201
+ $._macro_only_declaration,
202
+ $._macro_declaration_specifiers,
203
+ $._statement_declaration_modifiers,
204
+ $._guarded_type_specifiers,
205
+ $._statement_empty_declaration,
206
+ ],
207
+ [
208
+ $._macro_declaration_specifiers,
209
+ $._statement_declaration_modifiers,
210
+ $._guarded_type_specifiers,
538
211
  $.attributed_statement,
212
+ $.case_statement,
213
+ ],
214
+ [$._macro_declaration_specifiers, $._statement_declaration_modifiers, $._guarded_type_specifiers],
215
+ [$._declarator, sym('_braced_macro_function_declarator')],
216
+ [
217
+ $._macro_declaration_specifiers,
218
+ $._declaration_modifiers,
219
+ $._guarded_type_specifiers,
220
+ $.attributed_statement,
221
+ $.case_statement,
222
+ ],
223
+ [$._sized_bit_int_type_name, $._sized_bit_int_specifier],
224
+ [$.type_specifier, $._type_name_specifier, $._sized_bit_int_type_name, $._sized_bit_int_specifier],
225
+ [$._declaration_modifiers, $.type_descriptor],
226
+ [$.type_specifier, $._type_name_specifier, $.macro_specifier],
227
+ [$.type_specifier, $._type_name_specifier, $.expression, $.macro_specifier],
228
+ [$.type_specifier, $._type_name_specifier, $.expression, $.macro_type_specifier],
229
+ [$.type_specifier, $._type_name_specifier, $._sized_type_name, $.sized_type_specifier],
230
+ [$._sized_type_name, $._sized_bit_int_type_name, $.sized_type_specifier, $._sized_bit_int_specifier],
231
+ [$._sized_type_name, $.sized_type_specifier],
232
+ [$.storage_class_specifier, $.type_specifier, $._type_name_specifier, $.expression],
233
+ [$.storage_class_specifier, $.type_specifier, $._type_name_specifier],
234
+ [$.type_specifier, $._type_name_specifier, $.expression, $.va_arg_expression, $.macro_type_specifier],
235
+ [$.type_specifier, $._type_name_specifier],
236
+ [$.type_specifier, $._type_name_specifier, $.expression],
237
+ [$._known_annotation_type_specifier, $.sized_type_specifier],
238
+ [$._known_annotation_type_specifier, $._sized_bit_int_specifier],
239
+ [$._braced_macro_attribute_argument_list, $._variadic_macro_type_specifier],
240
+ [$._braced_macro_attribute_argument_list, $.macro_type_specifier],
241
+ [$._annotation_type_specifier, $.macro_specifier],
242
+ [$._macro_attribute_specifier, $._braced_leading_macro_attribute_specifier],
243
+ [$._annotation_type_specifier, $.sized_type_specifier],
244
+ [$._annotation_type_specifier, $._sized_bit_int_specifier],
245
+ [$._bare_initializer_type, $._annotation_type_specifier, $.type_specifier],
246
+ [$._bare_initializer_type, $._annotation_type_specifier, $.type_specifier, $.macro_specifier],
247
+ [$._annotation_type_specifier, $.type_specifier, $.macro_specifier],
248
+ [$._annotation_type_specifier, $.type_specifier, $.expression, $.macro_specifier],
249
+ [$.type_definition, $._annotation_type_specifier, $.type_specifier, $.sized_type_specifier],
250
+ [$.type_definition, $._annotation_type_specifier, $.type_specifier, $._sized_bit_int_specifier],
251
+ [$.type_definition, $._annotation_type_specifier, $.type_specifier],
252
+ [$._statement_type_definition, $._annotation_type_specifier, $.type_specifier, $.sized_type_specifier],
253
+ [$._statement_type_definition, $._annotation_type_specifier, $.type_specifier, $._sized_bit_int_specifier],
254
+ [$._statement_type_definition, $._annotation_type_specifier, $.type_specifier],
255
+ [$._annotation_type_specifier, $.type_specifier, $.sized_type_specifier],
256
+ [$._annotation_type_specifier, $.type_specifier, $._sized_bit_int_specifier],
257
+ [$._annotation_type_specifier, $.type_specifier, $.expression],
258
+ [$._annotation_type_specifier, $.type_specifier],
259
+ [
260
+ $._macro_declaration_specifiers,
261
+ $._statement_declaration_modifiers,
262
+ $._case_body_attributed_statement,
263
+ $._case_label_attributes,
264
+ ],
265
+ [$._statement_declaration, $._macro_declaration_specifiers, $._statement_declaration_modifiers],
266
+ [
267
+ $._statement_declaration,
268
+ $._statement_type_definition,
269
+ $._macro_declaration_specifiers,
270
+ $._statement_declaration_modifiers,
271
+ $._statement_empty_declaration,
272
+ ],
273
+ [
274
+ $._statement_declaration,
275
+ $._statement_type_definition,
276
+ $._macro_declaration_specifiers,
277
+ $._statement_declaration_modifiers,
278
+ ],
279
+ [$._macro_declaration_specifiers, $._statement_declaration_modifiers, $._statement_empty_declaration],
280
+ [$._macro_declaration_specifiers, $._statement_declaration_modifiers],
281
+ [$._macro_declaration_specifiers, $._statement_declaration_modifiers, $.attributed_statement, $.case_statement],
282
+ [$._bare_initializer_type, $.macro_specifier],
283
+ [$.declaration, $._declaration_modifiers, $._marked_macro_type_specifiers],
284
+ [$._bare_initializer_type, $.type_specifier, $.macro_specifier],
285
+ [$._bare_initializer_type, $.type_specifier, $.macro_type_specifier],
286
+ [$._bare_initializer_type, $.type_specifier],
287
+ [$._guarded_macro_type_specifier, $.type_specifier],
288
+ [$._macro_declaration_specifiers, $._guarded_type_specifiers],
289
+ [$._macro_declaration_specifiers, $._guarded_type_specifiers, $._marked_macro_type_specifiers],
290
+ [$._macro_only_declaration, $._macro_declaration_specifiers, $._guarded_type_specifiers],
291
+ [$._macro_declaration_specifiers, $._declaration_modifiers, $._marked_macro_type_specifiers],
292
+ [
293
+ $._macro_declaration_specifiers,
294
+ $._declaration_modifiers,
295
+ $._guarded_type_specifiers,
296
+ $._marked_macro_type_specifiers,
297
+ ],
298
+ [$._declaration_modifiers, $._marked_macro_type_specifiers],
299
+ [$.declaration, $._macro_declaration_specifiers, $._declaration_modifiers],
300
+ [$.declaration, $._macro_declaration_specifiers, $._declaration_modifiers, $._guarded_type_specifiers],
301
+ [
302
+ $.declaration,
539
303
  $.type_definition,
304
+ $._macro_only_declaration,
305
+ $._macro_declaration_specifiers,
306
+ $._declaration_modifiers,
307
+ $._guarded_type_specifiers,
308
+ $._statement_empty_declaration,
309
+ ],
310
+ [
311
+ $._macro_only_declaration,
312
+ $._macro_declaration_specifiers,
313
+ $._declaration_modifiers,
314
+ $._guarded_type_specifiers,
540
315
  $._empty_declaration,
541
- alias(sym('preproc_if_in_header'), sym('preproc_if')),
542
- alias(sym('preproc_ifdef_in_header'), sym('preproc_ifdef')),
543
- $.preproc_include,
544
- $.preproc_def,
545
- $.preproc_function_def,
546
- $.preproc_call
547
- ),
548
-
549
- _block_item: ($) =>
550
- choice(
551
- alias($._statement_function_definition, $.function_definition),
552
- alias($._statement_old_style_function_definition, $.function_definition),
553
- $.linkage_specification,
554
- alias($._statement_declaration, $.declaration),
555
- $.statement,
556
- alias($._statement_type_definition, $.type_definition),
557
316
  $._statement_empty_declaration,
558
- alias(sym('preproc_if_in_statement'), sym('preproc_if')),
559
- alias(sym('preproc_ifdef_in_statement'), sym('preproc_ifdef')),
560
- $.preproc_include,
561
- $.preproc_def,
562
- $.preproc_function_def,
563
- $.preproc_call
564
- ),
565
-
566
- _header_preproc_item: ($) =>
567
- choice(
568
- $.function_definition,
569
- alias($._old_style_function_definition, $.function_definition),
570
- alias(sym('_conditional_function_definition'), $.function_definition),
571
- alias(sym('_conditional_old_style_function_definition'), $.function_definition),
572
- $.linkage_specification,
317
+ ],
318
+ [
319
+ $._macro_only_declaration,
320
+ $._macro_declaration_specifiers,
321
+ $._declaration_modifiers,
322
+ $._guarded_type_specifiers,
323
+ ],
324
+ [
325
+ $._macro_only_declaration,
326
+ $._macro_declaration_specifiers,
327
+ $._declaration_modifiers,
328
+ $._guarded_type_specifiers,
329
+ $._statement_empty_declaration,
330
+ ],
331
+ [$._macro_attribute_specifier, $.type_specifier, $.macro_type_specifier],
332
+ [$.type_specifier, $.macro_type_specifier, $._variadic_macro_type_specifier],
333
+ [$._macro_declaration_specifiers],
334
+ [$._macro_attribute_argument_list, $.macro_type_specifier],
335
+ [
336
+ $._macro_attribute_specifier,
337
+ $._braced_leading_macro_attribute_specifier,
338
+ $.type_specifier,
339
+ $.macro_type_specifier,
340
+ $._variadic_macro_type_specifier,
341
+ ],
342
+ [$.declaration, $._declaration_modifiers, $._guarded_type_specifiers],
343
+ [$._declaration_modifiers, $._guarded_type_specifiers],
344
+ // Required by derived C++ declarations although unnecessary in C alone.
345
+ [
346
+ $._macro_declaration_specifiers,
347
+ $._declaration_modifiers,
348
+ $._guarded_type_specifiers,
349
+ $._empty_declaration,
350
+ $._statement_empty_declaration,
351
+ ],
352
+ [$._macro_declaration_specifiers, $._declaration_modifiers, $._guarded_type_specifiers],
353
+ // Required by derived C++ declarations although unnecessary in C alone.
354
+ [
355
+ $._macro_declaration_specifiers,
356
+ $._declaration_modifiers,
357
+ $._guarded_type_specifiers,
358
+ $._statement_empty_declaration,
359
+ ],
360
+ [$._string, $._raw_string_type_argument],
361
+ [
362
+ $._conditional_function_specifiers,
363
+ $._declaration_specifiers,
364
+ $._empty_declaration,
365
+ $._statement_empty_declaration,
366
+ ],
367
+ [$._empty_declaration, $._statement_empty_declaration],
368
+ [
573
369
  $.declaration,
574
- alias(sym('_macro_modified_declaration'), $.declaration),
575
- alias(sym('_macro_only_declaration'), $.declaration),
576
- alias(sym('_trailing_macro_modified_declaration'), $.declaration),
577
- alias(sym('_conditional_declaration'), $.declaration),
578
- $.statement,
579
370
  $.type_definition,
371
+ $._macro_declaration_specifiers,
372
+ $._declaration_modifiers,
373
+ $._statement_empty_declaration,
374
+ ],
375
+ [
376
+ $._macro_declaration_specifiers,
377
+ $._declaration_modifiers,
580
378
  $._empty_declaration,
581
- alias(sym('preproc_if_in_header'), sym('preproc_if')),
582
- alias(sym('preproc_ifdef_in_header'), sym('preproc_ifdef')),
583
- $.preproc_include,
584
- $.preproc_def,
585
- $.preproc_function_def,
586
- $.preproc_call
587
- ),
379
+ $._statement_empty_declaration,
380
+ ],
381
+ [$._conditional_function_specifiers, $._declaration_specifiers, $._statement_empty_declaration],
382
+ [$._macro_declaration_specifiers, $._declaration_modifiers, $._statement_empty_declaration],
383
+ [$.macro_specifier, $._type_name_specifier],
384
+ [$._type_name_specifier, $.expression, $.va_arg_expression, $.macro_type_specifier],
385
+ [$._type_name_specifier, $.expression],
386
+ [$._type_name_specifier, $.expression, $.macro_type_specifier],
387
+ [$._type_name_specifier, $.macro_type_specifier],
388
+ [$._type_name_specifier, $._sized_type_name],
389
+ [$._type_name_specifier, $._sized_bit_int_type_name],
390
+ [$._sized_type_name],
391
+ [$._sized_bit_int_type_name],
392
+ [$._sized_type_name, $._sized_bit_int_type_name],
393
+ [$.storage_class_specifier, $._type_name_specifier],
394
+ [$._compound_literal_storage_class_specifier, $._type_name_specifier],
395
+ [$._field_declaration_specifiers],
396
+ [$._sized_type_identifier, $._enum_underlying_type],
397
+ [$.type_specifier, $._sized_type_identifier, $.macro_specifier],
398
+ [$.type_specifier, $._sized_type_identifier],
399
+ [$._sized_type_identifier, $.macro_specifier],
400
+ [$.declaration, $._declaration_modifiers],
401
+ [$.type_definition, $.type_specifier],
402
+ [$._macro_declaration_specifiers, $._declaration_modifiers, $.attributed_statement, $.case_statement],
403
+ [$.macro_specifier, $._type_declarator],
404
+ [$.macro_specifier, $._field_declarator],
405
+ [$.macro_specifier, $._declarator],
406
+ [$.macro_specifier, $._declarator, $.attributed_declarator, $.type_specifier],
407
+ [$.macro_specifier, $._declarator, $.attributed_declarator],
408
+ [$._statement_type_definition, $.type_specifier, $.sized_type_specifier],
409
+ [$._statement_type_definition, $.type_specifier, $._sized_bit_int_specifier],
410
+ [$.type_definition, $.type_specifier, $.sized_type_specifier],
411
+ [$.type_definition, $.type_specifier, $._sized_bit_int_specifier],
412
+ [$._type_declarator, $.sized_type_specifier],
413
+ [$.macro_specifier, $.expression],
414
+ [$.macro_specifier, $.type_specifier],
415
+ [$._macro_declaration_specifiers, $._declaration_modifiers],
416
+ [$.preproc_include_argument],
417
+ [$._preproc_include_token, $.preproc_argument_list],
418
+ [$._preproc_include_path, $.preproc_include_argument],
419
+ [$.compound_statement, $.initializer_list],
420
+ [$.comma_expression, $._initializer_element],
421
+ [$.comma_expression, $.initializer_pair],
422
+ [$._block_item, $._initializer_directive],
423
+ [sym('preproc_if_in_statement'), sym('preproc_if_in_initializer_list')],
424
+ [sym('preproc_ifdef_in_statement'), sym('preproc_ifdef_in_initializer_list')],
425
+ [sym('preproc_else_in_statement'), sym('preproc_else_in_initializer_list')],
426
+ [sym('preproc_elif_in_statement'), sym('preproc_elif_in_initializer_list')],
427
+ [sym('preproc_elifdef_in_statement'), sym('preproc_elifdef_in_initializer_list')],
428
+ [$.type_specifier, $.expression, $.va_arg_expression, $.macro_type_specifier],
429
+ [$.va_arg_expression, $.expression],
430
+ [$.type_definition, $._declaration_modifiers],
431
+ [$._statement_type_definition, $._statement_declaration_modifiers],
432
+ [$._statement_type_definition, $.type_specifier],
433
+ [$.type_definition, $.type_qualifier, $.extension_expression],
434
+ [$._statement_type_definition, $.type_qualifier, $.extension_expression],
435
+ [$.type_definition, $.type_qualifier],
436
+ [$._statement_type_definition, $.type_qualifier],
437
+ [$._statement_declaration_modifiers, $._statement_empty_declaration],
438
+ [$.declaration, $.storage_class_specifier],
439
+ [$._statement_declaration, $.storage_class_specifier],
440
+ [$.type_specifier, $._declarator],
441
+ [$.type_specifier, $._declarator, $.macro_type_specifier],
442
+ [$.type_specifier, $.expression],
443
+ [$.type_specifier, $.expression, $.macro_type_specifier],
444
+ [$.type_specifier, $.macro_type_specifier],
445
+ [$.type_specifier, $.sized_type_specifier],
446
+ [$.type_specifier, $._sized_bit_int_specifier],
447
+ [$.sized_type_specifier],
448
+ [$._sized_bit_int_specifier],
449
+ [$.sized_type_specifier, $._sized_bit_int_specifier],
450
+ [$.type_qualifier, $.atomic_type_specifier],
451
+ [$.type_definition, $._type_declarator],
452
+ [$.type_definition, $.sized_type_specifier],
453
+ [$.type_definition, $._sized_bit_int_specifier],
454
+ [$.case_statement],
455
+ [$.enum_specifier],
456
+ [sym('preproc_if_in_enumerator_list'), sym('preproc_if_in_enumerator_list_no_comma')],
457
+ [sym('preproc_ifdef_in_enumerator_list'), sym('preproc_ifdef_in_enumerator_list_no_comma')],
458
+ [sym('preproc_else_in_enumerator_list'), sym('preproc_else_in_enumerator_list_no_comma')],
459
+ [sym('preproc_elif_in_enumerator_list'), sym('preproc_elif_in_enumerator_list_no_comma')],
460
+ [sym('preproc_elifdef_in_enumerator_list'), sym('preproc_elifdef_in_enumerator_list_no_comma')],
461
+ [$.type_specifier, $._old_style_parameter_list],
462
+ [$.parameter_list, $._old_style_parameter_list],
463
+ [$.function_declarator, $._function_declaration_declarator],
464
+ [$.function_declarator, $._parameter_function_declarator],
465
+ [$._parameter_pointer_declarator, $.pointer_declarator, $.abstract_pointer_declarator],
466
+ [$._parameter_declarator, $.macro_specifier],
467
+ [$.pointer_declarator],
468
+ [$.pointer_declarator, $._initialized_declarator],
469
+ [$._initialized_pointer_declarator],
470
+ [$.pointer_declarator, $.abstract_pointer_declarator],
471
+ [$.pointer_field_declarator],
472
+ [$.pointer_type_declarator],
473
+ [$.abstract_pointer_declarator],
474
+ [$._top_level_item, $._top_level_statement],
475
+ [$.type_specifier, $._top_level_expression_statement],
476
+ [$.type_qualifier, $.extension_expression],
477
+ [$.storage_class_specifier, $.type_specifier],
478
+ [$.storage_class_specifier, $.type_specifier, $.expression],
479
+ [$.storage_class_specifier, $.expression],
480
+ [$.attributed_declarator],
481
+ [$.attributed_declarator, $._declarator],
482
+ [$.attributed_declarator, $._declarator, $.type_specifier],
483
+ [$.attributed_field_declarator],
484
+ [$.attributed_field_declarator, $._field_declarator],
485
+ [$.attributed_type_declarator],
486
+ [$.attributed_type_declarator, $._type_declarator],
487
+ [$._declaration_modifiers, $._field_declaration_list_item],
488
+ [$._declaration_specifiers],
489
+ [$._compound_literal_constexpr_specifier, $.type_qualifier],
490
+ [$._marked_macro_type_specifiers],
491
+ [$._braced_leading_macro_attribute_specifier, $._post_type_macro_attribute_specifier],
492
+ [
493
+ $._annotation_type_specifier,
494
+ $._known_annotation_type_specifier,
495
+ $.type_specifier,
496
+ $._sized_bit_int_specifier,
497
+ ],
498
+ [$._annotation_type_specifier, $._known_annotation_type_specifier, $.type_specifier],
499
+ [$._annotation_type_specifier, $._known_annotation_type_specifier, $.type_specifier, $.sized_type_specifier],
500
+ [$._annotation_type_specifier, $._macro_attribute_suffix, $.macro_type_specifier],
501
+ [$._annotation_type_specifier, $.macro_type_specifier],
502
+ [$._known_annotation_type_specifier, $.type_specifier, $.sized_type_specifier],
503
+ [$._known_annotation_type_specifier, $.type_specifier, $._sized_bit_int_specifier],
504
+ [$._known_annotation_type_specifier, $.type_specifier],
505
+ ],
588
506
 
589
- // Derived grammars that replace externals still need this lexical fallback. Comment-rich spacing makes the
590
- // lexer too large for the pinned Node Wasm optimizer; the external scanner handles those forms.
591
- pragma_operator: () =>
592
- token(
593
- seq(
594
- '_Pragma',
595
- PRAGMA_SPACING,
596
- '(',
597
- PRAGMA_SPACING,
598
- optional(choice('L', 'u8', 'u', 'U')),
599
- '"',
600
- repeat(choice(/[^\\"\r\n]/, seq('\\', choice(/[^\r\n]/, /\r\n?|\n\r?/)))),
601
- '"',
602
- PRAGMA_SPACING,
603
- ')'
604
- )
605
- ),
507
+ externals: () => [
508
+ sym('pragma_operator'),
509
+ sym('preproc_arg'),
510
+ sym('_preproc_newline'),
511
+ sym('_preproc_lparen'),
512
+ sym('_preproc_directive_arg'),
513
+ sym('_preproc_function_name'),
514
+ sym('_function_attribute_start'),
515
+ sym('_post_type_function_attribute_start'),
516
+ sym('_post_type_function_attribute_suffix'),
517
+ sym('_trailing_macro_attribute_name'),
518
+ sym('_trailing_object_declaration_start'),
519
+ sym('_conditional_marker_ifdef'),
520
+ sym('_conditional_marker_ifndef'),
521
+ sym('_leading_conditional_marker_ifdef'),
522
+ sym('_leading_conditional_marker_ifndef'),
523
+ sym('_gnu_raw_string_body'),
524
+ sym('_raw_macro_type_tail'),
525
+ sym('_braced_function_attribute_start'),
526
+ sym('_braced_macro_type_start'),
527
+ sym('_directive_context'),
528
+ sym('preproc_empty'),
529
+ sym('_preproc_directive_start'),
530
+ ],
606
531
 
607
- preproc_include: ($) =>
608
- seq(
609
- preprocessor('include'),
610
- field('path', choice($._preproc_include_path, $.preproc_include_argument)),
611
- repeat(choice($.comment, $.pragma_operator)),
612
- sym('_preproc_newline')
613
- ),
532
+ extras: ($) => [
533
+ sym('_directive_context'),
534
+ sym('preproc_empty'),
535
+ $.pragma_operator,
536
+ /\s|\\(?:\r\n?|\n\r?)/,
537
+ $.comment,
538
+ ],
614
539
 
615
- _preproc_include_path: ($) =>
616
- choice(
617
- $.string_literal,
618
- $.system_lib_string,
619
- $.identifier,
620
- alias($.preproc_call_expression, $.call_expression)
621
- ),
540
+ inline: ($) => [
541
+ $._bare_marker_initializer_declaration,
542
+ $._unattributed_non_case_statement,
543
+ $._single_unattributed_non_case_statement,
544
+ $._unlabeled_non_case_statement,
545
+ $._non_identifier_type_specifier,
546
+ $._non_macro_declaration_modifiers,
547
+ $._unattributed_declarator,
548
+ $._unattributed_field_declarator,
549
+ $._unattributed_type_declarator,
550
+ $._type_identifier,
551
+ $._field_identifier,
552
+ $._statement_identifier,
553
+ $._assignment_left_expression,
554
+ $._expression_not_binary,
555
+ ],
622
556
 
623
- preproc_include_argument: ($) => prec.dynamic(-1, seq($.identifier, repeat1($._preproc_include_segment))),
557
+ supertypes: ($) => [
558
+ $.expression,
559
+ $.statement,
560
+ $._single_noncompound_statement,
561
+ $._non_case_statement,
562
+ $._attributed_body_statement,
563
+ $._single_non_case_statement,
564
+ $._single_attributed_body_statement,
565
+ $._case_body_statement,
566
+ $._case_body_unattributed_statement,
567
+ $._case_label_tail,
568
+ $._case_label_statement,
569
+ $._case_label_chain_statement,
570
+ $.type_specifier,
571
+ $._type_name_specifier,
572
+ $._guarded_type_specifier,
573
+ sym('_annotation_type_specifier'),
574
+ sym('_known_annotation_type_specifier'),
575
+ $._guarded_macro_type_specifier,
576
+ sym('_bare_initializer_type'),
577
+ $._declarator,
578
+ $._old_style_declarator,
579
+ $._initialized_declarator,
580
+ sym('_guarded_initialized_declarator'),
581
+ sym('_braced_macro_declarator'),
582
+ $._initialized_parenthesized_content,
583
+ $._field_declarator,
584
+ $._type_declarator,
585
+ $._abstract_declarator,
586
+ ],
624
587
 
625
- _preproc_include_segment: ($) =>
626
- prec.dynamic(-1, seq(repeat(choice($.comment, $.pragma_operator)), $._preproc_include_token)),
588
+ reserved: { global: () => [], marker: ($) => [$.primitive_type] },
627
589
 
628
- _preproc_include_token: ($) =>
629
- choice(
630
- $.identifier,
631
- $.number_literal,
632
- $.char_literal,
633
- $.string_literal,
634
- $.system_lib_string,
635
- ...BINARY_OPERATORS.map(([operator]) => operator),
636
- '!',
637
- '~',
638
- '(',
639
- ')',
640
- ',',
641
- 'defined',
642
- token(prec(-3, /\S/))
643
- ),
590
+ word: ($) => $.identifier,
644
591
 
645
- preproc_def: ($) =>
646
- seq(
647
- preprocessor('define'),
648
- field('name', $.identifier),
649
- repeat(choice($.comment, $.pragma_operator)),
650
- optional(seq(field('value', $.preproc_arg), repeat(choice($.comment, $.pragma_operator)))),
651
- sym('_preproc_newline')
652
- ),
592
+ rules: {
593
+ translation_unit: ($) => repeat($._top_level_item),
653
594
 
654
- preproc_function_def: ($) =>
655
- seq(
656
- preprocessor('define'),
657
- field('name', alias(sym('_preproc_function_name'), $.identifier)),
658
- field('parameters', $.preproc_params),
659
- repeat(choice($.comment, $.pragma_operator)),
660
- optional(seq(field('value', $.preproc_arg), repeat(choice($.comment, $.pragma_operator)))),
661
- sym('_preproc_newline')
662
- ),
595
+ _top_level_item: ($) =>
596
+ choice(
597
+ $.function_definition,
598
+ alias($._old_style_function_definition, $.function_definition),
599
+ alias(sym('_conditional_function_definition'), $.function_definition),
600
+ alias(sym('_conditional_old_style_function_definition'), $.function_definition),
601
+ $.linkage_specification,
602
+ $.declaration,
603
+ alias(sym('_macro_modified_declaration'), $.declaration),
604
+ alias(sym('_macro_only_declaration'), $.declaration),
605
+ alias(sym('_trailing_macro_modified_declaration'), $.declaration),
606
+ alias(sym('_conditional_declaration'), $.declaration),
607
+ $._top_level_statement,
608
+ $.attributed_statement,
609
+ $.type_definition,
610
+ $._empty_declaration,
611
+ alias(sym('preproc_if_in_header'), sym('preproc_if')),
612
+ alias(sym('preproc_ifdef_in_header'), sym('preproc_ifdef')),
613
+ $.preproc_include,
614
+ $.preproc_def,
615
+ $.preproc_function_def,
616
+ $.preproc_call
617
+ ),
663
618
 
664
- preproc_params: ($) => seq(alias($._preproc_lparen, '('), commaSep(choice($.identifier, '...')), ')'),
619
+ _block_item: ($) =>
620
+ choice(
621
+ alias($._statement_function_definition, $.function_definition),
622
+ alias($._statement_old_style_function_definition, $.function_definition),
623
+ $.linkage_specification,
624
+ alias($._statement_declaration, $.declaration),
625
+ $.statement,
626
+ alias($._statement_type_definition, $.type_definition),
627
+ $._statement_empty_declaration,
628
+ alias(sym('preproc_if_in_statement'), sym('preproc_if')),
629
+ alias(sym('preproc_ifdef_in_statement'), sym('preproc_ifdef')),
630
+ $.preproc_include,
631
+ $.preproc_def,
632
+ $.preproc_function_def,
633
+ $.preproc_call
634
+ ),
665
635
 
666
- preproc_call: ($) =>
667
- choice(
668
- preprocCall(
669
- $,
670
- alias(preprocessorToken('pragma'), $.preproc_directive),
671
- choice($._preproc_directive_arg, $.preproc_arg)
636
+ _header_preproc_item: ($) =>
637
+ choice(
638
+ $.function_definition,
639
+ alias($._old_style_function_definition, $.function_definition),
640
+ alias(sym('_conditional_function_definition'), $.function_definition),
641
+ alias(sym('_conditional_old_style_function_definition'), $.function_definition),
642
+ $.linkage_specification,
643
+ $.declaration,
644
+ alias(sym('_macro_modified_declaration'), $.declaration),
645
+ alias(sym('_macro_only_declaration'), $.declaration),
646
+ alias(sym('_trailing_macro_modified_declaration'), $.declaration),
647
+ alias(sym('_conditional_declaration'), $.declaration),
648
+ $.statement,
649
+ $.type_definition,
650
+ $._empty_declaration,
651
+ alias(sym('preproc_if_in_header'), sym('preproc_if')),
652
+ alias(sym('preproc_ifdef_in_header'), sym('preproc_ifdef')),
653
+ $.preproc_include,
654
+ $.preproc_def,
655
+ $.preproc_function_def,
656
+ $.preproc_call
672
657
  ),
673
- preprocCall($, $.preproc_directive, $._preproc_directive_arg)
674
- ),
675
658
 
676
- ...preprocIf('_in_header', () => sym('_header_preproc_item')),
677
- ...preprocIf('', () => sym('_block_item')),
678
- ...preprocIf('_in_statement', () => sym('_block_item')),
679
- ...preprocIf('_in_single_case', () => sym('_single_case_body'), 0, true),
680
- ...preprocIf('_in_field_declaration_list', () => sym('_field_declaration_list_item')),
681
- ...preprocIf('_in_enumerator_list', () => sym('_enumerator_list_item')),
682
- ...preprocIf(
683
- '_in_enumerator_list_no_comma',
684
- () =>
659
+ // Derived grammars that replace externals still need this lexical fallback. Comment-rich spacing makes the
660
+ // lexer too large for the pinned Node Wasm optimizer; the external scanner handles those forms.
661
+ pragma_operator: () =>
662
+ token(
663
+ seq(
664
+ '_Pragma',
665
+ PRAGMA_SPACING,
666
+ '(',
667
+ PRAGMA_SPACING,
668
+ optional(choice('L', 'u8', 'u', 'U')),
669
+ '"',
670
+ repeat(choice(/[^\\"\r\n]/, seq('\\', choice(/[^\r\n]/, /\r\n?|\n\r?/)))),
671
+ '"',
672
+ PRAGMA_SPACING,
673
+ ')'
674
+ )
675
+ ),
676
+
677
+ preproc_include: ($) =>
678
+ seq(
679
+ preprocessor('include'),
680
+ field('path', choice($._preproc_include_path, $.preproc_include_argument)),
681
+ repeat(choice($.comment, $.pragma_operator)),
682
+ sym('_preproc_newline')
683
+ ),
684
+
685
+ _preproc_include_path: ($) =>
685
686
  choice(
686
- seq(repeat(sym('_enumerator_list_item')), sym('enumerator'), optional(sym('_enumerator_directives'))),
687
- repeat1(sym('_enumerator_list_item'))
687
+ $.string_literal,
688
+ $.system_lib_string,
689
+ $.identifier,
690
+ alias($.preproc_call_expression, $.call_expression)
688
691
  ),
689
- 0,
690
- false
691
- ),
692
692
 
693
- _enumerator_list_item: ($) => choice(seq($.enumerator, ','), $._enumerator_macro, $._enumerator_directives),
693
+ preproc_include_argument: ($) => prec.dynamic(-1, seq($.identifier, repeat1($._preproc_include_segment))),
694
694
 
695
- _enumerator_directives: ($) => prec.right(repeat1($.preproc_call)),
695
+ _preproc_include_segment: ($) =>
696
+ prec.dynamic(-1, seq(repeat(choice($.comment, $.pragma_operator)), $._preproc_include_token)),
696
697
 
697
- _preproc_newline: () => token.immediate(/\r?\n/),
698
+ _preproc_include_token: ($) =>
699
+ choice(
700
+ $.identifier,
701
+ $.number_literal,
702
+ $.char_literal,
703
+ $.string_literal,
704
+ $.system_lib_string,
705
+ ...BINARY_OPERATORS.map(([operator]) => operator),
706
+ '!',
707
+ '~',
708
+ '(',
709
+ ')',
710
+ ',',
711
+ 'defined',
712
+ token(prec(-3, /\S/))
713
+ ),
698
714
 
699
- _preproc_lparen: () => token.immediate(/\(/),
715
+ preproc_def: ($) =>
716
+ seq(
717
+ preprocessor('define'),
718
+ field('name', $.identifier),
719
+ repeat(choice($.comment, $.pragma_operator)),
720
+ optional(seq(field('value', $.preproc_arg), repeat(choice($.comment, $.pragma_operator)))),
721
+ sym('_preproc_newline')
722
+ ),
700
723
 
701
- preproc_arg: () => token(prec(-1, PREPROC_ARGUMENT)),
724
+ preproc_function_def: ($) =>
725
+ seq(
726
+ preprocessor('define'),
727
+ field('name', alias(sym('_preproc_function_name'), $.identifier)),
728
+ field('parameters', $.preproc_params),
729
+ repeat(choice($.comment, $.pragma_operator)),
730
+ optional(seq(field('value', $.preproc_arg), repeat(choice($.comment, $.pragma_operator)))),
731
+ sym('_preproc_newline')
732
+ ),
702
733
 
703
- _preproc_directive_arg: () => token(prec(-2, PREPROC_ARGUMENT)),
704
- preproc_directive: () => token(seq(PREPROC_PREFIX, /[a-zA-Z0-9]/, repeat(seq(repeat(LINE_SPLICE), /\w/)))),
734
+ preproc_params: ($) => seq(alias($._preproc_lparen, '('), commaSep(choice($.identifier, '...')), ')'),
705
735
 
706
- _preproc_expression: ($) =>
707
- choice(
708
- $.identifier,
709
- alias($.preproc_call_expression, $.call_expression),
710
- $.number_literal,
711
- $.char_literal,
712
- $.preproc_defined,
713
- alias($.preproc_unary_expression, $.unary_expression),
714
- alias($.preproc_binary_expression, $.binary_expression),
715
- alias($.preproc_parenthesized_expression, $.parenthesized_expression)
736
+ preproc_call: ($) =>
737
+ choice(
738
+ preprocCall(
739
+ $,
740
+ alias(preprocessorToken('pragma'), $.preproc_directive),
741
+ choice($._preproc_directive_arg, $.preproc_arg)
742
+ ),
743
+ preprocCall($, $.preproc_directive, $._preproc_directive_arg)
744
+ ),
745
+
746
+ ...preprocIf('_in_header', () => sym('_header_preproc_item')),
747
+ ...preprocIf('', () => sym('_block_item')),
748
+ ...preprocIf('_in_statement', () => sym('_block_item')),
749
+ ...preprocIf('_in_single_case', () => sym('_single_case_body'), 0, true),
750
+ ...preprocIf('_in_field_declaration_list', () => sym('_field_declaration_list_item')),
751
+ ...preprocIf('_in_enumerator_list', () => sym('_enumerator_list_item')),
752
+ ...preprocIf(
753
+ '_in_enumerator_list_no_comma',
754
+ () =>
755
+ choice(
756
+ seq(repeat(sym('_enumerator_list_item')), sym('enumerator'), optional(sym('_enumerator_directives'))),
757
+ repeat1(sym('_enumerator_list_item'))
758
+ ),
759
+ 0,
760
+ false
716
761
  ),
717
762
 
718
- preproc_parenthesized_expression: ($) => seq('(', $._preproc_expression, ')'),
763
+ _enumerator_list_item: ($) => choice(seq($.enumerator, ','), $._enumerator_macro, $._enumerator_directives),
719
764
 
720
- preproc_defined: ($) =>
721
- choice(prec(PREC.CALL, seq('defined', '(', $.identifier, ')')), seq('defined', $.identifier)),
765
+ _enumerator_directives: ($) => prec.right(repeat1($.preproc_call)),
722
766
 
723
- preproc_unary_expression: ($) =>
724
- prec.left(
725
- PREC.UNARY,
726
- seq(field('operator', choice('!', '~', '-', '+')), field('argument', $._preproc_expression))
727
- ),
767
+ _preproc_newline: () => token.immediate(/\r?\n/),
728
768
 
729
- preproc_call_expression: ($) =>
730
- prec(
731
- PREC.CALL,
732
- seq(field('function', $.identifier), field('arguments', alias($.preproc_argument_list, $.argument_list)))
733
- ),
769
+ _preproc_lparen: () => token.immediate(/\(/),
734
770
 
735
- preproc_argument_list: ($) =>
736
- seq(
737
- '(',
738
- commaSep(choice($._preproc_expression, $.system_lib_string, $.string_literal, $.raw_string_literal)),
739
- ')'
740
- ),
771
+ preproc_arg: () => token(prec(-1, PREPROC_ARGUMENT)),
741
772
 
742
- preproc_binary_expression: ($) => {
743
- return choice(
744
- ...BINARY_OPERATORS.map(([operator, precedence]) => {
745
- return prec.left(
746
- precedence,
747
- seq(
748
- field('left', $._preproc_expression),
749
- field('operator', operator),
750
- field('right', $._preproc_expression)
751
- )
752
- );
753
- })
754
- );
755
- },
773
+ _preproc_directive_arg: () => token(prec(-2, PREPROC_ARGUMENT)),
774
+ preproc_directive: () => token(seq(PREPROC_PREFIX, /[a-zA-Z0-9]/, repeat(seq(repeat(LINE_SPLICE), /\w/)))),
756
775
 
757
- function_definition: ($) =>
758
- functionDefinitionRule($, functionDefinitionSpecifiers($, declarationSpecifiers($, true)), false),
759
- _statement_function_definition: ($) =>
760
- functionDefinitionRule($, functionDefinitionSpecifiers($, $._statement_declaration_specifiers), false),
761
- _old_style_function_definition: ($) =>
762
- functionDefinitionRule($, functionDefinitionSpecifiers($, declarationSpecifiers($, true)), true),
763
- _statement_old_style_function_definition: ($) =>
764
- functionDefinitionRule($, functionDefinitionSpecifiers($, $._statement_declaration_specifiers), true),
776
+ _preproc_expression: ($) =>
777
+ choice(
778
+ $.identifier,
779
+ alias($.preproc_call_expression, $.call_expression),
780
+ $.number_literal,
781
+ $.char_literal,
782
+ $.preproc_defined,
783
+ alias($.preproc_unary_expression, $.unary_expression),
784
+ alias($.preproc_binary_expression, $.binary_expression),
785
+ alias($.preproc_parenthesized_expression, $.parenthesized_expression)
786
+ ),
765
787
 
766
- _old_style_declarator: ($) =>
767
- choice(
768
- alias($._old_style_function_declarator, $.function_declarator),
769
- alias($._old_style_pointer_declarator, $.pointer_declarator)
770
- ),
788
+ preproc_parenthesized_expression: ($) => seq('(', $._preproc_expression, ')'),
771
789
 
772
- _old_style_pointer_declarator: ($) =>
773
- prec.dynamic(
774
- 1,
775
- prec.right(
776
- seq(
777
- optional($.ms_based_modifier),
778
- optional(prec.dynamic(2, $.ms_call_modifier)),
779
- '*',
780
- repeat($.attribute_declaration),
781
- repeat($.ms_pointer_modifier),
782
- repeat(
783
- choice(
784
- $.type_qualifier,
785
- $.attribute_specifier,
786
- prec(-1, $.ms_call_modifier),
787
- $.macro_specifier,
788
- $._conditional_macro_specifier
790
+ preproc_defined: ($) =>
791
+ choice(prec(PREC.CALL, seq('defined', '(', $.identifier, ')')), seq('defined', $.identifier)),
792
+
793
+ preproc_unary_expression: ($) =>
794
+ prec.left(
795
+ PREC.UNARY,
796
+ seq(field('operator', choice('!', '~', '-', '+')), field('argument', $._preproc_expression))
797
+ ),
798
+
799
+ preproc_call_expression: ($) =>
800
+ prec(
801
+ PREC.CALL,
802
+ seq(field('function', $.identifier), field('arguments', alias($.preproc_argument_list, $.argument_list)))
803
+ ),
804
+
805
+ preproc_argument_list: ($) =>
806
+ seq(
807
+ '(',
808
+ commaSep(choice($._preproc_expression, $.system_lib_string, $.string_literal, $.raw_string_literal)),
809
+ ')'
810
+ ),
811
+
812
+ preproc_binary_expression: ($) => {
813
+ return choice(
814
+ ...BINARY_OPERATORS.map(([operator, precedence]) => {
815
+ return prec.left(
816
+ precedence,
817
+ seq(
818
+ field('left', $._preproc_expression),
819
+ field('operator', operator),
820
+ field('right', $._preproc_expression)
789
821
  )
790
- ),
791
- field('declarator', alias($._old_style_declarator, $._declarator))
822
+ );
823
+ })
824
+ );
825
+ },
826
+
827
+ function_definition: ($) =>
828
+ functionDefinitionRule($, functionDefinitionSpecifiers($, declarationSpecifiers($, true)), false),
829
+ _statement_function_definition: ($) =>
830
+ functionDefinitionRule($, functionDefinitionSpecifiers($, $._statement_declaration_specifiers), false),
831
+ _old_style_function_definition: ($) =>
832
+ functionDefinitionRule($, functionDefinitionSpecifiers($, declarationSpecifiers($, true)), true),
833
+ _statement_old_style_function_definition: ($) =>
834
+ functionDefinitionRule($, functionDefinitionSpecifiers($, $._statement_declaration_specifiers), true),
835
+
836
+ _old_style_declarator: ($) =>
837
+ choice(
838
+ alias($._old_style_function_declarator, $.function_declarator),
839
+ alias($._old_style_pointer_declarator, $.pointer_declarator)
840
+ ),
841
+
842
+ _old_style_pointer_declarator: ($) =>
843
+ prec.dynamic(
844
+ 1,
845
+ prec.right(
846
+ seq(
847
+ optional($.ms_based_modifier),
848
+ optional(prec.dynamic(2, $.ms_call_modifier)),
849
+ '*',
850
+ repeat($.attribute_declaration),
851
+ repeat($.ms_pointer_modifier),
852
+ repeat(
853
+ choice(
854
+ $.type_qualifier,
855
+ $.attribute_specifier,
856
+ prec(-1, $.ms_call_modifier),
857
+ $.macro_specifier,
858
+ $._conditional_macro_specifier
859
+ )
860
+ ),
861
+ field('declarator', alias($._old_style_declarator, $._declarator))
862
+ )
792
863
  )
793
- )
794
- ),
864
+ ),
795
865
 
796
- _conditional_function_definition: ($) =>
797
- functionDefinitionRule($, sym('_conditional_function_specifiers'), false),
798
- _conditional_old_style_function_definition: ($) =>
799
- functionDefinitionRule($, sym('_conditional_function_specifiers'), true),
800
- _conditional_function_specifiers: ($) =>
801
- seq(
802
- repeat($._declaration_modifiers),
803
- field('type', $.type_specifier),
804
- repeat($._non_macro_declaration_modifiers),
805
- $._conditional_macro_specifier,
806
- repeat(choice($._non_macro_declaration_modifiers, $._conditional_macro_specifier))
807
- ),
866
+ _conditional_function_definition: ($) =>
867
+ functionDefinitionRule($, sym('_conditional_function_specifiers'), false),
868
+ _conditional_old_style_function_definition: ($) =>
869
+ functionDefinitionRule($, sym('_conditional_function_specifiers'), true),
870
+ _conditional_function_specifiers: ($) =>
871
+ seq(
872
+ repeat($._declaration_modifiers),
873
+ field('type', $.type_specifier),
874
+ repeat($._non_macro_declaration_modifiers),
875
+ $._conditional_macro_specifier,
876
+ repeat(choice($._non_macro_declaration_modifiers, $._conditional_macro_specifier))
877
+ ),
808
878
 
809
- _declaration_declarators: ($) => declarationDeclarators($),
879
+ _declaration_declarators: ($) => declarationDeclarators($),
810
880
 
811
- declaration: ($) =>
812
- choice(
881
+ declaration: ($) =>
882
+ choice(
883
+ declarationRule(
884
+ $,
885
+ choice(declarationSpecifiers($, true), $._guarded_type_specifiers, $._marked_macro_type_specifiers),
886
+ $._declaration_modifiers
887
+ ),
888
+ sym('_bare_marker_initializer_declaration')
889
+ ),
890
+ _statement_declaration: ($) =>
891
+ choice(
892
+ declarationRule(
893
+ $,
894
+ choice($._statement_declaration_specifiers, $._guarded_type_specifiers, $._marked_macro_type_specifiers),
895
+ $._statement_declaration_modifiers
896
+ ),
897
+ sym('_bare_marker_initializer_declaration'),
898
+ $._macro_modified_declaration,
899
+ $._macro_only_declaration
900
+ ),
901
+ _bare_marker_initializer_declaration: ($) =>
813
902
  declarationRule(
814
903
  $,
815
- choice(declarationSpecifiers($, true), $._guarded_type_specifiers, $._marked_macro_type_specifiers),
816
- $._declaration_modifiers
904
+ seq(
905
+ sym('_braced_macro_type_start'),
906
+ repeat($.macro_specifier),
907
+ field('type', alias(sym('_bare_initializer_type'), $.type_specifier))
908
+ ),
909
+ $._statement_declaration_modifiers,
910
+ false,
911
+ $._declaration_declarator,
912
+ { guard: sym('_braced_function_attribute_start'), bareMarkerInitializer: true }
817
913
  ),
818
- sym('_bare_marker_initializer_declaration')
819
- ),
820
- _statement_declaration: ($) =>
821
- choice(
914
+ _bare_initializer_type: ($) => $._type_identifier,
915
+
916
+ type_definition: ($) => typeDefinitionRule($, $._declaration_modifiers, true),
917
+ _statement_type_definition: ($) => typeDefinitionRule($, $._statement_declaration_modifiers, false),
918
+
919
+ _macro_modified_declaration: ($) =>
822
920
  declarationRule(
823
921
  $,
824
- choice($._statement_declaration_specifiers, $._guarded_type_specifiers, $._marked_macro_type_specifiers),
825
- $._statement_declaration_modifiers
922
+ $._macro_declaration_specifiers,
923
+ $._non_macro_declaration_modifiers,
924
+ false,
925
+ $._macro_declaration_declarator,
926
+ { guard: choice(sym('_post_type_function_attribute_suffix'), sym('_braced_function_attribute_start')) }
826
927
  ),
827
- sym('_bare_marker_initializer_declaration'),
828
- $._macro_modified_declaration,
829
- $._macro_only_declaration
830
- ),
831
- _bare_marker_initializer_declaration: ($) =>
832
- declarationRule(
833
- $,
928
+
929
+ _macro_only_declaration: ($) =>
834
930
  seq(
835
- sym('_braced_macro_type_start'),
836
- repeat($.macro_specifier),
837
- field('type', alias(sym('_bare_initializer_type'), $.type_specifier))
931
+ choice($.storage_class_specifier, $.type_qualifier, $.ms_declspec_modifier),
932
+ repeat($._non_macro_declaration_modifiers),
933
+ alias($._macro_attribute_specifier, $.attribute_specifier),
934
+ repeat(choice($._non_macro_declaration_modifiers, alias($._macro_attribute_suffix, $.attribute_specifier))),
935
+ ';'
838
936
  ),
839
- $._statement_declaration_modifiers,
840
- false,
841
- $._declaration_declarator,
842
- { guard: sym('_braced_function_attribute_start'), bareMarkerInitializer: true }
843
- ),
844
- _bare_initializer_type: ($) => $._type_identifier,
845
-
846
- type_definition: ($) => typeDefinitionRule($, $._declaration_modifiers, true),
847
- _statement_type_definition: ($) => typeDefinitionRule($, $._statement_declaration_modifiers, false),
848
937
 
849
- _macro_modified_declaration: ($) =>
850
- declarationRule(
851
- $,
852
- $._macro_declaration_specifiers,
853
- $._non_macro_declaration_modifiers,
854
- false,
855
- $._macro_declaration_declarator,
856
- { guard: choice(sym('_post_type_function_attribute_suffix'), sym('_braced_function_attribute_start')) }
857
- ),
938
+ _conditional_declaration: ($) =>
939
+ declarationRule($, sym('_conditional_function_specifiers'), $._non_macro_declaration_modifiers, false),
858
940
 
859
- _macro_only_declaration: ($) =>
860
- seq(
861
- choice($.storage_class_specifier, $.type_qualifier, $.ms_declspec_modifier),
862
- repeat($._non_macro_declaration_modifiers),
863
- alias($._macro_attribute_specifier, $.attribute_specifier),
864
- repeat(choice($._non_macro_declaration_modifiers, alias($._macro_attribute_suffix, $.attribute_specifier))),
865
- ';'
866
- ),
867
-
868
- _conditional_declaration: ($) =>
869
- declarationRule($, sym('_conditional_function_specifiers'), $._non_macro_declaration_modifiers, false),
870
-
871
- _trailing_macro_modified_declaration: ($) =>
872
- seq(
873
- sym('_trailing_object_declaration_start'),
874
- declarationSpecifiers($, true),
875
- field('declarator', $._trailing_macro_object_declarator),
876
- repeat1(alias($._trailing_macro_attribute_specifier, $.attribute_specifier)),
877
- ';'
878
- ),
941
+ _trailing_macro_modified_declaration: ($) =>
942
+ seq(
943
+ sym('_trailing_object_declaration_start'),
944
+ declarationSpecifiers($, true),
945
+ field('declarator', $._trailing_macro_object_declarator),
946
+ repeat1(alias($._trailing_macro_attribute_specifier, $.attribute_specifier)),
947
+ ';'
948
+ ),
879
949
 
880
- _trailing_macro_object_declarator: ($) =>
881
- choice($.identifier, alias($._trailing_macro_pointer_declarator, $.pointer_declarator)),
950
+ _trailing_macro_object_declarator: ($) =>
951
+ choice($.identifier, alias($._trailing_macro_pointer_declarator, $.pointer_declarator)),
882
952
 
883
- _trailing_macro_pointer_declarator: ($) => pointerDeclaratorRule($, $._trailing_macro_object_declarator),
953
+ _trailing_macro_pointer_declarator: ($) => pointerDeclaratorRule($, $._trailing_macro_object_declarator),
884
954
 
885
- _macro_declaration_specifiers: ($) => {
886
- const modifier = choice(
887
- $._non_macro_declaration_modifiers,
888
- alias($._macro_attribute_suffix, $.attribute_specifier)
889
- );
890
- const postModifier = choice(
891
- $._non_macro_declaration_modifiers,
892
- alias($._post_type_macro_attribute_suffix, $.attribute_specifier)
893
- );
894
- return choice(
895
- seq(
896
- choice($.storage_class_specifier, $.type_qualifier, $.ms_declspec_modifier),
897
- repeat($._non_macro_declaration_modifiers),
898
- choice(
899
- seq(
900
- alias($._macro_attribute_specifier, $.attribute_specifier),
901
- repeat(modifier),
902
- field('type', alias(sym('_known_annotation_type_specifier'), $.type_specifier))
903
- ),
904
- seq(
905
- alias(sym('_braced_leading_macro_attribute_specifier'), $.attribute_specifier),
906
- repeat(modifier),
907
- field(
908
- 'type',
909
- choice(
910
- alias(sym('_annotation_type_specifier'), $.type_specifier),
911
- alias($._guarded_macro_type_specifier, $.type_specifier)
955
+ _macro_declaration_specifiers: ($) => {
956
+ const modifier = choice(
957
+ $._non_macro_declaration_modifiers,
958
+ alias($._macro_attribute_suffix, $.attribute_specifier)
959
+ );
960
+ const postModifier = choice(
961
+ $._non_macro_declaration_modifiers,
962
+ alias($._post_type_macro_attribute_suffix, $.attribute_specifier)
963
+ );
964
+ return choice(
965
+ seq(
966
+ choice($.storage_class_specifier, $.type_qualifier, $.ms_declspec_modifier),
967
+ repeat($._non_macro_declaration_modifiers),
968
+ choice(
969
+ seq(
970
+ alias($._macro_attribute_specifier, $.attribute_specifier),
971
+ repeat(modifier),
972
+ field('type', alias(sym('_known_annotation_type_specifier'), $.type_specifier))
973
+ ),
974
+ seq(
975
+ alias(sym('_braced_leading_macro_attribute_specifier'), $.attribute_specifier),
976
+ repeat(modifier),
977
+ field(
978
+ 'type',
979
+ choice(
980
+ alias(sym('_annotation_type_specifier'), $.type_specifier),
981
+ alias($._guarded_macro_type_specifier, $.type_specifier)
982
+ )
912
983
  )
913
984
  )
914
- )
915
- ),
916
- repeat(postModifier)
917
- ),
918
- seq(
919
- repeat($._non_macro_declaration_modifiers),
920
- choice(
921
- field('type', alias(sym('_annotation_type_specifier'), $.type_specifier)),
922
- seq(
923
- optional(choice(sym('_function_attribute_start'), sym('_braced_function_attribute_start'))),
924
- field('type', alias($._guarded_macro_type_specifier, $.type_specifier))
925
- )
985
+ ),
986
+ repeat(postModifier)
926
987
  ),
927
- repeat($._non_macro_declaration_modifiers),
928
- alias($._post_type_macro_attribute_specifier, $.attribute_specifier),
929
- repeat(postModifier)
930
- )
931
- );
932
- },
988
+ seq(
989
+ repeat($._non_macro_declaration_modifiers),
990
+ choice(
991
+ field('type', alias(sym('_annotation_type_specifier'), $.type_specifier)),
992
+ seq(
993
+ optional(choice(sym('_function_attribute_start'), sym('_braced_function_attribute_start'))),
994
+ field('type', alias($._guarded_macro_type_specifier, $.type_specifier))
995
+ )
996
+ ),
997
+ repeat($._non_macro_declaration_modifiers),
998
+ alias($._post_type_macro_attribute_specifier, $.attribute_specifier),
999
+ repeat(postModifier)
1000
+ )
1001
+ );
1002
+ },
933
1003
 
934
- _annotation_type_specifier: ($) => choice($._non_identifier_type_specifier, $._type_identifier),
935
- _known_annotation_type_specifier: ($) => $._non_identifier_type_specifier,
1004
+ _annotation_type_specifier: ($) => choice($._non_identifier_type_specifier, $._type_identifier),
1005
+ _known_annotation_type_specifier: ($) => $._non_identifier_type_specifier,
936
1006
 
937
- _type_definition_type: ($) =>
938
- seq(
939
- repeat(choice($.type_qualifier, $.macro_specifier, $._leading_conditional_macro_specifier)),
940
- field('type', $.type_specifier),
941
- repeat($.type_qualifier)
942
- ),
943
- _type_definition_declarators: ($) => commaSep1(field('declarator', $._type_declarator)),
1007
+ _type_definition_type: ($) =>
1008
+ seq(
1009
+ repeat(choice($.type_qualifier, $.macro_specifier, $._leading_conditional_macro_specifier)),
1010
+ field('type', $.type_specifier),
1011
+ repeat($.type_qualifier)
1012
+ ),
1013
+ _type_definition_declarators: ($) => commaSep1(field('declarator', $._type_declarator)),
944
1014
 
945
- _declaration_modifiers: ($) =>
946
- choice($._non_macro_declaration_modifiers, $.macro_specifier, $._leading_conditional_macro_specifier),
1015
+ _declaration_modifiers: ($) =>
1016
+ choice($._non_macro_declaration_modifiers, $.macro_specifier, $._leading_conditional_macro_specifier),
947
1017
 
948
- _statement_declaration_modifiers: ($) => $._non_macro_declaration_modifiers,
1018
+ _statement_declaration_modifiers: ($) => $._non_macro_declaration_modifiers,
949
1019
 
950
- _non_macro_declaration_modifiers: ($) =>
951
- choice(
952
- $.storage_class_specifier,
953
- $.type_qualifier,
954
- $.attribute_specifier,
955
- $.attribute_declaration,
956
- $.ms_declspec_modifier
957
- ),
1020
+ _non_macro_declaration_modifiers: ($) =>
1021
+ choice(
1022
+ $.storage_class_specifier,
1023
+ $.type_qualifier,
1024
+ $.attribute_specifier,
1025
+ $.attribute_declaration,
1026
+ $.ms_declspec_modifier
1027
+ ),
958
1028
 
959
- _declaration_specifiers: ($) => declarationSpecifiers($),
1029
+ _declaration_specifiers: ($) => declarationSpecifiers($),
960
1030
 
961
- _guarded_type_specifiers: ($) =>
962
- prec.dynamic(
963
- 1,
1031
+ _guarded_type_specifiers: ($) =>
1032
+ prec.dynamic(
1033
+ 1,
1034
+ seq(
1035
+ $._non_macro_declaration_modifiers,
1036
+ repeat($._non_macro_declaration_modifiers),
1037
+ choice(
1038
+ seq(sym('_function_attribute_start'), field('type', $.type_specifier)),
1039
+ seq(
1040
+ sym('_braced_function_attribute_start'),
1041
+ field('type', alias($._guarded_type_specifier, $.type_specifier))
1042
+ )
1043
+ ),
1044
+ repeat(choice($._non_macro_declaration_modifiers, $._conditional_macro_specifier))
1045
+ )
1046
+ ),
1047
+
1048
+ _marked_macro_type_specifiers: ($) =>
964
1049
  seq(
965
- $._non_macro_declaration_modifiers,
966
- repeat($._non_macro_declaration_modifiers),
1050
+ sym('_braced_macro_type_start'),
967
1051
  choice(
968
- seq(sym('_function_attribute_start'), field('type', $.type_specifier)),
969
- seq(
970
- sym('_braced_function_attribute_start'),
971
- field('type', alias($._guarded_type_specifier, $.type_specifier))
972
- )
973
- ),
974
- repeat(choice($._non_macro_declaration_modifiers, $._conditional_macro_specifier))
975
- )
976
- ),
977
-
978
- _marked_macro_type_specifiers: ($) =>
979
- seq(
980
- sym('_braced_macro_type_start'),
981
- choice(
982
- prec.dynamic(
983
- 2,
1052
+ prec.dynamic(
1053
+ 2,
1054
+ seq(
1055
+ repeat($._non_macro_declaration_modifiers),
1056
+ repeat1(seq($.macro_specifier, repeat($._non_macro_declaration_modifiers))),
1057
+ optional(sym('_braced_function_attribute_start')),
1058
+ field(
1059
+ 'type',
1060
+ choice(
1061
+ alias(sym('_known_annotation_type_specifier'), $.type_specifier),
1062
+ alias($._guarded_macro_type_specifier, $.type_specifier)
1063
+ )
1064
+ ),
1065
+ repeat($._non_macro_declaration_modifiers)
1066
+ )
1067
+ ),
1068
+ declarationSpecifiers($, true),
1069
+ $._guarded_type_specifiers,
1070
+ $._macro_declaration_specifiers,
984
1071
  seq(
985
- repeat($._non_macro_declaration_modifiers),
986
- repeat1(seq($.macro_specifier, repeat($._non_macro_declaration_modifiers))),
987
- optional(sym('_braced_function_attribute_start')),
1072
+ repeat($._declaration_modifiers),
988
1073
  field(
989
1074
  'type',
990
1075
  choice(
@@ -992,680 +1077,754 @@ module.exports = Object.assign(
992
1077
  alias($._guarded_macro_type_specifier, $.type_specifier)
993
1078
  )
994
1079
  ),
995
- repeat($._non_macro_declaration_modifiers)
996
- )
997
- ),
998
- declarationSpecifiers($, true),
999
- $._guarded_type_specifiers,
1000
- $._macro_declaration_specifiers,
1001
- seq(
1002
- repeat($._declaration_modifiers),
1003
- field(
1004
- 'type',
1005
- choice(
1006
- alias(sym('_known_annotation_type_specifier'), $.type_specifier),
1007
- alias($._guarded_macro_type_specifier, $.type_specifier)
1008
- )
1009
- ),
1010
- repeat($._non_macro_declaration_modifiers),
1011
- alias(sym('_braced_leading_macro_attribute_specifier'), $.attribute_specifier),
1012
- repeat(
1013
- choice(
1014
- $._non_macro_declaration_modifiers,
1015
- $.macro_specifier,
1016
- alias($._post_type_macro_attribute_suffix, $.attribute_specifier)
1080
+ repeat($._non_macro_declaration_modifiers),
1081
+ alias(sym('_braced_leading_macro_attribute_specifier'), $.attribute_specifier),
1082
+ repeat(
1083
+ choice(
1084
+ $._non_macro_declaration_modifiers,
1085
+ $.macro_specifier,
1086
+ alias($._post_type_macro_attribute_suffix, $.attribute_specifier)
1087
+ )
1017
1088
  )
1018
1089
  )
1019
1090
  )
1020
- )
1021
- ),
1091
+ ),
1022
1092
 
1023
- _guarded_macro_type_specifier: ($) => $.macro_type_specifier,
1093
+ _guarded_macro_type_specifier: ($) => $.macro_type_specifier,
1024
1094
 
1025
- _guarded_type_specifier: ($) =>
1026
- choice($.type_specifier, alias($._variadic_macro_type_specifier, $.macro_type_specifier)),
1095
+ _guarded_type_specifier: ($) =>
1096
+ choice($.type_specifier, alias($._variadic_macro_type_specifier, $.macro_type_specifier)),
1027
1097
 
1028
- _field_declaration_specifiers: ($) =>
1029
- seq(
1030
- repeat($._declaration_modifiers),
1031
- field('type', alias($._type_name_specifier, $.type_specifier)),
1032
- repeat($._non_macro_declaration_modifiers)
1033
- ),
1098
+ _field_declaration_specifiers: ($) =>
1099
+ seq(
1100
+ repeat($._declaration_modifiers),
1101
+ field('type', alias($._type_name_specifier, $.type_specifier)),
1102
+ repeat($._non_macro_declaration_modifiers)
1103
+ ),
1034
1104
 
1035
- _statement_declaration_specifiers: ($) =>
1036
- seq(
1037
- repeat($._statement_declaration_modifiers),
1038
- field('type', $.type_specifier),
1039
- repeat($._statement_declaration_modifiers)
1040
- ),
1105
+ _statement_declaration_specifiers: ($) =>
1106
+ seq(
1107
+ repeat($._statement_declaration_modifiers),
1108
+ field('type', $.type_specifier),
1109
+ repeat($._statement_declaration_modifiers)
1110
+ ),
1041
1111
 
1042
- linkage_specification: ($) =>
1043
- seq(
1044
- 'extern',
1045
- field('value', choice($.string_literal, $.raw_string_literal)),
1046
- field('body', choice($.function_definition, $.declaration, $.declaration_list))
1047
- ),
1112
+ linkage_specification: ($) =>
1113
+ seq(
1114
+ 'extern',
1115
+ field('value', choice($.string_literal, $.raw_string_literal)),
1116
+ field('body', choice($.function_definition, $.declaration, $.declaration_list))
1117
+ ),
1048
1118
 
1049
- attribute_specifier: ($) => seq(choice('__attribute__', '__attribute'), '(', $.argument_list, ')'),
1119
+ attribute_specifier: ($) => seq(choice('__attribute__', '__attribute'), '(', $.argument_list, ')'),
1050
1120
 
1051
- _macro_attribute_specifier: ($) => macroAttributeRule($, 'leading'),
1121
+ _macro_attribute_specifier: ($) => macroAttributeRule($, 'leading'),
1052
1122
 
1053
- _braced_leading_macro_attribute_specifier: ($) => macroAttributeRule($, 'braced-leading'),
1123
+ _braced_leading_macro_attribute_specifier: ($) => macroAttributeRule($, 'braced-leading'),
1054
1124
 
1055
- _post_type_macro_attribute_specifier: ($) => macroAttributeRule($, 'post-type'),
1125
+ _post_type_macro_attribute_specifier: ($) => macroAttributeRule($, 'post-type'),
1056
1126
 
1057
- _macro_attribute_suffix: ($) => macroAttributeRule($, 'continuation'),
1127
+ _macro_attribute_suffix: ($) => macroAttributeRule($, 'continuation'),
1058
1128
 
1059
- _trailing_macro_attribute_specifier: ($) => macroAttributeRule($, 'trailing'),
1129
+ _trailing_macro_attribute_specifier: ($) => macroAttributeRule($, 'trailing'),
1060
1130
 
1061
- _post_type_macro_attribute_suffix: ($) => macroAttributeRule($, 'post-type-continuation'),
1131
+ _post_type_macro_attribute_suffix: ($) => macroAttributeRule($, 'post-type-continuation'),
1062
1132
 
1063
- _macro_attribute_parameter: ($) =>
1064
- seq($._declaration_specifiers, field('declarator', $._declarator), repeat($.attribute_specifier)),
1133
+ _macro_attribute_parameter: ($) =>
1134
+ seq($._declaration_specifiers, field('declarator', $._declarator), repeat($.attribute_specifier)),
1065
1135
 
1066
- _macro_attribute_argument_list: ($) => macroAttributeArgumentList(macroAttributeArgument($)),
1067
- _braced_macro_attribute_argument_list: ($) =>
1068
- macroAttributeArgumentList(
1069
- choice(macroAttributeArgument($), alias(sym('_macro_attribute_parameter'), $.parameter_declaration))
1070
- ),
1136
+ _macro_attribute_argument_list: ($) => macroAttributeArgumentList(macroAttributeArgument($)),
1137
+ _braced_macro_attribute_argument_list: ($) =>
1138
+ macroAttributeArgumentList(
1139
+ choice(macroAttributeArgument($), alias(sym('_macro_attribute_parameter'), $.parameter_declaration))
1140
+ ),
1071
1141
 
1072
- attribute: ($) =>
1073
- seq(optional(seq(field('prefix', $.identifier), '::')), field('name', $.identifier), optional($.argument_list)),
1142
+ attribute: ($) =>
1143
+ seq(
1144
+ optional(seq(field('prefix', $.identifier), '::')),
1145
+ field('name', $.identifier),
1146
+ optional($.argument_list)
1147
+ ),
1074
1148
 
1075
- attribute_declaration: ($) => seq('[', '[', commaSep1($.attribute), ']', ']'),
1149
+ attribute_declaration: ($) => seq('[', '[', commaSep1($.attribute), ']', ']'),
1076
1150
 
1077
- ms_declspec_modifier: ($) => seq('__declspec', '(', repeat(seq($.identifier, optional($.argument_list))), ')'),
1151
+ ms_declspec_modifier: ($) => seq('__declspec', '(', repeat(seq($.identifier, optional($.argument_list))), ')'),
1078
1152
 
1079
- ms_based_modifier: ($) => seq('__based', $.argument_list),
1153
+ ms_based_modifier: ($) => seq('__based', $.argument_list),
1080
1154
 
1081
- ms_call_modifier: () => choice('__cdecl', '__clrcall', '__stdcall', '__fastcall', '__thiscall', '__vectorcall'),
1155
+ ms_call_modifier: () => choice('__cdecl', '__clrcall', '__stdcall', '__fastcall', '__thiscall', '__vectorcall'),
1082
1156
 
1083
- ms_restrict_modifier: () => '__restrict',
1157
+ ms_restrict_modifier: () => '__restrict',
1084
1158
 
1085
- ms_unsigned_ptr_modifier: () => '__uptr',
1159
+ ms_unsigned_ptr_modifier: () => '__uptr',
1086
1160
 
1087
- ms_signed_ptr_modifier: () => '__sptr',
1161
+ ms_signed_ptr_modifier: () => '__sptr',
1088
1162
 
1089
- ms_unaligned_ptr_modifier: () => choice('_unaligned', '__unaligned'),
1163
+ ms_unaligned_ptr_modifier: () => choice('_unaligned', '__unaligned'),
1090
1164
 
1091
- ms_pointer_size_modifier: () => choice('__ptr32', '__ptr64'),
1165
+ ms_pointer_size_modifier: () => choice('__ptr32', '__ptr64'),
1092
1166
 
1093
- ms_pointer_modifier: ($) =>
1094
- choice(
1095
- $.ms_unaligned_ptr_modifier,
1096
- $.ms_restrict_modifier,
1097
- $.ms_unsigned_ptr_modifier,
1098
- $.ms_signed_ptr_modifier,
1099
- $.ms_pointer_size_modifier
1100
- ),
1167
+ ms_pointer_modifier: ($) =>
1168
+ choice(
1169
+ $.ms_unaligned_ptr_modifier,
1170
+ $.ms_restrict_modifier,
1171
+ $.ms_unsigned_ptr_modifier,
1172
+ $.ms_signed_ptr_modifier,
1173
+ $.ms_pointer_size_modifier
1174
+ ),
1101
1175
 
1102
- declaration_list: ($) => seq('{', repeat($._top_level_item), '}'),
1176
+ declaration_list: ($) => seq('{', repeat($._top_level_item), '}'),
1103
1177
 
1104
- _declarator: ($) => choice($.attributed_declarator, $._unattributed_declarator),
1178
+ _declarator: ($) => choice($.attributed_declarator, $._unattributed_declarator),
1105
1179
 
1106
- _unattributed_declarator: ($) =>
1107
- choice(
1108
- $.pointer_declarator,
1109
- $.function_declarator,
1110
- $.array_declarator,
1111
- $.parenthesized_declarator,
1112
- $.identifier,
1113
- alias(VA_ARG_KEYWORDS, $.identifier)
1114
- ),
1180
+ _unattributed_declarator: ($) =>
1181
+ choice(
1182
+ $.pointer_declarator,
1183
+ $.function_declarator,
1184
+ $.array_declarator,
1185
+ $.parenthesized_declarator,
1186
+ $.identifier,
1187
+ alias(VA_ARG_KEYWORDS, $.identifier)
1188
+ ),
1115
1189
 
1116
- _declaration_declarator: ($) =>
1117
- declarationDeclaratorRule($, alias($._function_declaration_declarator, $.function_declarator)),
1190
+ _declaration_declarator: ($) =>
1191
+ declarationDeclaratorRule($, alias($._function_declaration_declarator, $.function_declarator)),
1118
1192
 
1119
- _macro_declaration_declarator: ($) => declarationDeclaratorRule($, $.function_declarator),
1193
+ _macro_declaration_declarator: ($) => declarationDeclaratorRule($, $.function_declarator),
1120
1194
 
1121
- _braced_macro_declarator: ($) => alias(sym('_braced_macro_function_declarator'), $.function_declarator),
1122
- _braced_macro_function_declarator: ($) =>
1123
- seq(
1124
- field('declarator', $.identifier),
1125
- field('parameters', alias(sym('_braced_macro_attribute_argument_list'), $.parameter_list))
1126
- ),
1195
+ // A parameter keeps its trailing annotations however deeply its function declarator sits under pointers, as in
1196
+ // `int *callback(int) unused`.
1197
+ _parameter_declarator: ($) =>
1198
+ choice(
1199
+ $.attributed_declarator,
1200
+ alias($._parameter_pointer_declarator, $.pointer_declarator),
1201
+ alias($._parameter_function_declarator, $.function_declarator),
1202
+ $.array_declarator,
1203
+ $.parenthesized_declarator,
1204
+ $.identifier,
1205
+ alias(VA_ARG_KEYWORDS, $.identifier)
1206
+ ),
1127
1207
 
1128
- _field_declarator: ($) =>
1129
- choice(alias($.attributed_field_declarator, $.attributed_declarator), $._unattributed_field_declarator),
1208
+ _parameter_pointer_declarator: ($) => pointerDeclaratorRule($, $._parameter_declarator),
1130
1209
 
1131
- _unattributed_field_declarator: ($) =>
1132
- choice(
1133
- alias($.pointer_field_declarator, $.pointer_declarator),
1134
- alias($.function_field_declarator, $.function_declarator),
1135
- alias($.array_field_declarator, $.array_declarator),
1136
- alias($.parenthesized_field_declarator, $.parenthesized_declarator),
1137
- $._field_identifier
1138
- ),
1210
+ _braced_macro_declarator: ($) => alias(sym('_braced_macro_function_declarator'), $.function_declarator),
1211
+ _braced_macro_function_declarator: ($) =>
1212
+ seq(
1213
+ field('declarator', $.identifier),
1214
+ field('parameters', alias(sym('_braced_macro_attribute_argument_list'), $.parameter_list))
1215
+ ),
1139
1216
 
1140
- _type_declarator: ($) =>
1141
- choice(alias($.attributed_type_declarator, $.attributed_declarator), $._unattributed_type_declarator),
1217
+ _field_declarator: ($) =>
1218
+ choice(alias($.attributed_field_declarator, $.attributed_declarator), $._unattributed_field_declarator),
1142
1219
 
1143
- _unattributed_type_declarator: ($) =>
1144
- choice(
1145
- alias($.pointer_type_declarator, $.pointer_declarator),
1146
- alias($.function_type_declarator, $.function_declarator),
1147
- alias($.array_type_declarator, $.array_declarator),
1148
- alias($.parenthesized_type_declarator, $.parenthesized_declarator),
1149
- $._type_identifier,
1150
- alias('thread_local', sym('type_identifier')),
1151
- alias(choice('signed', 'unsigned', 'long', 'short'), $.primitive_type),
1152
- $.primitive_type
1153
- ),
1220
+ _unattributed_field_declarator: ($) =>
1221
+ choice(
1222
+ alias($.pointer_field_declarator, $.pointer_declarator),
1223
+ alias($.function_field_declarator, $.function_declarator),
1224
+ alias($.array_field_declarator, $.array_declarator),
1225
+ alias($.parenthesized_field_declarator, $.parenthesized_declarator),
1226
+ $._field_identifier
1227
+ ),
1154
1228
 
1155
- _abstract_declarator: ($) =>
1156
- choice(
1157
- $.abstract_pointer_declarator,
1158
- $.abstract_function_declarator,
1159
- $.abstract_array_declarator,
1160
- $.abstract_parenthesized_declarator
1161
- ),
1229
+ _type_declarator: ($) =>
1230
+ choice(alias($.attributed_type_declarator, $.attributed_declarator), $._unattributed_type_declarator),
1231
+
1232
+ _unattributed_type_declarator: ($) =>
1233
+ choice(
1234
+ alias($.pointer_type_declarator, $.pointer_declarator),
1235
+ alias($.function_type_declarator, $.function_declarator),
1236
+ alias($.array_type_declarator, $.array_declarator),
1237
+ alias($.parenthesized_type_declarator, $.parenthesized_declarator),
1238
+ $._type_identifier,
1239
+ alias('thread_local', sym('type_identifier')),
1240
+ alias(choice('signed', 'unsigned', 'long', 'short'), $.primitive_type),
1241
+ $.primitive_type
1242
+ ),
1243
+
1244
+ _abstract_declarator: ($) =>
1245
+ choice(
1246
+ $.abstract_pointer_declarator,
1247
+ $.abstract_function_declarator,
1248
+ $.abstract_array_declarator,
1249
+ $.abstract_parenthesized_declarator
1250
+ ),
1251
+
1252
+ parenthesized_declarator: ($) =>
1253
+ prec.dynamic(PREC.PAREN_DECLARATOR, parenthesizedDeclaratorRule($, $._declarator)),
1254
+ parenthesized_field_declarator: ($) =>
1255
+ prec.dynamic(PREC.PAREN_DECLARATOR, parenthesizedDeclaratorRule($, $._field_declarator)),
1256
+ parenthesized_type_declarator: ($) =>
1257
+ prec.dynamic(PREC.PAREN_DECLARATOR, parenthesizedDeclaratorRule($, $._type_declarator)),
1258
+ abstract_parenthesized_declarator: ($) => prec(1, parenthesizedDeclaratorRule($, $._abstract_declarator)),
1259
+
1260
+ attributed_declarator: ($) => seq($._unattributed_declarator, repeat1($.attribute_declaration)),
1261
+ attributed_field_declarator: ($) => seq($._unattributed_field_declarator, repeat1($.attribute_declaration)),
1262
+ attributed_type_declarator: ($) => seq($._unattributed_type_declarator, repeat1($.attribute_declaration)),
1263
+
1264
+ pointer_declarator: ($) => pointerDeclaratorRule($, $._declarator),
1265
+ pointer_field_declarator: ($) =>
1266
+ prec.dynamic(
1267
+ 1,
1268
+ prec.right(
1269
+ seq(
1270
+ optional($.ms_based_modifier),
1271
+ optional(prec.dynamic(2, $.ms_call_modifier)),
1272
+ '*',
1273
+ repeat($.attribute_declaration),
1274
+ repeat($.ms_pointer_modifier),
1275
+ repeat(
1276
+ choice(
1277
+ $.type_qualifier,
1278
+ $.attribute_specifier,
1279
+ prec(-1, $.ms_call_modifier),
1280
+ $.macro_specifier,
1281
+ $._conditional_macro_specifier
1282
+ )
1283
+ ),
1284
+ field('declarator', $._field_declarator)
1285
+ )
1286
+ )
1287
+ ),
1288
+ pointer_type_declarator: ($) =>
1289
+ prec.dynamic(
1290
+ 1,
1291
+ prec.right(
1292
+ seq(
1293
+ optional($.ms_based_modifier),
1294
+ optional(prec.dynamic(2, $.ms_call_modifier)),
1295
+ '*',
1296
+ repeat($.attribute_declaration),
1297
+ repeat($.ms_pointer_modifier),
1298
+ repeat(
1299
+ choice(
1300
+ $.type_qualifier,
1301
+ $.attribute_specifier,
1302
+ prec(-1, $.ms_call_modifier),
1303
+ $.macro_specifier,
1304
+ $._conditional_macro_specifier
1305
+ )
1306
+ ),
1307
+ field('declarator', $._type_declarator)
1308
+ )
1309
+ )
1310
+ ),
1311
+ abstract_pointer_declarator: ($) =>
1312
+ prec.dynamic(
1313
+ 1,
1314
+ prec.right(
1315
+ seq(
1316
+ optional(prec.dynamic(2, $.ms_call_modifier)),
1317
+ '*',
1318
+ repeat($.attribute_declaration),
1319
+ repeat($.ms_pointer_modifier),
1320
+ repeat(choice($.type_qualifier, $.attribute_specifier, prec(-1, $.ms_call_modifier))),
1321
+ field('declarator', optional($._abstract_declarator))
1322
+ )
1323
+ )
1324
+ ),
1162
1325
 
1163
- parenthesized_declarator: ($) =>
1164
- prec.dynamic(PREC.PAREN_DECLARATOR, parenthesizedDeclaratorRule($, $._declarator)),
1165
- parenthesized_field_declarator: ($) =>
1166
- prec.dynamic(PREC.PAREN_DECLARATOR, parenthesizedDeclaratorRule($, $._field_declarator)),
1167
- parenthesized_type_declarator: ($) =>
1168
- prec.dynamic(PREC.PAREN_DECLARATOR, parenthesizedDeclaratorRule($, $._type_declarator)),
1169
- abstract_parenthesized_declarator: ($) => prec(1, parenthesizedDeclaratorRule($, $._abstract_declarator)),
1170
-
1171
- attributed_declarator: ($) => seq($._unattributed_declarator, repeat1($.attribute_declaration)),
1172
- attributed_field_declarator: ($) => seq($._unattributed_field_declarator, repeat1($.attribute_declaration)),
1173
- attributed_type_declarator: ($) => seq($._unattributed_type_declarator, repeat1($.attribute_declaration)),
1174
-
1175
- pointer_declarator: ($) => pointerDeclaratorRule($, $._declarator),
1176
- pointer_field_declarator: ($) =>
1177
- prec.dynamic(
1178
- 1,
1326
+ function_declarator: ($) =>
1179
1327
  prec.right(
1328
+ 1,
1180
1329
  seq(
1181
- optional($.ms_based_modifier),
1182
- optional(prec.dynamic(2, $.ms_call_modifier)),
1183
- '*',
1184
- repeat($.attribute_declaration),
1185
- repeat($.ms_pointer_modifier),
1330
+ field('declarator', $._declarator),
1331
+ field('parameters', $.parameter_list),
1332
+ optional($.gnu_asm_expression),
1186
1333
  repeat(
1187
1334
  choice(
1188
- $.type_qualifier,
1189
1335
  $.attribute_specifier,
1190
- prec(-1, $.ms_call_modifier),
1191
- $.macro_specifier,
1192
- $._conditional_macro_specifier
1336
+ alias($._function_macro_specifier, $.macro_specifier),
1337
+ alias($.preproc_call_expression, $.call_expression)
1193
1338
  )
1194
- ),
1195
- field('declarator', $._field_declarator)
1339
+ )
1196
1340
  )
1197
- )
1198
- ),
1199
- pointer_type_declarator: ($) =>
1200
- prec.dynamic(
1201
- 1,
1341
+ ),
1342
+
1343
+ _function_declaration_declarator: ($) =>
1202
1344
  prec.right(
1345
+ 1,
1203
1346
  seq(
1204
- optional($.ms_based_modifier),
1205
- optional(prec.dynamic(2, $.ms_call_modifier)),
1206
- '*',
1207
- repeat($.attribute_declaration),
1208
- repeat($.ms_pointer_modifier),
1209
- repeat(
1210
- choice(
1211
- $.type_qualifier,
1212
- $.attribute_specifier,
1213
- prec(-1, $.ms_call_modifier),
1214
- $.macro_specifier,
1215
- $._conditional_macro_specifier
1216
- )
1217
- ),
1218
- field('declarator', $._type_declarator)
1347
+ field('declarator', $._declarator),
1348
+ field('parameters', $.parameter_list),
1349
+ optional($.gnu_asm_expression),
1350
+ repeat($.attribute_specifier)
1219
1351
  )
1220
- )
1221
- ),
1222
- abstract_pointer_declarator: ($) =>
1223
- prec.dynamic(
1224
- 1,
1352
+ ),
1353
+
1354
+ // Outranks the shift into a `function_declarator` (precedence 1) that an identifier after `(*callback)(int)` would
1355
+ // otherwise take, so a trailing marker belongs to the parameter whatever its spelling.
1356
+ _parameter_function_declarator: ($) =>
1225
1357
  prec.right(
1358
+ 2,
1226
1359
  seq(
1227
- optional(prec.dynamic(2, $.ms_call_modifier)),
1228
- '*',
1229
- repeat($.attribute_declaration),
1230
- repeat($.ms_pointer_modifier),
1231
- repeat(choice($.type_qualifier, $.attribute_specifier, prec(-1, $.ms_call_modifier))),
1232
- field('declarator', optional($._abstract_declarator))
1360
+ field('declarator', $._declarator),
1361
+ field('parameters', $.parameter_list),
1362
+ optional($.gnu_asm_expression),
1363
+ repeat($.attribute_specifier)
1233
1364
  )
1234
- )
1235
- ),
1365
+ ),
1236
1366
 
1237
- function_declarator: ($) =>
1238
- prec.right(
1239
- 1,
1240
- seq(
1241
- field('declarator', $._declarator),
1242
- field('parameters', $.parameter_list),
1243
- optional($.gnu_asm_expression),
1244
- repeat(choice($.attribute_specifier, $.identifier, alias($.preproc_call_expression, $.call_expression)))
1245
- )
1246
- ),
1367
+ function_field_declarator: ($) =>
1368
+ prec(1, seq(field('declarator', $._field_declarator), field('parameters', $.parameter_list))),
1369
+ function_type_declarator: ($) =>
1370
+ prec(1, seq(field('declarator', $._type_declarator), field('parameters', $.parameter_list))),
1371
+ abstract_function_declarator: ($) =>
1372
+ prec(1, seq(field('declarator', optional($._abstract_declarator)), field('parameters', $.parameter_list))),
1247
1373
 
1248
- _function_declaration_declarator: ($) =>
1249
- prec.right(
1250
- 1,
1374
+ _old_style_function_declarator: ($) =>
1251
1375
  seq(
1252
1376
  field('declarator', $._declarator),
1253
- field('parameters', $.parameter_list),
1254
- optional($.gnu_asm_expression),
1255
- repeat($.attribute_specifier)
1256
- )
1257
- ),
1258
-
1259
- function_field_declarator: ($) =>
1260
- prec(1, seq(field('declarator', $._field_declarator), field('parameters', $.parameter_list))),
1261
- function_type_declarator: ($) =>
1262
- prec(1, seq(field('declarator', $._type_declarator), field('parameters', $.parameter_list))),
1263
- abstract_function_declarator: ($) =>
1264
- prec(1, seq(field('declarator', optional($._abstract_declarator)), field('parameters', $.parameter_list))),
1377
+ field('parameters', alias($._old_style_parameter_list, $.parameter_list))
1378
+ ),
1265
1379
 
1266
- _old_style_function_declarator: ($) =>
1267
- seq(
1268
- field('declarator', $._declarator),
1269
- field('parameters', alias($._old_style_parameter_list, $.parameter_list))
1270
- ),
1380
+ array_declarator: ($) =>
1381
+ prec(
1382
+ 1,
1383
+ seq(
1384
+ field('declarator', $._declarator),
1385
+ '[',
1386
+ repeat(choice($.type_qualifier, 'static')),
1387
+ field('size', optional(choice($.expression, '*'))),
1388
+ ']'
1389
+ )
1390
+ ),
1391
+ array_field_declarator: ($) =>
1392
+ prec(
1393
+ 1,
1394
+ seq(
1395
+ field('declarator', $._field_declarator),
1396
+ '[',
1397
+ repeat(choice($.type_qualifier, 'static')),
1398
+ field('size', optional(choice($.expression, '*'))),
1399
+ ']'
1400
+ )
1401
+ ),
1402
+ array_type_declarator: ($) =>
1403
+ prec(
1404
+ 1,
1405
+ seq(
1406
+ field('declarator', $._type_declarator),
1407
+ '[',
1408
+ repeat(choice($.type_qualifier, 'static')),
1409
+ field('size', optional(choice($.expression, '*'))),
1410
+ ']'
1411
+ )
1412
+ ),
1413
+ abstract_array_declarator: ($) =>
1414
+ prec(
1415
+ 1,
1416
+ seq(
1417
+ field('declarator', optional($._abstract_declarator)),
1418
+ '[',
1419
+ repeat(choice($.type_qualifier, 'static')),
1420
+ field('size', optional(choice($.expression, '*'))),
1421
+ ']'
1422
+ )
1423
+ ),
1271
1424
 
1272
- array_declarator: ($) =>
1273
- prec(
1274
- 1,
1275
- seq(
1276
- field('declarator', $._declarator),
1277
- '[',
1278
- repeat(choice($.type_qualifier, 'static')),
1279
- field('size', optional(choice($.expression, '*'))),
1280
- ']'
1281
- )
1282
- ),
1283
- array_field_declarator: ($) =>
1284
- prec(
1285
- 1,
1286
- seq(
1287
- field('declarator', $._field_declarator),
1288
- '[',
1289
- repeat(choice($.type_qualifier, 'static')),
1290
- field('size', optional(choice($.expression, '*'))),
1291
- ']'
1292
- )
1293
- ),
1294
- array_type_declarator: ($) =>
1295
- prec(
1296
- 1,
1297
- seq(
1298
- field('declarator', $._type_declarator),
1299
- '[',
1300
- repeat(choice($.type_qualifier, 'static')),
1301
- field('size', optional(choice($.expression, '*'))),
1302
- ']'
1303
- )
1304
- ),
1305
- abstract_array_declarator: ($) =>
1306
- prec(
1307
- 1,
1308
- seq(
1309
- field('declarator', optional($._abstract_declarator)),
1310
- '[',
1311
- repeat(choice($.type_qualifier, 'static')),
1312
- field('size', optional(choice($.expression, '*'))),
1313
- ']'
1314
- )
1315
- ),
1425
+ init_declarator: ($) => initDeclaratorRule($, alias($._initialized_declarator, $._declarator)),
1426
+ _guarded_init_declarator: ($) =>
1427
+ initDeclaratorRule($, alias(sym('_guarded_initialized_declarator'), $._declarator)),
1428
+ _guarded_initialized_declarator: ($) => $._declaration_declarator,
1316
1429
 
1317
- init_declarator: ($) => initDeclaratorRule($, alias($._initialized_declarator, $._declarator)),
1318
- _guarded_init_declarator: ($) =>
1319
- initDeclaratorRule($, alias(sym('_guarded_initialized_declarator'), $._declarator)),
1320
- _guarded_initialized_declarator: ($) => $._declaration_declarator,
1430
+ _braced_macro_init_declarator: ($) =>
1431
+ initDeclaratorRule($, alias(sym('_braced_macro_declarator'), $._declarator)),
1321
1432
 
1322
- _braced_macro_init_declarator: ($) =>
1323
- initDeclaratorRule($, alias(sym('_braced_macro_declarator'), $._declarator)),
1433
+ _initialized_declarator: ($) =>
1434
+ choice(
1435
+ $._declarator,
1436
+ alias($._initialized_parenthesized_declarator, $.parenthesized_declarator),
1437
+ alias($._initialized_pointer_declarator, $.pointer_declarator)
1438
+ ),
1324
1439
 
1325
- _initialized_declarator: ($) =>
1326
- choice(
1327
- $._declarator,
1328
- alias($._initialized_parenthesized_declarator, $.parenthesized_declarator),
1329
- alias($._initialized_pointer_declarator, $.pointer_declarator)
1330
- ),
1440
+ _initialized_parenthesized_declarator: ($) =>
1441
+ parenthesizedDeclaratorRule($, alias($._initialized_parenthesized_content, $._declarator)),
1331
1442
 
1332
- _initialized_parenthesized_declarator: ($) =>
1333
- parenthesizedDeclaratorRule($, alias($._initialized_parenthesized_content, $._declarator)),
1443
+ _initialized_parenthesized_content: ($) =>
1444
+ choice(
1445
+ alias($._initialized_pointer_declarator, $.pointer_declarator),
1446
+ alias($._initialized_parenthesized_declarator, $.parenthesized_declarator)
1447
+ ),
1334
1448
 
1335
- _initialized_parenthesized_content: ($) =>
1336
- choice(
1337
- alias($._initialized_pointer_declarator, $.pointer_declarator),
1338
- alias($._initialized_parenthesized_declarator, $.parenthesized_declarator)
1339
- ),
1449
+ _initialized_pointer_declarator: ($) =>
1450
+ pointerDeclaratorRule($, alias($._initialized_declarator, $._declarator)),
1340
1451
 
1341
- _initialized_pointer_declarator: ($) => pointerDeclaratorRule($, alias($._initialized_declarator, $._declarator)),
1452
+ compound_statement: ($) => seq('{', repeat($._block_item), '}'),
1342
1453
 
1343
- compound_statement: ($) => seq('{', repeat($._block_item), '}'),
1454
+ storage_class_specifier: () =>
1455
+ choice(
1456
+ 'extern',
1457
+ 'static',
1458
+ 'auto',
1459
+ 'register',
1460
+ 'inline',
1461
+ '__inline',
1462
+ '__inline__',
1463
+ '__forceinline',
1464
+ 'thread_local',
1465
+ '_Thread_local',
1466
+ '__thread'
1467
+ ),
1344
1468
 
1345
- storage_class_specifier: () =>
1346
- choice(
1347
- 'extern',
1348
- 'static',
1349
- 'auto',
1350
- 'register',
1351
- 'inline',
1352
- '__inline',
1353
- '__inline__',
1354
- '__forceinline',
1355
- 'thread_local',
1356
- '_Thread_local',
1357
- '__thread'
1358
- ),
1469
+ type_qualifier: ($) =>
1470
+ choice(
1471
+ 'const',
1472
+ 'constexpr',
1473
+ 'volatile',
1474
+ 'restrict',
1475
+ '__restrict__',
1476
+ '__extension__',
1477
+ '_Atomic',
1478
+ '_Noreturn',
1479
+ 'noreturn',
1480
+ '_Nonnull',
1481
+ $.alignas_qualifier
1482
+ ),
1359
1483
 
1360
- type_qualifier: ($) =>
1361
- choice(
1362
- 'const',
1363
- 'constexpr',
1364
- 'volatile',
1365
- 'restrict',
1366
- '__restrict__',
1367
- '__extension__',
1368
- '_Atomic',
1369
- '_Noreturn',
1370
- 'noreturn',
1371
- '_Nonnull',
1372
- $.alignas_qualifier
1373
- ),
1484
+ alignas_qualifier: ($) => seq(choice('alignas', '_Alignas'), '(', choice($.expression, $.type_descriptor), ')'),
1374
1485
 
1375
- alignas_qualifier: ($) => seq(choice('alignas', '_Alignas'), '(', choice($.expression, $.type_descriptor), ')'),
1486
+ type_specifier: ($) => typeSpecifier($, $.sized_type_specifier, $._sized_bit_int_specifier),
1376
1487
 
1377
- type_specifier: ($) => typeSpecifier($, $.sized_type_specifier, $._sized_bit_int_specifier),
1488
+ _type_name_specifier: ($) => typeSpecifier($, $._sized_type_name, $._sized_bit_int_type_name),
1378
1489
 
1379
- _type_name_specifier: ($) => typeSpecifier($, $._sized_type_name, $._sized_bit_int_type_name),
1490
+ _non_identifier_type_specifier: ($) =>
1491
+ nonIdentifierTypeSpecifier($, $.sized_type_specifier, $._sized_bit_int_specifier),
1380
1492
 
1381
- _non_identifier_type_specifier: ($) =>
1382
- nonIdentifierTypeSpecifier($, $.sized_type_specifier, $._sized_bit_int_specifier),
1493
+ _sized_type_name: ($) => sizedTypeSpecifier($.primitive_type, true, $._sized_type_identifier, false),
1383
1494
 
1384
- _sized_type_name: ($) => sizedTypeSpecifier($.primitive_type, true, $._sized_type_identifier, false),
1495
+ _sized_bit_int_type_name: ($) => sizedTypeSpecifier($.bit_int_specifier, false, undefined, false),
1385
1496
 
1386
- _sized_bit_int_type_name: ($) => sizedTypeSpecifier($.bit_int_specifier, false, undefined, false),
1497
+ typeof_specifier: ($) =>
1498
+ seq(
1499
+ choice('typeof', 'typeof_unqual', '__typeof__', '__typeof', '__typeof_unqual', '__typeof_unqual__'),
1500
+ '(',
1501
+ choice($.type_descriptor, $.expression, $.comma_expression),
1502
+ ')'
1503
+ ),
1504
+ atomic_type_specifier: ($) => seq('_Atomic', '(', field('type', $.type_descriptor), ')'),
1387
1505
 
1388
- typeof_specifier: ($) =>
1389
- seq(
1390
- choice('typeof', 'typeof_unqual', '__typeof__', '__typeof', '__typeof_unqual', '__typeof_unqual__'),
1391
- '(',
1392
- choice($.type_descriptor, $.expression, $.comma_expression),
1393
- ')'
1394
- ),
1395
- atomic_type_specifier: ($) => seq('_Atomic', '(', field('type', $.type_descriptor), ')'),
1506
+ bit_int_specifier: ($) => seq('_BitInt', '(', $.expression, ')'),
1396
1507
 
1397
- bit_int_specifier: ($) => seq('_BitInt', '(', $.expression, ')'),
1508
+ sized_type_specifier: ($) => sizedTypeSpecifier($.primitive_type, true, $._sized_type_identifier),
1398
1509
 
1399
- sized_type_specifier: ($) => sizedTypeSpecifier($.primitive_type, true, $._sized_type_identifier),
1510
+ _sized_type_identifier: ($) => prec.dynamic(-3, $._type_identifier),
1400
1511
 
1401
- _sized_type_identifier: ($) => prec.dynamic(-3, $._type_identifier),
1512
+ _sized_bit_int_specifier: ($) => sizedTypeSpecifier($.bit_int_specifier),
1402
1513
 
1403
- _sized_bit_int_specifier: ($) => sizedTypeSpecifier($.bit_int_specifier),
1514
+ primitive_type: () =>
1515
+ token(
1516
+ choice(
1517
+ ...primitiveTypeKeywords,
1518
+ 'size_t',
1519
+ 'ssize_t',
1520
+ 'ptrdiff_t',
1521
+ 'intptr_t',
1522
+ 'uintptr_t',
1523
+ 'charptr_t',
1524
+ 'nullptr_t',
1525
+ 'max_align_t',
1526
+ ...[8, 16, 32, 64].map((n) => `int${n}_t`),
1527
+ ...[8, 16, 32, 64].map((n) => `uint${n}_t`),
1528
+ ...[8, 16, 32, 64].map((n) => `char${n}_t`)
1529
+ )
1530
+ ),
1404
1531
 
1405
- primitive_type: () =>
1406
- token(
1407
- choice(
1408
- ...primitiveTypeKeywords,
1409
- 'size_t',
1410
- 'ssize_t',
1411
- 'ptrdiff_t',
1412
- 'intptr_t',
1413
- 'uintptr_t',
1414
- 'charptr_t',
1415
- 'nullptr_t',
1416
- 'max_align_t',
1417
- ...[8, 16, 32, 64].map((n) => `int${n}_t`),
1418
- ...[8, 16, 32, 64].map((n) => `uint${n}_t`),
1419
- ...[8, 16, 32, 64].map((n) => `char${n}_t`)
1420
- )
1421
- ),
1532
+ enum_specifier: ($) =>
1533
+ seq(
1534
+ 'enum',
1535
+ repeat(choice($.attribute_specifier, $.attribute_declaration)),
1536
+ choice(
1537
+ seq(
1538
+ field('name', $._type_identifier),
1539
+ optional($._enum_underlying_type),
1540
+ field('body', optional($.enumerator_list))
1541
+ ),
1542
+ seq(optional($._enum_underlying_type), field('body', $.enumerator_list))
1543
+ ),
1544
+ optional($.attribute_specifier)
1545
+ ),
1422
1546
 
1423
- enum_specifier: ($) =>
1424
- seq(
1425
- 'enum',
1426
- repeat(choice($.attribute_specifier, $.attribute_declaration)),
1427
- choice(
1547
+ _enum_underlying_type: ($) =>
1548
+ prec.right(
1428
1549
  seq(
1429
- field('name', $._type_identifier),
1430
- optional($._enum_underlying_type),
1431
- field('body', optional($.enumerator_list))
1432
- ),
1433
- seq(optional($._enum_underlying_type), field('body', $.enumerator_list))
1550
+ ':',
1551
+ repeat($.type_qualifier),
1552
+ field(
1553
+ 'underlying_type',
1554
+ choice(
1555
+ $.primitive_type,
1556
+ alias($._sized_type_name, $.sized_type_specifier),
1557
+ $.typeof_specifier,
1558
+ $._type_identifier
1559
+ )
1560
+ ),
1561
+ repeat($.type_qualifier)
1562
+ )
1434
1563
  ),
1435
- optional($.attribute_specifier)
1436
- ),
1437
1564
 
1438
- _enum_underlying_type: ($) =>
1439
- prec.right(
1565
+ enumerator_list: ($) =>
1440
1566
  seq(
1441
- ':',
1442
- repeat($.type_qualifier),
1443
- field(
1444
- 'underlying_type',
1567
+ '{',
1568
+ repeat(
1445
1569
  choice(
1446
- $.primitive_type,
1447
- alias($._sized_type_name, $.sized_type_specifier),
1448
- $.typeof_specifier,
1449
- $._type_identifier
1570
+ seq($.enumerator, ','),
1571
+ $._enumerator_macro,
1572
+ alias(sym('preproc_if_in_enumerator_list'), sym('preproc_if')),
1573
+ alias(sym('preproc_ifdef_in_enumerator_list'), sym('preproc_ifdef')),
1574
+ seq($.preproc_call, ','),
1575
+ prec(1, $.preproc_call)
1450
1576
  )
1451
1577
  ),
1452
- repeat($.type_qualifier)
1453
- )
1454
- ),
1578
+ optional(
1579
+ seq(
1580
+ choice(
1581
+ $.enumerator,
1582
+ alias(sym('preproc_if_in_enumerator_list_no_comma'), sym('preproc_if')),
1583
+ alias(sym('preproc_ifdef_in_enumerator_list_no_comma'), sym('preproc_ifdef'))
1584
+ )
1585
+ )
1586
+ ),
1587
+ repeat($.preproc_call),
1588
+ '}'
1589
+ ),
1455
1590
 
1456
- enumerator_list: ($) =>
1457
- seq(
1458
- '{',
1459
- repeat(
1460
- choice(
1461
- seq($.enumerator, ','),
1462
- $._enumerator_macro,
1463
- alias(sym('preproc_if_in_enumerator_list'), sym('preproc_if')),
1464
- alias(sym('preproc_ifdef_in_enumerator_list'), sym('preproc_ifdef')),
1465
- seq($.preproc_call, ','),
1466
- prec(1, $.preproc_call)
1591
+ struct_specifier: ($) =>
1592
+ prec.right(
1593
+ seq(
1594
+ 'struct',
1595
+ repeat(choice($.attribute_specifier, $.attribute_declaration, $.ms_declspec_modifier)),
1596
+ choice(
1597
+ seq(field('name', $._type_identifier), field('body', optional($.field_declaration_list))),
1598
+ field('body', $.field_declaration_list)
1599
+ ),
1600
+ optional($.attribute_specifier)
1467
1601
  )
1468
1602
  ),
1469
- optional(
1603
+
1604
+ union_specifier: ($) =>
1605
+ prec.right(
1470
1606
  seq(
1607
+ 'union',
1608
+ repeat(choice($.attribute_specifier, $.attribute_declaration, $.ms_declspec_modifier)),
1471
1609
  choice(
1472
- $.enumerator,
1473
- alias(sym('preproc_if_in_enumerator_list_no_comma'), sym('preproc_if')),
1474
- alias(sym('preproc_ifdef_in_enumerator_list_no_comma'), sym('preproc_ifdef'))
1475
- )
1610
+ seq(field('name', $._type_identifier), field('body', optional($.field_declaration_list))),
1611
+ field('body', $.field_declaration_list)
1612
+ ),
1613
+ optional($.attribute_specifier)
1476
1614
  )
1477
1615
  ),
1478
- repeat($.preproc_call),
1479
- '}'
1480
- ),
1481
1616
 
1482
- struct_specifier: ($) =>
1483
- prec.right(
1484
- seq(
1485
- 'struct',
1486
- repeat(choice($.attribute_specifier, $.attribute_declaration, $.ms_declspec_modifier)),
1487
- choice(
1488
- seq(field('name', $._type_identifier), field('body', optional($.field_declaration_list))),
1489
- field('body', $.field_declaration_list)
1490
- ),
1491
- optional($.attribute_specifier)
1492
- )
1493
- ),
1617
+ field_declaration_list: ($) => seq('{', repeat($._field_declaration_list_item), '}'),
1494
1618
 
1495
- union_specifier: ($) =>
1496
- prec.right(
1497
- seq(
1498
- 'union',
1499
- repeat(choice($.attribute_specifier, $.attribute_declaration, $.ms_declspec_modifier)),
1500
- choice(
1501
- seq(field('name', $._type_identifier), field('body', optional($.field_declaration_list))),
1502
- field('body', $.field_declaration_list)
1503
- ),
1504
- optional($.attribute_specifier)
1505
- )
1506
- ),
1619
+ _field_declaration_list_item: ($) =>
1620
+ choice(
1621
+ $.field_declaration,
1622
+ prec.dynamic(-1, $.macro_specifier),
1623
+ $.preproc_def,
1624
+ $.preproc_function_def,
1625
+ $.preproc_call,
1626
+ alias(sym('preproc_if_in_field_declaration_list'), sym('preproc_if')),
1627
+ alias(sym('preproc_ifdef_in_field_declaration_list'), sym('preproc_ifdef'))
1628
+ ),
1507
1629
 
1508
- field_declaration_list: ($) => seq('{', repeat($._field_declaration_list_item), '}'),
1630
+ field_declaration: ($) =>
1631
+ seq(
1632
+ $._field_declaration_specifiers,
1633
+ optional($._field_declaration_declarator),
1634
+ optional($.attribute_specifier),
1635
+ ';'
1636
+ ),
1637
+ _field_declaration_declarator: ($) =>
1638
+ commaSep1(
1639
+ choice(seq(field('declarator', $._field_declarator), optional($.bitfield_clause)), $.bitfield_clause)
1640
+ ),
1509
1641
 
1510
- _field_declaration_list_item: ($) =>
1511
- choice(
1512
- $.field_declaration,
1513
- prec.dynamic(-1, $.macro_specifier),
1514
- $.preproc_def,
1515
- $.preproc_function_def,
1516
- $.preproc_call,
1517
- alias(sym('preproc_if_in_field_declaration_list'), sym('preproc_if')),
1518
- alias(sym('preproc_ifdef_in_field_declaration_list'), sym('preproc_ifdef'))
1519
- ),
1642
+ bitfield_clause: ($) => seq(':', $.expression),
1520
1643
 
1521
- field_declaration: ($) =>
1522
- seq(
1523
- $._field_declaration_specifiers,
1524
- optional($._field_declaration_declarator),
1525
- optional($.attribute_specifier),
1526
- ';'
1527
- ),
1528
- _field_declaration_declarator: ($) =>
1529
- commaSep1(
1530
- choice(seq(field('declarator', $._field_declarator), optional($.bitfield_clause)), $.bitfield_clause)
1531
- ),
1644
+ _enumerator_macro: ($) => seq(alias($._enumerator_macro_call, $.call_expression), optional(',')),
1532
1645
 
1533
- bitfield_clause: ($) => seq(':', $.expression),
1646
+ _enumerator_macro_call: ($) =>
1647
+ seq(
1648
+ field('function', $.identifier),
1649
+ field('arguments', alias($._macro_attribute_argument_list, $.argument_list))
1650
+ ),
1534
1651
 
1535
- _enumerator_macro: ($) => seq(alias($._enumerator_macro_call, $.call_expression), optional(',')),
1652
+ enumerator: ($) => seq(field('name', $.identifier), optional(seq('=', field('value', $.expression)))),
1536
1653
 
1537
- _enumerator_macro_call: ($) =>
1538
- seq(
1539
- field('function', $.identifier),
1540
- field('arguments', alias($._macro_attribute_argument_list, $.argument_list))
1541
- ),
1654
+ variadic_parameter: () => '...',
1542
1655
 
1543
- enumerator: ($) => seq(field('name', $.identifier), optional(seq('=', field('value', $.expression)))),
1656
+ parameter_list: ($) =>
1657
+ seq('(', choice(commaSep(choice($.parameter_declaration, $.variadic_parameter)), $.compound_statement), ')'),
1658
+ _old_style_parameter_list: ($) =>
1659
+ seq('(', commaSep1(choice($.identifier, alias(VA_ARG_KEYWORDS, $.identifier), $.variadic_parameter)), ')'),
1544
1660
 
1545
- variadic_parameter: () => '...',
1661
+ parameter_declaration: ($) =>
1662
+ seq(
1663
+ $._declaration_specifiers,
1664
+ choice(
1665
+ seq(
1666
+ field('declarator', $._parameter_declarator),
1667
+ repeat(
1668
+ choice(
1669
+ $.attribute_specifier,
1670
+ alias($._trailing_macro_specifier, $.macro_specifier),
1671
+ alias($._trailing_macro_call_expression, $.call_expression)
1672
+ )
1673
+ )
1674
+ ),
1675
+ seq(optional(field('declarator', $._abstract_declarator)), repeat($.attribute_specifier))
1676
+ )
1677
+ ),
1546
1678
 
1547
- parameter_list: ($) =>
1548
- seq('(', choice(commaSep(choice($.parameter_declaration, $.variadic_parameter)), $.compound_statement), ')'),
1549
- _old_style_parameter_list: ($) =>
1550
- seq('(', commaSep1(choice($.identifier, alias(VA_ARG_KEYWORDS, $.identifier), $.variadic_parameter)), ')'),
1679
+ attributed_statement: ($) =>
1680
+ seq(repeat1($.attribute_declaration), alias($._attributed_body_statement, $.statement)),
1551
1681
 
1552
- parameter_declaration: ($) =>
1553
- seq(
1554
- $._declaration_specifiers,
1555
- optional(field('declarator', choice($._declarator, $._abstract_declarator))),
1556
- repeat($.attribute_specifier)
1557
- ),
1682
+ _attributed_body_statement: ($) => $._unattributed_non_case_statement,
1558
1683
 
1559
- attributed_statement: ($) =>
1560
- seq(repeat1($.attribute_declaration), alias($._attributed_body_statement, $.statement)),
1684
+ statement: ($) => choice($.case_statement, alias($._non_case_statement, $.statement)),
1561
1685
 
1562
- _attributed_body_statement: ($) => $._unattributed_non_case_statement,
1686
+ _non_case_statement: ($) => choice($.attributed_statement, $._unattributed_non_case_statement),
1563
1687
 
1564
- statement: ($) => choice($.case_statement, alias($._non_case_statement, $.statement)),
1688
+ _unattributed_non_case_statement: ($) => choice($.labeled_statement, $._unlabeled_non_case_statement),
1565
1689
 
1566
- _non_case_statement: ($) => choice($.attributed_statement, $._unattributed_non_case_statement),
1690
+ _unlabeled_non_case_statement: ($) =>
1691
+ choice(
1692
+ $.compound_statement,
1693
+ $.expression_statement,
1694
+ $.if_statement,
1695
+ $.defer_statement,
1696
+ $.switch_statement,
1697
+ $.do_statement,
1698
+ $.while_statement,
1699
+ $.for_statement,
1700
+ $.return_statement,
1701
+ $.break_statement,
1702
+ $.continue_statement,
1703
+ $.goto_statement,
1704
+ $.seh_try_statement,
1705
+ $.seh_leave_statement
1706
+ ),
1567
1707
 
1568
- _unattributed_non_case_statement: ($) => choice($.labeled_statement, $._unlabeled_non_case_statement),
1708
+ _top_level_statement: ($) =>
1709
+ choice(
1710
+ $.case_statement,
1711
+ $.attributed_statement,
1712
+ $.labeled_statement,
1713
+ $.compound_statement,
1714
+ alias($._top_level_expression_statement, $.expression_statement),
1715
+ $.if_statement,
1716
+ $.defer_statement,
1717
+ $.switch_statement,
1718
+ $.do_statement,
1719
+ $.while_statement,
1720
+ $.for_statement,
1721
+ $.return_statement,
1722
+ $.break_statement,
1723
+ $.continue_statement,
1724
+ $.goto_statement
1725
+ ),
1569
1726
 
1570
- _unlabeled_non_case_statement: ($) =>
1571
- choice(
1572
- $.compound_statement,
1573
- $.expression_statement,
1574
- $.if_statement,
1575
- $.defer_statement,
1576
- $.switch_statement,
1577
- $.do_statement,
1578
- $.while_statement,
1579
- $.for_statement,
1580
- $.return_statement,
1581
- $.break_statement,
1582
- $.continue_statement,
1583
- $.goto_statement,
1584
- $.seh_try_statement,
1585
- $.seh_leave_statement
1586
- ),
1727
+ labeled_statement: ($) =>
1728
+ seq(
1729
+ field('label', $._statement_identifier),
1730
+ ':',
1731
+ choice(alias($._statement_declaration, $.declaration), $.statement)
1732
+ ),
1587
1733
 
1588
- _top_level_statement: ($) =>
1589
- choice(
1590
- $.case_statement,
1591
- $.attributed_statement,
1592
- $.labeled_statement,
1593
- $.compound_statement,
1594
- alias($._top_level_expression_statement, $.expression_statement),
1595
- $.if_statement,
1596
- $.defer_statement,
1597
- $.switch_statement,
1598
- $.do_statement,
1599
- $.while_statement,
1600
- $.for_statement,
1601
- $.return_statement,
1602
- $.break_statement,
1603
- $.continue_statement,
1604
- $.goto_statement
1605
- ),
1734
+ // This is missing binary expressions, others were kept so that macro code can be parsed better and code examples
1735
+ _top_level_expression_statement: ($) => seq(optional($._expression_not_binary), ';'),
1606
1736
 
1607
- labeled_statement: ($) =>
1608
- seq(
1609
- field('label', $._statement_identifier),
1610
- ':',
1611
- choice(alias($._statement_declaration, $.declaration), $.statement)
1612
- ),
1737
+ expression_statement: ($) => seq(optional(choice($.expression, $.comma_expression)), ';'),
1613
1738
 
1614
- // This is missing binary expressions, others were kept so that macro code can be parsed better and code examples
1615
- _top_level_expression_statement: ($) => seq(optional($._expression_not_binary), ';'),
1739
+ if_statement: ($) =>
1740
+ prec.right(
1741
+ seq(
1742
+ 'if',
1743
+ field('condition', $.parenthesized_expression),
1744
+ field('consequence', $._single_statement),
1745
+ optional(field('alternative', $.else_clause))
1746
+ )
1747
+ ),
1616
1748
 
1617
- expression_statement: ($) => seq(optional(choice($.expression, $.comma_expression)), ';'),
1749
+ defer_statement: ($) => seq('_Defer', field('body', $._single_statement)),
1618
1750
 
1619
- if_statement: ($) =>
1620
- prec.right(
1621
- seq(
1622
- 'if',
1623
- field('condition', $.parenthesized_expression),
1624
- field('consequence', $._single_statement),
1625
- optional(field('alternative', $.else_clause))
1626
- )
1627
- ),
1751
+ else_clause: ($) => seq('else', $._single_statement),
1628
1752
 
1629
- defer_statement: ($) => seq('_Defer', field('body', $._single_statement)),
1753
+ switch_statement: ($) =>
1754
+ seq('switch', field('condition', $.parenthesized_expression), field('body', $._single_statement)),
1630
1755
 
1631
- else_clause: ($) => seq('else', $._single_statement),
1756
+ _single_statement: ($) => choice($.compound_statement, alias($._single_noncompound_statement, $.statement)),
1632
1757
 
1633
- switch_statement: ($) =>
1634
- seq('switch', field('condition', $.parenthesized_expression), field('body', $._single_statement)),
1758
+ _single_noncompound_statement: ($) =>
1759
+ choice(alias($._single_case_statement, $.case_statement), alias($._single_non_case_statement, $.statement)),
1635
1760
 
1636
- _single_statement: ($) => choice($.compound_statement, alias($._single_noncompound_statement, $.statement)),
1761
+ _single_non_case_statement: ($) =>
1762
+ choice(
1763
+ $._single_unattributed_non_case_statement,
1764
+ alias($._single_attributed_statement, $.attributed_statement)
1765
+ ),
1637
1766
 
1638
- _single_noncompound_statement: ($) =>
1639
- choice(alias($._single_case_statement, $.case_statement), alias($._single_non_case_statement, $.statement)),
1767
+ _single_unattributed_non_case_statement: ($) =>
1768
+ choice(
1769
+ $.expression_statement,
1770
+ $.switch_statement,
1771
+ $.return_statement,
1772
+ $.break_statement,
1773
+ $.continue_statement,
1774
+ $.goto_statement,
1775
+ $.seh_try_statement,
1776
+ $.seh_leave_statement,
1777
+ alias($._single_labeled_statement, $.labeled_statement),
1778
+ $.if_statement,
1779
+ $.defer_statement,
1780
+ $.while_statement,
1781
+ $.do_statement,
1782
+ $.for_statement
1783
+ ),
1640
1784
 
1641
- _single_non_case_statement: ($) =>
1642
- choice(
1643
- $._single_unattributed_non_case_statement,
1644
- alias($._single_attributed_statement, $.attributed_statement)
1645
- ),
1785
+ _single_case_statement: ($) =>
1786
+ prec.dynamic(
1787
+ 1,
1788
+ prec.right(
1789
+ seq(
1790
+ repeat($.attribute_declaration),
1791
+ choice(
1792
+ seq('case', field('value', $.expression), optional(seq('...', field('end_value', $.expression)))),
1793
+ 'default'
1794
+ ),
1795
+ ':',
1796
+ optional($._single_case_body)
1797
+ )
1798
+ )
1799
+ ),
1800
+ _single_case_body: ($) =>
1801
+ prec.dynamic(
1802
+ 1,
1803
+ choice(
1804
+ $._single_statement,
1805
+ alias($._statement_declaration, $.declaration),
1806
+ alias($._statement_type_definition, $.type_definition),
1807
+ alias(sym('preproc_if_in_single_case'), sym('preproc_if')),
1808
+ alias(sym('preproc_ifdef_in_single_case'), sym('preproc_ifdef'))
1809
+ )
1810
+ ),
1811
+ _single_labeled_statement: ($) =>
1812
+ seq(
1813
+ field('label', $._statement_identifier),
1814
+ ':',
1815
+ choice($._single_statement, alias($._statement_declaration, $.declaration))
1816
+ ),
1817
+ _single_attributed_statement: ($) =>
1818
+ seq(
1819
+ repeat1($.attribute_declaration),
1820
+ choice($.compound_statement, alias($._single_attributed_body_statement, $.statement))
1821
+ ),
1646
1822
 
1647
- _single_unattributed_non_case_statement: ($) =>
1648
- choice(
1649
- $.expression_statement,
1650
- $.switch_statement,
1651
- $.return_statement,
1652
- $.break_statement,
1653
- $.continue_statement,
1654
- $.goto_statement,
1655
- $.seh_try_statement,
1656
- $.seh_leave_statement,
1657
- alias($._single_labeled_statement, $.labeled_statement),
1658
- $.if_statement,
1659
- $.defer_statement,
1660
- $.while_statement,
1661
- $.do_statement,
1662
- $.for_statement
1663
- ),
1823
+ _single_attributed_body_statement: ($) => $._single_unattributed_non_case_statement,
1664
1824
 
1665
- _single_case_statement: ($) =>
1666
- prec.dynamic(
1667
- 1,
1668
- prec.right(
1825
+ case_statement: ($) =>
1826
+ prec.dynamic(
1827
+ 1,
1669
1828
  seq(
1670
1829
  repeat($.attribute_declaration),
1671
1830
  choice(
@@ -1673,664 +1832,721 @@ module.exports = Object.assign(
1673
1832
  'default'
1674
1833
  ),
1675
1834
  ':',
1676
- optional($._single_case_body)
1835
+ repeat($._case_statement_item),
1836
+ optional(alias($._case_label_tail, $.statement))
1677
1837
  )
1678
- )
1679
- ),
1680
- _single_case_body: ($) =>
1681
- prec.dynamic(
1682
- 1,
1683
- choice(
1684
- $._single_statement,
1685
- alias($._statement_declaration, $.declaration),
1686
- alias($._statement_type_definition, $.type_definition),
1687
- alias(sym('preproc_if_in_single_case'), sym('preproc_if')),
1688
- alias(sym('preproc_ifdef_in_single_case'), sym('preproc_ifdef'))
1689
- )
1690
- ),
1691
- _single_labeled_statement: ($) =>
1692
- seq(
1693
- field('label', $._statement_identifier),
1694
- ':',
1695
- choice($._single_statement, alias($._statement_declaration, $.declaration))
1696
- ),
1697
- _single_attributed_statement: ($) =>
1698
- seq(
1699
- repeat1($.attribute_declaration),
1700
- choice($.compound_statement, alias($._single_attributed_body_statement, $.statement))
1701
- ),
1702
-
1703
- _single_attributed_body_statement: ($) => $._single_unattributed_non_case_statement,
1838
+ ),
1704
1839
 
1705
- case_statement: ($) =>
1706
- prec.dynamic(
1707
- 1,
1708
- seq(
1709
- repeat($.attribute_declaration),
1840
+ _case_statement_item: ($) =>
1841
+ prec.dynamic(
1842
+ 1,
1710
1843
  choice(
1711
- seq('case', field('value', $.expression), optional(seq('...', field('end_value', $.expression)))),
1712
- 'default'
1713
- ),
1714
- ':',
1715
- repeat($._case_statement_item),
1716
- optional(alias($._case_label_tail, $.statement))
1717
- )
1718
- ),
1719
-
1720
- _case_statement_item: ($) =>
1721
- prec.dynamic(
1722
- 1,
1723
- choice(
1724
- alias($._case_body_statement, $.statement),
1725
- alias($._statement_declaration, $.declaration),
1726
- alias($._statement_type_definition, $.type_definition)
1727
- )
1728
- ),
1844
+ alias($._case_body_statement, $.statement),
1845
+ alias($._statement_declaration, $.declaration),
1846
+ alias($._statement_type_definition, $.type_definition)
1847
+ )
1848
+ ),
1729
1849
 
1730
- _case_body_statement: ($) =>
1731
- choice(
1732
- alias($._case_body_unattributed_statement, $.statement),
1733
- alias($._case_body_attributed_statement, $.attributed_statement)
1734
- ),
1735
- _case_body_unattributed_statement: ($) =>
1736
- choice($._unlabeled_non_case_statement, alias($._case_body_labeled_statement, $.labeled_statement)),
1737
- _case_body_labeled_statement: ($) =>
1738
- seq(
1739
- field('label', $._statement_identifier),
1740
- ':',
1741
- choice(alias($._statement_declaration, $.declaration), alias($._case_body_statement, $.statement))
1742
- ),
1743
- _case_body_attributed_statement: ($) =>
1744
- prec(1, seq(repeat1($.attribute_declaration), alias($._case_body_unattributed_statement, $.statement))),
1745
- _case_label_tail: ($) =>
1746
- prec.dynamic(
1747
- 1,
1850
+ _case_body_statement: ($) =>
1748
1851
  choice(
1749
- alias($._case_label_chain, $.labeled_statement),
1750
- alias($._case_label_attributes, $.attributed_statement)
1751
- )
1752
- ),
1753
- _case_label_attributes: ($) =>
1754
- seq(repeat1($.attribute_declaration), alias($._case_label_chain_statement, $.statement)),
1755
- _case_label_chain_statement: ($) => alias($._case_label_chain, $.labeled_statement),
1756
- _case_label_chain: ($) =>
1757
- seq(field('label', $._statement_identifier), ':', alias($._case_label_statement, $.statement)),
1758
- _case_label_statement: ($) => choice($.case_statement, alias($._case_label_tail, $.statement)),
1852
+ alias($._case_body_unattributed_statement, $.statement),
1853
+ alias($._case_body_attributed_statement, $.attributed_statement)
1854
+ ),
1855
+ _case_body_unattributed_statement: ($) =>
1856
+ choice($._unlabeled_non_case_statement, alias($._case_body_labeled_statement, $.labeled_statement)),
1857
+ _case_body_labeled_statement: ($) =>
1858
+ seq(
1859
+ field('label', $._statement_identifier),
1860
+ ':',
1861
+ choice(alias($._statement_declaration, $.declaration), alias($._case_body_statement, $.statement))
1862
+ ),
1863
+ _case_body_attributed_statement: ($) =>
1864
+ prec(1, seq(repeat1($.attribute_declaration), alias($._case_body_unattributed_statement, $.statement))),
1865
+ _case_label_tail: ($) =>
1866
+ prec.dynamic(
1867
+ 1,
1868
+ choice(
1869
+ alias($._case_label_chain, $.labeled_statement),
1870
+ alias($._case_label_attributes, $.attributed_statement)
1871
+ )
1872
+ ),
1873
+ _case_label_attributes: ($) =>
1874
+ seq(repeat1($.attribute_declaration), alias($._case_label_chain_statement, $.statement)),
1875
+ _case_label_chain_statement: ($) => alias($._case_label_chain, $.labeled_statement),
1876
+ _case_label_chain: ($) =>
1877
+ seq(field('label', $._statement_identifier), ':', alias($._case_label_statement, $.statement)),
1878
+ _case_label_statement: ($) => choice($.case_statement, alias($._case_label_tail, $.statement)),
1759
1879
 
1760
- while_statement: ($) =>
1761
- seq('while', field('condition', $.parenthesized_expression), field('body', $._single_statement)),
1880
+ while_statement: ($) =>
1881
+ seq('while', field('condition', $.parenthesized_expression), field('body', $._single_statement)),
1762
1882
 
1763
- do_statement: ($) =>
1764
- seq('do', field('body', $._single_statement), 'while', field('condition', $.parenthesized_expression), ';'),
1883
+ do_statement: ($) =>
1884
+ seq('do', field('body', $._single_statement), 'while', field('condition', $.parenthesized_expression), ';'),
1765
1885
 
1766
- for_statement: ($) => seq('for', '(', $._for_statement_body, ')', field('body', $._single_statement)),
1767
- _for_statement_body: ($) =>
1768
- seq(
1769
- choice(
1770
- field('initializer', alias($._statement_declaration, $.declaration)),
1771
- field('initializer', alias($._for_empty_declaration, $.declaration)),
1772
- seq(field('initializer', optional(choice($.expression, $.comma_expression))), ';')
1886
+ for_statement: ($) => seq('for', '(', $._for_statement_body, ')', field('body', $._single_statement)),
1887
+ _for_statement_body: ($) =>
1888
+ seq(
1889
+ choice(
1890
+ field('initializer', alias($._statement_declaration, $.declaration)),
1891
+ field('initializer', alias($._for_empty_declaration, $.declaration)),
1892
+ seq(field('initializer', optional(choice($.expression, $.comma_expression))), ';')
1893
+ ),
1894
+ field('condition', optional(choice($.expression, $.comma_expression))),
1895
+ ';',
1896
+ field('update', optional(choice($.expression, $.comma_expression)))
1773
1897
  ),
1774
- field('condition', optional(choice($.expression, $.comma_expression))),
1775
- ';',
1776
- field('update', optional(choice($.expression, $.comma_expression)))
1777
- ),
1778
1898
 
1779
- _for_empty_declaration: ($) => prec.dynamic(-1, seq($._statement_declaration_specifiers, ';')),
1899
+ _for_empty_declaration: ($) => prec.dynamic(-1, seq($._statement_declaration_specifiers, ';')),
1780
1900
 
1781
- return_statement: ($) => seq('return', optional(choice($.expression, $.comma_expression)), ';'),
1901
+ return_statement: ($) => seq('return', optional(choice($.expression, $.comma_expression)), ';'),
1782
1902
 
1783
- break_statement: () => seq('break', ';'),
1903
+ break_statement: () => seq('break', ';'),
1784
1904
 
1785
- continue_statement: () => seq('continue', ';'),
1905
+ continue_statement: () => seq('continue', ';'),
1786
1906
 
1787
- goto_statement: ($) =>
1788
- seq(
1789
- 'goto',
1790
- choice(
1791
- field('label', $._statement_identifier),
1792
- seq('*', field('label', choice($.expression, $.comma_expression)))
1907
+ goto_statement: ($) =>
1908
+ seq(
1909
+ 'goto',
1910
+ choice(
1911
+ field('label', $._statement_identifier),
1912
+ seq('*', field('label', choice($.expression, $.comma_expression)))
1913
+ ),
1914
+ ';'
1793
1915
  ),
1794
- ';'
1795
- ),
1796
1916
 
1797
- seh_try_statement: ($) =>
1798
- seq('__try', field('body', $.compound_statement), choice($.seh_except_clause, $.seh_finally_clause)),
1917
+ seh_try_statement: ($) =>
1918
+ seq('__try', field('body', $.compound_statement), choice($.seh_except_clause, $.seh_finally_clause)),
1799
1919
 
1800
- seh_except_clause: ($) =>
1801
- seq('__except', field('filter', $.parenthesized_expression), field('body', $.compound_statement)),
1920
+ seh_except_clause: ($) =>
1921
+ seq('__except', field('filter', $.parenthesized_expression), field('body', $.compound_statement)),
1802
1922
 
1803
- seh_finally_clause: ($) => seq('__finally', field('body', $.compound_statement)),
1923
+ seh_finally_clause: ($) => seq('__finally', field('body', $.compound_statement)),
1804
1924
 
1805
- seh_leave_statement: () => seq('__leave', ';'),
1925
+ seh_leave_statement: () => seq('__leave', ';'),
1806
1926
 
1807
- expression: ($) => choice($._expression_not_binary, $.binary_expression),
1927
+ expression: ($) => choice($._expression_not_binary, $.binary_expression),
1808
1928
 
1809
- _expression_not_binary: ($) =>
1810
- choice(
1811
- $.conditional_expression,
1812
- $.assignment_expression,
1813
- $.unary_expression,
1814
- $.update_expression,
1815
- $.cast_expression,
1816
- $.pointer_expression,
1817
- $.sizeof_expression,
1818
- $.countof_expression,
1819
- $.alignof_expression,
1820
- $.offsetof_expression,
1821
- $.va_arg_expression,
1822
- $.generic_expression,
1823
- $.subscript_expression,
1824
- $.call_expression,
1825
- $.field_expression,
1826
- $.compound_literal_expression,
1827
- $.identifier,
1828
- alias('thread_local', $.identifier),
1829
- alias(VA_ARG_KEYWORDS, $.identifier),
1830
- $.number_literal,
1831
- $._string,
1832
- $.true,
1833
- $.false,
1834
- $.null,
1835
- $.char_literal,
1836
- $.parenthesized_expression,
1837
- $.gnu_asm_expression,
1838
- $.extension_expression,
1839
- $.builtin_available_expression
1840
- ),
1929
+ _expression_not_binary: ($) =>
1930
+ choice(
1931
+ $.conditional_expression,
1932
+ $.assignment_expression,
1933
+ $.unary_expression,
1934
+ $.update_expression,
1935
+ $.cast_expression,
1936
+ $.pointer_expression,
1937
+ $.sizeof_expression,
1938
+ $.countof_expression,
1939
+ $.alignof_expression,
1940
+ $.offsetof_expression,
1941
+ $.va_arg_expression,
1942
+ $.generic_expression,
1943
+ $.subscript_expression,
1944
+ $.call_expression,
1945
+ $.field_expression,
1946
+ $.compound_literal_expression,
1947
+ $.identifier,
1948
+ alias('thread_local', $.identifier),
1949
+ alias(VA_ARG_KEYWORDS, $.identifier),
1950
+ $.number_literal,
1951
+ $._string,
1952
+ $.true,
1953
+ $.false,
1954
+ $.null,
1955
+ $.char_literal,
1956
+ $.parenthesized_expression,
1957
+ $.gnu_asm_expression,
1958
+ $.extension_expression,
1959
+ $.builtin_available_expression
1960
+ ),
1841
1961
 
1842
- _string: ($) => prec.left(choice($.string_literal, $.raw_string_literal, $.concatenated_string)),
1962
+ _string: ($) => prec.left(choice($.string_literal, $.raw_string_literal, $.concatenated_string)),
1843
1963
 
1844
- raw_string_literal: () =>
1845
- seq(
1846
- token(
1964
+ raw_string_literal: () =>
1965
+ seq(
1966
+ token(
1967
+ seq(
1968
+ optional(seq(choice('L', 'U', 'u', seq('u', repeat(LINE_SPLICE), '8')), repeat(LINE_SPLICE))),
1969
+ 'R',
1970
+ repeat(LINE_SPLICE),
1971
+ '"'
1972
+ )
1973
+ ),
1974
+ sym('_gnu_raw_string_body'),
1975
+ '"'
1976
+ ),
1977
+
1978
+ comma_expression: ($) =>
1979
+ seq(field('left', $.expression), ',', field('right', choice($.expression, $.comma_expression))),
1980
+
1981
+ conditional_expression: ($) =>
1982
+ prec.right(
1983
+ PREC.CONDITIONAL,
1847
1984
  seq(
1848
- optional(seq(choice('L', 'U', 'u', seq('u', repeat(LINE_SPLICE), '8')), repeat(LINE_SPLICE))),
1849
- 'R',
1850
- repeat(LINE_SPLICE),
1851
- '"'
1985
+ field('condition', $.expression),
1986
+ '?',
1987
+ optional(field('consequence', choice($.expression, $.comma_expression))),
1988
+ ':',
1989
+ field('alternative', $.expression)
1852
1990
  )
1853
1991
  ),
1854
- sym('_gnu_raw_string_body'),
1855
- '"'
1856
- ),
1857
1992
 
1858
- comma_expression: ($) =>
1859
- seq(field('left', $.expression), ',', field('right', choice($.expression, $.comma_expression))),
1860
-
1861
- conditional_expression: ($) =>
1862
- prec.right(
1863
- PREC.CONDITIONAL,
1864
- seq(
1865
- field('condition', $.expression),
1866
- '?',
1867
- optional(field('consequence', choice($.expression, $.comma_expression))),
1868
- ':',
1869
- field('alternative', $.expression)
1870
- )
1871
- ),
1993
+ _assignment_left_expression: ($) =>
1994
+ choice(
1995
+ alias(VA_ARG_KEYWORDS, $.identifier),
1996
+ $.identifier,
1997
+ $.call_expression,
1998
+ $.field_expression,
1999
+ $.pointer_expression,
2000
+ $.subscript_expression,
2001
+ $.parenthesized_expression
2002
+ ),
1872
2003
 
1873
- _assignment_left_expression: ($) =>
1874
- choice(
1875
- alias(VA_ARG_KEYWORDS, $.identifier),
1876
- $.identifier,
1877
- $.call_expression,
1878
- $.field_expression,
1879
- $.pointer_expression,
1880
- $.subscript_expression,
1881
- $.parenthesized_expression
1882
- ),
2004
+ assignment_expression: ($) =>
2005
+ prec.right(
2006
+ PREC.ASSIGNMENT,
2007
+ seq(
2008
+ field('left', $._assignment_left_expression),
2009
+ field('operator', choice('=', '*=', '/=', '%=', '+=', '-=', '<<=', '>>=', '&=', '^=', '|=')),
2010
+ field('right', $.expression)
2011
+ )
2012
+ ),
1883
2013
 
1884
- assignment_expression: ($) =>
1885
- prec.right(
1886
- PREC.ASSIGNMENT,
1887
- seq(
1888
- field('left', $._assignment_left_expression),
1889
- field('operator', choice('=', '*=', '/=', '%=', '+=', '-=', '<<=', '>>=', '&=', '^=', '|=')),
1890
- field('right', $.expression)
1891
- )
1892
- ),
2014
+ pointer_expression: ($) =>
2015
+ prec.left(PREC.CAST, seq(field('operator', choice('*', '&')), field('argument', $.expression))),
1893
2016
 
1894
- pointer_expression: ($) =>
1895
- prec.left(PREC.CAST, seq(field('operator', choice('*', '&')), field('argument', $.expression))),
2017
+ unary_expression: ($) =>
2018
+ prec.left(PREC.UNARY, seq(field('operator', choice('!', '~', '-', '+')), field('argument', $.expression))),
1896
2019
 
1897
- unary_expression: ($) =>
1898
- prec.left(PREC.UNARY, seq(field('operator', choice('!', '~', '-', '+')), field('argument', $.expression))),
2020
+ binary_expression: ($) => {
2021
+ return choice(
2022
+ ...BINARY_OPERATORS.map(([operator, precedence]) => {
2023
+ const body = seq(field('left', $.expression), field('operator', operator), field('right', $.expression));
2024
+ return prec.left(precedence, operator === '&&' ? prec.dynamic(1, body) : body);
2025
+ })
2026
+ );
2027
+ },
1899
2028
 
1900
- binary_expression: ($) => {
1901
- return choice(
1902
- ...BINARY_OPERATORS.map(([operator, precedence]) => {
1903
- const body = seq(field('left', $.expression), field('operator', operator), field('right', $.expression));
1904
- return prec.left(precedence, operator === '&&' ? prec.dynamic(1, body) : body);
1905
- })
1906
- );
1907
- },
2029
+ update_expression: ($) => {
2030
+ const argument = field('argument', $.expression);
2031
+ const operator = field('operator', choice('--', '++'));
2032
+ return prec.right(PREC.UNARY, choice(seq(operator, argument), seq(argument, operator)));
2033
+ },
1908
2034
 
1909
- update_expression: ($) => {
1910
- const argument = field('argument', $.expression);
1911
- const operator = field('operator', choice('--', '++'));
1912
- return prec.right(PREC.UNARY, choice(seq(operator, argument), seq(argument, operator)));
1913
- },
2035
+ cast_expression: ($) =>
2036
+ prec(PREC.CAST, seq('(', field('type', $.type_descriptor), ')', field('value', $.expression))),
1914
2037
 
1915
- cast_expression: ($) =>
1916
- prec(PREC.CAST, seq('(', field('type', $.type_descriptor), ')', field('value', $.expression))),
2038
+ type_descriptor: ($) =>
2039
+ seq(
2040
+ repeat(choice($.type_qualifier, $.attribute_specifier)),
2041
+ field('type', alias($._type_name_specifier, $.type_specifier)),
2042
+ repeat(choice($.type_qualifier, $.attribute_specifier)),
2043
+ field('declarator', optional($._abstract_declarator))
2044
+ ),
1917
2045
 
1918
- type_descriptor: ($) =>
1919
- seq(
1920
- repeat(choice($.type_qualifier, $.attribute_specifier)),
1921
- field('type', alias($._type_name_specifier, $.type_specifier)),
1922
- repeat(choice($.type_qualifier, $.attribute_specifier)),
1923
- field('declarator', optional($._abstract_declarator))
1924
- ),
2046
+ sizeof_expression: ($) =>
2047
+ prec.dynamic(
2048
+ 2,
2049
+ prec(
2050
+ PREC.SIZEOF,
2051
+ seq(
2052
+ 'sizeof',
2053
+ choice(field('value', prec.dynamic(3, $.expression)), seq('(', field('type', $.type_descriptor), ')'))
2054
+ )
2055
+ )
2056
+ ),
1925
2057
 
1926
- sizeof_expression: ($) =>
1927
- prec.dynamic(
1928
- 2,
2058
+ countof_expression: ($) =>
1929
2059
  prec(
1930
2060
  PREC.SIZEOF,
1931
2061
  seq(
1932
- 'sizeof',
1933
- choice(field('value', prec.dynamic(3, $.expression)), seq('(', field('type', $.type_descriptor), ')'))
2062
+ '_Countof',
2063
+ choice(
2064
+ field('value', prec.dynamic(3, $.expression)),
2065
+ prec.dynamic(2, seq('(', field('type', $.type_descriptor), ')'))
2066
+ )
1934
2067
  )
1935
- )
1936
- ),
2068
+ ),
1937
2069
 
1938
- countof_expression: ($) =>
1939
- prec(
1940
- PREC.SIZEOF,
1941
- seq(
1942
- '_Countof',
1943
- choice(
1944
- field('value', prec.dynamic(3, $.expression)),
1945
- prec.dynamic(2, seq('(', field('type', $.type_descriptor), ')'))
2070
+ alignof_expression: ($) =>
2071
+ prec.dynamic(
2072
+ 2,
2073
+ prec(
2074
+ PREC.SIZEOF,
2075
+ seq(
2076
+ choice('__alignof__', '__alignof', '_alignof', 'alignof', '_Alignof'),
2077
+ seq('(', field('type', $.type_descriptor), ')')
2078
+ )
1946
2079
  )
1947
- )
1948
- ),
2080
+ ),
1949
2081
 
1950
- alignof_expression: ($) =>
1951
- prec.dynamic(
1952
- 2,
2082
+ offsetof_expression: ($) =>
1953
2083
  prec(
1954
- PREC.SIZEOF,
1955
- seq(
1956
- choice('__alignof__', '__alignof', '_alignof', 'alignof', '_Alignof'),
1957
- seq('(', field('type', $.type_descriptor), ')')
1958
- )
1959
- )
1960
- ),
1961
-
1962
- offsetof_expression: ($) =>
1963
- prec(
1964
- PREC.OFFSETOF,
1965
- seq('offsetof', seq('(', field('type', $.type_descriptor), ',', field('member', $._field_identifier), ')'))
1966
- ),
2084
+ PREC.OFFSETOF,
2085
+ seq('offsetof', seq('(', field('type', $.type_descriptor), ',', field('member', $._field_identifier), ')'))
2086
+ ),
1967
2087
 
1968
- va_arg_expression: ($) =>
1969
- prec.dynamic(
1970
- 1,
1971
- seq(VA_ARG_KEYWORDS, '(', field('value', $.expression), ',', field('type', $.type_descriptor), ')')
1972
- ),
2088
+ va_arg_expression: ($) =>
2089
+ prec.dynamic(
2090
+ 1,
2091
+ seq(VA_ARG_KEYWORDS, '(', field('value', $.expression), ',', field('type', $.type_descriptor), ')')
2092
+ ),
1973
2093
 
1974
- generic_expression: ($) =>
1975
- prec(
1976
- PREC.CALL,
1977
- seq('_Generic', '(', $.expression, ',', commaSep1(seq($.type_descriptor, ':', $.expression)), ')')
1978
- ),
2094
+ generic_expression: ($) =>
2095
+ prec(
2096
+ PREC.CALL,
2097
+ seq('_Generic', '(', $.expression, ',', commaSep1(seq($.type_descriptor, ':', $.expression)), ')')
2098
+ ),
1979
2099
 
1980
- subscript_expression: ($) =>
1981
- prec(PREC.SUBSCRIPT, seq(field('argument', $.expression), '[', field('index', $.expression), ']')),
2100
+ subscript_expression: ($) =>
2101
+ prec(PREC.SUBSCRIPT, seq(field('argument', $.expression), '[', field('index', $.expression), ']')),
1982
2102
 
1983
- call_expression: ($) =>
1984
- prec(PREC.CALL, seq(field('function', $.expression), field('arguments', $.argument_list))),
2103
+ call_expression: ($) =>
2104
+ prec(PREC.CALL, seq(field('function', $.expression), field('arguments', $.argument_list))),
1985
2105
 
1986
- builtin_available_expression: ($) =>
1987
- seq('__builtin_available', '(', commaSep1(choice($.platform_version, '*')), ')'),
2106
+ builtin_available_expression: ($) =>
2107
+ seq('__builtin_available', '(', commaSep1(choice($.platform_version, '*')), ')'),
1988
2108
 
1989
- platform_version: ($) => seq(field('platform', $.identifier), field('version', $.version_number)),
2109
+ platform_version: ($) => seq(field('platform', $.identifier), field('version', $.version_number)),
1990
2110
 
1991
- version_number: () => /\d+(\.\d+){0,2}/,
2111
+ version_number: () => /\d+(\.\d+){0,2}/,
1992
2112
 
1993
- gnu_asm_expression: ($) =>
1994
- prec(
1995
- PREC.CALL,
1996
- seq(
1997
- choice('asm', '__asm__', '__asm'),
1998
- repeat($.gnu_asm_qualifier),
1999
- '(',
2000
- field('assembly_code', $._string),
2001
- optional(
2002
- seq(
2003
- field('output_operands', $.gnu_asm_output_operand_list),
2004
- optional(
2005
- seq(
2006
- field('input_operands', $.gnu_asm_input_operand_list),
2007
- optional(
2008
- seq(
2009
- field('clobbers', $.gnu_asm_clobber_list),
2010
- optional(field('goto_labels', $.gnu_asm_goto_list))
2113
+ gnu_asm_expression: ($) =>
2114
+ prec(
2115
+ PREC.CALL,
2116
+ seq(
2117
+ choice('asm', '__asm__', '__asm'),
2118
+ repeat($.gnu_asm_qualifier),
2119
+ '(',
2120
+ field('assembly_code', $._string),
2121
+ optional(
2122
+ seq(
2123
+ field('output_operands', $.gnu_asm_output_operand_list),
2124
+ optional(
2125
+ seq(
2126
+ field('input_operands', $.gnu_asm_input_operand_list),
2127
+ optional(
2128
+ seq(
2129
+ field('clobbers', $.gnu_asm_clobber_list),
2130
+ optional(field('goto_labels', $.gnu_asm_goto_list))
2131
+ )
2011
2132
  )
2012
2133
  )
2013
2134
  )
2014
2135
  )
2015
- )
2016
- ),
2017
- ')'
2018
- )
2019
- ),
2136
+ ),
2137
+ ')'
2138
+ )
2139
+ ),
2020
2140
 
2021
- gnu_asm_qualifier: () => choice('volatile', '__volatile__', 'inline', 'goto'),
2141
+ gnu_asm_qualifier: () => choice('volatile', '__volatile__', 'inline', 'goto'),
2022
2142
 
2023
- gnu_asm_output_operand_list: ($) => seq(':', commaSep(field('operand', $.gnu_asm_output_operand))),
2143
+ gnu_asm_output_operand_list: ($) => seq(':', commaSep(field('operand', $.gnu_asm_output_operand))),
2024
2144
 
2025
- gnu_asm_output_operand: ($) =>
2026
- seq(
2027
- optional(seq('[', field('symbol', $.identifier), ']')),
2028
- field('constraint', choice($.string_literal, $.raw_string_literal)),
2029
- '(',
2030
- field('value', $.expression),
2031
- ')'
2032
- ),
2145
+ gnu_asm_output_operand: ($) =>
2146
+ seq(
2147
+ optional(seq('[', field('symbol', $.identifier), ']')),
2148
+ field('constraint', choice($.string_literal, $.raw_string_literal)),
2149
+ '(',
2150
+ field('value', $.expression),
2151
+ ')'
2152
+ ),
2033
2153
 
2034
- gnu_asm_input_operand_list: ($) => seq(':', commaSep(field('operand', $.gnu_asm_input_operand))),
2154
+ gnu_asm_input_operand_list: ($) => seq(':', commaSep(field('operand', $.gnu_asm_input_operand))),
2035
2155
 
2036
- gnu_asm_input_operand: ($) =>
2037
- seq(
2038
- optional(seq('[', field('symbol', $.identifier), ']')),
2039
- field('constraint', choice($.string_literal, $.raw_string_literal)),
2040
- '(',
2041
- field('value', $.expression),
2042
- ')'
2043
- ),
2156
+ gnu_asm_input_operand: ($) =>
2157
+ seq(
2158
+ optional(seq('[', field('symbol', $.identifier), ']')),
2159
+ field('constraint', choice($.string_literal, $.raw_string_literal)),
2160
+ '(',
2161
+ field('value', $.expression),
2162
+ ')'
2163
+ ),
2044
2164
 
2045
- gnu_asm_clobber_list: ($) => seq(':', commaSep(field('register', $._string))),
2165
+ gnu_asm_clobber_list: ($) => seq(':', commaSep(field('register', $._string))),
2046
2166
 
2047
- gnu_asm_goto_list: ($) => seq(':', commaSep(field('label', $.identifier))),
2167
+ gnu_asm_goto_list: ($) => seq(':', commaSep(field('label', $.identifier))),
2048
2168
 
2049
- extension_expression: ($) => seq('__extension__', $.expression),
2169
+ extension_expression: ($) => seq('__extension__', $.expression),
2050
2170
 
2051
- argument_list: ($) =>
2052
- seq(
2053
- '(',
2054
- optional(
2055
- seq(
2056
- commaSep1(
2057
- choice($.expression, $.compound_statement, $.initializer_pair, prec.dynamic(-1, $.initializer_list))
2058
- ),
2059
- optional(',')
2060
- )
2171
+ argument_list: ($) =>
2172
+ seq(
2173
+ '(',
2174
+ optional(
2175
+ seq(
2176
+ commaSep1(
2177
+ choice($.expression, $.compound_statement, $.initializer_pair, prec.dynamic(-1, $.initializer_list))
2178
+ ),
2179
+ optional(',')
2180
+ )
2181
+ ),
2182
+ ')'
2061
2183
  ),
2062
- ')'
2063
- ),
2064
2184
 
2065
- field_expression: ($) =>
2066
- seq(
2067
- prec(PREC.FIELD, seq(field('argument', $.expression), field('operator', choice('.', '->')))),
2068
- field('field', $._field_identifier)
2069
- ),
2185
+ field_expression: ($) =>
2186
+ seq(
2187
+ prec(PREC.FIELD, seq(field('argument', $.expression), field('operator', choice('.', '->')))),
2188
+ field('field', $._field_identifier)
2189
+ ),
2070
2190
 
2071
- compound_literal_expression: ($) =>
2072
- seq(
2073
- '(',
2074
- repeat(
2075
- seq(
2076
- optional(
2077
- field('storage_class', alias($._compound_literal_constexpr_specifier, $.storage_class_specifier))
2078
- ),
2079
- field('storage_class', alias($._compound_literal_storage_class_specifier, $.storage_class_specifier))
2080
- )
2191
+ compound_literal_expression: ($) =>
2192
+ seq(
2193
+ '(',
2194
+ repeat(
2195
+ seq(
2196
+ optional(
2197
+ field('storage_class', alias($._compound_literal_constexpr_specifier, $.storage_class_specifier))
2198
+ ),
2199
+ field('storage_class', alias($._compound_literal_storage_class_specifier, $.storage_class_specifier))
2200
+ )
2201
+ ),
2202
+ field('type', $.type_descriptor),
2203
+ ')',
2204
+ field('value', $.initializer_list)
2081
2205
  ),
2082
- field('type', $.type_descriptor),
2083
- ')',
2084
- field('value', $.initializer_list)
2085
- ),
2086
2206
 
2087
- _compound_literal_constexpr_specifier: () => 'constexpr',
2207
+ _compound_literal_constexpr_specifier: () => 'constexpr',
2088
2208
 
2089
- _compound_literal_storage_class_specifier: () =>
2090
- choice('static', 'register', 'thread_local', '_Thread_local', '__thread'),
2209
+ _compound_literal_storage_class_specifier: () =>
2210
+ choice('static', 'register', 'thread_local', '_Thread_local', '__thread'),
2091
2211
 
2092
- parenthesized_expression: ($) => seq('(', choice($.expression, $.comma_expression, $.compound_statement), ')'),
2212
+ parenthesized_expression: ($) => seq('(', choice($.expression, $.comma_expression, $.compound_statement), ')'),
2093
2213
 
2094
- initializer_list: ($) => seq('{', optional($._initializer_sequence), '}'),
2214
+ initializer_list: ($) => seq('{', optional($._initializer_sequence), '}'),
2095
2215
 
2096
- _initializer_sequence: ($) =>
2097
- choice(
2098
- seq(
2099
- $._initializer_element,
2100
- optional(choice(seq(',', optional($._initializer_sequence)), $._initializer_directives))
2216
+ _initializer_sequence: ($) =>
2217
+ choice(
2218
+ seq(
2219
+ $._initializer_element,
2220
+ optional(choice(seq(',', optional($._initializer_sequence)), $._initializer_directives))
2221
+ ),
2222
+ $._initializer_directives
2101
2223
  ),
2102
- $._initializer_directives
2103
- ),
2104
2224
 
2105
- _initializer_directives: ($) =>
2106
- seq(
2107
- $._initializer_directive,
2108
- optional(choice($._initializer_sequence, seq(',', optional($._initializer_sequence))))
2109
- ),
2225
+ _initializer_directives: ($) =>
2226
+ seq(
2227
+ $._initializer_directive,
2228
+ optional(choice($._initializer_sequence, seq(',', optional($._initializer_sequence))))
2229
+ ),
2110
2230
 
2111
- _initializer_directive: ($) =>
2112
- choice(
2113
- alias(sym('preproc_if_in_initializer_list'), sym('preproc_if')),
2114
- alias(sym('preproc_ifdef_in_initializer_list'), sym('preproc_ifdef')),
2115
- $.preproc_def,
2116
- $.preproc_function_def,
2117
- $.preproc_include,
2118
- $.preproc_call
2119
- ),
2231
+ _initializer_directive: ($) =>
2232
+ choice(
2233
+ alias(sym('preproc_if_in_initializer_list'), sym('preproc_if')),
2234
+ alias(sym('preproc_ifdef_in_initializer_list'), sym('preproc_ifdef')),
2235
+ $.preproc_def,
2236
+ $.preproc_function_def,
2237
+ $.preproc_include,
2238
+ $.preproc_call
2239
+ ),
2120
2240
 
2121
- _initializer_element: ($) => choice($.initializer_pair, $.expression, $.initializer_list),
2241
+ _initializer_element: ($) => choice($.initializer_pair, $.expression, $.initializer_list),
2122
2242
 
2123
- _initializer_branch: ($) => choice(seq(',', optional($._initializer_sequence)), $._initializer_sequence),
2243
+ _initializer_branch: ($) => choice(seq(',', optional($._initializer_sequence)), $._initializer_sequence),
2124
2244
 
2125
- ...preprocIf('_in_initializer_list', () => sym('_initializer_branch'), 0, false),
2245
+ ...preprocIf('_in_initializer_list', () => sym('_initializer_branch'), 0, false),
2126
2246
 
2127
- initializer_pair: ($) =>
2128
- choice(
2129
- seq(
2130
- field(
2131
- 'designator',
2132
- repeat1(choice($.subscript_designator, $.field_designator, $.subscript_range_designator))
2247
+ initializer_pair: ($) =>
2248
+ choice(
2249
+ seq(
2250
+ field(
2251
+ 'designator',
2252
+ repeat1(choice($.subscript_designator, $.field_designator, $.subscript_range_designator))
2253
+ ),
2254
+ '=',
2255
+ field('value', choice($.expression, $.initializer_list))
2133
2256
  ),
2134
- '=',
2135
- field('value', choice($.expression, $.initializer_list))
2257
+ seq(field('designator', $._field_identifier), ':', field('value', choice($.expression, $.initializer_list)))
2136
2258
  ),
2137
- seq(field('designator', $._field_identifier), ':', field('value', choice($.expression, $.initializer_list)))
2138
- ),
2139
2259
 
2140
- subscript_designator: ($) => seq('[', $.expression, ']'),
2260
+ subscript_designator: ($) => seq('[', $.expression, ']'),
2141
2261
 
2142
- subscript_range_designator: ($) => seq('[', field('start', $.expression), '...', field('end', $.expression), ']'),
2262
+ subscript_range_designator: ($) =>
2263
+ seq('[', field('start', $.expression), '...', field('end', $.expression), ']'),
2143
2264
 
2144
- field_designator: ($) => seq('.', $._field_identifier),
2265
+ field_designator: ($) => seq('.', $._field_identifier),
2145
2266
 
2146
- number_literal: () => {
2147
- const separator = "'";
2148
- const hex = /[0-9a-fA-F]/;
2149
- const decimal = /[0-9]/;
2150
- const hexDigits = seq(repeat1(hex), repeat(seq(separator, repeat1(hex))));
2151
- const decimalDigits = seq(repeat1(decimal), repeat(seq(separator, repeat1(decimal))));
2152
- return token(
2153
- seq(
2154
- optional(/[-+]/),
2155
- choice(
2156
- seq(
2157
- choice(decimalDigits, seq(/0[bB]/, decimalDigits), seq(/0[xX]/, hexDigits)),
2158
- optional(seq('.', optional(hexDigits)))
2267
+ number_literal: () => {
2268
+ const separator = "'";
2269
+ const hex = /[0-9a-fA-F]/;
2270
+ const decimal = /[0-9]/;
2271
+ const hexDigits = seq(repeat1(hex), repeat(seq(separator, repeat1(hex))));
2272
+ const decimalDigits = seq(repeat1(decimal), repeat(seq(separator, repeat1(decimal))));
2273
+ return token(
2274
+ seq(
2275
+ optional(/[-+]/),
2276
+ choice(
2277
+ seq(
2278
+ choice(decimalDigits, seq(/0[bB]/, decimalDigits), seq(/0[xX]/, hexDigits)),
2279
+ optional(seq('.', optional(hexDigits)))
2280
+ ),
2281
+ seq('.', decimalDigits),
2282
+ seq(/0[xX]/, '.', hexDigits)
2159
2283
  ),
2160
- seq('.', decimalDigits),
2161
- seq(/0[xX]/, '.', hexDigits)
2162
- ),
2163
- optional(seq(/[eEpP]/, optional(seq(optional(/[-+]/), hexDigits)))),
2164
- /[uUlLwWfFbBdD]*/
2165
- )
2166
- );
2167
- },
2168
-
2169
- char_literal: ($) =>
2170
- seq(
2171
- choice("L'", "u'", "U'", "u8'", "'"),
2172
- repeat1(
2173
- choice($.escape_sequence, $.invalid_escape_sequence, alias(token.immediate(/[^\\\n']/), sym('character')))
2174
- ),
2175
- "'"
2176
- ),
2284
+ optional(seq(/[eEpP]/, optional(seq(optional(/[-+]/), hexDigits)))),
2285
+ /[uUlLwWfFbBdD]*/
2286
+ )
2287
+ );
2288
+ },
2177
2289
 
2178
- // Identifier is added to parse macros that are strings, like PRIu64.
2179
- concatenated_string: ($) =>
2180
- prec.right(
2290
+ char_literal: ($) =>
2181
2291
  seq(
2182
- choice(
2183
- seq($.identifier, choice($.string_literal, $.raw_string_literal)),
2184
- seq(choice($.string_literal, $.raw_string_literal), choice($.string_literal, $.raw_string_literal)),
2185
- seq(choice($.string_literal, $.raw_string_literal), $.identifier)
2292
+ choice("L'", "u'", "U'", "u8'", "'"),
2293
+ repeat1(
2294
+ choice($.escape_sequence, $.invalid_escape_sequence, alias(token.immediate(/[^\\\n']/), sym('character')))
2186
2295
  ),
2187
- repeat(choice($.string_literal, $.raw_string_literal, $.identifier))
2188
- )
2189
- ),
2296
+ "'"
2297
+ ),
2190
2298
 
2191
- string_literal: ($) =>
2192
- seq(
2193
- choice('L"', 'u"', 'U"', 'u8"', '"'),
2194
- repeat(
2195
- choice(
2196
- alias(token.immediate(prec(1, /[^\\"\n]+/)), sym('string_content')),
2197
- $.escape_sequence,
2198
- $.invalid_escape_sequence
2299
+ // Identifier is added to parse macros that are strings, like PRIu64.
2300
+ concatenated_string: ($) =>
2301
+ prec.right(
2302
+ seq(
2303
+ choice(
2304
+ seq($.identifier, choice($.string_literal, $.raw_string_literal)),
2305
+ seq(choice($.string_literal, $.raw_string_literal), choice($.string_literal, $.raw_string_literal)),
2306
+ seq(choice($.string_literal, $.raw_string_literal), $.identifier)
2307
+ ),
2308
+ repeat(choice($.string_literal, $.raw_string_literal, $.identifier))
2199
2309
  )
2200
2310
  ),
2201
- '"'
2202
- ),
2203
2311
 
2204
- escape_sequence: () =>
2205
- token(
2206
- prec(
2207
- 1,
2208
- seq(
2209
- '\\',
2312
+ string_literal: ($) =>
2313
+ seq(
2314
+ choice('L"', 'u"', 'U"', 'u8"', '"'),
2315
+ repeat(
2210
2316
  choice(
2211
- /['"?\\abefnrtvE]/,
2212
- '(',
2213
- '[',
2214
- '{',
2215
- '%',
2216
- /\r\n?|\n\r?/,
2217
- /[xu]\{[0-9a-fA-F]+\}/,
2218
- /o\{[0-7]+\}/,
2219
- /N\{[^}\n]+\}/,
2220
- /[0-7]{1,3}/,
2221
- /x[0-9a-fA-F]+/,
2222
- /u[0-9a-fA-F]{4}/,
2223
- /U[0-9a-fA-F]{8}/
2317
+ alias(token.immediate(prec(1, /[^\\"\n]+/)), sym('string_content')),
2318
+ $.escape_sequence,
2319
+ $.invalid_escape_sequence
2320
+ )
2321
+ ),
2322
+ '"'
2323
+ ),
2324
+
2325
+ escape_sequence: () =>
2326
+ token(
2327
+ prec(
2328
+ 1,
2329
+ seq(
2330
+ '\\',
2331
+ choice(
2332
+ /['"?\\abefnrtvE]/,
2333
+ '(',
2334
+ '[',
2335
+ '{',
2336
+ '%',
2337
+ /\r\n?|\n\r?/,
2338
+ /[xu]\{[0-9a-fA-F]+\}/,
2339
+ /o\{[0-7]+\}/,
2340
+ /N\{[^}\n]+\}/,
2341
+ /[0-7]{1,3}/,
2342
+ /x[0-9a-fA-F]+/,
2343
+ /u[0-9a-fA-F]{4}/,
2344
+ /U[0-9a-fA-F]{8}/
2345
+ )
2224
2346
  )
2225
2347
  )
2226
- )
2227
- ),
2348
+ ),
2228
2349
 
2229
- invalid_escape_sequence: () => token(seq('\\', choice(/[^\r\n]/, /u[0-9a-fA-F]{1,3}/, /U[0-9a-fA-F]{1,7}/))),
2350
+ invalid_escape_sequence: () => token(seq('\\', choice(/[^\r\n]/, /u[0-9a-fA-F]{1,3}/, /U[0-9a-fA-F]{1,7}/))),
2230
2351
 
2231
- system_lib_string: () => token(seq('<', repeat(choice(/[^>\n]/, String.raw`\>`)), '>')),
2352
+ system_lib_string: () => token(seq('<', repeat(choice(/[^>\n]/, String.raw`\>`)), '>')),
2232
2353
 
2233
- true: () => 'true',
2234
- false: () => 'false',
2235
- null: () => choice('NULL', 'nullptr'),
2354
+ true: () => 'true',
2355
+ false: () => 'false',
2356
+ null: () => choice('NULL', 'nullptr'),
2236
2357
 
2237
- identifier: () =>
2238
- /(\p{XID_Start}|\$|_|\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8})(\p{XID_Continue}|\$|\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8})*/u,
2239
- _type_identifier: ($) => alias(choice($.identifier, VA_ARG_KEYWORDS), sym('type_identifier')),
2240
- _field_identifier: ($) => alias(choice($.identifier, VA_ARG_KEYWORDS), sym('field_identifier')),
2241
- _statement_identifier: ($) => alias(choice($.identifier, VA_ARG_KEYWORDS), sym('statement_identifier')),
2358
+ // Names spelled like macros, or reserved for the implementation (C11 7.1.3) and so never a parameter's own name,
2359
+ // other than keywords (see `assertMacroCaseIdentifierSpellsNoKeyword`). Declared before `identifier` so that rule
2360
+ // order, not precedence, settles names both match in full; keywords lex through `identifier`, the word token.
2361
+ _macro_case_identifier: () => MACRO_CASE_IDENTIFIER,
2362
+ identifier: () =>
2363
+ /(\p{XID_Start}|\$|_|\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8})(\p{XID_Continue}|\$|\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8})*/u,
2364
+ _type_identifier: ($) => alias(choice($.identifier, VA_ARG_KEYWORDS), sym('type_identifier')),
2365
+ _field_identifier: ($) => alias(choice($.identifier, VA_ARG_KEYWORDS), sym('field_identifier')),
2366
+ _statement_identifier: ($) => alias(choice($.identifier, VA_ARG_KEYWORDS), sym('statement_identifier')),
2242
2367
 
2243
- _empty_declaration: ($) =>
2244
- choice(
2368
+ _empty_declaration: ($) =>
2369
+ choice(
2370
+ seq(
2371
+ repeat(choice($.ms_declspec_modifier, $.macro_specifier, $._leading_conditional_macro_specifier)),
2372
+ $.type_specifier,
2373
+ repeat($.type_qualifier),
2374
+ ';'
2375
+ ),
2376
+ $._statement_empty_declaration
2377
+ ),
2378
+
2379
+ _statement_empty_declaration: ($) =>
2245
2380
  seq(
2246
- repeat(choice($.ms_declspec_modifier, $.macro_specifier, $._leading_conditional_macro_specifier)),
2381
+ repeat(
2382
+ choice(
2383
+ $.ms_declspec_modifier,
2384
+ prec.dynamic(-1, $.storage_class_specifier),
2385
+ prec.dynamic(-1, $.type_qualifier)
2386
+ )
2387
+ ),
2247
2388
  $.type_specifier,
2248
- repeat($.type_qualifier),
2389
+ repeat(choice($.type_qualifier, prec.dynamic(-1, $.storage_class_specifier))),
2249
2390
  ';'
2250
2391
  ),
2251
- $._statement_empty_declaration
2252
- ),
2253
2392
 
2254
- _statement_empty_declaration: ($) =>
2255
- seq(
2256
- repeat(
2257
- choice(
2258
- $.ms_declspec_modifier,
2259
- prec.dynamic(-1, $.storage_class_specifier),
2260
- prec.dynamic(-1, $.type_qualifier)
2261
- )
2262
- ),
2263
- $.type_specifier,
2264
- repeat(choice($.type_qualifier, prec.dynamic(-1, $.storage_class_specifier))),
2265
- ';'
2266
- ),
2393
+ macro_specifier: ($) => prec.dynamic(-2, field('name', reserved('marker', $.identifier))),
2394
+
2395
+ _function_macro_specifier: ($) => field('name', reserved('marker', $.identifier)),
2267
2396
 
2268
- macro_specifier: ($) => prec.dynamic(-2, field('name', reserved('marker', $.identifier))),
2397
+ _trailing_macro_specifier: ($) => trailingAnnotationRule($, (name) => field('name', name)),
2269
2398
 
2270
- _conditional_macro_specifier: () => alias(sym('_marker_preproc_ifdef'), sym('preproc_ifdef')),
2271
- _leading_conditional_macro_specifier: () => alias(sym('_leading_marker_preproc_ifdef'), sym('preproc_ifdef')),
2399
+ _trailing_macro_call_expression: ($) =>
2400
+ trailingAnnotationRule($, (name) =>
2401
+ seq(field('function', name), field('arguments', alias($.preproc_argument_list, $.argument_list)))
2402
+ ),
2272
2403
 
2273
- _marker_preproc_ifdef: ($) =>
2274
- conditionalMacroRule($, sym('_conditional_marker_ifdef'), sym('_conditional_marker_ifndef')),
2275
- _leading_marker_preproc_ifdef: ($) =>
2276
- conditionalMacroRule($, sym('_leading_conditional_marker_ifdef'), sym('_leading_conditional_marker_ifndef')),
2404
+ _conditional_macro_specifier: () => alias(sym('_marker_preproc_ifdef'), sym('preproc_ifdef')),
2405
+ _leading_conditional_macro_specifier: () => alias(sym('_leading_marker_preproc_ifdef'), sym('preproc_ifdef')),
2277
2406
 
2278
- macro_type_specifier: ($) =>
2279
- prec.dynamic(
2280
- -1,
2281
- seq(
2282
- field('name', choice($.identifier, alias(VA_ARG_KEYWORDS, $.identifier))),
2283
- choice(
2284
- seq('(', field('type', $.type_descriptor), ')'),
2285
- field('arguments', alias($._raw_string_macro_type_arguments, $.argument_list))
2407
+ _marker_preproc_ifdef: ($) =>
2408
+ conditionalMacroRule($, sym('_conditional_marker_ifdef'), sym('_conditional_marker_ifndef')),
2409
+ _leading_marker_preproc_ifdef: ($) =>
2410
+ conditionalMacroRule($, sym('_leading_conditional_marker_ifdef'), sym('_leading_conditional_marker_ifndef')),
2411
+
2412
+ macro_type_specifier: ($) =>
2413
+ prec.dynamic(
2414
+ -1,
2415
+ seq(
2416
+ field('name', choice($.identifier, alias(VA_ARG_KEYWORDS, $.identifier))),
2417
+ choice(
2418
+ seq('(', field('type', $.type_descriptor), ')'),
2419
+ field('arguments', alias($._raw_string_macro_type_arguments, $.argument_list))
2420
+ )
2286
2421
  )
2287
- )
2288
- ),
2422
+ ),
2289
2423
 
2290
- _variadic_macro_type_specifier: ($) =>
2291
- prec.dynamic(
2292
- -2,
2293
- seq(
2294
- field('name', choice($.identifier, alias(VA_ARG_KEYWORDS, $.identifier))),
2295
- '(',
2296
- field('type', $.type_descriptor),
2297
- repeat1(seq(',', optional(macroAttributeArgument($)))),
2298
- ')'
2299
- )
2300
- ),
2424
+ _variadic_macro_type_specifier: ($) =>
2425
+ prec.dynamic(
2426
+ -2,
2427
+ seq(
2428
+ field('name', choice($.identifier, alias(VA_ARG_KEYWORDS, $.identifier))),
2429
+ '(',
2430
+ field('type', $.type_descriptor),
2431
+ repeat1(seq(',', optional(macroAttributeArgument($)))),
2432
+ ')'
2433
+ )
2434
+ ),
2301
2435
 
2302
- _raw_string_macro_type_arguments: ($) =>
2303
- seq('(', $._raw_string_type_argument, optional($._raw_string_type_tail), ')'),
2436
+ _raw_string_macro_type_arguments: ($) =>
2437
+ seq('(', $._raw_string_type_argument, optional($._raw_string_type_tail), ')'),
2304
2438
 
2305
- _raw_string_type_argument: ($) =>
2306
- choice($.raw_string_literal, alias($._parenthesized_raw_string_type_argument, $.parenthesized_expression)),
2439
+ _raw_string_type_argument: ($) =>
2440
+ choice($.raw_string_literal, alias($._parenthesized_raw_string_type_argument, $.parenthesized_expression)),
2307
2441
 
2308
- _parenthesized_raw_string_type_argument: ($) =>
2309
- seq('(', $._raw_string_type_argument, optional($._raw_string_type_tail), ')'),
2442
+ _parenthesized_raw_string_type_argument: ($) =>
2443
+ seq('(', $._raw_string_type_argument, optional($._raw_string_type_tail), ')'),
2310
2444
 
2311
- // The opaque tail scanner stops before a balanced group's first brace, so those arguments are parsed here.
2312
- _raw_string_type_tail: ($) =>
2313
- choice(
2314
- alias(sym('_raw_macro_type_tail'), $.preproc_arg),
2315
- repeat1(
2316
- seq(
2317
- ',',
2318
- optional(
2319
- choice(macroAttributeArgument($), alias(sym('_macro_attribute_parameter'), $.parameter_declaration))
2445
+ // The opaque tail scanner stops before a balanced group's first brace, so those arguments are parsed here.
2446
+ _raw_string_type_tail: ($) =>
2447
+ choice(
2448
+ alias(sym('_raw_macro_type_tail'), $.preproc_arg),
2449
+ repeat1(
2450
+ seq(
2451
+ ',',
2452
+ optional(
2453
+ choice(macroAttributeArgument($), alias(sym('_macro_attribute_parameter'), $.parameter_declaration))
2454
+ )
2320
2455
  )
2321
2456
  )
2322
- )
2323
- ),
2457
+ ),
2324
2458
 
2325
- _preproc_number: () =>
2326
- /(\d|\.\d)([\p{XID_Continue}.]|[eEpP][+-]|'[_a-zA-Z0-9]|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8})*/u,
2459
+ _preproc_number: () =>
2460
+ /(\d|\.\d)([\p{XID_Continue}.]|[eEpP][+-]|'[_a-zA-Z0-9]|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8})*/u,
2327
2461
 
2328
- comment: () => token(choice(LINE_COMMENT, BLOCK_COMMENT)),
2329
- },
2330
- }),
2331
- { PREC, preprocIf, preprocessor, commaSep, commaSep1, declarationSpecifiers }
2462
+ comment: () => token(choice(LINE_COMMENT, BLOCK_COMMENT)),
2463
+ },
2464
+ })
2465
+ ),
2466
+ {
2467
+ PREC,
2468
+ preprocIf,
2469
+ preprocessor,
2470
+ commaSep,
2471
+ commaSep1,
2472
+ declarationSpecifiers,
2473
+ assertMacroCaseIdentifierSpellsNoKeyword,
2474
+ }
2332
2475
  );
2333
2476
 
2477
+ /**
2478
+ * Throws when `_macro_case_identifier` matches a keyword of the grammar in full, since it would take the keyword's place
2479
+ * wherever both are valid. Returns the grammar unchanged.
2480
+ * @template T
2481
+ * @param {T} grammar
2482
+ * @returns {T}
2483
+ */
2484
+ function assertMacroCaseIdentifierSpellsNoKeyword(grammar) {
2485
+ const whole = new RegExp(`^(?:${MACRO_CASE_IDENTIFIER.source})$`);
2486
+ for (const keyword of keywordStrings(grammar)) {
2487
+ if (whole.test(keyword)) {
2488
+ throw new Error(`_macro_case_identifier spells the keyword ${keyword}; add it to MACRO_CASE_KEYWORDS`);
2489
+ }
2490
+ }
2491
+ return grammar;
2492
+ }
2493
+
2494
+ /**
2495
+ * Yields the string literals of a grammar outside `token(...)`, which are the candidates for keywords.
2496
+ * @param {unknown} node
2497
+ * @returns {Generator<string>}
2498
+ */
2499
+ function* keywordStrings(node) {
2500
+ if (!node || typeof node !== 'object') return;
2501
+ const record = /** @type {Record<string, unknown>} */ (node);
2502
+ if (record.type === 'TOKEN' || record.type === 'IMMEDIATE_TOKEN') return;
2503
+ if (record.type === 'STRING' && typeof record.value === 'string') yield record.value;
2504
+ for (const child of Object.values(record)) yield* keywordStrings(child);
2505
+ }
2506
+
2507
+ /**
2508
+ * Ranks a trailing parameter annotation against a leading marker (-2) that reads `int *A B` the other way: an
2509
+ * annotation named like a macro (`char **argv UNUSED`, `int *CC cb(int) ATTR(1)`) outranks it, and any other name ranks
2510
+ * below it (`int *CC pointer`, `int *CC callback(int)`), since macro definitions are unknown.
2511
+ * @param {import('./types/treeSitterDsl').GrammarSymbols<'identifier' | '_macro_case_identifier'>} $
2512
+ * @param {(name: import('./types/treeSitterDsl').Rule) => import('./types/treeSitterDsl').Rule} annotation
2513
+ */
2514
+ function trailingAnnotationRule($, annotation) {
2515
+ return choice(
2516
+ prec.dynamic(-1, annotation(alias($._macro_case_identifier, $.identifier))),
2517
+ prec.dynamic(-3, annotation(reserved('marker', $.identifier)))
2518
+ );
2519
+ }
2520
+
2521
+ /**
2522
+ * Returns a regular expression source that matches every string of a character in `first` followed by characters in
2523
+ * `rest`, the empty string included, except the given words.
2524
+ * @param {string[]} words
2525
+ * @param {string} first
2526
+ * @param {string} rest
2527
+ * @returns {string}
2528
+ */
2529
+ function identifierExcept(words, first, rest) {
2530
+ /** @type {Map<string, string[]>} */
2531
+ const byFirst = new Map();
2532
+ let excludesEmpty = false;
2533
+ for (const word of words) {
2534
+ if (word === '') {
2535
+ excludesEmpty = true;
2536
+ continue;
2537
+ }
2538
+ const character = word.charAt(0);
2539
+ byFirst.set(character, [...(byFirst.get(character) ?? []), word.slice(1)]);
2540
+ }
2541
+ const others = first
2542
+ .split('')
2543
+ .filter((character) => !byFirst.has(character))
2544
+ .join('');
2545
+ const alternatives = [`[${others}][${rest}]*`];
2546
+ for (const [character, rests] of byFirst) alternatives.push(`${character}${identifierExcept(rests, rest, rest)}`);
2547
+ return `(?:${alternatives.join('|')})${excludesEmpty ? '' : '?'}`;
2548
+ }
2549
+
2334
2550
  /**
2335
2551
  * Build declaration specifiers, optionally retaining real types after a braced group guard.
2336
2552
  * @param {import('./types/treeSitterDsl').GrammarSymbols<'_declaration_specifiers' | '_declaration_modifiers' | 'type_specifier' | '_non_macro_declaration_modifiers'>} $