@willbooster/tree-sitter-c 18.3.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 +80 -16
- package/grammar.js +583 -98
- package/package.json +4 -3
- package/queries/highlights.scm +1 -0
- package/src/conditionalMacro.h +2 -2
- package/src/functionMacro.h +285 -51
- package/src/gnuRawString.h +70 -0
- package/src/keywords.h +37 -0
- package/src/node-types.json +113 -24
- package/src/pragma.h +58 -7
- package/src/scanner.c +22 -5
- package/tree-sitter-c.wasm +0 -0
- package/tree-sitter.json +3 -2
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.
|
|
@@ -60,6 +60,7 @@ const BINARY_OPERATORS = [
|
|
|
60
60
|
['>>', PREC.SHIFT],
|
|
61
61
|
];
|
|
62
62
|
|
|
63
|
+
const LINE_SPLICE = /\\(?:\r\n?|\n\r?)/;
|
|
63
64
|
const LINE_COMMENT = seq('//', /(\\+(.|\r?\n)|[^\\\n])*/);
|
|
64
65
|
const PRAGMA_SPACING = repeat(choice(/\s/, /\\(?:\r\n?|\n\r?)/));
|
|
65
66
|
const PREPROC_ARGUMENT = /\S([^/\n]|\/[^*]|\\\r?\n)*/;
|
|
@@ -71,6 +72,206 @@ module.exports = Object.assign(
|
|
|
71
72
|
name: 'c',
|
|
72
73
|
|
|
73
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
|
+
],
|
|
274
|
+
[$._string, $._raw_string_type_argument],
|
|
74
275
|
[
|
|
75
276
|
$._conditional_function_specifiers,
|
|
76
277
|
$._declaration_specifiers,
|
|
@@ -105,42 +306,21 @@ module.exports = Object.assign(
|
|
|
105
306
|
[$.type_specifier, $._sized_type_identifier, $.macro_specifier],
|
|
106
307
|
[$.type_specifier, $._sized_type_identifier],
|
|
107
308
|
[$._sized_type_identifier, $.macro_specifier],
|
|
108
|
-
[$._declaration_modifiers, $._empty_declaration],
|
|
109
|
-
[$._statement_declaration, $._statement_declaration_modifiers],
|
|
110
309
|
[$.declaration, $._declaration_modifiers],
|
|
111
|
-
[$._statement_declaration, $._statement_type_definition, $._statement_declaration_modifiers],
|
|
112
|
-
[
|
|
113
|
-
$._statement_declaration,
|
|
114
|
-
$._statement_type_definition,
|
|
115
|
-
$._statement_declaration_modifiers,
|
|
116
|
-
$._statement_empty_declaration,
|
|
117
|
-
],
|
|
118
310
|
[$.type_definition, $.type_specifier],
|
|
119
|
-
[$.type_definition, $._macro_declaration_specifiers],
|
|
120
311
|
[$._macro_declaration_specifiers, $._declaration_modifiers, $.attributed_statement, $.case_statement],
|
|
121
|
-
[$._macro_declaration_specifiers, $.type_specifier, $.expression, $.macro_specifier],
|
|
122
|
-
[$._macro_declaration_specifiers, $.type_specifier, $.macro_specifier],
|
|
123
312
|
[$.macro_specifier, $._type_declarator],
|
|
124
313
|
[$.macro_specifier, $._field_declarator],
|
|
125
314
|
[$.macro_specifier, $._declarator],
|
|
126
315
|
[$.macro_specifier, $._declarator, $.attributed_declarator, $.type_specifier],
|
|
127
316
|
[$.macro_specifier, $._declarator, $.attributed_declarator],
|
|
128
|
-
[$._macro_declaration_specifiers, $.type_specifier, $.sized_type_specifier],
|
|
129
|
-
[$.type_definition, $._macro_declaration_specifiers, $.type_specifier, $.sized_type_specifier],
|
|
130
|
-
[$._macro_declaration_specifiers, $.type_specifier, $._sized_bit_int_specifier],
|
|
131
|
-
[$.type_definition, $._macro_declaration_specifiers, $.type_specifier, $._sized_bit_int_specifier],
|
|
132
317
|
[$._statement_type_definition, $.type_specifier, $.sized_type_specifier],
|
|
133
318
|
[$._statement_type_definition, $.type_specifier, $._sized_bit_int_specifier],
|
|
134
|
-
[$._macro_declaration_specifiers, $.sized_type_specifier],
|
|
135
|
-
[$.type_definition, $._macro_declaration_specifiers, $.sized_type_specifier],
|
|
136
319
|
[$.type_definition, $.type_specifier, $.sized_type_specifier],
|
|
137
320
|
[$.type_definition, $.type_specifier, $._sized_bit_int_specifier],
|
|
138
321
|
[$._type_declarator, $.sized_type_specifier],
|
|
139
322
|
[$.macro_specifier, $.expression],
|
|
140
323
|
[$.macro_specifier, $.type_specifier],
|
|
141
|
-
[$._macro_declaration_specifiers, $.type_definition, $.type_specifier],
|
|
142
|
-
[$._macro_declaration_specifiers, $.type_specifier, $.expression],
|
|
143
|
-
[$._macro_declaration_specifiers, $.type_specifier],
|
|
144
324
|
[$._macro_declaration_specifiers, $._declaration_modifiers],
|
|
145
325
|
[$.preproc_include_argument],
|
|
146
326
|
[$._preproc_include_token, $.preproc_argument_list],
|
|
@@ -154,7 +334,6 @@ module.exports = Object.assign(
|
|
|
154
334
|
[sym('preproc_else_in_statement'), sym('preproc_else_in_initializer_list')],
|
|
155
335
|
[sym('preproc_elif_in_statement'), sym('preproc_elif_in_initializer_list')],
|
|
156
336
|
[sym('preproc_elifdef_in_statement'), sym('preproc_elifdef_in_initializer_list')],
|
|
157
|
-
|
|
158
337
|
[$.type_specifier, $.expression, $.va_arg_expression, $.macro_type_specifier],
|
|
159
338
|
[$.va_arg_expression, $.expression],
|
|
160
339
|
[$.type_definition, $._declaration_modifiers],
|
|
@@ -163,7 +342,6 @@ module.exports = Object.assign(
|
|
|
163
342
|
[$.type_definition, $.type_qualifier, $.extension_expression],
|
|
164
343
|
[$._statement_type_definition, $.type_qualifier, $.extension_expression],
|
|
165
344
|
[$.type_definition, $.type_qualifier],
|
|
166
|
-
[$.type_definition, $._declaration_modifiers, $._empty_declaration],
|
|
167
345
|
[$._statement_type_definition, $.type_qualifier],
|
|
168
346
|
[$._statement_declaration_modifiers, $._statement_empty_declaration],
|
|
169
347
|
[$.declaration, $.storage_class_specifier],
|
|
@@ -183,8 +361,6 @@ module.exports = Object.assign(
|
|
|
183
361
|
[$.type_definition, $.sized_type_specifier],
|
|
184
362
|
[$.type_definition, $._sized_bit_int_specifier],
|
|
185
363
|
[$.case_statement],
|
|
186
|
-
[$._statement_declaration_modifiers, $._case_body_attributed_statement, $._case_label_attributes],
|
|
187
|
-
[$._statement_declaration_modifiers, $.attributed_statement, $.case_statement],
|
|
188
364
|
[$.enum_specifier],
|
|
189
365
|
[sym('preproc_if_in_enumerator_list'), sym('preproc_if_in_enumerator_list_no_comma')],
|
|
190
366
|
[sym('preproc_ifdef_in_enumerator_list'), sym('preproc_ifdef_in_enumerator_list_no_comma')],
|
|
@@ -217,6 +393,16 @@ module.exports = Object.assign(
|
|
|
217
393
|
[$._declaration_modifiers, $._field_declaration_list_item],
|
|
218
394
|
[$._declaration_specifiers],
|
|
219
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],
|
|
220
406
|
],
|
|
221
407
|
|
|
222
408
|
externals: () => [
|
|
@@ -235,11 +421,16 @@ module.exports = Object.assign(
|
|
|
235
421
|
sym('_conditional_marker_ifndef'),
|
|
236
422
|
sym('_leading_conditional_marker_ifdef'),
|
|
237
423
|
sym('_leading_conditional_marker_ifndef'),
|
|
424
|
+
sym('_gnu_raw_string_body'),
|
|
425
|
+
sym('_raw_macro_type_tail'),
|
|
426
|
+
sym('_braced_function_attribute_start'),
|
|
427
|
+
sym('_braced_macro_type_start'),
|
|
238
428
|
],
|
|
239
429
|
|
|
240
430
|
extras: ($) => [$.pragma_operator, /\s|\\(?:\r\n?|\n\r?)/, $.comment],
|
|
241
431
|
|
|
242
432
|
inline: ($) => [
|
|
433
|
+
$._bare_marker_initializer_declaration,
|
|
243
434
|
$._unattributed_non_case_statement,
|
|
244
435
|
$._single_unattributed_non_case_statement,
|
|
245
436
|
$._unlabeled_non_case_statement,
|
|
@@ -270,15 +461,24 @@ module.exports = Object.assign(
|
|
|
270
461
|
$._case_label_chain_statement,
|
|
271
462
|
$.type_specifier,
|
|
272
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'),
|
|
273
469
|
$._declarator,
|
|
274
470
|
$._old_style_declarator,
|
|
275
471
|
$._initialized_declarator,
|
|
472
|
+
sym('_guarded_initialized_declarator'),
|
|
473
|
+
sym('_braced_macro_declarator'),
|
|
276
474
|
$._initialized_parenthesized_content,
|
|
277
475
|
$._field_declarator,
|
|
278
476
|
$._type_declarator,
|
|
279
477
|
$._abstract_declarator,
|
|
280
478
|
],
|
|
281
479
|
|
|
480
|
+
reserved: { global: () => [], marker: ($) => [$.primitive_type] },
|
|
481
|
+
|
|
282
482
|
word: ($) => $.identifier,
|
|
283
483
|
|
|
284
484
|
rules: {
|
|
@@ -293,6 +493,7 @@ module.exports = Object.assign(
|
|
|
293
493
|
$.linkage_specification,
|
|
294
494
|
$.declaration,
|
|
295
495
|
alias(sym('_macro_modified_declaration'), $.declaration),
|
|
496
|
+
alias(sym('_macro_only_declaration'), $.declaration),
|
|
296
497
|
alias(sym('_trailing_macro_modified_declaration'), $.declaration),
|
|
297
498
|
alias(sym('_conditional_declaration'), $.declaration),
|
|
298
499
|
$._top_level_statement,
|
|
@@ -333,6 +534,7 @@ module.exports = Object.assign(
|
|
|
333
534
|
$.linkage_specification,
|
|
334
535
|
$.declaration,
|
|
335
536
|
alias(sym('_macro_modified_declaration'), $.declaration),
|
|
537
|
+
alias(sym('_macro_only_declaration'), $.declaration),
|
|
336
538
|
alias(sym('_trailing_macro_modified_declaration'), $.declaration),
|
|
337
539
|
alias(sym('_conditional_declaration'), $.declaration),
|
|
338
540
|
$.statement,
|
|
@@ -424,16 +626,9 @@ module.exports = Object.assign(
|
|
|
424
626
|
preproc_params: ($) => seq(alias($._preproc_lparen, '('), commaSep(choice($.identifier, '...')), ')'),
|
|
425
627
|
|
|
426
628
|
preproc_call: ($) =>
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
optional(
|
|
431
|
-
seq(
|
|
432
|
-
field('argument', alias($._preproc_directive_arg, $.preproc_arg)),
|
|
433
|
-
repeat(choice($.comment, $.pragma_operator))
|
|
434
|
-
)
|
|
435
|
-
),
|
|
436
|
-
sym('_preproc_newline')
|
|
629
|
+
choice(
|
|
630
|
+
preprocCall($, alias(/#[ \t]*pragma/, $.preproc_directive), choice($._preproc_directive_arg, $.preproc_arg)),
|
|
631
|
+
preprocCall($, $.preproc_directive, $._preproc_directive_arg)
|
|
437
632
|
),
|
|
438
633
|
|
|
439
634
|
...preprocIf('_in_header', () => sym('_header_preproc_item')),
|
|
@@ -494,7 +689,11 @@ module.exports = Object.assign(
|
|
|
494
689
|
),
|
|
495
690
|
|
|
496
691
|
preproc_argument_list: ($) =>
|
|
497
|
-
seq(
|
|
692
|
+
seq(
|
|
693
|
+
'(',
|
|
694
|
+
commaSep(choice($._preproc_expression, $.system_lib_string, $.string_literal, $.raw_string_literal)),
|
|
695
|
+
')'
|
|
696
|
+
),
|
|
498
697
|
|
|
499
698
|
preproc_binary_expression: ($) => {
|
|
500
699
|
return choice(
|
|
@@ -511,11 +710,14 @@ module.exports = Object.assign(
|
|
|
511
710
|
);
|
|
512
711
|
},
|
|
513
712
|
|
|
514
|
-
function_definition: ($) =>
|
|
515
|
-
|
|
516
|
-
|
|
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),
|
|
517
719
|
_statement_old_style_function_definition: ($) =>
|
|
518
|
-
functionDefinitionRule($, $._statement_declaration_specifiers, true),
|
|
720
|
+
functionDefinitionRule($, functionDefinitionSpecifiers($, $._statement_declaration_specifiers), true),
|
|
519
721
|
|
|
520
722
|
_old_style_declarator: ($) =>
|
|
521
723
|
choice(
|
|
@@ -560,9 +762,40 @@ module.exports = Object.assign(
|
|
|
560
762
|
repeat(choice($._non_macro_declaration_modifiers, $._conditional_macro_specifier))
|
|
561
763
|
),
|
|
562
764
|
|
|
563
|
-
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
|
+
),
|
|
564
774
|
_statement_declaration: ($) =>
|
|
565
|
-
|
|
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,
|
|
566
799
|
|
|
567
800
|
type_definition: ($) => typeDefinitionRule($, $._declaration_modifiers, true),
|
|
568
801
|
_statement_type_definition: ($) => typeDefinitionRule($, $._statement_declaration_modifiers, false),
|
|
@@ -573,7 +806,17 @@ module.exports = Object.assign(
|
|
|
573
806
|
$._macro_declaration_specifiers,
|
|
574
807
|
$._non_macro_declaration_modifiers,
|
|
575
808
|
false,
|
|
576
|
-
$._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
|
+
';'
|
|
577
820
|
),
|
|
578
821
|
|
|
579
822
|
_conditional_declaration: ($) =>
|
|
@@ -582,7 +825,7 @@ module.exports = Object.assign(
|
|
|
582
825
|
_trailing_macro_modified_declaration: ($) =>
|
|
583
826
|
seq(
|
|
584
827
|
sym('_trailing_object_declaration_start'),
|
|
585
|
-
|
|
828
|
+
declarationSpecifiers($, true),
|
|
586
829
|
field('declarator', $._trailing_macro_object_declarator),
|
|
587
830
|
repeat1(alias($._trailing_macro_attribute_specifier, $.attribute_specifier)),
|
|
588
831
|
';'
|
|
@@ -606,14 +849,35 @@ module.exports = Object.assign(
|
|
|
606
849
|
seq(
|
|
607
850
|
choice($.storage_class_specifier, $.type_qualifier, $.ms_declspec_modifier),
|
|
608
851
|
repeat($._non_macro_declaration_modifiers),
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
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
|
+
),
|
|
612
870
|
repeat(postModifier)
|
|
613
871
|
),
|
|
614
872
|
seq(
|
|
615
873
|
repeat($._non_macro_declaration_modifiers),
|
|
616
|
-
|
|
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
|
+
),
|
|
617
881
|
repeat($._non_macro_declaration_modifiers),
|
|
618
882
|
alias($._post_type_macro_attribute_specifier, $.attribute_specifier),
|
|
619
883
|
repeat(postModifier)
|
|
@@ -621,6 +885,9 @@ module.exports = Object.assign(
|
|
|
621
885
|
);
|
|
622
886
|
},
|
|
623
887
|
|
|
888
|
+
_annotation_type_specifier: ($) => choice($._non_identifier_type_specifier, $._type_identifier),
|
|
889
|
+
_known_annotation_type_specifier: ($) => $._non_identifier_type_specifier,
|
|
890
|
+
|
|
624
891
|
_type_definition_type: ($) =>
|
|
625
892
|
seq(
|
|
626
893
|
repeat(choice($.type_qualifier, $.macro_specifier, $._leading_conditional_macro_specifier)),
|
|
@@ -643,13 +910,75 @@ module.exports = Object.assign(
|
|
|
643
910
|
$.ms_declspec_modifier
|
|
644
911
|
),
|
|
645
912
|
|
|
646
|
-
_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: ($) =>
|
|
647
933
|
seq(
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
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
|
+
)
|
|
651
975
|
),
|
|
652
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
|
+
|
|
653
982
|
_field_declaration_specifiers: ($) =>
|
|
654
983
|
seq(
|
|
655
984
|
repeat($._declaration_modifiers),
|
|
@@ -667,7 +996,7 @@ module.exports = Object.assign(
|
|
|
667
996
|
linkage_specification: ($) =>
|
|
668
997
|
seq(
|
|
669
998
|
'extern',
|
|
670
|
-
field('value', $.string_literal),
|
|
999
|
+
field('value', choice($.string_literal, $.raw_string_literal)),
|
|
671
1000
|
field('body', choice($.function_definition, $.declaration, $.declaration_list))
|
|
672
1001
|
),
|
|
673
1002
|
|
|
@@ -675,6 +1004,8 @@ module.exports = Object.assign(
|
|
|
675
1004
|
|
|
676
1005
|
_macro_attribute_specifier: ($) => macroAttributeRule($, 'leading'),
|
|
677
1006
|
|
|
1007
|
+
_braced_leading_macro_attribute_specifier: ($) => macroAttributeRule($, 'braced-leading'),
|
|
1008
|
+
|
|
678
1009
|
_post_type_macro_attribute_specifier: ($) => macroAttributeRule($, 'post-type'),
|
|
679
1010
|
|
|
680
1011
|
_macro_attribute_suffix: ($) => macroAttributeRule($, 'continuation'),
|
|
@@ -683,10 +1014,14 @@ module.exports = Object.assign(
|
|
|
683
1014
|
|
|
684
1015
|
_post_type_macro_attribute_suffix: ($) => macroAttributeRule($, 'post-type-continuation'),
|
|
685
1016
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
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
|
+
),
|
|
690
1025
|
|
|
691
1026
|
attribute: ($) =>
|
|
692
1027
|
seq(optional(seq(field('prefix', $.identifier), '::')), field('name', $.identifier), optional($.argument_list)),
|
|
@@ -737,6 +1072,13 @@ module.exports = Object.assign(
|
|
|
737
1072
|
|
|
738
1073
|
_macro_declaration_declarator: ($) => declarationDeclaratorRule($, $.function_declarator),
|
|
739
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
|
+
|
|
740
1082
|
_field_declarator: ($) =>
|
|
741
1083
|
choice(alias($.attributed_field_declarator, $.attributed_declarator), $._unattributed_field_declarator),
|
|
742
1084
|
|
|
@@ -926,12 +1268,13 @@ module.exports = Object.assign(
|
|
|
926
1268
|
)
|
|
927
1269
|
),
|
|
928
1270
|
|
|
929
|
-
init_declarator: ($) =>
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
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)),
|
|
935
1278
|
|
|
936
1279
|
_initialized_declarator: ($) =>
|
|
937
1280
|
choice(
|
|
@@ -1441,7 +1784,21 @@ module.exports = Object.assign(
|
|
|
1441
1784
|
$.builtin_available_expression
|
|
1442
1785
|
),
|
|
1443
1786
|
|
|
1444
|
-
_string: ($) => prec.left(choice($.string_literal, $.concatenated_string)),
|
|
1787
|
+
_string: ($) => prec.left(choice($.string_literal, $.raw_string_literal, $.concatenated_string)),
|
|
1788
|
+
|
|
1789
|
+
raw_string_literal: () =>
|
|
1790
|
+
seq(
|
|
1791
|
+
token(
|
|
1792
|
+
seq(
|
|
1793
|
+
optional(seq(choice('L', 'U', 'u', seq('u', repeat(LINE_SPLICE), '8')), repeat(LINE_SPLICE))),
|
|
1794
|
+
'R',
|
|
1795
|
+
repeat(LINE_SPLICE),
|
|
1796
|
+
'"'
|
|
1797
|
+
)
|
|
1798
|
+
),
|
|
1799
|
+
sym('_gnu_raw_string_body'),
|
|
1800
|
+
'"'
|
|
1801
|
+
),
|
|
1445
1802
|
|
|
1446
1803
|
comma_expression: ($) =>
|
|
1447
1804
|
seq(field('left', $.expression), ',', field('right', choice($.expression, $.comma_expression))),
|
|
@@ -1613,7 +1970,7 @@ module.exports = Object.assign(
|
|
|
1613
1970
|
gnu_asm_output_operand: ($) =>
|
|
1614
1971
|
seq(
|
|
1615
1972
|
optional(seq('[', field('symbol', $.identifier), ']')),
|
|
1616
|
-
field('constraint', $.string_literal),
|
|
1973
|
+
field('constraint', choice($.string_literal, $.raw_string_literal)),
|
|
1617
1974
|
'(',
|
|
1618
1975
|
field('value', $.expression),
|
|
1619
1976
|
')'
|
|
@@ -1624,7 +1981,7 @@ module.exports = Object.assign(
|
|
|
1624
1981
|
gnu_asm_input_operand: ($) =>
|
|
1625
1982
|
seq(
|
|
1626
1983
|
optional(seq('[', field('symbol', $.identifier), ']')),
|
|
1627
|
-
field('constraint', $.string_literal),
|
|
1984
|
+
field('constraint', choice($.string_literal, $.raw_string_literal)),
|
|
1628
1985
|
'(',
|
|
1629
1986
|
field('value', $.expression),
|
|
1630
1987
|
')'
|
|
@@ -1768,11 +2125,11 @@ module.exports = Object.assign(
|
|
|
1768
2125
|
prec.right(
|
|
1769
2126
|
seq(
|
|
1770
2127
|
choice(
|
|
1771
|
-
seq($.identifier, $.string_literal),
|
|
1772
|
-
seq($.string_literal, $.string_literal),
|
|
1773
|
-
seq($.string_literal, $.identifier)
|
|
2128
|
+
seq($.identifier, choice($.string_literal, $.raw_string_literal)),
|
|
2129
|
+
seq(choice($.string_literal, $.raw_string_literal), choice($.string_literal, $.raw_string_literal)),
|
|
2130
|
+
seq(choice($.string_literal, $.raw_string_literal), $.identifier)
|
|
1774
2131
|
),
|
|
1775
|
-
repeat(choice($.string_literal, $.identifier))
|
|
2132
|
+
repeat(choice($.string_literal, $.raw_string_literal, $.identifier))
|
|
1776
2133
|
)
|
|
1777
2134
|
),
|
|
1778
2135
|
|
|
@@ -1853,7 +2210,7 @@ module.exports = Object.assign(
|
|
|
1853
2210
|
';'
|
|
1854
2211
|
),
|
|
1855
2212
|
|
|
1856
|
-
macro_specifier: ($) => prec.dynamic(-2, field('name', $.identifier)),
|
|
2213
|
+
macro_specifier: ($) => prec.dynamic(-2, field('name', reserved('marker', $.identifier))),
|
|
1857
2214
|
|
|
1858
2215
|
_conditional_macro_specifier: () => alias(sym('_marker_preproc_ifdef'), sym('preproc_ifdef')),
|
|
1859
2216
|
_leading_conditional_macro_specifier: () => alias(sym('_leading_marker_preproc_ifdef'), sym('preproc_ifdef')),
|
|
@@ -1866,23 +2223,88 @@ module.exports = Object.assign(
|
|
|
1866
2223
|
macro_type_specifier: ($) =>
|
|
1867
2224
|
prec.dynamic(
|
|
1868
2225
|
-1,
|
|
2226
|
+
seq(
|
|
2227
|
+
field('name', choice($.identifier, alias(VA_ARG_KEYWORDS, $.identifier))),
|
|
2228
|
+
choice(
|
|
2229
|
+
seq('(', field('type', $.type_descriptor), ')'),
|
|
2230
|
+
field('arguments', alias($._raw_string_macro_type_arguments, $.argument_list))
|
|
2231
|
+
)
|
|
2232
|
+
)
|
|
2233
|
+
),
|
|
2234
|
+
|
|
2235
|
+
_variadic_macro_type_specifier: ($) =>
|
|
2236
|
+
prec.dynamic(
|
|
2237
|
+
-2,
|
|
1869
2238
|
seq(
|
|
1870
2239
|
field('name', choice($.identifier, alias(VA_ARG_KEYWORDS, $.identifier))),
|
|
1871
2240
|
'(',
|
|
1872
2241
|
field('type', $.type_descriptor),
|
|
2242
|
+
repeat1(seq(',', optional(macroAttributeArgument($)))),
|
|
1873
2243
|
')'
|
|
1874
2244
|
)
|
|
1875
2245
|
),
|
|
1876
2246
|
|
|
2247
|
+
_raw_string_macro_type_arguments: ($) =>
|
|
2248
|
+
seq('(', $._raw_string_type_argument, optional($._raw_string_type_tail), ')'),
|
|
2249
|
+
|
|
2250
|
+
_raw_string_type_argument: ($) =>
|
|
2251
|
+
choice($.raw_string_literal, alias($._parenthesized_raw_string_type_argument, $.parenthesized_expression)),
|
|
2252
|
+
|
|
2253
|
+
_parenthesized_raw_string_type_argument: ($) =>
|
|
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
|
+
),
|
|
2269
|
+
|
|
1877
2270
|
_preproc_number: () =>
|
|
1878
2271
|
/(\d|\.\d)([\p{XID_Continue}.]|[eEpP][+-]|'[_a-zA-Z0-9]|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8})*/u,
|
|
1879
2272
|
|
|
1880
2273
|
comment: () => token(choice(LINE_COMMENT, seq('/*', /[^*]*\*+([^/*][^*]*\*+)*/, '/'))),
|
|
1881
2274
|
},
|
|
1882
2275
|
}),
|
|
1883
|
-
{ PREC, preprocIf, preprocessor, commaSep, commaSep1 }
|
|
2276
|
+
{ PREC, preprocIf, preprocessor, commaSep, commaSep1, declarationSpecifiers }
|
|
1884
2277
|
);
|
|
1885
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
|
+
|
|
2294
|
+
/**
|
|
2295
|
+
* @param {import('./types/treeSitterDsl').GrammarSymbols<'comment' | 'pragma_operator' | 'preproc_arg'>} $
|
|
2296
|
+
* @param {import('./types/treeSitterDsl').Rule} directive
|
|
2297
|
+
* @param {import('./types/treeSitterDsl').Rule} argument
|
|
2298
|
+
*/
|
|
2299
|
+
function preprocCall($, directive, argument) {
|
|
2300
|
+
return seq(
|
|
2301
|
+
field('directive', directive),
|
|
2302
|
+
repeat(choice($.comment, $.pragma_operator)),
|
|
2303
|
+
optional(seq(field('argument', alias(argument, $.preproc_arg)), repeat(choice($.comment, $.pragma_operator)))),
|
|
2304
|
+
sym('_preproc_newline')
|
|
2305
|
+
);
|
|
2306
|
+
}
|
|
2307
|
+
|
|
1886
2308
|
/**
|
|
1887
2309
|
* @param {import('./types/treeSitterDsl').GrammarSymbols<'identifier' | 'macro_specifier'>} $
|
|
1888
2310
|
* @param {import('./types/treeSitterDsl').Rule} ifdef
|
|
@@ -1932,6 +2354,14 @@ function pointerDeclaratorRule($, declarator) {
|
|
|
1932
2354
|
);
|
|
1933
2355
|
}
|
|
1934
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
|
+
|
|
1935
2365
|
/**
|
|
1936
2366
|
* @param {import('./types/treeSitterDsl').GrammarSymbols<'ms_call_modifier' | '_old_style_declarator' | '_declarator' | 'declaration' | 'compound_statement'>} $
|
|
1937
2367
|
* @param {import('./types/treeSitterDsl').Rule} specifiers
|
|
@@ -1942,20 +2372,54 @@ function functionDefinitionRule($, specifiers, oldStyle) {
|
|
|
1942
2372
|
optional($.ms_call_modifier),
|
|
1943
2373
|
specifiers,
|
|
1944
2374
|
...(oldStyle ? [] : [optional($.ms_call_modifier)]),
|
|
1945
|
-
|
|
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
|
+
),
|
|
1946
2385
|
...(oldStyle ? [repeat1($.declaration)] : []),
|
|
1947
2386
|
field('body', $.compound_statement)
|
|
1948
2387
|
);
|
|
1949
2388
|
}
|
|
1950
2389
|
|
|
1951
2390
|
/**
|
|
1952
|
-
* @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'>} $
|
|
1953
2392
|
* @param {import('./types/treeSitterDsl').Rule} specifiers
|
|
1954
2393
|
* @param {import('./types/treeSitterDsl').Rule} modifiers
|
|
1955
2394
|
* @param {boolean} allowInferredType
|
|
1956
2395
|
* @param {import('./types/treeSitterDsl').Rule} declarator
|
|
2396
|
+
* @param {{guard?: import('./types/treeSitterDsl').Rule, bareMarkerInitializer?: boolean}} options
|
|
1957
2397
|
*/
|
|
1958
|
-
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));
|
|
1959
2423
|
return choice(
|
|
1960
2424
|
seq(
|
|
1961
2425
|
prec.dynamic(
|
|
@@ -1970,12 +2434,7 @@ function declarationRule($, specifiers, modifiers, allowInferredType = true, dec
|
|
|
1970
2434
|
)
|
|
1971
2435
|
: specifiers
|
|
1972
2436
|
),
|
|
1973
|
-
|
|
1974
|
-
field(
|
|
1975
|
-
'declarator',
|
|
1976
|
-
choice(seq(optional($.ms_call_modifier), declarator, optional($.gnu_asm_expression)), $.init_declarator)
|
|
1977
|
-
)
|
|
1978
|
-
),
|
|
2437
|
+
items,
|
|
1979
2438
|
';'
|
|
1980
2439
|
),
|
|
1981
2440
|
...(allowInferredType
|
|
@@ -1984,6 +2443,14 @@ function declarationRule($, specifiers, modifiers, allowInferredType = true, dec
|
|
|
1984
2443
|
);
|
|
1985
2444
|
}
|
|
1986
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
|
+
|
|
1987
2454
|
/**
|
|
1988
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'>} $
|
|
1989
2456
|
* @param {import('./types/treeSitterDsl').Rule} modifiers
|
|
@@ -2027,13 +2494,25 @@ function declarationDeclaratorRule($, functionDeclarator) {
|
|
|
2027
2494
|
|
|
2028
2495
|
/**
|
|
2029
2496
|
* @param {import('./types/treeSitterDsl').GrammarSymbols<'identifier' | 'argument_list' | '_macro_attribute_argument_list'>} $
|
|
2030
|
-
* @param {'leading' | 'post-type' | 'continuation' | 'post-type-continuation' | 'trailing'} context
|
|
2497
|
+
* @param {'leading' | 'braced-leading' | 'post-type' | 'continuation' | 'post-type-continuation' | 'trailing'} context
|
|
2031
2498
|
*/
|
|
2032
2499
|
function macroAttributeRule($, context) {
|
|
2033
|
-
const
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
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(
|
|
2037
2516
|
sym(
|
|
2038
2517
|
context === 'leading'
|
|
2039
2518
|
? '_function_attribute_start'
|
|
@@ -2041,20 +2520,26 @@ function macroAttributeRule($, context) {
|
|
|
2041
2520
|
? '_post_type_function_attribute_start'
|
|
2042
2521
|
: '_post_type_function_attribute_suffix'
|
|
2043
2522
|
),
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
seq(
|
|
2048
|
-
...guard,
|
|
2049
|
-
field('name', context === 'trailing' ? alias(sym('_trailing_macro_attribute_name'), $.identifier) : $.identifier),
|
|
2050
|
-
field('arguments', alias($._macro_attribute_argument_list, $.argument_list))
|
|
2051
|
-
)
|
|
2052
|
-
);
|
|
2523
|
+
ordinary
|
|
2524
|
+
);
|
|
2525
|
+
return prec.dynamic(-2, choice(guarded, braced));
|
|
2053
2526
|
}
|
|
2054
2527
|
|
|
2055
|
-
/** @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'>} $ */
|
|
2056
2534
|
function macroAttributeArgument($) {
|
|
2057
|
-
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
|
+
);
|
|
2058
2543
|
}
|
|
2059
2544
|
|
|
2060
2545
|
/**
|