@willbooster/tree-sitter-c 19.0.0 → 20.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -13
- package/grammar.js +527 -81
- package/package.json +3 -3
- package/src/functionMacro.h +209 -29
- package/src/keywords.h +37 -0
- package/src/node-types.json +60 -22
- package/src/pragma.h +8 -2
- package/src/scanner.c +9 -3
- package/tree-sitter-c.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// @ts-check
|
|
9
9
|
|
|
10
10
|
// Tree-sitter injects its DSL before loading this CommonJS grammar.
|
|
11
|
-
const { grammar, alias, choice, field, optional, prec, repeat, repeat1, seq, sym, token } =
|
|
11
|
+
const { grammar, alias, choice, field, optional, prec, repeat, repeat1, reserved, seq, sym, token } =
|
|
12
12
|
/** @type {typeof globalThis & typeof import('./types/treeSitterDsl')} */ (globalThis);
|
|
13
13
|
|
|
14
14
|
// oxlint-disable-next-line unicorn/prefer-module -- Tree-sitter loads this grammar as CommonJS.
|
|
@@ -72,6 +72,205 @@ module.exports = Object.assign(
|
|
|
72
72
|
name: 'c',
|
|
73
73
|
|
|
74
74
|
conflicts: ($) => [
|
|
75
|
+
[$._declaration_modifiers, $._empty_declaration],
|
|
76
|
+
[$.type_definition, $._declaration_modifiers, $._empty_declaration],
|
|
77
|
+
[
|
|
78
|
+
$._statement_declaration,
|
|
79
|
+
$._statement_type_definition,
|
|
80
|
+
$._macro_only_declaration,
|
|
81
|
+
$._macro_declaration_specifiers,
|
|
82
|
+
$._statement_declaration_modifiers,
|
|
83
|
+
$._guarded_type_specifiers,
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
$._macro_declaration_specifiers,
|
|
87
|
+
$._statement_declaration_modifiers,
|
|
88
|
+
$._guarded_type_specifiers,
|
|
89
|
+
$._case_body_attributed_statement,
|
|
90
|
+
$._case_label_attributes,
|
|
91
|
+
],
|
|
92
|
+
[
|
|
93
|
+
$._statement_declaration,
|
|
94
|
+
$._macro_only_declaration,
|
|
95
|
+
$._macro_declaration_specifiers,
|
|
96
|
+
$._statement_declaration_modifiers,
|
|
97
|
+
$._guarded_type_specifiers,
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
$._statement_declaration,
|
|
101
|
+
$._statement_type_definition,
|
|
102
|
+
$._macro_only_declaration,
|
|
103
|
+
$._macro_declaration_specifiers,
|
|
104
|
+
$._statement_declaration_modifiers,
|
|
105
|
+
$._guarded_type_specifiers,
|
|
106
|
+
$._statement_empty_declaration,
|
|
107
|
+
],
|
|
108
|
+
[
|
|
109
|
+
$._macro_only_declaration,
|
|
110
|
+
$._macro_declaration_specifiers,
|
|
111
|
+
$._statement_declaration_modifiers,
|
|
112
|
+
$._guarded_type_specifiers,
|
|
113
|
+
],
|
|
114
|
+
[
|
|
115
|
+
$._macro_only_declaration,
|
|
116
|
+
$._macro_declaration_specifiers,
|
|
117
|
+
$._statement_declaration_modifiers,
|
|
118
|
+
$._guarded_type_specifiers,
|
|
119
|
+
$._statement_empty_declaration,
|
|
120
|
+
],
|
|
121
|
+
[
|
|
122
|
+
$._macro_declaration_specifiers,
|
|
123
|
+
$._statement_declaration_modifiers,
|
|
124
|
+
$._guarded_type_specifiers,
|
|
125
|
+
$.attributed_statement,
|
|
126
|
+
$.case_statement,
|
|
127
|
+
],
|
|
128
|
+
[$._macro_declaration_specifiers, $._statement_declaration_modifiers, $._guarded_type_specifiers],
|
|
129
|
+
[$._declarator, sym('_braced_macro_function_declarator')],
|
|
130
|
+
[
|
|
131
|
+
$._macro_declaration_specifiers,
|
|
132
|
+
$._declaration_modifiers,
|
|
133
|
+
$._guarded_type_specifiers,
|
|
134
|
+
$.attributed_statement,
|
|
135
|
+
$.case_statement,
|
|
136
|
+
],
|
|
137
|
+
[$._sized_bit_int_type_name, $._sized_bit_int_specifier],
|
|
138
|
+
[$.type_specifier, $._type_name_specifier, $._sized_bit_int_type_name, $._sized_bit_int_specifier],
|
|
139
|
+
[$._declaration_modifiers, $.type_descriptor],
|
|
140
|
+
[$.type_specifier, $._type_name_specifier, $.macro_specifier],
|
|
141
|
+
[$.type_specifier, $._type_name_specifier, $.expression, $.macro_specifier],
|
|
142
|
+
[$.type_specifier, $._type_name_specifier, $.expression, $.macro_type_specifier],
|
|
143
|
+
[$.type_specifier, $._type_name_specifier, $._sized_type_name, $.sized_type_specifier],
|
|
144
|
+
[$._sized_type_name, $._sized_bit_int_type_name, $.sized_type_specifier, $._sized_bit_int_specifier],
|
|
145
|
+
[$._sized_type_name, $.sized_type_specifier],
|
|
146
|
+
[$.storage_class_specifier, $.type_specifier, $._type_name_specifier, $.expression],
|
|
147
|
+
[$.storage_class_specifier, $.type_specifier, $._type_name_specifier],
|
|
148
|
+
[$.type_specifier, $._type_name_specifier, $.expression, $.va_arg_expression, $.macro_type_specifier],
|
|
149
|
+
[$.type_specifier, $._type_name_specifier],
|
|
150
|
+
[$.type_specifier, $._type_name_specifier, $.expression],
|
|
151
|
+
[$._known_annotation_type_specifier, $.sized_type_specifier],
|
|
152
|
+
[$._known_annotation_type_specifier, $._sized_bit_int_specifier],
|
|
153
|
+
[$._braced_macro_attribute_argument_list, $._variadic_macro_type_specifier],
|
|
154
|
+
[$._braced_macro_attribute_argument_list, $.macro_type_specifier],
|
|
155
|
+
[$._annotation_type_specifier, $.macro_specifier],
|
|
156
|
+
[$._macro_attribute_specifier, $._braced_leading_macro_attribute_specifier],
|
|
157
|
+
[$._annotation_type_specifier, $.sized_type_specifier],
|
|
158
|
+
[$._annotation_type_specifier, $._sized_bit_int_specifier],
|
|
159
|
+
[$._bare_initializer_type, $._annotation_type_specifier, $.type_specifier],
|
|
160
|
+
[$._bare_initializer_type, $._annotation_type_specifier, $.type_specifier, $.macro_specifier],
|
|
161
|
+
[$._annotation_type_specifier, $.type_specifier, $.macro_specifier],
|
|
162
|
+
[$._annotation_type_specifier, $.type_specifier, $.expression, $.macro_specifier],
|
|
163
|
+
[$.type_definition, $._annotation_type_specifier, $.type_specifier, $.sized_type_specifier],
|
|
164
|
+
[$.type_definition, $._annotation_type_specifier, $.type_specifier, $._sized_bit_int_specifier],
|
|
165
|
+
[$.type_definition, $._annotation_type_specifier, $.type_specifier],
|
|
166
|
+
[$._statement_type_definition, $._annotation_type_specifier, $.type_specifier, $.sized_type_specifier],
|
|
167
|
+
[$._statement_type_definition, $._annotation_type_specifier, $.type_specifier, $._sized_bit_int_specifier],
|
|
168
|
+
[$._statement_type_definition, $._annotation_type_specifier, $.type_specifier],
|
|
169
|
+
[$._annotation_type_specifier, $.type_specifier, $.sized_type_specifier],
|
|
170
|
+
[$._annotation_type_specifier, $.type_specifier, $._sized_bit_int_specifier],
|
|
171
|
+
[$._annotation_type_specifier, $.type_specifier, $.expression],
|
|
172
|
+
[$._annotation_type_specifier, $.type_specifier],
|
|
173
|
+
[
|
|
174
|
+
$._macro_declaration_specifiers,
|
|
175
|
+
$._statement_declaration_modifiers,
|
|
176
|
+
$._case_body_attributed_statement,
|
|
177
|
+
$._case_label_attributes,
|
|
178
|
+
],
|
|
179
|
+
[$._statement_declaration, $._macro_declaration_specifiers, $._statement_declaration_modifiers],
|
|
180
|
+
[
|
|
181
|
+
$._statement_declaration,
|
|
182
|
+
$._statement_type_definition,
|
|
183
|
+
$._macro_declaration_specifiers,
|
|
184
|
+
$._statement_declaration_modifiers,
|
|
185
|
+
$._statement_empty_declaration,
|
|
186
|
+
],
|
|
187
|
+
[
|
|
188
|
+
$._statement_declaration,
|
|
189
|
+
$._statement_type_definition,
|
|
190
|
+
$._macro_declaration_specifiers,
|
|
191
|
+
$._statement_declaration_modifiers,
|
|
192
|
+
],
|
|
193
|
+
[$._macro_declaration_specifiers, $._statement_declaration_modifiers, $._statement_empty_declaration],
|
|
194
|
+
[$._macro_declaration_specifiers, $._statement_declaration_modifiers],
|
|
195
|
+
[$._macro_declaration_specifiers, $._statement_declaration_modifiers, $.attributed_statement, $.case_statement],
|
|
196
|
+
[$._bare_initializer_type, $.macro_specifier],
|
|
197
|
+
[$.declaration, $._declaration_modifiers, $._marked_macro_type_specifiers],
|
|
198
|
+
[$._bare_initializer_type, $.type_specifier, $.macro_specifier],
|
|
199
|
+
[$._bare_initializer_type, $.type_specifier, $.macro_type_specifier],
|
|
200
|
+
[$._bare_initializer_type, $.type_specifier],
|
|
201
|
+
[$._guarded_macro_type_specifier, $.type_specifier],
|
|
202
|
+
[$._macro_declaration_specifiers, $._guarded_type_specifiers],
|
|
203
|
+
[$._macro_declaration_specifiers, $._guarded_type_specifiers, $._marked_macro_type_specifiers],
|
|
204
|
+
[$._macro_only_declaration, $._macro_declaration_specifiers, $._guarded_type_specifiers],
|
|
205
|
+
[$._macro_declaration_specifiers, $._declaration_modifiers, $._marked_macro_type_specifiers],
|
|
206
|
+
[
|
|
207
|
+
$._macro_declaration_specifiers,
|
|
208
|
+
$._declaration_modifiers,
|
|
209
|
+
$._guarded_type_specifiers,
|
|
210
|
+
$._marked_macro_type_specifiers,
|
|
211
|
+
],
|
|
212
|
+
[$._declaration_modifiers, $._marked_macro_type_specifiers],
|
|
213
|
+
[$.declaration, $._macro_declaration_specifiers, $._declaration_modifiers],
|
|
214
|
+
[$.declaration, $._macro_declaration_specifiers, $._declaration_modifiers, $._guarded_type_specifiers],
|
|
215
|
+
[
|
|
216
|
+
$.declaration,
|
|
217
|
+
$.type_definition,
|
|
218
|
+
$._macro_only_declaration,
|
|
219
|
+
$._macro_declaration_specifiers,
|
|
220
|
+
$._declaration_modifiers,
|
|
221
|
+
$._guarded_type_specifiers,
|
|
222
|
+
$._statement_empty_declaration,
|
|
223
|
+
],
|
|
224
|
+
[
|
|
225
|
+
$._macro_only_declaration,
|
|
226
|
+
$._macro_declaration_specifiers,
|
|
227
|
+
$._declaration_modifiers,
|
|
228
|
+
$._guarded_type_specifiers,
|
|
229
|
+
$._empty_declaration,
|
|
230
|
+
$._statement_empty_declaration,
|
|
231
|
+
],
|
|
232
|
+
[
|
|
233
|
+
$._macro_only_declaration,
|
|
234
|
+
$._macro_declaration_specifiers,
|
|
235
|
+
$._declaration_modifiers,
|
|
236
|
+
$._guarded_type_specifiers,
|
|
237
|
+
],
|
|
238
|
+
[
|
|
239
|
+
$._macro_only_declaration,
|
|
240
|
+
$._macro_declaration_specifiers,
|
|
241
|
+
$._declaration_modifiers,
|
|
242
|
+
$._guarded_type_specifiers,
|
|
243
|
+
$._statement_empty_declaration,
|
|
244
|
+
],
|
|
245
|
+
[$._macro_attribute_specifier, $.type_specifier, $.macro_type_specifier],
|
|
246
|
+
[$.type_specifier, $.macro_type_specifier, $._variadic_macro_type_specifier],
|
|
247
|
+
[$._macro_declaration_specifiers],
|
|
248
|
+
[$._macro_attribute_argument_list, $.macro_type_specifier],
|
|
249
|
+
[
|
|
250
|
+
$._macro_attribute_specifier,
|
|
251
|
+
$._braced_leading_macro_attribute_specifier,
|
|
252
|
+
$.type_specifier,
|
|
253
|
+
$.macro_type_specifier,
|
|
254
|
+
$._variadic_macro_type_specifier,
|
|
255
|
+
],
|
|
256
|
+
[$.declaration, $._declaration_modifiers, $._guarded_type_specifiers],
|
|
257
|
+
[$._declaration_modifiers, $._guarded_type_specifiers],
|
|
258
|
+
// Required by derived C++ declarations although unnecessary in C alone.
|
|
259
|
+
[
|
|
260
|
+
$._macro_declaration_specifiers,
|
|
261
|
+
$._declaration_modifiers,
|
|
262
|
+
$._guarded_type_specifiers,
|
|
263
|
+
$._empty_declaration,
|
|
264
|
+
$._statement_empty_declaration,
|
|
265
|
+
],
|
|
266
|
+
[$._macro_declaration_specifiers, $._declaration_modifiers, $._guarded_type_specifiers],
|
|
267
|
+
// Required by derived C++ declarations although unnecessary in C alone.
|
|
268
|
+
[
|
|
269
|
+
$._macro_declaration_specifiers,
|
|
270
|
+
$._declaration_modifiers,
|
|
271
|
+
$._guarded_type_specifiers,
|
|
272
|
+
$._statement_empty_declaration,
|
|
273
|
+
],
|
|
75
274
|
[$._string, $._raw_string_type_argument],
|
|
76
275
|
[
|
|
77
276
|
$._conditional_function_specifiers,
|
|
@@ -107,42 +306,21 @@ module.exports = Object.assign(
|
|
|
107
306
|
[$.type_specifier, $._sized_type_identifier, $.macro_specifier],
|
|
108
307
|
[$.type_specifier, $._sized_type_identifier],
|
|
109
308
|
[$._sized_type_identifier, $.macro_specifier],
|
|
110
|
-
[$._declaration_modifiers, $._empty_declaration],
|
|
111
|
-
[$._statement_declaration, $._statement_declaration_modifiers],
|
|
112
309
|
[$.declaration, $._declaration_modifiers],
|
|
113
|
-
[$._statement_declaration, $._statement_type_definition, $._statement_declaration_modifiers],
|
|
114
|
-
[
|
|
115
|
-
$._statement_declaration,
|
|
116
|
-
$._statement_type_definition,
|
|
117
|
-
$._statement_declaration_modifiers,
|
|
118
|
-
$._statement_empty_declaration,
|
|
119
|
-
],
|
|
120
310
|
[$.type_definition, $.type_specifier],
|
|
121
|
-
[$.type_definition, $._macro_declaration_specifiers],
|
|
122
311
|
[$._macro_declaration_specifiers, $._declaration_modifiers, $.attributed_statement, $.case_statement],
|
|
123
|
-
[$._macro_declaration_specifiers, $.type_specifier, $.expression, $.macro_specifier],
|
|
124
|
-
[$._macro_declaration_specifiers, $.type_specifier, $.macro_specifier],
|
|
125
312
|
[$.macro_specifier, $._type_declarator],
|
|
126
313
|
[$.macro_specifier, $._field_declarator],
|
|
127
314
|
[$.macro_specifier, $._declarator],
|
|
128
315
|
[$.macro_specifier, $._declarator, $.attributed_declarator, $.type_specifier],
|
|
129
316
|
[$.macro_specifier, $._declarator, $.attributed_declarator],
|
|
130
|
-
[$._macro_declaration_specifiers, $.type_specifier, $.sized_type_specifier],
|
|
131
|
-
[$.type_definition, $._macro_declaration_specifiers, $.type_specifier, $.sized_type_specifier],
|
|
132
|
-
[$._macro_declaration_specifiers, $.type_specifier, $._sized_bit_int_specifier],
|
|
133
|
-
[$.type_definition, $._macro_declaration_specifiers, $.type_specifier, $._sized_bit_int_specifier],
|
|
134
317
|
[$._statement_type_definition, $.type_specifier, $.sized_type_specifier],
|
|
135
318
|
[$._statement_type_definition, $.type_specifier, $._sized_bit_int_specifier],
|
|
136
|
-
[$._macro_declaration_specifiers, $.sized_type_specifier],
|
|
137
|
-
[$.type_definition, $._macro_declaration_specifiers, $.sized_type_specifier],
|
|
138
319
|
[$.type_definition, $.type_specifier, $.sized_type_specifier],
|
|
139
320
|
[$.type_definition, $.type_specifier, $._sized_bit_int_specifier],
|
|
140
321
|
[$._type_declarator, $.sized_type_specifier],
|
|
141
322
|
[$.macro_specifier, $.expression],
|
|
142
323
|
[$.macro_specifier, $.type_specifier],
|
|
143
|
-
[$._macro_declaration_specifiers, $.type_definition, $.type_specifier],
|
|
144
|
-
[$._macro_declaration_specifiers, $.type_specifier, $.expression],
|
|
145
|
-
[$._macro_declaration_specifiers, $.type_specifier],
|
|
146
324
|
[$._macro_declaration_specifiers, $._declaration_modifiers],
|
|
147
325
|
[$.preproc_include_argument],
|
|
148
326
|
[$._preproc_include_token, $.preproc_argument_list],
|
|
@@ -156,7 +334,6 @@ module.exports = Object.assign(
|
|
|
156
334
|
[sym('preproc_else_in_statement'), sym('preproc_else_in_initializer_list')],
|
|
157
335
|
[sym('preproc_elif_in_statement'), sym('preproc_elif_in_initializer_list')],
|
|
158
336
|
[sym('preproc_elifdef_in_statement'), sym('preproc_elifdef_in_initializer_list')],
|
|
159
|
-
|
|
160
337
|
[$.type_specifier, $.expression, $.va_arg_expression, $.macro_type_specifier],
|
|
161
338
|
[$.va_arg_expression, $.expression],
|
|
162
339
|
[$.type_definition, $._declaration_modifiers],
|
|
@@ -165,7 +342,6 @@ module.exports = Object.assign(
|
|
|
165
342
|
[$.type_definition, $.type_qualifier, $.extension_expression],
|
|
166
343
|
[$._statement_type_definition, $.type_qualifier, $.extension_expression],
|
|
167
344
|
[$.type_definition, $.type_qualifier],
|
|
168
|
-
[$.type_definition, $._declaration_modifiers, $._empty_declaration],
|
|
169
345
|
[$._statement_type_definition, $.type_qualifier],
|
|
170
346
|
[$._statement_declaration_modifiers, $._statement_empty_declaration],
|
|
171
347
|
[$.declaration, $.storage_class_specifier],
|
|
@@ -185,8 +361,6 @@ module.exports = Object.assign(
|
|
|
185
361
|
[$.type_definition, $.sized_type_specifier],
|
|
186
362
|
[$.type_definition, $._sized_bit_int_specifier],
|
|
187
363
|
[$.case_statement],
|
|
188
|
-
[$._statement_declaration_modifiers, $._case_body_attributed_statement, $._case_label_attributes],
|
|
189
|
-
[$._statement_declaration_modifiers, $.attributed_statement, $.case_statement],
|
|
190
364
|
[$.enum_specifier],
|
|
191
365
|
[sym('preproc_if_in_enumerator_list'), sym('preproc_if_in_enumerator_list_no_comma')],
|
|
192
366
|
[sym('preproc_ifdef_in_enumerator_list'), sym('preproc_ifdef_in_enumerator_list_no_comma')],
|
|
@@ -219,6 +393,16 @@ module.exports = Object.assign(
|
|
|
219
393
|
[$._declaration_modifiers, $._field_declaration_list_item],
|
|
220
394
|
[$._declaration_specifiers],
|
|
221
395
|
[$._compound_literal_constexpr_specifier, $.type_qualifier],
|
|
396
|
+
[$._marked_macro_type_specifiers],
|
|
397
|
+
[$._braced_leading_macro_attribute_specifier, $._post_type_macro_attribute_specifier],
|
|
398
|
+
[$._annotation_type_specifier, $._known_annotation_type_specifier, $.type_specifier, $._sized_bit_int_specifier],
|
|
399
|
+
[$._annotation_type_specifier, $._known_annotation_type_specifier, $.type_specifier],
|
|
400
|
+
[$._annotation_type_specifier, $._known_annotation_type_specifier, $.type_specifier, $.sized_type_specifier],
|
|
401
|
+
[$._annotation_type_specifier, $._macro_attribute_suffix, $.macro_type_specifier],
|
|
402
|
+
[$._annotation_type_specifier, $.macro_type_specifier],
|
|
403
|
+
[$._known_annotation_type_specifier, $.type_specifier, $.sized_type_specifier],
|
|
404
|
+
[$._known_annotation_type_specifier, $.type_specifier, $._sized_bit_int_specifier],
|
|
405
|
+
[$._known_annotation_type_specifier, $.type_specifier],
|
|
222
406
|
],
|
|
223
407
|
|
|
224
408
|
externals: () => [
|
|
@@ -239,11 +423,14 @@ module.exports = Object.assign(
|
|
|
239
423
|
sym('_leading_conditional_marker_ifndef'),
|
|
240
424
|
sym('_gnu_raw_string_body'),
|
|
241
425
|
sym('_raw_macro_type_tail'),
|
|
426
|
+
sym('_braced_function_attribute_start'),
|
|
427
|
+
sym('_braced_macro_type_start'),
|
|
242
428
|
],
|
|
243
429
|
|
|
244
430
|
extras: ($) => [$.pragma_operator, /\s|\\(?:\r\n?|\n\r?)/, $.comment],
|
|
245
431
|
|
|
246
432
|
inline: ($) => [
|
|
433
|
+
$._bare_marker_initializer_declaration,
|
|
247
434
|
$._unattributed_non_case_statement,
|
|
248
435
|
$._single_unattributed_non_case_statement,
|
|
249
436
|
$._unlabeled_non_case_statement,
|
|
@@ -274,15 +461,24 @@ module.exports = Object.assign(
|
|
|
274
461
|
$._case_label_chain_statement,
|
|
275
462
|
$.type_specifier,
|
|
276
463
|
$._type_name_specifier,
|
|
464
|
+
$._guarded_type_specifier,
|
|
465
|
+
sym('_annotation_type_specifier'),
|
|
466
|
+
sym('_known_annotation_type_specifier'),
|
|
467
|
+
$._guarded_macro_type_specifier,
|
|
468
|
+
sym('_bare_initializer_type'),
|
|
277
469
|
$._declarator,
|
|
278
470
|
$._old_style_declarator,
|
|
279
471
|
$._initialized_declarator,
|
|
472
|
+
sym('_guarded_initialized_declarator'),
|
|
473
|
+
sym('_braced_macro_declarator'),
|
|
280
474
|
$._initialized_parenthesized_content,
|
|
281
475
|
$._field_declarator,
|
|
282
476
|
$._type_declarator,
|
|
283
477
|
$._abstract_declarator,
|
|
284
478
|
],
|
|
285
479
|
|
|
480
|
+
reserved: { global: () => [], marker: ($) => [$.primitive_type] },
|
|
481
|
+
|
|
286
482
|
word: ($) => $.identifier,
|
|
287
483
|
|
|
288
484
|
rules: {
|
|
@@ -297,6 +493,7 @@ module.exports = Object.assign(
|
|
|
297
493
|
$.linkage_specification,
|
|
298
494
|
$.declaration,
|
|
299
495
|
alias(sym('_macro_modified_declaration'), $.declaration),
|
|
496
|
+
alias(sym('_macro_only_declaration'), $.declaration),
|
|
300
497
|
alias(sym('_trailing_macro_modified_declaration'), $.declaration),
|
|
301
498
|
alias(sym('_conditional_declaration'), $.declaration),
|
|
302
499
|
$._top_level_statement,
|
|
@@ -337,6 +534,7 @@ module.exports = Object.assign(
|
|
|
337
534
|
$.linkage_specification,
|
|
338
535
|
$.declaration,
|
|
339
536
|
alias(sym('_macro_modified_declaration'), $.declaration),
|
|
537
|
+
alias(sym('_macro_only_declaration'), $.declaration),
|
|
340
538
|
alias(sym('_trailing_macro_modified_declaration'), $.declaration),
|
|
341
539
|
alias(sym('_conditional_declaration'), $.declaration),
|
|
342
540
|
$.statement,
|
|
@@ -512,11 +710,14 @@ module.exports = Object.assign(
|
|
|
512
710
|
);
|
|
513
711
|
},
|
|
514
712
|
|
|
515
|
-
function_definition: ($) =>
|
|
516
|
-
|
|
517
|
-
|
|
713
|
+
function_definition: ($) =>
|
|
714
|
+
functionDefinitionRule($, functionDefinitionSpecifiers($, declarationSpecifiers($, true)), false),
|
|
715
|
+
_statement_function_definition: ($) =>
|
|
716
|
+
functionDefinitionRule($, functionDefinitionSpecifiers($, $._statement_declaration_specifiers), false),
|
|
717
|
+
_old_style_function_definition: ($) =>
|
|
718
|
+
functionDefinitionRule($, functionDefinitionSpecifiers($, declarationSpecifiers($, true)), true),
|
|
518
719
|
_statement_old_style_function_definition: ($) =>
|
|
519
|
-
functionDefinitionRule($, $._statement_declaration_specifiers, true),
|
|
720
|
+
functionDefinitionRule($, functionDefinitionSpecifiers($, $._statement_declaration_specifiers), true),
|
|
520
721
|
|
|
521
722
|
_old_style_declarator: ($) =>
|
|
522
723
|
choice(
|
|
@@ -561,9 +762,40 @@ module.exports = Object.assign(
|
|
|
561
762
|
repeat(choice($._non_macro_declaration_modifiers, $._conditional_macro_specifier))
|
|
562
763
|
),
|
|
563
764
|
|
|
564
|
-
declaration: ($) =>
|
|
765
|
+
declaration: ($) =>
|
|
766
|
+
choice(
|
|
767
|
+
declarationRule(
|
|
768
|
+
$,
|
|
769
|
+
choice(declarationSpecifiers($, true), $._guarded_type_specifiers, $._marked_macro_type_specifiers),
|
|
770
|
+
$._declaration_modifiers
|
|
771
|
+
),
|
|
772
|
+
sym('_bare_marker_initializer_declaration')
|
|
773
|
+
),
|
|
565
774
|
_statement_declaration: ($) =>
|
|
566
|
-
|
|
775
|
+
choice(
|
|
776
|
+
declarationRule(
|
|
777
|
+
$,
|
|
778
|
+
choice($._statement_declaration_specifiers, $._guarded_type_specifiers, $._marked_macro_type_specifiers),
|
|
779
|
+
$._statement_declaration_modifiers
|
|
780
|
+
),
|
|
781
|
+
sym('_bare_marker_initializer_declaration'),
|
|
782
|
+
$._macro_modified_declaration,
|
|
783
|
+
$._macro_only_declaration
|
|
784
|
+
),
|
|
785
|
+
_bare_marker_initializer_declaration: ($) =>
|
|
786
|
+
declarationRule(
|
|
787
|
+
$,
|
|
788
|
+
seq(
|
|
789
|
+
sym('_braced_macro_type_start'),
|
|
790
|
+
repeat($.macro_specifier),
|
|
791
|
+
field('type', alias(sym('_bare_initializer_type'), $.type_specifier))
|
|
792
|
+
),
|
|
793
|
+
$._statement_declaration_modifiers,
|
|
794
|
+
false,
|
|
795
|
+
$._declaration_declarator,
|
|
796
|
+
{ guard: sym('_braced_function_attribute_start'), bareMarkerInitializer: true }
|
|
797
|
+
),
|
|
798
|
+
_bare_initializer_type: ($) => $._type_identifier,
|
|
567
799
|
|
|
568
800
|
type_definition: ($) => typeDefinitionRule($, $._declaration_modifiers, true),
|
|
569
801
|
_statement_type_definition: ($) => typeDefinitionRule($, $._statement_declaration_modifiers, false),
|
|
@@ -574,7 +806,17 @@ module.exports = Object.assign(
|
|
|
574
806
|
$._macro_declaration_specifiers,
|
|
575
807
|
$._non_macro_declaration_modifiers,
|
|
576
808
|
false,
|
|
577
|
-
$._macro_declaration_declarator
|
|
809
|
+
$._macro_declaration_declarator,
|
|
810
|
+
{ guard: choice(sym('_post_type_function_attribute_suffix'), sym('_braced_function_attribute_start')) }
|
|
811
|
+
),
|
|
812
|
+
|
|
813
|
+
_macro_only_declaration: ($) =>
|
|
814
|
+
seq(
|
|
815
|
+
choice($.storage_class_specifier, $.type_qualifier, $.ms_declspec_modifier),
|
|
816
|
+
repeat($._non_macro_declaration_modifiers),
|
|
817
|
+
alias($._macro_attribute_specifier, $.attribute_specifier),
|
|
818
|
+
repeat(choice($._non_macro_declaration_modifiers, alias($._macro_attribute_suffix, $.attribute_specifier))),
|
|
819
|
+
';'
|
|
578
820
|
),
|
|
579
821
|
|
|
580
822
|
_conditional_declaration: ($) =>
|
|
@@ -583,7 +825,7 @@ module.exports = Object.assign(
|
|
|
583
825
|
_trailing_macro_modified_declaration: ($) =>
|
|
584
826
|
seq(
|
|
585
827
|
sym('_trailing_object_declaration_start'),
|
|
586
|
-
|
|
828
|
+
declarationSpecifiers($, true),
|
|
587
829
|
field('declarator', $._trailing_macro_object_declarator),
|
|
588
830
|
repeat1(alias($._trailing_macro_attribute_specifier, $.attribute_specifier)),
|
|
589
831
|
';'
|
|
@@ -607,14 +849,35 @@ module.exports = Object.assign(
|
|
|
607
849
|
seq(
|
|
608
850
|
choice($.storage_class_specifier, $.type_qualifier, $.ms_declspec_modifier),
|
|
609
851
|
repeat($._non_macro_declaration_modifiers),
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
852
|
+
choice(
|
|
853
|
+
seq(
|
|
854
|
+
alias($._macro_attribute_specifier, $.attribute_specifier),
|
|
855
|
+
repeat(modifier),
|
|
856
|
+
field('type', alias(sym('_known_annotation_type_specifier'), $.type_specifier))
|
|
857
|
+
),
|
|
858
|
+
seq(
|
|
859
|
+
alias(sym('_braced_leading_macro_attribute_specifier'), $.attribute_specifier),
|
|
860
|
+
repeat(modifier),
|
|
861
|
+
field(
|
|
862
|
+
'type',
|
|
863
|
+
choice(
|
|
864
|
+
alias(sym('_annotation_type_specifier'), $.type_specifier),
|
|
865
|
+
alias($._guarded_macro_type_specifier, $.type_specifier)
|
|
866
|
+
)
|
|
867
|
+
)
|
|
868
|
+
)
|
|
869
|
+
),
|
|
613
870
|
repeat(postModifier)
|
|
614
871
|
),
|
|
615
872
|
seq(
|
|
616
873
|
repeat($._non_macro_declaration_modifiers),
|
|
617
|
-
|
|
874
|
+
choice(
|
|
875
|
+
field('type', alias(sym('_annotation_type_specifier'), $.type_specifier)),
|
|
876
|
+
seq(
|
|
877
|
+
optional(choice(sym('_function_attribute_start'), sym('_braced_function_attribute_start'))),
|
|
878
|
+
field('type', alias($._guarded_macro_type_specifier, $.type_specifier))
|
|
879
|
+
)
|
|
880
|
+
),
|
|
618
881
|
repeat($._non_macro_declaration_modifiers),
|
|
619
882
|
alias($._post_type_macro_attribute_specifier, $.attribute_specifier),
|
|
620
883
|
repeat(postModifier)
|
|
@@ -622,6 +885,9 @@ module.exports = Object.assign(
|
|
|
622
885
|
);
|
|
623
886
|
},
|
|
624
887
|
|
|
888
|
+
_annotation_type_specifier: ($) => choice($._non_identifier_type_specifier, $._type_identifier),
|
|
889
|
+
_known_annotation_type_specifier: ($) => $._non_identifier_type_specifier,
|
|
890
|
+
|
|
625
891
|
_type_definition_type: ($) =>
|
|
626
892
|
seq(
|
|
627
893
|
repeat(choice($.type_qualifier, $.macro_specifier, $._leading_conditional_macro_specifier)),
|
|
@@ -644,13 +910,75 @@ module.exports = Object.assign(
|
|
|
644
910
|
$.ms_declspec_modifier
|
|
645
911
|
),
|
|
646
912
|
|
|
647
|
-
_declaration_specifiers: ($) =>
|
|
913
|
+
_declaration_specifiers: ($) => declarationSpecifiers($),
|
|
914
|
+
|
|
915
|
+
_guarded_type_specifiers: ($) =>
|
|
916
|
+
prec.dynamic(
|
|
917
|
+
1,
|
|
918
|
+
seq(
|
|
919
|
+
$._non_macro_declaration_modifiers,
|
|
920
|
+
repeat($._non_macro_declaration_modifiers),
|
|
921
|
+
choice(
|
|
922
|
+
seq(sym('_function_attribute_start'), field('type', $.type_specifier)),
|
|
923
|
+
seq(
|
|
924
|
+
sym('_braced_function_attribute_start'),
|
|
925
|
+
field('type', alias($._guarded_type_specifier, $.type_specifier))
|
|
926
|
+
)
|
|
927
|
+
),
|
|
928
|
+
repeat(choice($._non_macro_declaration_modifiers, $._conditional_macro_specifier))
|
|
929
|
+
)
|
|
930
|
+
),
|
|
931
|
+
|
|
932
|
+
_marked_macro_type_specifiers: ($) =>
|
|
648
933
|
seq(
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
934
|
+
sym('_braced_macro_type_start'),
|
|
935
|
+
choice(
|
|
936
|
+
prec.dynamic(
|
|
937
|
+
2,
|
|
938
|
+
seq(
|
|
939
|
+
repeat($._non_macro_declaration_modifiers),
|
|
940
|
+
repeat1(seq($.macro_specifier, repeat($._non_macro_declaration_modifiers))),
|
|
941
|
+
optional(sym('_braced_function_attribute_start')),
|
|
942
|
+
field(
|
|
943
|
+
'type',
|
|
944
|
+
choice(
|
|
945
|
+
alias(sym('_known_annotation_type_specifier'), $.type_specifier),
|
|
946
|
+
alias($._guarded_macro_type_specifier, $.type_specifier)
|
|
947
|
+
)
|
|
948
|
+
),
|
|
949
|
+
repeat($._non_macro_declaration_modifiers)
|
|
950
|
+
)
|
|
951
|
+
),
|
|
952
|
+
declarationSpecifiers($, true),
|
|
953
|
+
$._guarded_type_specifiers,
|
|
954
|
+
$._macro_declaration_specifiers,
|
|
955
|
+
seq(
|
|
956
|
+
repeat($._declaration_modifiers),
|
|
957
|
+
field(
|
|
958
|
+
'type',
|
|
959
|
+
choice(
|
|
960
|
+
alias(sym('_known_annotation_type_specifier'), $.type_specifier),
|
|
961
|
+
alias($._guarded_macro_type_specifier, $.type_specifier)
|
|
962
|
+
)
|
|
963
|
+
),
|
|
964
|
+
repeat($._non_macro_declaration_modifiers),
|
|
965
|
+
alias(sym('_braced_leading_macro_attribute_specifier'), $.attribute_specifier),
|
|
966
|
+
repeat(
|
|
967
|
+
choice(
|
|
968
|
+
$._non_macro_declaration_modifiers,
|
|
969
|
+
$.macro_specifier,
|
|
970
|
+
alias($._post_type_macro_attribute_suffix, $.attribute_specifier)
|
|
971
|
+
)
|
|
972
|
+
)
|
|
973
|
+
)
|
|
974
|
+
)
|
|
652
975
|
),
|
|
653
976
|
|
|
977
|
+
_guarded_macro_type_specifier: ($) => $.macro_type_specifier,
|
|
978
|
+
|
|
979
|
+
_guarded_type_specifier: ($) =>
|
|
980
|
+
choice($.type_specifier, alias($._variadic_macro_type_specifier, $.macro_type_specifier)),
|
|
981
|
+
|
|
654
982
|
_field_declaration_specifiers: ($) =>
|
|
655
983
|
seq(
|
|
656
984
|
repeat($._declaration_modifiers),
|
|
@@ -676,6 +1004,8 @@ module.exports = Object.assign(
|
|
|
676
1004
|
|
|
677
1005
|
_macro_attribute_specifier: ($) => macroAttributeRule($, 'leading'),
|
|
678
1006
|
|
|
1007
|
+
_braced_leading_macro_attribute_specifier: ($) => macroAttributeRule($, 'braced-leading'),
|
|
1008
|
+
|
|
679
1009
|
_post_type_macro_attribute_specifier: ($) => macroAttributeRule($, 'post-type'),
|
|
680
1010
|
|
|
681
1011
|
_macro_attribute_suffix: ($) => macroAttributeRule($, 'continuation'),
|
|
@@ -684,10 +1014,14 @@ module.exports = Object.assign(
|
|
|
684
1014
|
|
|
685
1015
|
_post_type_macro_attribute_suffix: ($) => macroAttributeRule($, 'post-type-continuation'),
|
|
686
1016
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
1017
|
+
_macro_attribute_parameter: ($) =>
|
|
1018
|
+
seq($._declaration_specifiers, field('declarator', $._declarator), repeat($.attribute_specifier)),
|
|
1019
|
+
|
|
1020
|
+
_macro_attribute_argument_list: ($) => macroAttributeArgumentList(macroAttributeArgument($)),
|
|
1021
|
+
_braced_macro_attribute_argument_list: ($) =>
|
|
1022
|
+
macroAttributeArgumentList(
|
|
1023
|
+
choice(macroAttributeArgument($), alias(sym('_macro_attribute_parameter'), $.parameter_declaration))
|
|
1024
|
+
),
|
|
691
1025
|
|
|
692
1026
|
attribute: ($) =>
|
|
693
1027
|
seq(optional(seq(field('prefix', $.identifier), '::')), field('name', $.identifier), optional($.argument_list)),
|
|
@@ -738,6 +1072,13 @@ module.exports = Object.assign(
|
|
|
738
1072
|
|
|
739
1073
|
_macro_declaration_declarator: ($) => declarationDeclaratorRule($, $.function_declarator),
|
|
740
1074
|
|
|
1075
|
+
_braced_macro_declarator: ($) => alias(sym('_braced_macro_function_declarator'), $.function_declarator),
|
|
1076
|
+
_braced_macro_function_declarator: ($) =>
|
|
1077
|
+
seq(
|
|
1078
|
+
field('declarator', $.identifier),
|
|
1079
|
+
field('parameters', alias(sym('_braced_macro_attribute_argument_list'), $.parameter_list))
|
|
1080
|
+
),
|
|
1081
|
+
|
|
741
1082
|
_field_declarator: ($) =>
|
|
742
1083
|
choice(alias($.attributed_field_declarator, $.attributed_declarator), $._unattributed_field_declarator),
|
|
743
1084
|
|
|
@@ -927,12 +1268,13 @@ module.exports = Object.assign(
|
|
|
927
1268
|
)
|
|
928
1269
|
),
|
|
929
1270
|
|
|
930
|
-
init_declarator: ($) =>
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
1271
|
+
init_declarator: ($) => initDeclaratorRule($, alias($._initialized_declarator, $._declarator)),
|
|
1272
|
+
_guarded_init_declarator: ($) =>
|
|
1273
|
+
initDeclaratorRule($, alias(sym('_guarded_initialized_declarator'), $._declarator)),
|
|
1274
|
+
_guarded_initialized_declarator: ($) => $._declaration_declarator,
|
|
1275
|
+
|
|
1276
|
+
_braced_macro_init_declarator: ($) =>
|
|
1277
|
+
initDeclaratorRule($, alias(sym('_braced_macro_declarator'), $._declarator)),
|
|
936
1278
|
|
|
937
1279
|
_initialized_declarator: ($) =>
|
|
938
1280
|
choice(
|
|
@@ -1868,7 +2210,7 @@ module.exports = Object.assign(
|
|
|
1868
2210
|
';'
|
|
1869
2211
|
),
|
|
1870
2212
|
|
|
1871
|
-
macro_specifier: ($) => prec.dynamic(-2, field('name', $.identifier)),
|
|
2213
|
+
macro_specifier: ($) => prec.dynamic(-2, field('name', reserved('marker', $.identifier))),
|
|
1872
2214
|
|
|
1873
2215
|
_conditional_macro_specifier: () => alias(sym('_marker_preproc_ifdef'), sym('preproc_ifdef')),
|
|
1874
2216
|
_leading_conditional_macro_specifier: () => alias(sym('_leading_marker_preproc_ifdef'), sym('preproc_ifdef')),
|
|
@@ -1890,14 +2232,40 @@ module.exports = Object.assign(
|
|
|
1890
2232
|
)
|
|
1891
2233
|
),
|
|
1892
2234
|
|
|
2235
|
+
_variadic_macro_type_specifier: ($) =>
|
|
2236
|
+
prec.dynamic(
|
|
2237
|
+
-2,
|
|
2238
|
+
seq(
|
|
2239
|
+
field('name', choice($.identifier, alias(VA_ARG_KEYWORDS, $.identifier))),
|
|
2240
|
+
'(',
|
|
2241
|
+
field('type', $.type_descriptor),
|
|
2242
|
+
repeat1(seq(',', optional(macroAttributeArgument($)))),
|
|
2243
|
+
')'
|
|
2244
|
+
)
|
|
2245
|
+
),
|
|
2246
|
+
|
|
1893
2247
|
_raw_string_macro_type_arguments: ($) =>
|
|
1894
|
-
seq('(', $._raw_string_type_argument, optional(
|
|
2248
|
+
seq('(', $._raw_string_type_argument, optional($._raw_string_type_tail), ')'),
|
|
1895
2249
|
|
|
1896
2250
|
_raw_string_type_argument: ($) =>
|
|
1897
2251
|
choice($.raw_string_literal, alias($._parenthesized_raw_string_type_argument, $.parenthesized_expression)),
|
|
1898
2252
|
|
|
1899
2253
|
_parenthesized_raw_string_type_argument: ($) =>
|
|
1900
|
-
seq('(', $._raw_string_type_argument, optional(
|
|
2254
|
+
seq('(', $._raw_string_type_argument, optional($._raw_string_type_tail), ')'),
|
|
2255
|
+
|
|
2256
|
+
// The opaque tail scanner stops before a balanced group's first brace, so those arguments are parsed here.
|
|
2257
|
+
_raw_string_type_tail: ($) =>
|
|
2258
|
+
choice(
|
|
2259
|
+
alias(sym('_raw_macro_type_tail'), $.preproc_arg),
|
|
2260
|
+
repeat1(
|
|
2261
|
+
seq(
|
|
2262
|
+
',',
|
|
2263
|
+
optional(
|
|
2264
|
+
choice(macroAttributeArgument($), alias(sym('_macro_attribute_parameter'), $.parameter_declaration))
|
|
2265
|
+
)
|
|
2266
|
+
)
|
|
2267
|
+
)
|
|
2268
|
+
),
|
|
1901
2269
|
|
|
1902
2270
|
_preproc_number: () =>
|
|
1903
2271
|
/(\d|\.\d)([\p{XID_Continue}.]|[eEpP][+-]|'[_a-zA-Z0-9]|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8})*/u,
|
|
@@ -1905,9 +2273,24 @@ module.exports = Object.assign(
|
|
|
1905
2273
|
comment: () => token(choice(LINE_COMMENT, seq('/*', /[^*]*\*+([^/*][^*]*\*+)*/, '/'))),
|
|
1906
2274
|
},
|
|
1907
2275
|
}),
|
|
1908
|
-
{ PREC, preprocIf, preprocessor, commaSep, commaSep1 }
|
|
2276
|
+
{ PREC, preprocIf, preprocessor, commaSep, commaSep1, declarationSpecifiers }
|
|
1909
2277
|
);
|
|
1910
2278
|
|
|
2279
|
+
/**
|
|
2280
|
+
* Build declaration specifiers, optionally retaining real types after a braced group guard.
|
|
2281
|
+
* @param {import('./types/treeSitterDsl').GrammarSymbols<'_declaration_specifiers' | '_declaration_modifiers' | 'type_specifier' | '_non_macro_declaration_modifiers'>} $
|
|
2282
|
+
* @param {boolean} [braced=false] Enable the guard for declaration owners; parameter and annotation readers keep it off.
|
|
2283
|
+
*/
|
|
2284
|
+
function declarationSpecifiers($, braced = false) {
|
|
2285
|
+
const specifiers = seq(
|
|
2286
|
+
repeat($._declaration_modifiers),
|
|
2287
|
+
...(braced ? [sym('_braced_function_attribute_start')] : []),
|
|
2288
|
+
field('type', $.type_specifier),
|
|
2289
|
+
repeat($._non_macro_declaration_modifiers)
|
|
2290
|
+
);
|
|
2291
|
+
return braced ? choice($._declaration_specifiers, specifiers) : specifiers;
|
|
2292
|
+
}
|
|
2293
|
+
|
|
1911
2294
|
/**
|
|
1912
2295
|
* @param {import('./types/treeSitterDsl').GrammarSymbols<'comment' | 'pragma_operator' | 'preproc_arg'>} $
|
|
1913
2296
|
* @param {import('./types/treeSitterDsl').Rule} directive
|
|
@@ -1971,6 +2354,14 @@ function pointerDeclaratorRule($, declarator) {
|
|
|
1971
2354
|
);
|
|
1972
2355
|
}
|
|
1973
2356
|
|
|
2357
|
+
/**
|
|
2358
|
+
* @param {import('./types/treeSitterDsl').GrammarSymbols<'_guarded_type_specifiers' | '_marked_macro_type_specifiers' | '_macro_declaration_specifiers'>} $
|
|
2359
|
+
* @param {import('./types/treeSitterDsl').Rule} ordinary
|
|
2360
|
+
*/
|
|
2361
|
+
function functionDefinitionSpecifiers($, ordinary) {
|
|
2362
|
+
return choice(ordinary, $._guarded_type_specifiers, $._marked_macro_type_specifiers, $._macro_declaration_specifiers);
|
|
2363
|
+
}
|
|
2364
|
+
|
|
1974
2365
|
/**
|
|
1975
2366
|
* @param {import('./types/treeSitterDsl').GrammarSymbols<'ms_call_modifier' | '_old_style_declarator' | '_declarator' | 'declaration' | 'compound_statement'>} $
|
|
1976
2367
|
* @param {import('./types/treeSitterDsl').Rule} specifiers
|
|
@@ -1981,20 +2372,54 @@ function functionDefinitionRule($, specifiers, oldStyle) {
|
|
|
1981
2372
|
optional($.ms_call_modifier),
|
|
1982
2373
|
specifiers,
|
|
1983
2374
|
...(oldStyle ? [] : [optional($.ms_call_modifier)]),
|
|
1984
|
-
|
|
2375
|
+
choice(
|
|
2376
|
+
seq(
|
|
2377
|
+
optional(choice(sym('_post_type_function_attribute_start'), sym('_braced_function_attribute_start'))),
|
|
2378
|
+
field('declarator', oldStyle ? alias($._old_style_declarator, $._declarator) : $._declarator)
|
|
2379
|
+
),
|
|
2380
|
+
seq(
|
|
2381
|
+
sym('_braced_function_attribute_start'),
|
|
2382
|
+
field('declarator', alias(sym('_braced_macro_declarator'), $._declarator))
|
|
2383
|
+
)
|
|
2384
|
+
),
|
|
1985
2385
|
...(oldStyle ? [repeat1($.declaration)] : []),
|
|
1986
2386
|
field('body', $.compound_statement)
|
|
1987
2387
|
);
|
|
1988
2388
|
}
|
|
1989
2389
|
|
|
1990
2390
|
/**
|
|
1991
|
-
* @param {import('./types/treeSitterDsl').GrammarSymbols<'storage_class_specifier' | 'ms_call_modifier' | '_declaration_declarator' | 'gnu_asm_expression' | 'init_declarator' | 'type_qualifier' | 'identifier'>} $
|
|
2391
|
+
* @param {import('./types/treeSitterDsl').GrammarSymbols<'storage_class_specifier' | 'ms_call_modifier' | '_declaration_declarator' | '_declarator' | 'gnu_asm_expression' | 'init_declarator' | 'type_qualifier' | 'identifier'>} $
|
|
1992
2392
|
* @param {import('./types/treeSitterDsl').Rule} specifiers
|
|
1993
2393
|
* @param {import('./types/treeSitterDsl').Rule} modifiers
|
|
1994
2394
|
* @param {boolean} allowInferredType
|
|
1995
2395
|
* @param {import('./types/treeSitterDsl').Rule} declarator
|
|
2396
|
+
* @param {{guard?: import('./types/treeSitterDsl').Rule, bareMarkerInitializer?: boolean}} options
|
|
1996
2397
|
*/
|
|
1997
|
-
function declarationRule(
|
|
2398
|
+
function declarationRule(
|
|
2399
|
+
$,
|
|
2400
|
+
specifiers,
|
|
2401
|
+
modifiers,
|
|
2402
|
+
allowInferredType = true,
|
|
2403
|
+
declarator = $._declaration_declarator,
|
|
2404
|
+
{
|
|
2405
|
+
guard = choice(sym('_post_type_function_attribute_start'), sym('_braced_function_attribute_start')),
|
|
2406
|
+
bareMarkerInitializer = false,
|
|
2407
|
+
} = {}
|
|
2408
|
+
) {
|
|
2409
|
+
const initialized = choice(
|
|
2410
|
+
bareMarkerInitializer
|
|
2411
|
+
? seq(optional(guard), $.init_declarator)
|
|
2412
|
+
: choice($.init_declarator, seq(guard, alias(sym('_guarded_init_declarator'), $.init_declarator))),
|
|
2413
|
+
seq(sym('_braced_function_attribute_start'), alias(sym('_braced_macro_init_declarator'), $.init_declarator))
|
|
2414
|
+
);
|
|
2415
|
+
const item = choice(
|
|
2416
|
+
seq(optional($.ms_call_modifier), optional(guard), declarator, optional($.gnu_asm_expression)),
|
|
2417
|
+
seq(sym('_braced_function_attribute_start'), alias(sym('_braced_macro_declarator'), $._declarator)),
|
|
2418
|
+
initialized
|
|
2419
|
+
);
|
|
2420
|
+
const items = bareMarkerInitializer
|
|
2421
|
+
? seq(field('declarator', initialized), repeat(seq(',', field('declarator', item))))
|
|
2422
|
+
: commaSep1(field('declarator', item));
|
|
1998
2423
|
return choice(
|
|
1999
2424
|
seq(
|
|
2000
2425
|
prec.dynamic(
|
|
@@ -2009,12 +2434,7 @@ function declarationRule($, specifiers, modifiers, allowInferredType = true, dec
|
|
|
2009
2434
|
)
|
|
2010
2435
|
: specifiers
|
|
2011
2436
|
),
|
|
2012
|
-
|
|
2013
|
-
field(
|
|
2014
|
-
'declarator',
|
|
2015
|
-
choice(seq(optional($.ms_call_modifier), declarator, optional($.gnu_asm_expression)), $.init_declarator)
|
|
2016
|
-
)
|
|
2017
|
-
),
|
|
2437
|
+
items,
|
|
2018
2438
|
';'
|
|
2019
2439
|
),
|
|
2020
2440
|
...(allowInferredType
|
|
@@ -2023,6 +2443,14 @@ function declarationRule($, specifiers, modifiers, allowInferredType = true, dec
|
|
|
2023
2443
|
);
|
|
2024
2444
|
}
|
|
2025
2445
|
|
|
2446
|
+
/**
|
|
2447
|
+
* @param {import('./types/treeSitterDsl').GrammarSymbols<'initializer_list' | 'expression'>} $
|
|
2448
|
+
* @param {import('./types/treeSitterDsl').Rule} declarator
|
|
2449
|
+
*/
|
|
2450
|
+
function initDeclaratorRule($, declarator) {
|
|
2451
|
+
return seq(field('declarator', declarator), '=', field('value', choice($.initializer_list, $.expression)));
|
|
2452
|
+
}
|
|
2453
|
+
|
|
2026
2454
|
/**
|
|
2027
2455
|
* @param {import('./types/treeSitterDsl').GrammarSymbols<'macro_specifier' | '_leading_conditional_macro_specifier' | 'type_qualifier' | '_type_definition_type' | '_non_identifier_type_specifier' | '_type_definition_declarators' | 'attribute_specifier'>} $
|
|
2028
2456
|
* @param {import('./types/treeSitterDsl').Rule} modifiers
|
|
@@ -2066,13 +2494,25 @@ function declarationDeclaratorRule($, functionDeclarator) {
|
|
|
2066
2494
|
|
|
2067
2495
|
/**
|
|
2068
2496
|
* @param {import('./types/treeSitterDsl').GrammarSymbols<'identifier' | 'argument_list' | '_macro_attribute_argument_list'>} $
|
|
2069
|
-
* @param {'leading' | 'post-type' | 'continuation' | 'post-type-continuation' | 'trailing'} context
|
|
2497
|
+
* @param {'leading' | 'braced-leading' | 'post-type' | 'continuation' | 'post-type-continuation' | 'trailing'} context
|
|
2070
2498
|
*/
|
|
2071
2499
|
function macroAttributeRule($, context) {
|
|
2072
|
-
const
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2500
|
+
const name = field(
|
|
2501
|
+
'name',
|
|
2502
|
+
context === 'trailing' ? alias(sym('_trailing_macro_attribute_name'), $.identifier) : $.identifier
|
|
2503
|
+
);
|
|
2504
|
+
const ordinary = seq(name, field('arguments', alias($._macro_attribute_argument_list, $.argument_list)));
|
|
2505
|
+
if (context === 'trailing') return prec.dynamic(-2, ordinary);
|
|
2506
|
+
const braced = seq(
|
|
2507
|
+
sym('_braced_function_attribute_start'),
|
|
2508
|
+
name,
|
|
2509
|
+
field('arguments', alias(sym('_braced_macro_attribute_argument_list'), $.argument_list))
|
|
2510
|
+
);
|
|
2511
|
+
if (context === 'braced-leading') return prec.dynamic(-2, braced);
|
|
2512
|
+
const guarded =
|
|
2513
|
+
context === 'continuation'
|
|
2514
|
+
? ordinary
|
|
2515
|
+
: seq(
|
|
2076
2516
|
sym(
|
|
2077
2517
|
context === 'leading'
|
|
2078
2518
|
? '_function_attribute_start'
|
|
@@ -2080,20 +2520,26 @@ function macroAttributeRule($, context) {
|
|
|
2080
2520
|
? '_post_type_function_attribute_start'
|
|
2081
2521
|
: '_post_type_function_attribute_suffix'
|
|
2082
2522
|
),
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
seq(
|
|
2087
|
-
...guard,
|
|
2088
|
-
field('name', context === 'trailing' ? alias(sym('_trailing_macro_attribute_name'), $.identifier) : $.identifier),
|
|
2089
|
-
field('arguments', alias($._macro_attribute_argument_list, $.argument_list))
|
|
2090
|
-
)
|
|
2091
|
-
);
|
|
2523
|
+
ordinary
|
|
2524
|
+
);
|
|
2525
|
+
return prec.dynamic(-2, choice(guarded, braced));
|
|
2092
2526
|
}
|
|
2093
2527
|
|
|
2094
|
-
/** @param {import('./types/treeSitterDsl').
|
|
2528
|
+
/** @param {import('./types/treeSitterDsl').Rule} argument */
|
|
2529
|
+
function macroAttributeArgumentList(argument) {
|
|
2530
|
+
return seq('(', optional(argument), repeat(seq(',', optional(argument))), ')');
|
|
2531
|
+
}
|
|
2532
|
+
|
|
2533
|
+
/** @param {import('./types/treeSitterDsl').GrammarSymbols<'expression' | 'parameter_declaration' | 'type_descriptor' | '_preproc_number' | 'number_literal' | 'compound_statement' | 'initializer_pair' | 'initializer_list'>} $ */
|
|
2095
2534
|
function macroAttributeArgument($) {
|
|
2096
|
-
return choice(
|
|
2535
|
+
return choice(
|
|
2536
|
+
$.expression,
|
|
2537
|
+
prec.dynamic(-1, $.type_descriptor),
|
|
2538
|
+
alias($._preproc_number, $.number_literal),
|
|
2539
|
+
$.compound_statement,
|
|
2540
|
+
$.initializer_pair,
|
|
2541
|
+
prec.dynamic(-1, $.initializer_list)
|
|
2542
|
+
);
|
|
2097
2543
|
}
|
|
2098
2544
|
|
|
2099
2545
|
/**
|