@willbooster/tree-sitter-c 48.1.0 → 49.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/grammar.js CHANGED
@@ -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
- )}|__${identifierExcept(
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
- assertMacroCaseIdentifierSpellsNoKeyword(
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
- ...primitiveTypeKeywords,
1665
- 'size_t',
1666
- 'ssize_t',
1667
- 'ptrdiff_t',
1668
- 'intptr_t',
1669
- 'uintptr_t',
1670
- 'charptr_t',
1671
- 'nullptr_t',
1672
- 'max_align_t',
1673
- ...[8, 16, 32, 64].map((n) => `int${n}_t`),
1674
- ...[8, 16, 32, 64].map((n) => `uint${n}_t`),
1675
- ...[8, 16, 32, 64].map((n) => `char${n}_t`)
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: () => token(prec(-1, /\d+(\.\d+){0,2}/)),
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 separator = "'";
2416
+ const join = repeat(LINE_SPLICE);
2409
2417
  const hex = /[0-9a-fA-F]/;
2410
2418
  const decimal = /[0-9]/;
2411
- const hexDigits = seq(repeat1(hex), repeat(seq(separator, repeat1(hex))));
2412
- const decimalDigits = seq(repeat1(decimal), repeat(seq(separator, repeat1(decimal))));
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(/0[bB]/, decimalDigits), seq(/0[xX]/, hexDigits)),
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(/0[xX]/, '.', hexDigits)
2432
+ seq('.', join, decimalDigits),
2433
+ seq(hexPrefix, '.', join, hexDigits)
2423
2434
  ),
2424
- optional(seq(/[eEpP]/, optional(seq(optional(/[-+]/), hexDigits)))),
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
- token(
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
- /[xu]\{[0-9a-fA-F]+\}/,
2479
- /o\{[0-7]+\}/,
2480
- /N\{[^}\n]+\}/,
2481
- /[0-7]{1,3}/,
2482
- /x[0-9a-fA-F]+/,
2483
- /u[0-9a-fA-F]{4}/,
2484
- /U[0-9a-fA-F]{8}/
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
- `(?:\\p{XID_Start}|\\$|_|\\\\u[0-9A-Fa-f]{4}|\\\\U[0-9A-Fa-f]{8}|${C17_IDENTIFIER_START.source})(?:\\p{XID_Continue}|\\$|\\\\u[0-9A-Fa-f]{4}|\\\\U[0-9A-Fa-f]{8}|${C17_IDENTIFIER_CONTINUE.source})*`,
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
- /(\d|\.\d)([\p{XID_Continue}.]|[eEpP][+-]|'[_a-zA-Z0-9]|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8})*/u,
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
- * Returns a regular expression source that matches every string of a character in `first` followed by characters in
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 alternatives = [`[${others}][${rest}]*`];
2702
- for (const [character, rests] of byFirst) alternatives.push(`${character}${identifierExcept(rests, rest, rest)}`);
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,62 @@ 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
+ * @template {import('./types/treeSitterDsl').GrammarSchema<string>} Schema
3203
+ * @param {Schema} schema
3204
+ * @returns {Schema & import('./types/treeSitterDsl').GrammarSchema<import('./src/grammarRuleNames').GrammarRuleName>}
3205
+ */
3206
+ function prepareCGrammar(schema) {
3207
+ assertMacroCaseIdentifierSpellsNoKeyword(schema);
3208
+ const rules = schema.grammar.rules;
3209
+ /** @type {Record<string, import('./types/treeSitterDsl').Rule>} */
3210
+ const spellings = {};
3211
+ for (const [name, rule] of Object.entries(rules)) rules[name] = spliceSyntaxLiterals(rule, spellings);
3212
+ const start = rules.translation_unit;
3213
+ if (!start) throw new Error('Expected the C translation unit start rule');
3214
+ schema.grammar.rules = { translation_unit: start, ...spellings, ...rules };
3215
+ return schema;
3216
+ }
3217
+
3218
+ /**
3219
+ * @param {import('./types/treeSitterDsl').Rule} rule
3220
+ * @param {Record<string, import('./types/treeSitterDsl').Rule>} rules
3221
+ * @param {boolean} aliased
3222
+ * @returns {import('./types/treeSitterDsl').Rule}
3223
+ */
3224
+ function spliceSyntaxLiterals(rule, rules, aliased = false) {
3225
+ if (rule.type === 'STRING' && /^(?:[A-Za-z_][A-Za-z_0-9]+|(?:[LuU]|u8)["']|[.><=+&|!*/%:^-]{2,})$/.test(rule.value)) {
3226
+ const word = rule.value;
3227
+ const suffix = /^\w+$/.test(word)
3228
+ ? word
3229
+ : Array.from(word, (ch) => (ch.codePointAt(0) ?? 0).toString(16)).join('_');
3230
+ const name = '_spliced_' + suffix;
3231
+ if (!rules[name]) rules[name] = token(splicedLiteralPattern(word));
3232
+ return choice(rule, aliased ? sym(name) : alias(sym(name), word));
3233
+ }
3234
+ if (rule.type === 'TOKEN' || rule.type === 'IMMEDIATE_TOKEN') return rule;
3235
+ if ('members' in rule)
3236
+ return { ...rule, members: rule.members.map((child) => spliceSyntaxLiterals(child, rules, aliased)) };
3237
+ if ('content' in rule)
3238
+ return { ...rule, content: spliceSyntaxLiterals(rule.content, rules, aliased || rule.type === 'ALIAS') };
3239
+ return rule;
3240
+ }
3241
+
3242
+ /** @param {string} word */
3243
+ function splicedLiteralPattern(word) {
3244
+ const chars = Array.from(word, (ch) => String.raw`\x` + (ch.codePointAt(0) ?? 0).toString(16).padStart(2, '0'));
3245
+ const splice = '(?:' + LINE_SPLICE.source + ')';
3246
+ const spellings = chars.slice(1).map((_, offset) => {
3247
+ const i = offset + 1;
3248
+ return chars.slice(0, i).join('') + splice + '+' + chars.slice(i).join(splice + '*');
3249
+ });
3250
+ return new RegExp(spellings.join('|'));
3251
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c",
3
- "version": "48.1.0",
3
+ "version": "49.0.1",
4
4
  "description": "C grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "c",
@@ -20,6 +20,7 @@
20
20
  "tree-sitter.json",
21
21
  "*.wasm",
22
22
  "src/grammarKeywords.cjs",
23
+ "src/grammarRuleNames.d.ts",
23
24
  "script/buildIdentifierTables.mjs",
24
25
  "src/pragma.h",
25
26
  "src/identifier.h",
@@ -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 = lexer->lookahead == 'u' || lexer->lookahead == 'U';
204
- return *escaped;
203
+ *escaped = true;
204
+ return true;
205
205
  }
206
206
  return true;
207
207
  }
@@ -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) {
@@ -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
 
@@ -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 && continuation) return scan_preproc_splices(lexer);
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 = lexer->lookahead == 'u' || lexer->lookahead == 'U';
652
- return *escaped;
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 (escaped && !scan_macro_name_ucn(lexer)) return false;
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) {
@@ -0,0 +1,476 @@
1
+ // Generated from src/grammar.json by script/generateIdentifierRanges.js.
2
+ export type GrammarRuleName =
3
+ | '_abstract_declarator'
4
+ | '_annotation_type_specifier'
5
+ | '_assignment_left_expression'
6
+ | '_attributed_body_statement'
7
+ | '_bare_initializer_type'
8
+ | '_bare_marker_initializer_declaration'
9
+ | '_block_item'
10
+ | '_braced_leading_macro_attribute_specifier'
11
+ | '_braced_macro_attribute_argument_list'
12
+ | '_braced_macro_declarator'
13
+ | '_braced_macro_function_declarator'
14
+ | '_braced_macro_init_declarator'
15
+ | '_case_body_attributed_statement'
16
+ | '_case_body_labeled_statement'
17
+ | '_case_body_statement'
18
+ | '_case_body_unattributed_statement'
19
+ | '_case_label_attributes'
20
+ | '_case_label_chain'
21
+ | '_case_label_chain_statement'
22
+ | '_case_label_statement'
23
+ | '_case_label_tail'
24
+ | '_case_statement_item'
25
+ | '_compound_literal_storage_class_specifier'
26
+ | '_conditional_declaration'
27
+ | '_conditional_function_definition'
28
+ | '_conditional_function_specifiers'
29
+ | '_conditional_macro_specifier'
30
+ | '_conditional_old_style_function_definition'
31
+ | '_declaration_declarator'
32
+ | '_declaration_declarators'
33
+ | '_declaration_modifiers'
34
+ | '_declaration_specifiers'
35
+ | '_declarator'
36
+ | '_empty_declaration'
37
+ | '_enum_underlying_type'
38
+ | '_enumerator_directive'
39
+ | '_enumerator_directives'
40
+ | '_enumerator_list_item'
41
+ | '_enumerator_macro'
42
+ | '_enumerator_macro_call'
43
+ | '_expression_not_binary'
44
+ | '_field_declaration_declarator'
45
+ | '_field_declaration_list_item'
46
+ | '_field_declaration_specifiers'
47
+ | '_field_declarator'
48
+ | '_field_identifier'
49
+ | '_for_empty_declaration'
50
+ | '_for_statement_body'
51
+ | '_function_declaration_declarator'
52
+ | '_function_macro_specifier'
53
+ | '_guarded_init_declarator'
54
+ | '_guarded_initialized_declarator'
55
+ | '_guarded_macro_type_specifier'
56
+ | '_guarded_type_specifier'
57
+ | '_guarded_type_specifiers'
58
+ | '_header_preproc_item'
59
+ | '_initialized_declarator'
60
+ | '_initialized_parenthesized_content'
61
+ | '_initialized_parenthesized_declarator'
62
+ | '_initialized_pointer_declarator'
63
+ | '_initializer_branch'
64
+ | '_initializer_directive'
65
+ | '_initializer_directives'
66
+ | '_initializer_element'
67
+ | '_initializer_sequence'
68
+ | '_known_annotation_type_specifier'
69
+ | '_later_macro_call_expression'
70
+ | '_leading_conditional_macro_specifier'
71
+ | '_leading_macro_call_expression'
72
+ | '_leading_marker_preproc_ifdef'
73
+ | '_macro_attribute_argument_list'
74
+ | '_macro_attribute_parameter'
75
+ | '_macro_attribute_specifier'
76
+ | '_macro_attribute_suffix'
77
+ | '_macro_case_array_declarator'
78
+ | '_macro_case_attributed_declarator'
79
+ | '_macro_case_function_declarator'
80
+ | '_macro_case_identifier'
81
+ | '_macro_case_macro_specifier'
82
+ | '_macro_case_parameter_declarator'
83
+ | '_macro_case_unattributed_declarator'
84
+ | '_macro_declaration_declarator'
85
+ | '_macro_declaration_specifiers'
86
+ | '_macro_modified_declaration'
87
+ | '_macro_only_declaration'
88
+ | '_marked_macro_type_specifiers'
89
+ | '_marker_preproc_ifdef'
90
+ | '_non_case_statement'
91
+ | '_non_identifier_type_specifier'
92
+ | '_non_macro_declaration_modifiers'
93
+ | '_old_style_declarator'
94
+ | '_old_style_function_declarator'
95
+ | '_old_style_function_definition'
96
+ | '_old_style_parameter_list'
97
+ | '_old_style_pointer_declarator'
98
+ | '_parameter_declarator'
99
+ | '_parameter_function_declarator'
100
+ | '_parameter_macro_argument_list'
101
+ | '_parameter_pointer_declarator'
102
+ | '_parenthesized_raw_string_type_argument'
103
+ | '_post_type_macro_attribute_specifier'
104
+ | '_post_type_macro_attribute_suffix'
105
+ | '_preproc_directive_arg'
106
+ | '_preproc_expression'
107
+ | '_preproc_include_path'
108
+ | '_preproc_include_segment'
109
+ | '_preproc_include_token'
110
+ | '_preproc_lparen'
111
+ | '_preproc_newline'
112
+ | '_preproc_number'
113
+ | '_raw_string_macro_type_arguments'
114
+ | '_raw_string_type_argument'
115
+ | '_raw_string_type_tail'
116
+ | '_single_attributed_body_statement'
117
+ | '_single_attributed_statement'
118
+ | '_single_case_body'
119
+ | '_single_case_statement'
120
+ | '_single_labeled_statement'
121
+ | '_single_non_case_statement'
122
+ | '_single_noncompound_statement'
123
+ | '_single_statement'
124
+ | '_single_unattributed_non_case_statement'
125
+ | '_sized_bit_int_specifier'
126
+ | '_sized_bit_int_type_name'
127
+ | '_sized_type_identifier'
128
+ | '_sized_type_name'
129
+ | '_spliced_21_3d'
130
+ | '_spliced_25_3d'
131
+ | '_spliced_26_26'
132
+ | '_spliced_26_3d'
133
+ | '_spliced_2a_3d'
134
+ | '_spliced_2b_2b'
135
+ | '_spliced_2b_3d'
136
+ | '_spliced_2d_2d'
137
+ | '_spliced_2d_3d'
138
+ | '_spliced_2d_3e'
139
+ | '_spliced_2e_2e_2e'
140
+ | '_spliced_2f_3d'
141
+ | '_spliced_3a_3a'
142
+ | '_spliced_3c_3c'
143
+ | '_spliced_3c_3c_3d'
144
+ | '_spliced_3c_3d'
145
+ | '_spliced_3d_3d'
146
+ | '_spliced_3e_3d'
147
+ | '_spliced_3e_3e'
148
+ | '_spliced_3e_3e_3d'
149
+ | '_spliced_4c_22'
150
+ | '_spliced_4c_27'
151
+ | '_spliced_55_22'
152
+ | '_spliced_55_27'
153
+ | '_spliced_5e_3d'
154
+ | '_spliced_75_22'
155
+ | '_spliced_75_27'
156
+ | '_spliced_75_38_22'
157
+ | '_spliced_75_38_27'
158
+ | '_spliced_7c_3d'
159
+ | '_spliced_7c_7c'
160
+ | '_spliced_NULL'
161
+ | '_spliced__Alignas'
162
+ | '_spliced__Alignof'
163
+ | '_spliced__Atomic'
164
+ | '_spliced__BitInt'
165
+ | '_spliced__Complex'
166
+ | '_spliced__Countof'
167
+ | '_spliced__Defer'
168
+ | '_spliced__Generic'
169
+ | '_spliced__Imaginary'
170
+ | '_spliced__Nonnull'
171
+ | '_spliced__Noreturn'
172
+ | '_spliced__Thread_local'
173
+ | '_spliced___alignof'
174
+ | '_spliced___alignof__'
175
+ | '_spliced___asm'
176
+ | '_spliced___asm__'
177
+ | '_spliced___attribute'
178
+ | '_spliced___attribute__'
179
+ | '_spliced___based'
180
+ | '_spliced___builtin_available'
181
+ | '_spliced___builtin_va_arg'
182
+ | '_spliced___cdecl'
183
+ | '_spliced___clrcall'
184
+ | '_spliced___complex__'
185
+ | '_spliced___declspec'
186
+ | '_spliced___except'
187
+ | '_spliced___extension__'
188
+ | '_spliced___fastcall'
189
+ | '_spliced___finally'
190
+ | '_spliced___forceinline'
191
+ | '_spliced___inline'
192
+ | '_spliced___inline__'
193
+ | '_spliced___leave'
194
+ | '_spliced___ptr32'
195
+ | '_spliced___ptr64'
196
+ | '_spliced___restrict'
197
+ | '_spliced___restrict__'
198
+ | '_spliced___sptr'
199
+ | '_spliced___stdcall'
200
+ | '_spliced___thiscall'
201
+ | '_spliced___thread'
202
+ | '_spliced___try'
203
+ | '_spliced___typeof'
204
+ | '_spliced___typeof__'
205
+ | '_spliced___typeof_unqual'
206
+ | '_spliced___typeof_unqual__'
207
+ | '_spliced___unaligned'
208
+ | '_spliced___uptr'
209
+ | '_spliced___vectorcall'
210
+ | '_spliced___volatile__'
211
+ | '_spliced__alignof'
212
+ | '_spliced__unaligned'
213
+ | '_spliced_alignas'
214
+ | '_spliced_alignof'
215
+ | '_spliced_asm'
216
+ | '_spliced_auto'
217
+ | '_spliced_break'
218
+ | '_spliced_case'
219
+ | '_spliced_const'
220
+ | '_spliced_constexpr'
221
+ | '_spliced_continue'
222
+ | '_spliced_default'
223
+ | '_spliced_defined'
224
+ | '_spliced_do'
225
+ | '_spliced_else'
226
+ | '_spliced_enum'
227
+ | '_spliced_extern'
228
+ | '_spliced_false'
229
+ | '_spliced_for'
230
+ | '_spliced_goto'
231
+ | '_spliced_if'
232
+ | '_spliced_inline'
233
+ | '_spliced_long'
234
+ | '_spliced_noreturn'
235
+ | '_spliced_nullptr'
236
+ | '_spliced_offsetof'
237
+ | '_spliced_register'
238
+ | '_spliced_restrict'
239
+ | '_spliced_return'
240
+ | '_spliced_short'
241
+ | '_spliced_signed'
242
+ | '_spliced_sizeof'
243
+ | '_spliced_static'
244
+ | '_spliced_struct'
245
+ | '_spliced_switch'
246
+ | '_spliced_thread_local'
247
+ | '_spliced_true'
248
+ | '_spliced_typedef'
249
+ | '_spliced_typeof'
250
+ | '_spliced_typeof_unqual'
251
+ | '_spliced_union'
252
+ | '_spliced_unsigned'
253
+ | '_spliced_va_arg'
254
+ | '_spliced_volatile'
255
+ | '_spliced_while'
256
+ | '_statement_declaration'
257
+ | '_statement_declaration_modifiers'
258
+ | '_statement_declaration_specifiers'
259
+ | '_statement_empty_declaration'
260
+ | '_statement_function_definition'
261
+ | '_statement_identifier'
262
+ | '_statement_old_style_function_definition'
263
+ | '_statement_type_definition'
264
+ | '_string'
265
+ | '_top_level_expression_statement'
266
+ | '_top_level_item'
267
+ | '_top_level_statement'
268
+ | '_trailing_macro_attribute_specifier'
269
+ | '_trailing_macro_call_expression'
270
+ | '_trailing_macro_modified_declaration'
271
+ | '_trailing_macro_object_declarator'
272
+ | '_trailing_macro_pointer_declarator'
273
+ | '_trailing_macro_specifier'
274
+ | '_type_declarator'
275
+ | '_type_definition_declarators'
276
+ | '_type_definition_type'
277
+ | '_type_identifier'
278
+ | '_type_name_specifier'
279
+ | '_unattributed_declarator'
280
+ | '_unattributed_field_declarator'
281
+ | '_unattributed_non_case_statement'
282
+ | '_unattributed_type_declarator'
283
+ | '_unlabeled_non_case_statement'
284
+ | '_variadic_macro_type_specifier'
285
+ | 'abstract_array_declarator'
286
+ | 'abstract_function_declarator'
287
+ | 'abstract_parenthesized_declarator'
288
+ | 'abstract_pointer_declarator'
289
+ | 'alignas_qualifier'
290
+ | 'alignof_expression'
291
+ | 'argument_list'
292
+ | 'array_declarator'
293
+ | 'array_field_declarator'
294
+ | 'array_type_declarator'
295
+ | 'assignment_expression'
296
+ | 'atomic_type_specifier'
297
+ | 'attribute'
298
+ | 'attribute_declaration'
299
+ | 'attribute_specifier'
300
+ | 'attributed_declarator'
301
+ | 'attributed_field_declarator'
302
+ | 'attributed_statement'
303
+ | 'attributed_type_declarator'
304
+ | 'binary_expression'
305
+ | 'bit_int_specifier'
306
+ | 'bitfield_clause'
307
+ | 'break_statement'
308
+ | 'builtin_available_expression'
309
+ | 'call_expression'
310
+ | 'case_statement'
311
+ | 'cast_expression'
312
+ | 'char_literal'
313
+ | 'comma_expression'
314
+ | 'comment'
315
+ | 'compound_literal_expression'
316
+ | 'compound_statement'
317
+ | 'concatenated_string'
318
+ | 'conditional_expression'
319
+ | 'continue_statement'
320
+ | 'countof_expression'
321
+ | 'declaration'
322
+ | 'declaration_list'
323
+ | 'defer_statement'
324
+ | 'do_statement'
325
+ | 'else_clause'
326
+ | 'enum_specifier'
327
+ | 'enumerator'
328
+ | 'enumerator_list'
329
+ | 'escape_sequence'
330
+ | 'expression'
331
+ | 'expression_statement'
332
+ | 'extension_expression'
333
+ | 'false'
334
+ | 'field_declaration'
335
+ | 'field_declaration_list'
336
+ | 'field_designator'
337
+ | 'field_expression'
338
+ | 'for_statement'
339
+ | 'function_declarator'
340
+ | 'function_definition'
341
+ | 'function_field_declarator'
342
+ | 'function_type_declarator'
343
+ | 'generic_expression'
344
+ | 'gnu_asm_clobber_list'
345
+ | 'gnu_asm_expression'
346
+ | 'gnu_asm_goto_list'
347
+ | 'gnu_asm_input_operand'
348
+ | 'gnu_asm_input_operand_list'
349
+ | 'gnu_asm_output_operand'
350
+ | 'gnu_asm_output_operand_list'
351
+ | 'gnu_asm_qualifier'
352
+ | 'goto_statement'
353
+ | 'identifier'
354
+ | 'if_statement'
355
+ | 'init_declarator'
356
+ | 'initializer_list'
357
+ | 'initializer_pair'
358
+ | 'invalid_escape_sequence'
359
+ | 'labeled_statement'
360
+ | 'linkage_specification'
361
+ | 'macro_specifier'
362
+ | 'macro_type_specifier'
363
+ | 'ms_based_modifier'
364
+ | 'ms_call_modifier'
365
+ | 'ms_declspec_modifier'
366
+ | 'ms_pointer_modifier'
367
+ | 'ms_pointer_size_modifier'
368
+ | 'ms_restrict_modifier'
369
+ | 'ms_signed_ptr_modifier'
370
+ | 'ms_unaligned_ptr_modifier'
371
+ | 'ms_unsigned_ptr_modifier'
372
+ | 'null'
373
+ | 'number_literal'
374
+ | 'offsetof_expression'
375
+ | 'parameter_declaration'
376
+ | 'parameter_list'
377
+ | 'parenthesized_declarator'
378
+ | 'parenthesized_expression'
379
+ | 'parenthesized_field_declarator'
380
+ | 'parenthesized_type_declarator'
381
+ | 'platform_version'
382
+ | 'pointer_declarator'
383
+ | 'pointer_expression'
384
+ | 'pointer_field_declarator'
385
+ | 'pointer_type_declarator'
386
+ | 'pragma_operator'
387
+ | 'preproc_arg'
388
+ | 'preproc_argument_list'
389
+ | 'preproc_binary_expression'
390
+ | 'preproc_call'
391
+ | 'preproc_call_expression'
392
+ | 'preproc_def'
393
+ | 'preproc_defined'
394
+ | 'preproc_elif'
395
+ | 'preproc_elif_in_enumerator_directives'
396
+ | 'preproc_elif_in_enumerator_list'
397
+ | 'preproc_elif_in_enumerator_list_no_comma'
398
+ | 'preproc_elif_in_field_declaration_list'
399
+ | 'preproc_elif_in_header'
400
+ | 'preproc_elif_in_initializer_list'
401
+ | 'preproc_elif_in_single_case'
402
+ | 'preproc_elif_in_statement'
403
+ | 'preproc_elifdef'
404
+ | 'preproc_elifdef_in_enumerator_directives'
405
+ | 'preproc_elifdef_in_enumerator_list'
406
+ | 'preproc_elifdef_in_enumerator_list_no_comma'
407
+ | 'preproc_elifdef_in_field_declaration_list'
408
+ | 'preproc_elifdef_in_header'
409
+ | 'preproc_elifdef_in_initializer_list'
410
+ | 'preproc_elifdef_in_single_case'
411
+ | 'preproc_elifdef_in_statement'
412
+ | 'preproc_else'
413
+ | 'preproc_else_in_enumerator_directives'
414
+ | 'preproc_else_in_enumerator_list'
415
+ | 'preproc_else_in_enumerator_list_no_comma'
416
+ | 'preproc_else_in_field_declaration_list'
417
+ | 'preproc_else_in_header'
418
+ | 'preproc_else_in_initializer_list'
419
+ | 'preproc_else_in_single_case'
420
+ | 'preproc_else_in_statement'
421
+ | 'preproc_function_def'
422
+ | 'preproc_if'
423
+ | 'preproc_if_in_enumerator_directives'
424
+ | 'preproc_if_in_enumerator_list'
425
+ | 'preproc_if_in_enumerator_list_no_comma'
426
+ | 'preproc_if_in_field_declaration_list'
427
+ | 'preproc_if_in_header'
428
+ | 'preproc_if_in_initializer_list'
429
+ | 'preproc_if_in_single_case'
430
+ | 'preproc_if_in_statement'
431
+ | 'preproc_ifdef'
432
+ | 'preproc_ifdef_in_enumerator_directives'
433
+ | 'preproc_ifdef_in_enumerator_list'
434
+ | 'preproc_ifdef_in_enumerator_list_no_comma'
435
+ | 'preproc_ifdef_in_field_declaration_list'
436
+ | 'preproc_ifdef_in_header'
437
+ | 'preproc_ifdef_in_initializer_list'
438
+ | 'preproc_ifdef_in_single_case'
439
+ | 'preproc_ifdef_in_statement'
440
+ | 'preproc_include'
441
+ | 'preproc_include_argument'
442
+ | 'preproc_params'
443
+ | 'preproc_parenthesized_expression'
444
+ | 'preproc_unary_expression'
445
+ | 'primitive_type'
446
+ | 'raw_string_literal'
447
+ | 'return_statement'
448
+ | 'seh_except_clause'
449
+ | 'seh_finally_clause'
450
+ | 'seh_leave_statement'
451
+ | 'seh_try_statement'
452
+ | 'sized_type_specifier'
453
+ | 'sizeof_expression'
454
+ | 'statement'
455
+ | 'storage_class_specifier'
456
+ | 'string_literal'
457
+ | 'struct_specifier'
458
+ | 'subscript_designator'
459
+ | 'subscript_expression'
460
+ | 'subscript_range_designator'
461
+ | 'switch_statement'
462
+ | 'system_lib_string'
463
+ | 'translation_unit'
464
+ | 'true'
465
+ | 'type_definition'
466
+ | 'type_descriptor'
467
+ | 'type_qualifier'
468
+ | 'type_specifier'
469
+ | 'typeof_specifier'
470
+ | 'unary_expression'
471
+ | 'union_specifier'
472
+ | 'update_expression'
473
+ | 'va_arg_expression'
474
+ | 'variadic_parameter'
475
+ | 'version_number'
476
+ | 'while_statement';
@@ -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": true
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": true
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 c == 'u' || c == 'U';
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);
Binary file
package/tree-sitter.json CHANGED
@@ -28,7 +28,7 @@
28
28
  }
29
29
  ],
30
30
  "metadata": {
31
- "version": "48.1.0",
31
+ "version": "49.0.1",
32
32
  "license": "MIT",
33
33
  "description": "C grammar for tree-sitter",
34
34
  "authors": [