@willbooster/tree-sitter-c 48.0.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/README.md CHANGED
@@ -146,7 +146,21 @@ Keep the shared first-word dispatch so a failed lookahead never falls back from
146
146
  When both post-type guards are valid, prefer the continuation suffix so annotation chains remain on their existing path.
147
147
  First prototype guards check the prototype tail; post-type continuation guards inspect only their own argument group.
148
148
  Regenerate Unicode and keyword tables from the derived grammar's metadata.
149
- The generation source is `script/generateIdentifierRanges.js` in this repository.
149
+ Import `buildIdentifierTables` from `@willbooster/tree-sitter-c/script/buildIdentifierTables.mjs` and pass the text of the generated `src/parser.c` to obtain the C declarations for the identifier ranges and ASCII masks. Define `TREE_SITTER_C_IDENTIFIER_HEADER` and `TREE_SITTER_C_KEYWORDS_HEADER` as quoted header names before including the scanner headers to select the grammar’s own tables. The default headers are `identifier.h` and `keywords.h`. Add the selected header paths to the grammar’s `external-files` in `tree-sitter.json` so the CLI rebuilds its cached parser when either table changes.
150
+ The keyword header declares sorted arrays of ASCII strings. Use bytewise `strcmp` order within each array and size
151
+ `FUNCTION_MACRO_KEYWORD_MAX_LENGTH` for the longest spelling. The arrays have the following roles.
152
+
153
+ | Array | Words to include |
154
+ | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
155
+ | `function_macro_keywords` | All keyword spellings the scanner must distinguish from annotation names. |
156
+ | `function_macro_type_keywords` | Keywords that introduce a type specifier. |
157
+ | `function_macro_tagged_type_keywords` | Type introducers that admit a tag or a braced definition, such as C’s `struct`, `union`, and `enum`. |
158
+ | `function_macro_scalar_type_keywords` | Scalar primitive tokens recognized by this grammar, including typedef spellings such as `size_t` and `uint32_t` when the grammar treats them as primitives. |
159
+ | `function_macro_declaration_modifiers` | Qualifiers, attributes and calling-convention words in declarations. |
160
+ | `function_macro_type_prefix_modifiers` | Declaration modifiers and storage classes that can precede a type. |
161
+ | `function_macro_object_prefix_keywords` | Built-in type words, size modifiers, declaration modifiers, storage classes and typedef introducers that can start an object declaration. |
162
+ | `function_macro_group_modifiers` | Modifiers or type introducers whose following parenthesized group belongs to the same specifier. |
163
+
150
164
  The primitive keyword data shared by grammar generation and object-prefix classification is in `src/grammarKeywords.cjs`.
151
165
  The `_preproc_function_name` token ends before splices used to determine adjacency, so the `_preproc_lparen`
152
166
  scanner must skip those splices again to reach `(`.
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,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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-c",
3
- "version": "48.0.0",
3
+ "version": "49.0.0",
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
+ "script/buildIdentifierTables.mjs",
23
24
  "src/pragma.h",
24
25
  "src/identifier.h",
25
26
  "src/keywords.h",
@@ -0,0 +1,304 @@
1
+ // @ts-check
2
+ import assert from 'node:assert/strict';
3
+
4
+ /**
5
+ * @param {string} parserSource
6
+ */
7
+ export function buildIdentifierTables(parserSource) {
8
+ const symbolMatch = parserSource.match(/^\s*sym_identifier\s*=\s*(\d+),/m);
9
+ const tableMatch = parserSource.match(/static const uint16_t ts_lex_table\[\]\s*=\s*\{([\s\S]*?)\};/);
10
+ assert.ok(symbolMatch?.[1] && tableMatch?.[1], 'Missing sym_identifier or ts_lex_table in src/parser.c');
11
+ const identifierSymbol = Number(symbolMatch[1]);
12
+ const words = Uint16Array.from(tableMatch[1].match(/\d+/g) ?? [], Number);
13
+ const lex = createLexTableReader(words);
14
+ const { accepting, reachable } = statesReachingIdentifier(lex, identifierSymbol);
15
+ const startStates = new Set(
16
+ [...parserSource.matchAll(/\.lex_state(?:_after_extra)?\s*=\s*(\d+)/g)]
17
+ .map((match) => Number(match[1]))
18
+ .filter((state) => state < lex.stateCount)
19
+ );
20
+ assert.ok(startStates.size, 'Missing lexer modes in src/parser.c');
21
+ const startClasses = classifyIdentifierClasses(lex, [...startStates], reachable, true);
22
+ for (const char of [' ', '\t', '\v', '\f', '\r', '\n']) startClasses[lex.asciiClass(char.codePointAt(0) ?? 0)] = 0;
23
+ const continueClasses = classifyIdentifierClasses(lex, accepting, reachable, false);
24
+ return `${formatCharacterRanges('start', lex, startClasses)}${formatCharacterRanges('continue', lex, continueClasses)}${formatAsciiMask('start', lex, startClasses)}${formatAsciiMask('continue', lex, continueClasses)}\n`;
25
+ }
26
+
27
+ /**
28
+ * @param {ReturnType<typeof createLexTableReader>} lex
29
+ * @param {number} symbol
30
+ */
31
+ function statesReachingIdentifier(lex, symbol) {
32
+ const predecessors = identifierPredecessors(lex);
33
+ const reachable = Array.from({ length: lex.stateCount }, () => new Set());
34
+ /** @type {[number,number][]} */
35
+ const pending = [];
36
+ const accepting = [];
37
+ for (let state = 0; state < lex.stateCount; state++) {
38
+ const tag = lex.acceptTag(state, symbol);
39
+ if (tag === undefined) continue;
40
+ pending.push([state, tag]);
41
+ reachable[state]?.add(tag);
42
+ accepting.push(state);
43
+ }
44
+ assert.ok(accepting.length, 'Missing identifier accepting state');
45
+ while (pending.length > 0) {
46
+ const item = pending.pop();
47
+ assert.ok(item);
48
+ const [state, tag] = item;
49
+ for (const [action, origins] of predecessors[state] ?? []) {
50
+ const before = previousTag(action, tag);
51
+ if (before === undefined) continue;
52
+ for (const origin of unseenOrigins(origins, reachable, before)) {
53
+ reachable[origin]?.add(before);
54
+ pending.push([origin, before]);
55
+ }
56
+ }
57
+ }
58
+ return { accepting, reachable };
59
+ }
60
+
61
+ /**
62
+ * @param {Set<number>} origins
63
+ * @param {Set<number>[]} reachable
64
+ * @param {number} tag
65
+ */
66
+ function* unseenOrigins(origins, reachable, tag) {
67
+ for (const origin of origins) {
68
+ if (!reachable[origin]?.has(tag)) yield origin;
69
+ }
70
+ }
71
+
72
+ /** @param {ReturnType<typeof createLexTableReader>} lex */
73
+ function identifierPredecessors(lex) {
74
+ const predecessors = Array.from({ length: lex.stateCount }, () => new Map());
75
+ for (let state = 0; state < lex.stateCount; state++) {
76
+ for (let cls = 0; cls < lex.classCount; cls++) {
77
+ const action = lex.transition(state, cls);
78
+ if (!action) continue;
79
+ const from = predecessors[action.target];
80
+ assert.ok(from);
81
+ if (!from.has(action)) from.set(action, new Set());
82
+ from.get(action).add(state);
83
+ }
84
+ }
85
+ return predecessors;
86
+ }
87
+
88
+ /**
89
+ * @param {{tags: [number, number][]}} action
90
+ * @param {number} tag
91
+ */
92
+ function previousTag(action, tag) {
93
+ for (let i = action.tags.length - 1; i >= 0; i--) {
94
+ const assignment = action.tags[i];
95
+ if (assignment && assignment[0] === tag) {
96
+ if (assignment[1] === 0xff_ff) return;
97
+ tag = assignment[1];
98
+ }
99
+ }
100
+ return tag;
101
+ }
102
+
103
+ /**
104
+ * @param {ReturnType<typeof createLexTableReader>} lex
105
+ * @param {number[]} fromStates
106
+ * @param {Set<number>[]} reachable
107
+ * @param {boolean} atStart
108
+ */
109
+ function classifyIdentifierClasses(lex, fromStates, reachable, atStart) {
110
+ return Uint8Array.from({ length: lex.classCount }, (_, cls) =>
111
+ Number(
112
+ fromStates.some((state) => {
113
+ const action = lex.transition(state, cls);
114
+ if (!action) return false;
115
+ const tags = reachable[action.target];
116
+ return !!tags?.size && (atStart || [...tags].some((tag) => previousTag(action, tag) !== undefined));
117
+ })
118
+ )
119
+ );
120
+ }
121
+
122
+ /**
123
+ * @param {string} suffix
124
+ * @param {ReturnType<typeof createLexTableReader>} lex
125
+ * @param {Uint8Array} matchedClasses
126
+ */
127
+ function formatCharacterRanges(suffix, lex, matchedClasses) {
128
+ const entries = collectCharacterRanges(lex, matchedClasses);
129
+ let lines = `static const TSCharacterRange preproc_identifier_${suffix}[] = {\n`;
130
+ for (let i = 0; i < entries.length; i++) {
131
+ const column = i % 8;
132
+ lines += `${column ? ' ' : ' '}${entries[i]}${column === 7 || i === entries.length - 1 ? '\n' : ''}`;
133
+ }
134
+ return `${lines}};\n\n`;
135
+ }
136
+
137
+ /**
138
+ * @param {ReturnType<typeof createLexTableReader>} lex
139
+ * @param {Uint8Array} matchedClasses
140
+ */
141
+ function collectCharacterRanges(lex, matchedClasses) {
142
+ /** @type {string[]} */
143
+ const entries = [];
144
+ let rangeStart = -1;
145
+ const visit = (/** @type {number} */ start, /** @type {number} */ endExclusive, /** @type {number} */ cls) => {
146
+ if (matchedClasses[cls]) rangeStart = rangeStart < 0 ? start : rangeStart;
147
+ else if (rangeStart >= 0) {
148
+ entries.push(`{0x${rangeStart.toString(16)}, 0x${(start - 1).toString(16)}},`);
149
+ rangeStart = -1;
150
+ }
151
+ return endExclusive;
152
+ };
153
+ let cursor = 0;
154
+ for (let cp = 0; cp < 128; cp++) cursor = visit(cp, cp + 1, lex.asciiClass(cp));
155
+ for (let i = 0; i < lex.unicodeRanges; i++) cursor = visit(cursor, lex.unicodeEnd(i) + 1, lex.unicodeClass(i));
156
+ if (rangeStart >= 0) entries.push(`{0x${rangeStart.toString(16)}, 0x${(cursor - 1).toString(16)}},`);
157
+ return entries;
158
+ }
159
+
160
+ /**
161
+ * @param {string} suffix
162
+ * @param {ReturnType<typeof createLexTableReader>} lex
163
+ * @param {Uint8Array} matchedClasses
164
+ */
165
+ function formatAsciiMask(suffix, lex, matchedClasses) {
166
+ let low = 0n;
167
+ let high = 0n;
168
+ for (let cp = 0; cp < 64; cp++) {
169
+ if (matchedClasses[lex.asciiClass(cp)]) low |= 1n << BigInt(cp);
170
+ if (matchedClasses[lex.asciiClass(cp + 64)]) high |= 1n << BigInt(cp);
171
+ }
172
+ const lowHex = low.toString(16).padStart(16, '0');
173
+ const highHex = high.toString(16).padStart(16, '0');
174
+ return `static const uint64_t preproc_identifier_${suffix}_ascii[] = {0x${lowHex}ull, 0x${highHex}ull};\n`;
175
+ }
176
+
177
+ /**
178
+ * @param {Uint16Array} t
179
+ */
180
+ function createLexTableReader(t) {
181
+ const word = (/** @type {number} */ i) => t[i] ?? 0;
182
+ const readU32 = (/** @type {number} */ i) => (word(i) | (word(i + 1) << 16)) >>> 0;
183
+ const stateCount = word(2);
184
+ const classCount = word(4);
185
+ const unicodeRanges = word(5);
186
+ const wideBase = (word(6) & 0x40_00) !== 0;
187
+ const combLen = readU32(7);
188
+ const extTransLen = readU32(9);
189
+ const unicodeEndsOff = 141;
190
+ const unicodeClassesOff = unicodeEndsOff + unicodeRanges * 2;
191
+ const stateMetaOff = unicodeClassesOff + unicodeRanges;
192
+ const combOff = stateMetaOff + stateCount * (wideBase ? 5 : 4);
193
+ const extTransOff = combOff + combLen * 2;
194
+ const extAcceptsOff = extTransOff + extTransLen;
195
+ const layout = { word, readU32, wideBase, combLen, stateMetaOff, combOff, extTransOff, extAcceptsOff };
196
+ const asciiClass = (/** @type {number} */ cp) => word(13 + cp);
197
+ /** @type {Map<number, ReturnType<typeof decodeTransition>>} */
198
+ const actions = new Map();
199
+ function transition(/** @type {number} */ state, /** @type {number} */ cls) {
200
+ const action = readAction(layout, state, cls);
201
+ if (!actions.has(action)) actions.set(action, decodeTransition(layout, action));
202
+ return actions.get(action);
203
+ }
204
+ return {
205
+ stateCount,
206
+ classCount,
207
+ unicodeRanges,
208
+ asciiClass,
209
+ unicodeEnd: (/** @type {number} */ i) => readU32(unicodeEndsOff + i * 2),
210
+ unicodeClass: (/** @type {number} */ i) => word(unicodeClassesOff + i),
211
+ transition,
212
+ acceptTag: (/** @type {number} */ state, /** @type {number} */ symbol) => readAcceptTag(layout, state, symbol),
213
+ };
214
+ }
215
+
216
+ /**
217
+ * @typedef {{
218
+ * word: (i: number) => number,
219
+ * readU32: (i: number) => number,
220
+ * wideBase: boolean,
221
+ * combLen: number,
222
+ * stateMetaOff: number,
223
+ * combOff: number,
224
+ * extTransOff: number,
225
+ * extAcceptsOff: number,
226
+ * }} LexTableLayout
227
+ */
228
+
229
+ /**
230
+ * @param {LexTableLayout} layout
231
+ * @param {number} state
232
+ */
233
+ function readStateMeta(layout, state) {
234
+ const o = layout.stateMetaOff + state * (layout.wideBase ? 5 : 4);
235
+ return layout.wideBase
236
+ ? { base: layout.readU32(o), tmpl: layout.word(o + 2), def: layout.word(o + 3), acc: layout.word(o + 4) }
237
+ : { base: layout.word(o), tmpl: layout.word(o + 1), def: layout.word(o + 2), acc: layout.word(o + 3) };
238
+ }
239
+
240
+ /**
241
+ * @param {LexTableLayout} layout
242
+ * @param {number} state
243
+ * @param {number} cls
244
+ */
245
+ function readAction(layout, state, cls) {
246
+ const sm = readStateMeta(layout, state);
247
+ if (sm.tmpl === 0 || cls === 0xff_ff) return 0;
248
+ const idx = sm.base + cls;
249
+ const inComb = idx < layout.combLen && layout.word(layout.combOff + idx * 2) === sm.tmpl;
250
+ return inComb ? layout.word(layout.combOff + idx * 2 + 1) : sm.def;
251
+ }
252
+
253
+ /**
254
+ * @param {LexTableLayout} layout
255
+ * @param {number} act
256
+ */
257
+ function decodeTransition(layout, act) {
258
+ /** @type {[number,number][]} */
259
+ const tags = [];
260
+ if (!act) return;
261
+ if ((act & 0x80_00) === 0) {
262
+ if (act & 0x40_00) return;
263
+ if (act & 0x20_00) tags.push([0, 0xff_ff]);
264
+ return { target: (act & 0x1f_ff) - 1, tags };
265
+ }
266
+ const p = layout.extTransOff + (act & 0x7f_ff);
267
+ const count = layout.word(p + 1);
268
+ if (count & 0x80_00) return;
269
+ for (let i = 0; i < count; i++) tags.push([layout.word(p + 2 + i * 2), layout.word(p + 3 + i * 2)]);
270
+ return { target: layout.word(p), tags };
271
+ }
272
+
273
+ /**
274
+ * @param {LexTableLayout} layout
275
+ * @param {number} state
276
+ * @param {number} symbol
277
+ */
278
+ function readAcceptTag(layout, state, symbol) {
279
+ const acc = readStateMeta(layout, state).acc;
280
+ if (!acc) return;
281
+ if ((acc & 0x80_00) === 0) {
282
+ if ((acc & 0x3f_ff) - 1 !== symbol) return;
283
+ return acc & 0x40_00 ? 0 : -1;
284
+ }
285
+ return readExtendedAcceptTag(layout, layout.extAcceptsOff + (acc & 0x7f_ff), symbol);
286
+ }
287
+
288
+ /**
289
+ * @param {LexTableLayout} layout
290
+ * @param {number} p
291
+ * @param {number} symbol
292
+ */
293
+ function readExtendedAcceptTag(layout, p, symbol) {
294
+ const flags = layout.word(p++);
295
+ if (flags & 2) {
296
+ if (!(flags & 1) || layout.word(p) !== symbol) return;
297
+ const tag = layout.word(p + 3);
298
+ return tag === 0xff_ff ? -1 : tag;
299
+ }
300
+ if (flags & 1) p += 4;
301
+ if (!(flags & 4) || layout.word(p++) !== symbol) return;
302
+ if (flags & 8) p += 2;
303
+ return flags & 16 ? layout.word(p) : -1;
304
+ }
@@ -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
 
@@ -3,7 +3,10 @@
3
3
  #define TREE_SITTER_C_FUNCTION_MACRO_H_
4
4
 
5
5
  #include "pragma.h"
6
- #include "keywords.h"
6
+ #ifndef TREE_SITTER_C_KEYWORDS_HEADER
7
+ #define TREE_SITTER_C_KEYWORDS_HEADER "keywords.h"
8
+ #endif
9
+ #include TREE_SITTER_C_KEYWORDS_HEADER
7
10
  #include "macroProof.h"
8
11
 
9
12
  typedef struct {
@@ -328,7 +331,8 @@ static MacroTypePrefix function_macro_type_prefix_item(TSLexer *lexer, const Mac
328
331
 
329
332
  static MacroTypePrefix function_macro_known_type_item(TSLexer *lexer, const MacroName *name, const PragmaTrivia *trivia) {
330
333
  if (lexer->lookahead == '(' && (!function_macro_modifier_balanced(lexer, '(', ')', trivia) || !scan_pragma_spacing_with(lexer, trivia))) return MACRO_TYPE_PREFIX_INVALID;
331
- if (strcmp(name->word, "struct") == 0 || strcmp(name->word, "union") == 0 || strcmp(name->word, "enum") == 0) return MACRO_TYPE_PREFIX_TAGGED_TYPE;
334
+ if (function_macro_word_in(name->word, function_macro_tagged_type_keywords,
335
+ sizeof(function_macro_tagged_type_keywords) / sizeof(*function_macro_tagged_type_keywords))) return MACRO_TYPE_PREFIX_TAGGED_TYPE;
332
336
  return MACRO_TYPE_PREFIX_KNOWN_TYPE;
333
337
  }
334
338
 
@@ -348,6 +352,7 @@ static bool function_macro_trailing_argument_prefix(TSLexer *lexer, const Pragma
348
352
  int32_t first = lexer->lookahead;
349
353
  if (first == '.') {
350
354
  lexer->advance(lexer, false);
355
+ if (!scan_preproc_splices(lexer)) return false;
351
356
  first = lexer->lookahead;
352
357
  return first >= '0' && first <= '9';
353
358
  }
@@ -391,7 +396,7 @@ static bool function_macro_object_word(TSLexer *lexer, MacroName *name, bool esc
391
396
  for (;;) {
392
397
  MacroNameCharacter c = scan_macro_name_character(lexer, continuation, name);
393
398
  if (c == MACRO_NAME_END) return continuation;
394
- if (c == MACRO_NAME_SPLICE && continuation) return scan_preproc_splices(lexer);
399
+ if (c == MACRO_NAME_SPLICE) continue;
395
400
  if (c != MACRO_NAME_CHARACTER) return false;
396
401
  continuation = true;
397
402
  }
@@ -430,8 +435,11 @@ static PeekExtrasKind peek_extras_first(uint16_t first, bool allow_directive, bo
430
435
  return object_possible || pragma_possible ? PEEK_EXTRAS_UNKNOWN : PEEK_EXTRAS_NONE;
431
436
  }
432
437
 
438
+ enum { PEEK_EXTRAS_WORD_CAPACITY = FUNCTION_MACRO_KEYWORD_MAX_LENGTH + 1 > sizeof pragma_word ?
439
+ FUNCTION_MACRO_KEYWORD_MAX_LENGTH + 1 : sizeof pragma_word };
440
+
433
441
  static PeekExtrasKind peek_extras_word(PeekUnitsView view, uint32_t i, bool allow_object, bool allow_pragma) {
434
- char word[12] = {0};
442
+ char word[PEEK_EXTRAS_WORD_CAPACITY] = {0};
435
443
  unsigned length = 0;
436
444
  while (i < view.count) {
437
445
  uint16_t c = peek_unit_at(view.units, view.size, i);
@@ -475,10 +483,16 @@ static uint32_t peek_skip_ident(PeekUnitsView view, uint32_t i, bool *non_plain)
475
483
  }
476
484
 
477
485
  static inline bool peek_object_starter(uint16_t c) {
478
- static const uint64_t starter_hi = (1ULL << ('_' - 64)) | (1ULL << ('b' - 64)) | (1ULL << ('c' - 64)) |
479
- (1ULL << ('d' - 64)) | (1ULL << ('f' - 64)) | (1ULL << ('i' - 64)) | (1ULL << ('m' - 64)) |
480
- (1ULL << ('n' - 64)) | (1ULL << ('p' - 64)) | (1ULL << ('s' - 64)) | (1ULL << ('u' - 64)) | (1ULL << ('v' - 64));
481
- return c >= 64 && ((starter_hi >> (c - 64)) & 1ULL) != 0;
486
+ unsigned low = 0, high = sizeof(function_macro_scalar_type_keywords) / sizeof(*function_macro_scalar_type_keywords);
487
+ if (c >= 128) return false;
488
+ while (low < high) {
489
+ unsigned mid = low + (high - low) / 2;
490
+ unsigned first = (unsigned char)function_macro_scalar_type_keywords[mid][0];
491
+ if (first == c) return true;
492
+ if (first < c) low = mid + 1;
493
+ else high = mid;
494
+ }
495
+ return false;
482
496
  }
483
497
 
484
498
  static inline uint16_t peek_unit_at(const char *units, uint32_t size, uint32_t index) {
@@ -635,8 +649,8 @@ static bool function_macro_tail_spacing(TSLexer *lexer, bool *escaped, const Pra
635
649
  } else if (c == '\\') {
636
650
  lexer->advance(lexer, false);
637
651
  if (scan_preproc_newline(lexer, false)) continue;
638
- *escaped = lexer->lookahead == 'u' || lexer->lookahead == 'U';
639
- return *escaped;
652
+ *escaped = true;
653
+ return true;
640
654
  } else if (c == '/') {
641
655
  if (!function_macro_argument_slash(lexer, false)) return false;
642
656
  } else {
@@ -648,9 +662,7 @@ static bool function_macro_tail_spacing(TSLexer *lexer, bool *escaped, const Pra
648
662
  static bool function_macro_tail_word(TSLexer *lexer, bool escaped, MacroPrototypeTail *tail) {
649
663
  char word[FUNCTION_MACRO_KEYWORD_MAX_LENGTH + 1] = {0};
650
664
  MacroName name = {.word = word, .capacity = sizeof(word) - 1, .ascii = !escaped};
651
- if (escaped && !scan_macro_name_ucn(lexer)) return false;
652
- bool continuation = escaped;
653
- while (scan_macro_name_character(lexer, continuation, &name) == MACRO_NAME_CHARACTER) continuation = true;
665
+ if (!function_macro_object_word(lexer, &name, escaped)) return false;
654
666
  bool pragma = name.ascii && strcmp(word, pragma_word) == 0;
655
667
  bool keyword = name.ascii && function_macro_keyword(word);
656
668
  if (tail->post_type && !tail->declarator_group && !keyword && !pragma) {
package/src/keywords.h CHANGED
@@ -227,6 +227,11 @@ static const char *const function_macro_type_keywords[] = {
227
227
  "unsigned",
228
228
  "void",
229
229
  };
230
+ static const char *const function_macro_tagged_type_keywords[] = {
231
+ "enum",
232
+ "struct",
233
+ "union",
234
+ };
230
235
  static const char *const function_macro_scalar_type_keywords[] = {
231
236
  "_Bool",
232
237
  "_Decimal128",
@@ -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
@@ -3,7 +3,10 @@
3
3
  #define TREE_SITTER_C_PRAGMA_H_
4
4
 
5
5
  #include "tree_sitter/parser.h"
6
- #include "identifier.h"
6
+ #ifndef TREE_SITTER_C_IDENTIFIER_HEADER
7
+ #define TREE_SITTER_C_IDENTIFIER_HEADER "identifier.h"
8
+ #endif
9
+ #include TREE_SITTER_C_IDENTIFIER_HEADER
7
10
  #include "gnuRawString.h"
8
11
  #include <string.h>
9
12
 
@@ -441,7 +444,7 @@ static bool preproc_identifier_character(int32_t c, bool continuation) {
441
444
  static bool scan_pragma_word(TSLexer *lexer) {
442
445
  const char *word = pragma_word;
443
446
  for (; *word; word++) {
444
- if (lexer->lookahead != *word) return false;
447
+ if (!scan_preproc_splices(lexer) || lexer->lookahead != *word) return false;
445
448
  lexer->advance(lexer, false);
446
449
  }
447
450
  return true;
@@ -592,10 +595,7 @@ static bool scan_macro_name_tail(TSLexer *lexer, MacroName *name, bool has_name)
592
595
  MacroNameCharacter character = scan_macro_name_character(lexer, has_name, name);
593
596
  if (character == MACRO_NAME_INVALID) return false;
594
597
  if (character == MACRO_NAME_END) return has_name;
595
- if (character == MACRO_NAME_SPLICE) {
596
- if (!has_name) continue;
597
- return scan_preproc_splices(lexer);
598
- }
598
+ if (character == MACRO_NAME_SPLICE) continue;
599
599
  has_name = true;
600
600
  if (!name->lookahead_only) lexer->mark_end(lexer);
601
601
  }
@@ -639,10 +639,12 @@ static MacroNameCharacter scan_macro_name_character(TSLexer *lexer, bool continu
639
639
  }
640
640
 
641
641
  static bool scan_macro_name_ucn(TSLexer *lexer) {
642
+ if (!scan_preproc_splices(lexer)) return false;
642
643
  unsigned digits = lexer->lookahead == 'u' ? 4 : lexer->lookahead == 'U' ? 8 : 0;
643
644
  if (!digits) return false;
644
645
  lexer->advance(lexer, false);
645
646
  for (unsigned i = 0; i < digits; i++) {
647
+ if (!scan_preproc_splices(lexer)) return false;
646
648
  int32_t c = lexer->lookahead;
647
649
  if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) return false;
648
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.0.0",
31
+ "version": "49.0.0",
32
32
  "license": "MIT",
33
33
  "description": "C grammar for tree-sitter",
34
34
  "authors": [