@willbooster/tree-sitter-c 48.1.0 → 49.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/grammar.js +130 -49
- package/package.json +1 -1
- package/src/conditionalMacro.h +2 -2
- package/src/directiveBuffer.h +2 -2
- package/src/directiveScan.h +1 -1
- package/src/functionMacro.h +5 -6
- package/src/node-types.json +39 -14
- package/src/pragma.h +4 -5
- package/src/scanner.c +1 -1
- package/tree-sitter-c.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -66,6 +66,8 @@ const BINARY_OPERATORS = [
|
|
|
66
66
|
];
|
|
67
67
|
|
|
68
68
|
const LINE_SPLICE = /\\(?:\r\n?|\n\r?)/;
|
|
69
|
+
const SPLICES = `(?:${LINE_SPLICE.source})*`;
|
|
70
|
+
const UCN = String.raw`\\${SPLICES}(?:u(?:${SPLICES}[0-9a-fA-F]){4}|U(?:${SPLICES}[0-9a-fA-F]){8})`;
|
|
69
71
|
const LINE_COMMENT = seq('/', repeat(LINE_SPLICE), '/', repeat(choice(/[^\\\r\n]/, '\\', LINE_SPLICE)));
|
|
70
72
|
const COMMENT_SPLICES = repeat(seq('\\', /[\r\n]/));
|
|
71
73
|
const COMMENT_ESCAPE = seq('\\', /[^\r\n*]/);
|
|
@@ -148,16 +150,17 @@ const MACRO_CASE_IDENTIFIER = new RegExp(
|
|
|
148
150
|
['', ...MACRO_CASE_KEYWORDS.filter((keyword) => !keyword.startsWith('__'))],
|
|
149
151
|
`${UPPER_CASE}_`,
|
|
150
152
|
`${UPPER_CASE}0123456789_`
|
|
151
|
-
)}|
|
|
153
|
+
)}|_${SPLICES}_${identifierExcept(
|
|
152
154
|
MACRO_CASE_KEYWORDS.filter((keyword) => keyword.startsWith('__')).map((keyword) => keyword.slice(2)),
|
|
153
155
|
IDENTIFIER_CHARACTERS,
|
|
154
|
-
IDENTIFIER_CHARACTERS
|
|
156
|
+
IDENTIFIER_CHARACTERS,
|
|
157
|
+
true
|
|
155
158
|
)}`
|
|
156
159
|
);
|
|
157
160
|
|
|
158
161
|
// oxlint-disable-next-line unicorn/prefer-module -- This package is CommonJS, so tree-sitter loads grammar.js as CommonJS.
|
|
159
162
|
module.exports = Object.assign(
|
|
160
|
-
|
|
163
|
+
prepareCGrammar(
|
|
161
164
|
grammar({
|
|
162
165
|
name: 'c',
|
|
163
166
|
|
|
@@ -1661,18 +1664,20 @@ module.exports = Object.assign(
|
|
|
1661
1664
|
primitive_type: () =>
|
|
1662
1665
|
token(
|
|
1663
1666
|
choice(
|
|
1664
|
-
...
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1667
|
+
...[
|
|
1668
|
+
...primitiveTypeKeywords,
|
|
1669
|
+
'size_t',
|
|
1670
|
+
'ssize_t',
|
|
1671
|
+
'ptrdiff_t',
|
|
1672
|
+
'intptr_t',
|
|
1673
|
+
'uintptr_t',
|
|
1674
|
+
'charptr_t',
|
|
1675
|
+
'nullptr_t',
|
|
1676
|
+
'max_align_t',
|
|
1677
|
+
...[8, 16, 32, 64].map((n) => `int${n}_t`),
|
|
1678
|
+
...[8, 16, 32, 64].map((n) => `uint${n}_t`),
|
|
1679
|
+
...[8, 16, 32, 64].map((n) => `char${n}_t`),
|
|
1680
|
+
].map(splicedWord)
|
|
1676
1681
|
)
|
|
1677
1682
|
),
|
|
1678
1683
|
|
|
@@ -2255,7 +2260,10 @@ module.exports = Object.assign(
|
|
|
2255
2260
|
|
|
2256
2261
|
platform_version: ($) => seq(field('platform', $.identifier), field('version', $.version_number)),
|
|
2257
2262
|
|
|
2258
|
-
version_number: () =>
|
|
2263
|
+
version_number: () => {
|
|
2264
|
+
const digits = String.raw`\d(?:${SPLICES}\d)*`;
|
|
2265
|
+
return token(prec(-1, new RegExp(String.raw`${digits}(?:${SPLICES}\.${SPLICES}${digits}){0,2}`)));
|
|
2266
|
+
},
|
|
2259
2267
|
|
|
2260
2268
|
gnu_asm_expression: ($) =>
|
|
2261
2269
|
prec(
|
|
@@ -2405,24 +2413,27 @@ module.exports = Object.assign(
|
|
|
2405
2413
|
field_designator: ($) => seq('.', $._field_identifier),
|
|
2406
2414
|
|
|
2407
2415
|
number_literal: () => {
|
|
2408
|
-
const
|
|
2416
|
+
const join = repeat(LINE_SPLICE);
|
|
2409
2417
|
const hex = /[0-9a-fA-F]/;
|
|
2410
2418
|
const decimal = /[0-9]/;
|
|
2411
|
-
const
|
|
2412
|
-
|
|
2419
|
+
const digits = (/** @type {RegExp} */ digit) =>
|
|
2420
|
+
seq(digit, repeat(seq(join, optional(seq("'", join)), digit)));
|
|
2421
|
+
const hexDigits = digits(hex),
|
|
2422
|
+
decimalDigits = digits(decimal);
|
|
2423
|
+
const hexPrefix = seq('0', join, /[xX]/, join);
|
|
2413
2424
|
return token(
|
|
2414
2425
|
seq(
|
|
2415
|
-
optional(/[-+]
|
|
2426
|
+
optional(seq(/[-+]/, join)),
|
|
2416
2427
|
choice(
|
|
2417
2428
|
seq(
|
|
2418
|
-
choice(decimalDigits, seq(/
|
|
2419
|
-
optional(seq('.', optional(hexDigits)))
|
|
2429
|
+
choice(decimalDigits, seq('0', join, /[bB]/, join, decimalDigits), seq(hexPrefix, hexDigits)),
|
|
2430
|
+
optional(seq(join, '.', optional(seq(join, hexDigits))))
|
|
2420
2431
|
),
|
|
2421
|
-
seq('.', decimalDigits),
|
|
2422
|
-
seq(
|
|
2432
|
+
seq('.', join, decimalDigits),
|
|
2433
|
+
seq(hexPrefix, '.', join, hexDigits)
|
|
2423
2434
|
),
|
|
2424
|
-
optional(seq(/[eEpP]/, optional(seq(optional(/[-+]
|
|
2425
|
-
/[uUlLwWfFbBdD]
|
|
2435
|
+
optional(seq(join, /[eEpP]/, optional(seq(join, optional(seq(/[-+]/, join)), hexDigits)))),
|
|
2436
|
+
repeat(seq(join, /[uUlLwWfFbBdD]/))
|
|
2426
2437
|
)
|
|
2427
2438
|
);
|
|
2428
2439
|
},
|
|
@@ -2462,34 +2473,42 @@ module.exports = Object.assign(
|
|
|
2462
2473
|
'"'
|
|
2463
2474
|
),
|
|
2464
2475
|
|
|
2465
|
-
escape_sequence: () =>
|
|
2466
|
-
|
|
2476
|
+
escape_sequence: () => {
|
|
2477
|
+
const join = repeat(LINE_SPLICE);
|
|
2478
|
+
const hex = /[0-9a-fA-F]/;
|
|
2479
|
+
const octal = /[0-7]/;
|
|
2480
|
+
const hexDigit = seq(join, hex);
|
|
2481
|
+
const octalDigit = seq(join, octal);
|
|
2482
|
+
return token(
|
|
2467
2483
|
prec(
|
|
2468
2484
|
1,
|
|
2469
2485
|
seq(
|
|
2470
2486
|
'\\',
|
|
2471
2487
|
choice(
|
|
2472
|
-
/['"?\\abefnrtvE]/,
|
|
2473
|
-
'(',
|
|
2474
|
-
'[',
|
|
2475
|
-
'{',
|
|
2476
|
-
'%',
|
|
2477
2488
|
/\r\n?|\n\r?/,
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2489
|
+
seq(
|
|
2490
|
+
join,
|
|
2491
|
+
choice(
|
|
2492
|
+
/['"?\\abefnrtvE({%]/,
|
|
2493
|
+
'[',
|
|
2494
|
+
seq(/[xu]/, join, '{', repeat1(hexDigit), join, '}'),
|
|
2495
|
+
seq('o', join, '{', repeat1(octalDigit), join, '}'),
|
|
2496
|
+
seq('N', join, '{', repeat1(seq(join, /[^}\r\n]/)), join, '}'),
|
|
2497
|
+
seq(octal, optional(octalDigit), optional(octalDigit)),
|
|
2498
|
+
seq('x', repeat1(hexDigit)),
|
|
2499
|
+
seq('u', ...Array.from({ length: 4 }, () => hexDigit)),
|
|
2500
|
+
seq('U', ...Array.from({ length: 8 }, () => hexDigit))
|
|
2501
|
+
)
|
|
2502
|
+
)
|
|
2485
2503
|
)
|
|
2486
2504
|
)
|
|
2487
2505
|
)
|
|
2488
|
-
)
|
|
2506
|
+
);
|
|
2507
|
+
},
|
|
2489
2508
|
|
|
2490
2509
|
invalid_escape_sequence: () => token(seq('\\', choice(/[^\r\n]/, /u[0-9a-fA-F]{1,3}/, /U[0-9a-fA-F]{1,7}/))),
|
|
2491
2510
|
|
|
2492
|
-
system_lib_string: () => token(seq('<', repeat(choice(/[^>\n]/, String.raw`\>`)), '>')),
|
|
2511
|
+
system_lib_string: () => token(seq('<', repeat(choice(/[^>\r\n]/, LINE_SPLICE, String.raw`\>`)), '>')),
|
|
2493
2512
|
|
|
2494
2513
|
true: () => 'true',
|
|
2495
2514
|
false: () => 'false',
|
|
@@ -2501,7 +2520,7 @@ module.exports = Object.assign(
|
|
|
2501
2520
|
_macro_case_identifier: () => MACRO_CASE_IDENTIFIER,
|
|
2502
2521
|
identifier: () =>
|
|
2503
2522
|
new RegExp(
|
|
2504
|
-
`(
|
|
2523
|
+
String.raw`(?:\p{XID_Start}|\$|_|${UCN}|${C17_IDENTIFIER_START.source})(?:${SPLICES}(?:\p{XID_Continue}|\$|${UCN}|${C17_IDENTIFIER_CONTINUE.source}))*`,
|
|
2505
2524
|
'u'
|
|
2506
2525
|
),
|
|
2507
2526
|
_type_identifier: ($) => alias(choice($.identifier, VA_ARG_KEYWORDS), sym('type_identifier')),
|
|
@@ -2600,7 +2619,10 @@ module.exports = Object.assign(
|
|
|
2600
2619
|
),
|
|
2601
2620
|
|
|
2602
2621
|
_preproc_number: () =>
|
|
2603
|
-
|
|
2622
|
+
new RegExp(
|
|
2623
|
+
String.raw`(?:\d|\.${SPLICES}\d)(?:${SPLICES}(?:[\p{XID_Continue}.]|[eEpP]${SPLICES}[+-]|'${SPLICES}[_a-zA-Z0-9]|${UCN}))*`,
|
|
2624
|
+
'u'
|
|
2625
|
+
),
|
|
2604
2626
|
|
|
2605
2627
|
comment: () => token(choice(LINE_COMMENT, BLOCK_COMMENT)),
|
|
2606
2628
|
},
|
|
@@ -2675,14 +2697,14 @@ function leadingMacroCallRule($, precedence, name) {
|
|
|
2675
2697
|
}
|
|
2676
2698
|
|
|
2677
2699
|
/**
|
|
2678
|
-
*
|
|
2679
|
-
* `rest`, the empty string included, except the given words.
|
|
2700
|
+
* Excludes the same words after phase-2 line splicing, including when recursion continues an identifier prefix.
|
|
2680
2701
|
* @param {string[]} words
|
|
2681
2702
|
* @param {string} first
|
|
2682
2703
|
* @param {string} rest
|
|
2704
|
+
* @param {boolean} continuation Whether a preceding identifier character permits splices before this suffix.
|
|
2683
2705
|
* @returns {string}
|
|
2684
2706
|
*/
|
|
2685
|
-
function identifierExcept(words, first, rest) {
|
|
2707
|
+
function identifierExcept(words, first, rest, continuation = false) {
|
|
2686
2708
|
/** @type {Map<string, string[]>} */
|
|
2687
2709
|
const byFirst = new Map();
|
|
2688
2710
|
let excludesEmpty = false;
|
|
@@ -2698,8 +2720,10 @@ function identifierExcept(words, first, rest) {
|
|
|
2698
2720
|
.split('')
|
|
2699
2721
|
.filter((character) => !byFirst.has(character))
|
|
2700
2722
|
.join('');
|
|
2701
|
-
const
|
|
2702
|
-
|
|
2723
|
+
const prefix = continuation ? SPLICES : '';
|
|
2724
|
+
const alternatives = [`${prefix}[${others}](?:${SPLICES}[${rest}])*`];
|
|
2725
|
+
for (const [character, rests] of byFirst)
|
|
2726
|
+
alternatives.push(`${prefix}${character}${identifierExcept(rests, rest, rest, true)}`);
|
|
2703
2727
|
return `(?:${alternatives.join('|')})${excludesEmpty ? '' : '?'}`;
|
|
2704
2728
|
}
|
|
2705
2729
|
|
|
@@ -3166,3 +3190,60 @@ function commaSep(rule) {
|
|
|
3166
3190
|
function commaSep1(rule) {
|
|
3167
3191
|
return seq(rule, repeat(seq(',', rule)));
|
|
3168
3192
|
}
|
|
3193
|
+
|
|
3194
|
+
/** The literal also supplies keyword spellings for the generated scanner table.
|
|
3195
|
+
* @param {string} word
|
|
3196
|
+
*/
|
|
3197
|
+
function splicedWord(word) {
|
|
3198
|
+
return choice(word, seq(word[0] ?? '', ...Array.from(word.slice(1), (ch) => seq(repeat(LINE_SPLICE), ch))));
|
|
3199
|
+
}
|
|
3200
|
+
|
|
3201
|
+
/**
|
|
3202
|
+
* @param {import('./types/treeSitterDsl').GrammarSchema<string>} schema
|
|
3203
|
+
*/
|
|
3204
|
+
function prepareCGrammar(schema) {
|
|
3205
|
+
assertMacroCaseIdentifierSpellsNoKeyword(schema);
|
|
3206
|
+
const rules = schema.grammar.rules;
|
|
3207
|
+
/** @type {Record<string, import('./types/treeSitterDsl').Rule>} */
|
|
3208
|
+
const spellings = {};
|
|
3209
|
+
for (const [name, rule] of Object.entries(rules)) rules[name] = spliceSyntaxLiterals(rule, spellings);
|
|
3210
|
+
const start = rules.translation_unit;
|
|
3211
|
+
if (!start) throw new Error('Expected the C translation unit start rule');
|
|
3212
|
+
schema.grammar.rules = { translation_unit: start, ...spellings, ...rules };
|
|
3213
|
+
return schema;
|
|
3214
|
+
}
|
|
3215
|
+
|
|
3216
|
+
/**
|
|
3217
|
+
* @param {import('./types/treeSitterDsl').Rule} rule
|
|
3218
|
+
* @param {Record<string, import('./types/treeSitterDsl').Rule>} rules
|
|
3219
|
+
* @param {boolean} aliased
|
|
3220
|
+
* @returns {import('./types/treeSitterDsl').Rule}
|
|
3221
|
+
*/
|
|
3222
|
+
function spliceSyntaxLiterals(rule, rules, aliased = false) {
|
|
3223
|
+
if (rule.type === 'STRING' && /^(?:[A-Za-z_][A-Za-z_0-9]+|(?:[LuU]|u8)["']|[.><=+&|!*/%:^-]{2,})$/.test(rule.value)) {
|
|
3224
|
+
const word = rule.value;
|
|
3225
|
+
const suffix = /^\w+$/.test(word)
|
|
3226
|
+
? word
|
|
3227
|
+
: Array.from(word, (ch) => (ch.codePointAt(0) ?? 0).toString(16)).join('_');
|
|
3228
|
+
const name = '_spliced_' + suffix;
|
|
3229
|
+
if (!rules[name]) rules[name] = token(splicedLiteralPattern(word));
|
|
3230
|
+
return choice(rule, aliased ? sym(name) : alias(sym(name), word));
|
|
3231
|
+
}
|
|
3232
|
+
if (rule.type === 'TOKEN' || rule.type === 'IMMEDIATE_TOKEN') return rule;
|
|
3233
|
+
if ('members' in rule)
|
|
3234
|
+
return { ...rule, members: rule.members.map((child) => spliceSyntaxLiterals(child, rules, aliased)) };
|
|
3235
|
+
if ('content' in rule)
|
|
3236
|
+
return { ...rule, content: spliceSyntaxLiterals(rule.content, rules, aliased || rule.type === 'ALIAS') };
|
|
3237
|
+
return rule;
|
|
3238
|
+
}
|
|
3239
|
+
|
|
3240
|
+
/** @param {string} word */
|
|
3241
|
+
function splicedLiteralPattern(word) {
|
|
3242
|
+
const chars = Array.from(word, (ch) => String.raw`\x` + (ch.codePointAt(0) ?? 0).toString(16).padStart(2, '0'));
|
|
3243
|
+
const splice = '(?:' + LINE_SPLICE.source + ')';
|
|
3244
|
+
const spellings = chars.slice(1).map((_, offset) => {
|
|
3245
|
+
const i = offset + 1;
|
|
3246
|
+
return chars.slice(0, i).join('') + splice + '+' + chars.slice(i).join(splice + '*');
|
|
3247
|
+
});
|
|
3248
|
+
return new RegExp(spellings.join('|'));
|
|
3249
|
+
}
|
package/package.json
CHANGED
package/src/conditionalMacro.h
CHANGED
|
@@ -200,8 +200,8 @@ static bool conditional_macro_spacing(TSLexer *lexer, bool *separated, bool *esc
|
|
|
200
200
|
if (c != '\\') return true;
|
|
201
201
|
lexer->advance(lexer, false);
|
|
202
202
|
if (scan_preproc_newline(lexer, false)) continue;
|
|
203
|
-
*escaped =
|
|
204
|
-
return
|
|
203
|
+
*escaped = true;
|
|
204
|
+
return true;
|
|
205
205
|
}
|
|
206
206
|
return true;
|
|
207
207
|
}
|
package/src/directiveBuffer.h
CHANGED
|
@@ -311,7 +311,7 @@ static uint32_t directive_fill_units(DirectiveBuffer *buffer, uint32_t limit) {
|
|
|
311
311
|
uint16_t *page = buffer->characters[index >> DIRECTIVE_PAGE_SHIFT] + (index & (DIRECTIVE_PAGE_SIZE - 1));
|
|
312
312
|
uint32_t length = 0, c = 0;
|
|
313
313
|
uint8_t seen = 0;
|
|
314
|
-
while (length < count && (c = directive_unit(units, size, length)) < UNIT_CLASS_COUNT) {
|
|
314
|
+
while (length < count && (c = directive_unit(units, size, length)) < UNIT_CLASS_COUNT && c != '\\') {
|
|
315
315
|
page[length++] = (uint16_t)c;
|
|
316
316
|
seen |= buffer->classes[c];
|
|
317
317
|
if (directive_newline((int32_t)c)) break;
|
|
@@ -383,7 +383,7 @@ static bool directive_append_ascii(DirectiveBuffer *buffer, uint16_t c) {
|
|
|
383
383
|
|
|
384
384
|
static inline void directive_note(DirectiveBuffer *buffer, uint32_t c) {
|
|
385
385
|
buffer->recent = buffer->recent << 8 | (c < 0x80 ? c : 0);
|
|
386
|
-
if (directive_pragma_word(buffer->recent)) buffer->pragma = true;
|
|
386
|
+
if (directive_pragma_word(buffer->recent) || (c == '\\' && directive_pragma_pending(buffer->recent >> 8))) buffer->pragma = true;
|
|
387
387
|
}
|
|
388
388
|
|
|
389
389
|
static bool directive_reserve(DirectiveBuffer *buffer, unsigned width) {
|
package/src/directiveScan.h
CHANGED
|
@@ -481,7 +481,7 @@ static void directive_scan_raw_body(DirectiveScan *scan, int32_t c) {
|
|
|
481
481
|
// Adds `c` to the characters read last and returns them.
|
|
482
482
|
static inline uint64_t directive_scan_note(DirectiveScan *scan, uint64_t recent, int32_t c) {
|
|
483
483
|
recent = recent << 8 | ((uint32_t)c < 0x80 ? (uint64_t)c : 0);
|
|
484
|
-
if (directive_pragma_word(recent)) *scan->pragma = true;
|
|
484
|
+
if (directive_pragma_word(recent) || (c == '\\' && directive_pragma_pending(recent >> 8))) *scan->pragma = true;
|
|
485
485
|
return recent;
|
|
486
486
|
}
|
|
487
487
|
|
package/src/functionMacro.h
CHANGED
|
@@ -352,6 +352,7 @@ static bool function_macro_trailing_argument_prefix(TSLexer *lexer, const Pragma
|
|
|
352
352
|
int32_t first = lexer->lookahead;
|
|
353
353
|
if (first == '.') {
|
|
354
354
|
lexer->advance(lexer, false);
|
|
355
|
+
if (!scan_preproc_splices(lexer)) return false;
|
|
355
356
|
first = lexer->lookahead;
|
|
356
357
|
return first >= '0' && first <= '9';
|
|
357
358
|
}
|
|
@@ -395,7 +396,7 @@ static bool function_macro_object_word(TSLexer *lexer, MacroName *name, bool esc
|
|
|
395
396
|
for (;;) {
|
|
396
397
|
MacroNameCharacter c = scan_macro_name_character(lexer, continuation, name);
|
|
397
398
|
if (c == MACRO_NAME_END) return continuation;
|
|
398
|
-
if (c == MACRO_NAME_SPLICE
|
|
399
|
+
if (c == MACRO_NAME_SPLICE) continue;
|
|
399
400
|
if (c != MACRO_NAME_CHARACTER) return false;
|
|
400
401
|
continuation = true;
|
|
401
402
|
}
|
|
@@ -648,8 +649,8 @@ static bool function_macro_tail_spacing(TSLexer *lexer, bool *escaped, const Pra
|
|
|
648
649
|
} else if (c == '\\') {
|
|
649
650
|
lexer->advance(lexer, false);
|
|
650
651
|
if (scan_preproc_newline(lexer, false)) continue;
|
|
651
|
-
*escaped =
|
|
652
|
-
return
|
|
652
|
+
*escaped = true;
|
|
653
|
+
return true;
|
|
653
654
|
} else if (c == '/') {
|
|
654
655
|
if (!function_macro_argument_slash(lexer, false)) return false;
|
|
655
656
|
} else {
|
|
@@ -661,9 +662,7 @@ static bool function_macro_tail_spacing(TSLexer *lexer, bool *escaped, const Pra
|
|
|
661
662
|
static bool function_macro_tail_word(TSLexer *lexer, bool escaped, MacroPrototypeTail *tail) {
|
|
662
663
|
char word[FUNCTION_MACRO_KEYWORD_MAX_LENGTH + 1] = {0};
|
|
663
664
|
MacroName name = {.word = word, .capacity = sizeof(word) - 1, .ascii = !escaped};
|
|
664
|
-
if (
|
|
665
|
-
bool continuation = escaped;
|
|
666
|
-
while (scan_macro_name_character(lexer, continuation, &name) == MACRO_NAME_CHARACTER) continuation = true;
|
|
665
|
+
if (!function_macro_object_word(lexer, &name, escaped)) return false;
|
|
667
666
|
bool pragma = name.ascii && strcmp(word, pragma_word) == 0;
|
|
668
667
|
bool keyword = name.ascii && function_macro_keyword(word);
|
|
669
668
|
if (tail->post_type && !tail->declarator_group && !keyword && !pragma) {
|
package/src/node-types.json
CHANGED
|
@@ -1831,6 +1831,11 @@
|
|
|
1831
1831
|
]
|
|
1832
1832
|
}
|
|
1833
1833
|
},
|
|
1834
|
+
{
|
|
1835
|
+
"type": "false",
|
|
1836
|
+
"named": true,
|
|
1837
|
+
"fields": {}
|
|
1838
|
+
},
|
|
1834
1839
|
{
|
|
1835
1840
|
"type": "field_declaration",
|
|
1836
1841
|
"named": true,
|
|
@@ -2835,11 +2840,26 @@
|
|
|
2835
2840
|
"named": true,
|
|
2836
2841
|
"fields": {}
|
|
2837
2842
|
},
|
|
2843
|
+
{
|
|
2844
|
+
"type": "ms_restrict_modifier",
|
|
2845
|
+
"named": true,
|
|
2846
|
+
"fields": {}
|
|
2847
|
+
},
|
|
2848
|
+
{
|
|
2849
|
+
"type": "ms_signed_ptr_modifier",
|
|
2850
|
+
"named": true,
|
|
2851
|
+
"fields": {}
|
|
2852
|
+
},
|
|
2838
2853
|
{
|
|
2839
2854
|
"type": "ms_unaligned_ptr_modifier",
|
|
2840
2855
|
"named": true,
|
|
2841
2856
|
"fields": {}
|
|
2842
2857
|
},
|
|
2858
|
+
{
|
|
2859
|
+
"type": "ms_unsigned_ptr_modifier",
|
|
2860
|
+
"named": true,
|
|
2861
|
+
"fields": {}
|
|
2862
|
+
},
|
|
2843
2863
|
{
|
|
2844
2864
|
"type": "null",
|
|
2845
2865
|
"named": true,
|
|
@@ -4535,6 +4555,11 @@
|
|
|
4535
4555
|
]
|
|
4536
4556
|
}
|
|
4537
4557
|
},
|
|
4558
|
+
{
|
|
4559
|
+
"type": "true",
|
|
4560
|
+
"named": true,
|
|
4561
|
+
"fields": {}
|
|
4562
|
+
},
|
|
4538
4563
|
{
|
|
4539
4564
|
"type": "type_definition",
|
|
4540
4565
|
"named": true,
|
|
@@ -5254,10 +5279,18 @@
|
|
|
5254
5279
|
"type": "__ptr64",
|
|
5255
5280
|
"named": false
|
|
5256
5281
|
},
|
|
5282
|
+
{
|
|
5283
|
+
"type": "__restrict",
|
|
5284
|
+
"named": false
|
|
5285
|
+
},
|
|
5257
5286
|
{
|
|
5258
5287
|
"type": "__restrict__",
|
|
5259
5288
|
"named": false
|
|
5260
5289
|
},
|
|
5290
|
+
{
|
|
5291
|
+
"type": "__sptr",
|
|
5292
|
+
"named": false
|
|
5293
|
+
},
|
|
5261
5294
|
{
|
|
5262
5295
|
"type": "__stdcall",
|
|
5263
5296
|
"named": false
|
|
@@ -5294,6 +5327,10 @@
|
|
|
5294
5327
|
"type": "__unaligned",
|
|
5295
5328
|
"named": false
|
|
5296
5329
|
},
|
|
5330
|
+
{
|
|
5331
|
+
"type": "__uptr",
|
|
5332
|
+
"named": false
|
|
5333
|
+
},
|
|
5297
5334
|
{
|
|
5298
5335
|
"type": "__vectorcall",
|
|
5299
5336
|
"named": false
|
|
@@ -5385,7 +5422,7 @@
|
|
|
5385
5422
|
},
|
|
5386
5423
|
{
|
|
5387
5424
|
"type": "false",
|
|
5388
|
-
"named":
|
|
5425
|
+
"named": false
|
|
5389
5426
|
},
|
|
5390
5427
|
{
|
|
5391
5428
|
"type": "field_identifier",
|
|
@@ -5419,18 +5456,6 @@
|
|
|
5419
5456
|
"type": "long",
|
|
5420
5457
|
"named": false
|
|
5421
5458
|
},
|
|
5422
|
-
{
|
|
5423
|
-
"type": "ms_restrict_modifier",
|
|
5424
|
-
"named": true
|
|
5425
|
-
},
|
|
5426
|
-
{
|
|
5427
|
-
"type": "ms_signed_ptr_modifier",
|
|
5428
|
-
"named": true
|
|
5429
|
-
},
|
|
5430
|
-
{
|
|
5431
|
-
"type": "ms_unsigned_ptr_modifier",
|
|
5432
|
-
"named": true
|
|
5433
|
-
},
|
|
5434
5459
|
{
|
|
5435
5460
|
"type": "noreturn",
|
|
5436
5461
|
"named": false
|
|
@@ -5523,7 +5548,7 @@
|
|
|
5523
5548
|
},
|
|
5524
5549
|
{
|
|
5525
5550
|
"type": "true",
|
|
5526
|
-
"named":
|
|
5551
|
+
"named": false
|
|
5527
5552
|
},
|
|
5528
5553
|
{
|
|
5529
5554
|
"type": "type_identifier",
|
package/src/pragma.h
CHANGED
|
@@ -444,7 +444,7 @@ static bool preproc_identifier_character(int32_t c, bool continuation) {
|
|
|
444
444
|
static bool scan_pragma_word(TSLexer *lexer) {
|
|
445
445
|
const char *word = pragma_word;
|
|
446
446
|
for (; *word; word++) {
|
|
447
|
-
if (lexer->lookahead != *word) return false;
|
|
447
|
+
if (!scan_preproc_splices(lexer) || lexer->lookahead != *word) return false;
|
|
448
448
|
lexer->advance(lexer, false);
|
|
449
449
|
}
|
|
450
450
|
return true;
|
|
@@ -595,10 +595,7 @@ static bool scan_macro_name_tail(TSLexer *lexer, MacroName *name, bool has_name)
|
|
|
595
595
|
MacroNameCharacter character = scan_macro_name_character(lexer, has_name, name);
|
|
596
596
|
if (character == MACRO_NAME_INVALID) return false;
|
|
597
597
|
if (character == MACRO_NAME_END) return has_name;
|
|
598
|
-
if (character == MACRO_NAME_SPLICE)
|
|
599
|
-
if (!has_name) continue;
|
|
600
|
-
return scan_preproc_splices(lexer);
|
|
601
|
-
}
|
|
598
|
+
if (character == MACRO_NAME_SPLICE) continue;
|
|
602
599
|
has_name = true;
|
|
603
600
|
if (!name->lookahead_only) lexer->mark_end(lexer);
|
|
604
601
|
}
|
|
@@ -642,10 +639,12 @@ static MacroNameCharacter scan_macro_name_character(TSLexer *lexer, bool continu
|
|
|
642
639
|
}
|
|
643
640
|
|
|
644
641
|
static bool scan_macro_name_ucn(TSLexer *lexer) {
|
|
642
|
+
if (!scan_preproc_splices(lexer)) return false;
|
|
645
643
|
unsigned digits = lexer->lookahead == 'u' ? 4 : lexer->lookahead == 'U' ? 8 : 0;
|
|
646
644
|
if (!digits) return false;
|
|
647
645
|
lexer->advance(lexer, false);
|
|
648
646
|
for (unsigned i = 0; i < digits; i++) {
|
|
647
|
+
if (!scan_preproc_splices(lexer)) return false;
|
|
649
648
|
int32_t c = lexer->lookahead;
|
|
650
649
|
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) return false;
|
|
651
650
|
lexer->advance(lexer, false);
|
package/src/scanner.c
CHANGED
|
@@ -387,7 +387,7 @@ static bool is_c_space(int32_t c) {
|
|
|
387
387
|
}
|
|
388
388
|
|
|
389
389
|
static bool starts_macro_scan(int32_t c, bool consumed_backslash) {
|
|
390
|
-
if (consumed_backslash) return
|
|
390
|
+
if (consumed_backslash) return true;
|
|
391
391
|
if (c < 0) return false;
|
|
392
392
|
if (c < 0x80) return c == '\\' || ((preproc_identifier_start_ascii[c / 64] >> (c % 64)) & 1);
|
|
393
393
|
return preproc_identifier_character(c, false);
|
package/tree-sitter-c.wasm
CHANGED
|
Binary file
|