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