@willbooster/tree-sitter-c 10.0.0 → 11.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 +18 -4
- package/grammar.js +54 -25
- package/package.json +2 -1
- package/src/functionMacro.h +88 -5
- package/src/grammarKeywords.cjs +4 -0
- package/src/keywords.h +78 -0
- package/src/scanner.c +22 -8
- package/tree-sitter-c.wasm +0 -0
- package/tree-sitter.json +1 -1
package/README.md
CHANGED
|
@@ -65,20 +65,34 @@ Keep preprocessor argument/newline handling ahead of annotation lookahead.
|
|
|
65
65
|
The hidden `_function_attribute_start`, `_post_type_function_attribute_start`, and
|
|
66
66
|
`_post_type_function_attribute_suffix` guards look ahead before the ordinary identifier token;
|
|
67
67
|
keep them outside the name field so identifier leaves and ordinary C lexing retain their shape.
|
|
68
|
-
Port `scan_function_attribute_guard` and the
|
|
69
|
-
|
|
68
|
+
Port `scan_function_attribute_guard`, its `MacroAttributeSymbols` context, and the name-range handling in `pragma.h`.
|
|
69
|
+
The `_trailing_object_declaration_start` guard checks an object prefix before declaration parsing;
|
|
70
|
+
`_trailing_macro_attribute_name` consumes only the annotation name and preserves its ordinary identifier leaf.
|
|
71
|
+
Keep the shared first-word dispatch so a failed lookahead never falls back from an advanced lexer cursor.
|
|
72
|
+
First prototype guards check the prototype tail; post-type continuation guards inspect only their own argument group.
|
|
70
73
|
Regenerate Unicode and keyword tables from the derived grammar's metadata.
|
|
71
74
|
The generation source is `script/generateIdentifierRanges.js` in this repository.
|
|
75
|
+
The primitive keyword data shared by grammar generation and object-prefix classification is in `src/grammarKeywords.cjs`.
|
|
72
76
|
The `_preproc_function_name` token ends before splices used to determine adjacency, so the `_preproc_lparen`
|
|
73
77
|
scanner must skip those splices again to reach `(`.
|
|
74
78
|
|
|
75
|
-
|
|
79
|
+
Prototype annotation lookahead accepts argument/prototype groups without unquoted braces, semicolons or preprocessing directives.
|
|
76
80
|
Quoted punctuation remains literal content. GNU statement-expression, inline-tag, compound-literal
|
|
77
81
|
and directive-bearing annotation arguments need a separate grammar design to keep malformed-input recovery bounded.
|
|
78
82
|
|
|
79
83
|
Header annotation declarations use `_macro_modified_declaration`, `_macro_declaration_specifiers`,
|
|
80
84
|
`_macro_declaration_declarator`, and `_header_preproc_item`. Adapt these rules alongside public declaration/type
|
|
81
85
|
overrides when extending C. The annotation declarator uses `function_declarator` to retain trailing macro calls.
|
|
86
|
+
The separate `_trailing_macro_modified_declaration` route uses public declaration specifiers and
|
|
87
|
+
`_trailing_macro_object_declarator` / `_trailing_macro_pointer_declarator`; adapt these header rules when
|
|
88
|
+
overriding declaration or declarator behavior.
|
|
89
|
+
|
|
90
|
+
Trailing object annotations support one complete `primitive_type` token, plain pointer stars and an identifier,
|
|
91
|
+
for example `int *value ATTR((1));`. The first argument token after initial parentheses must be numeric,
|
|
92
|
+
a string/character quote or a comma. Comments and whitespace may separate the prefix tokens; the remaining
|
|
93
|
+
arguments use the structural annotation-argument grammar. Sized-only starts such as `unsigned` or `long`,
|
|
94
|
+
qualified/multiword/unknown-type prefixes,
|
|
95
|
+
arrays, parenthesized/function declarators, initializers and multiple declarators need separate support.
|
|
82
96
|
|
|
83
97
|
In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-c) and on
|
|
84
98
|
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
|
|
@@ -87,7 +101,7 @@ fuzzed with, at version 7.0.5 or later. No other runtime loads the parser:
|
|
|
87
101
|
```toml
|
|
88
102
|
[dependencies]
|
|
89
103
|
tree-sitter = { package = "willbooster-tree-sitter", version = "7.0.5" }
|
|
90
|
-
tree-sitter-c = { package = "willbooster-tree-sitter-c", version = "
|
|
104
|
+
tree-sitter-c = { package = "willbooster-tree-sitter-c", version = "11" }
|
|
91
105
|
```
|
|
92
106
|
|
|
93
107
|
```rust
|
package/grammar.js
CHANGED
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
const { grammar, alias, choice, field, optional, prec, repeat, repeat1, seq, sym, token } =
|
|
12
12
|
/** @type {typeof globalThis & typeof import('./types/treeSitterDsl')} */ (globalThis);
|
|
13
13
|
|
|
14
|
+
// oxlint-disable-next-line unicorn/prefer-module -- Tree-sitter loads this grammar as CommonJS.
|
|
15
|
+
const { primitiveTypeKeywords } = require('./src/grammarKeywords.cjs');
|
|
16
|
+
|
|
14
17
|
const PREC = {
|
|
15
18
|
PAREN_DECLARATOR: -10,
|
|
16
19
|
ASSIGNMENT: -2,
|
|
@@ -158,6 +161,8 @@ module.exports = Object.assign(
|
|
|
158
161
|
sym('_function_attribute_start'),
|
|
159
162
|
sym('_post_type_function_attribute_start'),
|
|
160
163
|
sym('_post_type_function_attribute_suffix'),
|
|
164
|
+
sym('_trailing_macro_attribute_name'),
|
|
165
|
+
sym('_trailing_object_declaration_start'),
|
|
161
166
|
],
|
|
162
167
|
|
|
163
168
|
extras: ($) => [$.pragma_operator, /\s|\\(?:\r\n?|\n\r?)/, $.comment],
|
|
@@ -205,6 +210,7 @@ module.exports = Object.assign(
|
|
|
205
210
|
$.linkage_specification,
|
|
206
211
|
$.declaration,
|
|
207
212
|
alias(sym('_macro_modified_declaration'), $.declaration),
|
|
213
|
+
alias(sym('_trailing_macro_modified_declaration'), $.declaration),
|
|
208
214
|
$._top_level_statement,
|
|
209
215
|
$.attributed_statement,
|
|
210
216
|
$.type_definition,
|
|
@@ -431,6 +437,20 @@ module.exports = Object.assign(
|
|
|
431
437
|
_macro_modified_declaration: ($) =>
|
|
432
438
|
declarationRule($, $._macro_declaration_specifiers, false, $._macro_declaration_declarator),
|
|
433
439
|
|
|
440
|
+
_trailing_macro_modified_declaration: ($) =>
|
|
441
|
+
seq(
|
|
442
|
+
sym('_trailing_object_declaration_start'),
|
|
443
|
+
$._declaration_specifiers,
|
|
444
|
+
field('declarator', $._trailing_macro_object_declarator),
|
|
445
|
+
repeat1(alias($._trailing_macro_attribute_specifier, $.attribute_specifier)),
|
|
446
|
+
';'
|
|
447
|
+
),
|
|
448
|
+
|
|
449
|
+
_trailing_macro_object_declarator: ($) =>
|
|
450
|
+
choice($.identifier, alias($._trailing_macro_pointer_declarator, $.pointer_declarator)),
|
|
451
|
+
|
|
452
|
+
_trailing_macro_pointer_declarator: ($) => pointerDeclaratorRule($, $._trailing_macro_object_declarator),
|
|
453
|
+
|
|
434
454
|
_macro_declaration_specifiers: ($) => {
|
|
435
455
|
const modifier = choice($._declaration_modifiers, alias($._macro_attribute_suffix, $.attribute_specifier));
|
|
436
456
|
const postModifier = choice(
|
|
@@ -504,6 +524,8 @@ module.exports = Object.assign(
|
|
|
504
524
|
|
|
505
525
|
_macro_attribute_suffix: ($) => macroAttributeRule($, 'continuation'),
|
|
506
526
|
|
|
527
|
+
_trailing_macro_attribute_specifier: ($) => macroAttributeRule($, 'trailing'),
|
|
528
|
+
|
|
507
529
|
_post_type_macro_attribute_suffix: ($) => macroAttributeRule($, 'post-type-continuation'),
|
|
508
530
|
|
|
509
531
|
_macro_attribute_argument_list: ($) => {
|
|
@@ -607,21 +629,7 @@ module.exports = Object.assign(
|
|
|
607
629
|
attributed_field_declarator: ($) => seq($._unattributed_field_declarator, repeat1($.attribute_declaration)),
|
|
608
630
|
attributed_type_declarator: ($) => seq($._unattributed_type_declarator, repeat1($.attribute_declaration)),
|
|
609
631
|
|
|
610
|
-
pointer_declarator: ($) =>
|
|
611
|
-
prec.dynamic(
|
|
612
|
-
1,
|
|
613
|
-
prec.right(
|
|
614
|
-
seq(
|
|
615
|
-
optional($.ms_based_modifier),
|
|
616
|
-
optional(prec.dynamic(2, $.ms_call_modifier)),
|
|
617
|
-
'*',
|
|
618
|
-
repeat($.attribute_declaration),
|
|
619
|
-
repeat($.ms_pointer_modifier),
|
|
620
|
-
repeat(choice($.type_qualifier, $.attribute_specifier)),
|
|
621
|
-
field('declarator', $._declarator)
|
|
622
|
-
)
|
|
623
|
-
)
|
|
624
|
-
),
|
|
632
|
+
pointer_declarator: ($) => pointerDeclaratorRule($, $._declarator),
|
|
625
633
|
pointer_field_declarator: ($) =>
|
|
626
634
|
prec.dynamic(
|
|
627
635
|
1,
|
|
@@ -824,12 +832,7 @@ module.exports = Object.assign(
|
|
|
824
832
|
primitive_type: () =>
|
|
825
833
|
token(
|
|
826
834
|
choice(
|
|
827
|
-
|
|
828
|
-
'char',
|
|
829
|
-
'int',
|
|
830
|
-
'float',
|
|
831
|
-
'double',
|
|
832
|
-
'void',
|
|
835
|
+
...primitiveTypeKeywords,
|
|
833
836
|
'size_t',
|
|
834
837
|
'ssize_t',
|
|
835
838
|
'ptrdiff_t',
|
|
@@ -1622,6 +1625,27 @@ module.exports = Object.assign(
|
|
|
1622
1625
|
{ PREC, preprocIf, preprocessor, commaSep, commaSep1 }
|
|
1623
1626
|
);
|
|
1624
1627
|
|
|
1628
|
+
/**
|
|
1629
|
+
* @param {import('./types/treeSitterDsl').GrammarSymbols<'ms_based_modifier' | 'ms_call_modifier' | 'attribute_declaration' | 'ms_pointer_modifier' | 'type_qualifier' | 'attribute_specifier'>} $
|
|
1630
|
+
* @param {import('./types/treeSitterDsl').Rule} declarator
|
|
1631
|
+
*/
|
|
1632
|
+
function pointerDeclaratorRule($, declarator) {
|
|
1633
|
+
return prec.dynamic(
|
|
1634
|
+
1,
|
|
1635
|
+
prec.right(
|
|
1636
|
+
seq(
|
|
1637
|
+
optional($.ms_based_modifier),
|
|
1638
|
+
optional(prec.dynamic(2, $.ms_call_modifier)),
|
|
1639
|
+
'*',
|
|
1640
|
+
repeat($.attribute_declaration),
|
|
1641
|
+
repeat($.ms_pointer_modifier),
|
|
1642
|
+
repeat(choice($.type_qualifier, $.attribute_specifier)),
|
|
1643
|
+
field('declarator', declarator)
|
|
1644
|
+
)
|
|
1645
|
+
)
|
|
1646
|
+
);
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1625
1649
|
/**
|
|
1626
1650
|
* @param {import('./types/treeSitterDsl').GrammarSymbols<'storage_class_specifier' | 'ms_call_modifier' | '_declaration_declarator' | 'gnu_asm_expression' | 'init_declarator' | '_declaration_modifiers'>} $
|
|
1627
1651
|
* @param {import('./types/treeSitterDsl').Rule} specifiers
|
|
@@ -1679,7 +1703,12 @@ function blockItemRule($, header) {
|
|
|
1679
1703
|
alias($._old_style_function_definition, $.function_definition),
|
|
1680
1704
|
$.linkage_specification,
|
|
1681
1705
|
$.declaration,
|
|
1682
|
-
...(header
|
|
1706
|
+
...(header
|
|
1707
|
+
? [
|
|
1708
|
+
alias($._macro_modified_declaration, $.declaration),
|
|
1709
|
+
alias(sym('_trailing_macro_modified_declaration'), $.declaration),
|
|
1710
|
+
]
|
|
1711
|
+
: []),
|
|
1683
1712
|
$.statement,
|
|
1684
1713
|
$.type_definition,
|
|
1685
1714
|
$._empty_declaration,
|
|
@@ -1694,11 +1723,11 @@ function blockItemRule($, header) {
|
|
|
1694
1723
|
|
|
1695
1724
|
/**
|
|
1696
1725
|
* @param {import('./types/treeSitterDsl').GrammarSymbols<'identifier' | 'argument_list' | '_macro_attribute_argument_list'>} $
|
|
1697
|
-
* @param {'leading' | 'post-type' | 'continuation' | 'post-type-continuation'} context
|
|
1726
|
+
* @param {'leading' | 'post-type' | 'continuation' | 'post-type-continuation' | 'trailing'} context
|
|
1698
1727
|
*/
|
|
1699
1728
|
function macroAttributeRule($, context) {
|
|
1700
1729
|
const guard =
|
|
1701
|
-
context === 'continuation'
|
|
1730
|
+
context === 'continuation' || context === 'trailing'
|
|
1702
1731
|
? []
|
|
1703
1732
|
: [
|
|
1704
1733
|
sym(
|
|
@@ -1713,7 +1742,7 @@ function macroAttributeRule($, context) {
|
|
|
1713
1742
|
-2,
|
|
1714
1743
|
seq(
|
|
1715
1744
|
...guard,
|
|
1716
|
-
field('name', $.identifier),
|
|
1745
|
+
field('name', context === 'trailing' ? alias(sym('_trailing_macro_attribute_name'), $.identifier) : $.identifier),
|
|
1717
1746
|
field('arguments', alias($._macro_attribute_argument_list, $.argument_list))
|
|
1718
1747
|
)
|
|
1719
1748
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/tree-sitter-c",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "C grammar for tree-sitter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"incremental",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"src/node-types.json",
|
|
22
22
|
"tree-sitter.json",
|
|
23
23
|
"*.wasm",
|
|
24
|
+
"src/grammarKeywords.cjs",
|
|
24
25
|
"src/pragma.h",
|
|
25
26
|
"src/identifier.h",
|
|
26
27
|
"src/keywords.h",
|
package/src/functionMacro.h
CHANGED
|
@@ -18,6 +18,13 @@ typedef struct {
|
|
|
18
18
|
bool declarator_name;
|
|
19
19
|
} MacroPrototypeTail;
|
|
20
20
|
|
|
21
|
+
typedef struct {
|
|
22
|
+
TSSymbol pragma;
|
|
23
|
+
TSSymbol object_start;
|
|
24
|
+
bool allow_pragma;
|
|
25
|
+
bool allow_object_start;
|
|
26
|
+
} MacroAttributeSymbols;
|
|
27
|
+
|
|
21
28
|
static bool function_macro_balanced(TSLexer *lexer, int32_t open, int32_t close, bool *literal);
|
|
22
29
|
static bool function_macro_group(int32_t c, int32_t open, int32_t close, unsigned *depth, unsigned *nested);
|
|
23
30
|
static void function_macro_note_literal(bool *literal, unsigned depth, unsigned nested, const MacroArgumentWord *word, int32_t c);
|
|
@@ -32,24 +39,100 @@ static bool function_macro_line_comment(TSLexer *lexer);
|
|
|
32
39
|
static bool function_macro_block_comment(TSLexer *lexer);
|
|
33
40
|
static void function_macro_argument_word(MacroArgumentWord *word, int32_t c);
|
|
34
41
|
|
|
42
|
+
static bool function_macro_trailing_argument_prefix(TSLexer *lexer);
|
|
43
|
+
static bool function_macro_object_prefix(TSLexer *lexer);
|
|
44
|
+
static bool function_macro_object_word(TSLexer *lexer, MacroName *name, bool escaped);
|
|
45
|
+
static bool function_macro_scalar_type_keyword(const char *word);
|
|
46
|
+
static bool function_macro_object_prefix_keyword(const char *word);
|
|
47
|
+
static bool function_macro_attribute_keyword(const char *word, bool trailing);
|
|
35
48
|
static bool function_macro_keyword(const char *word);
|
|
36
49
|
static bool function_macro_word_in(const char *word, const char *const *words, unsigned count);
|
|
37
50
|
|
|
38
|
-
static bool scan_function_attribute_guard(TSLexer *lexer, bool prototype, bool require_literal, bool
|
|
51
|
+
static bool scan_function_attribute_guard(TSLexer *lexer, bool prototype, bool require_literal, bool trailing, const MacroAttributeSymbols *symbols) {
|
|
39
52
|
char word[FUNCTION_MACRO_KEYWORD_MAX_LENGTH + 1] = {0};
|
|
40
|
-
MacroName name = {.word = word, .capacity = sizeof(word) - 1, .ascii = true, .lookahead_only =
|
|
53
|
+
MacroName name = {.word = word, .capacity = sizeof(word) - 1, .ascii = true, .lookahead_only = !trailing};
|
|
41
54
|
if (!scan_macro_name(lexer, &name)) return false;
|
|
42
55
|
if (name.ascii && strcmp(word, pragma_word) == 0) {
|
|
43
|
-
lexer->result_symbol =
|
|
44
|
-
return allow_pragma && scan_pragma_suffix(lexer);
|
|
56
|
+
lexer->result_symbol = symbols->pragma;
|
|
57
|
+
return symbols->allow_pragma && scan_pragma_suffix(lexer);
|
|
45
58
|
}
|
|
46
|
-
if (name.ascii &&
|
|
59
|
+
if (symbols->allow_object_start && name.ascii && function_macro_scalar_type_keyword(word)) {
|
|
60
|
+
lexer->result_symbol = symbols->object_start;
|
|
61
|
+
return function_macro_object_prefix(lexer);
|
|
62
|
+
}
|
|
63
|
+
if (lexer->result_symbol == symbols->object_start) return false;
|
|
64
|
+
if (name.ascii && function_macro_attribute_keyword(word, trailing)) return false;
|
|
47
65
|
if (!scan_pragma_spacing(lexer) || lexer->lookahead != '(') return false;
|
|
66
|
+
if (trailing) return function_macro_trailing_argument_prefix(lexer);
|
|
48
67
|
bool literal = false;
|
|
49
68
|
return function_macro_balanced(lexer, '(', ')', &literal) && (!require_literal || literal) &&
|
|
50
69
|
(!prototype || function_macro_declaration_continues(lexer, require_literal));
|
|
51
70
|
}
|
|
52
71
|
|
|
72
|
+
static bool function_macro_trailing_argument_prefix(TSLexer *lexer) {
|
|
73
|
+
do {
|
|
74
|
+
lexer->advance(lexer, false);
|
|
75
|
+
if (!scan_pragma_spacing(lexer)) return false;
|
|
76
|
+
} while (lexer->lookahead == '(');
|
|
77
|
+
int32_t first = lexer->lookahead;
|
|
78
|
+
if (first == '.') {
|
|
79
|
+
lexer->advance(lexer, false);
|
|
80
|
+
first = lexer->lookahead;
|
|
81
|
+
return first >= '0' && first <= '9';
|
|
82
|
+
}
|
|
83
|
+
return first == ',' || first == '"' || first == '\'' || (first >= '0' && first <= '9');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static bool function_macro_object_prefix(TSLexer *lexer) {
|
|
87
|
+
bool escaped = false;
|
|
88
|
+
if (!function_macro_tail_spacing(lexer, &escaped)) return false;
|
|
89
|
+
while (!escaped && lexer->lookahead == '*') {
|
|
90
|
+
lexer->advance(lexer, false);
|
|
91
|
+
if (!function_macro_tail_spacing(lexer, &escaped)) return false;
|
|
92
|
+
}
|
|
93
|
+
char word[FUNCTION_MACRO_KEYWORD_MAX_LENGTH + 1] = {0};
|
|
94
|
+
MacroName name = {.word = word, .capacity = sizeof(word) - 1, .ascii = true};
|
|
95
|
+
if (!function_macro_object_word(lexer, &name, escaped) ||
|
|
96
|
+
(name.ascii && (function_macro_object_prefix_keyword(word) || strcmp(word, pragma_word) == 0))) return false;
|
|
97
|
+
escaped = false;
|
|
98
|
+
if (!function_macro_tail_spacing(lexer, &escaped)) return false;
|
|
99
|
+
name = (MacroName){.word = word, .capacity = sizeof(word) - 1, .ascii = true};
|
|
100
|
+
if (!function_macro_object_word(lexer, &name, escaped) || (name.ascii && function_macro_attribute_keyword(word, true))) return false;
|
|
101
|
+
return scan_pragma_spacing(lexer) && lexer->lookahead == '(' && function_macro_trailing_argument_prefix(lexer);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static bool function_macro_object_word(TSLexer *lexer, MacroName *name, bool escaped) {
|
|
105
|
+
memset(name->word, 0, name->capacity + 1);
|
|
106
|
+
if (escaped) {
|
|
107
|
+
name->ascii = false;
|
|
108
|
+
if (!scan_macro_name_ucn(lexer)) return false;
|
|
109
|
+
}
|
|
110
|
+
bool continuation = escaped;
|
|
111
|
+
for (;;) {
|
|
112
|
+
MacroNameCharacter c = scan_macro_name_character(lexer, continuation, name);
|
|
113
|
+
if (c == MACRO_NAME_END) return continuation;
|
|
114
|
+
if (c == MACRO_NAME_SPLICE && continuation) return scan_preproc_splices(lexer);
|
|
115
|
+
if (c != MACRO_NAME_CHARACTER) return false;
|
|
116
|
+
continuation = true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static bool function_macro_scalar_type_keyword(const char *word) {
|
|
121
|
+
return function_macro_word_in(word, function_macro_scalar_type_keywords,
|
|
122
|
+
sizeof(function_macro_scalar_type_keywords) / sizeof(function_macro_scalar_type_keywords[0]));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static bool function_macro_object_prefix_keyword(const char *word) {
|
|
126
|
+
return function_macro_word_in(word, function_macro_object_prefix_keywords,
|
|
127
|
+
sizeof(function_macro_object_prefix_keywords) / sizeof(function_macro_object_prefix_keywords[0]));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static bool function_macro_attribute_keyword(const char *word, bool trailing) {
|
|
131
|
+
if (!trailing) return function_macro_keyword(word);
|
|
132
|
+
return strcmp(word, pragma_word) == 0 || function_macro_word_in(word, function_macro_group_modifiers,
|
|
133
|
+
sizeof(function_macro_group_modifiers) / sizeof(function_macro_group_modifiers[0]));
|
|
134
|
+
}
|
|
135
|
+
|
|
53
136
|
static bool function_macro_balanced(TSLexer *lexer, int32_t open, int32_t close, bool *literal) {
|
|
54
137
|
unsigned depth = 1;
|
|
55
138
|
unsigned nested = 0;
|
package/src/keywords.h
CHANGED
|
@@ -190,6 +190,84 @@ static const char *const function_macro_type_keywords[] = {
|
|
|
190
190
|
"unsigned",
|
|
191
191
|
"void",
|
|
192
192
|
};
|
|
193
|
+
static const char *const function_macro_scalar_type_keywords[] = {
|
|
194
|
+
"bool",
|
|
195
|
+
"char",
|
|
196
|
+
"char16_t",
|
|
197
|
+
"char32_t",
|
|
198
|
+
"char64_t",
|
|
199
|
+
"char8_t",
|
|
200
|
+
"charptr_t",
|
|
201
|
+
"double",
|
|
202
|
+
"float",
|
|
203
|
+
"int",
|
|
204
|
+
"int16_t",
|
|
205
|
+
"int32_t",
|
|
206
|
+
"int64_t",
|
|
207
|
+
"int8_t",
|
|
208
|
+
"intptr_t",
|
|
209
|
+
"max_align_t",
|
|
210
|
+
"nullptr_t",
|
|
211
|
+
"ptrdiff_t",
|
|
212
|
+
"size_t",
|
|
213
|
+
"ssize_t",
|
|
214
|
+
"uint16_t",
|
|
215
|
+
"uint32_t",
|
|
216
|
+
"uint64_t",
|
|
217
|
+
"uint8_t",
|
|
218
|
+
"uintptr_t",
|
|
219
|
+
"void",
|
|
220
|
+
};
|
|
221
|
+
static const char *const function_macro_object_prefix_keywords[] = {
|
|
222
|
+
"_Alignas",
|
|
223
|
+
"_Atomic",
|
|
224
|
+
"_Complex",
|
|
225
|
+
"_Imaginary",
|
|
226
|
+
"_Nonnull",
|
|
227
|
+
"_Noreturn",
|
|
228
|
+
"_Thread_local",
|
|
229
|
+
"__asm",
|
|
230
|
+
"__asm__",
|
|
231
|
+
"__attribute",
|
|
232
|
+
"__attribute__",
|
|
233
|
+
"__cdecl",
|
|
234
|
+
"__clrcall",
|
|
235
|
+
"__complex__",
|
|
236
|
+
"__declspec",
|
|
237
|
+
"__extension__",
|
|
238
|
+
"__fastcall",
|
|
239
|
+
"__forceinline",
|
|
240
|
+
"__inline",
|
|
241
|
+
"__inline__",
|
|
242
|
+
"__restrict__",
|
|
243
|
+
"__stdcall",
|
|
244
|
+
"__thiscall",
|
|
245
|
+
"__thread",
|
|
246
|
+
"__vectorcall",
|
|
247
|
+
"alignas",
|
|
248
|
+
"asm",
|
|
249
|
+
"auto",
|
|
250
|
+
"bool",
|
|
251
|
+
"char",
|
|
252
|
+
"const",
|
|
253
|
+
"constexpr",
|
|
254
|
+
"double",
|
|
255
|
+
"extern",
|
|
256
|
+
"float",
|
|
257
|
+
"inline",
|
|
258
|
+
"int",
|
|
259
|
+
"long",
|
|
260
|
+
"noreturn",
|
|
261
|
+
"register",
|
|
262
|
+
"restrict",
|
|
263
|
+
"short",
|
|
264
|
+
"signed",
|
|
265
|
+
"static",
|
|
266
|
+
"thread_local",
|
|
267
|
+
"unsigned",
|
|
268
|
+
"void",
|
|
269
|
+
"volatile",
|
|
270
|
+
};
|
|
193
271
|
static const char *const function_macro_declaration_modifiers[] = {
|
|
194
272
|
"_Alignas",
|
|
195
273
|
"_Atomic",
|
package/src/scanner.c
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#include "functionMacro.h"
|
|
2
2
|
|
|
3
|
-
enum TokenType { PRAGMA_OPERATOR, PREPROC_ARG, PREPROC_NEWLINE, PREPROC_LPAREN, PREPROC_DIRECTIVE_ARG, PREPROC_FUNCTION_NAME, FUNCTION_ATTRIBUTE_START, POST_TYPE_FUNCTION_ATTRIBUTE_START, POST_TYPE_FUNCTION_ATTRIBUTE_SUFFIX };
|
|
3
|
+
enum TokenType { PRAGMA_OPERATOR, PREPROC_ARG, PREPROC_NEWLINE, PREPROC_LPAREN, PREPROC_DIRECTIVE_ARG, PREPROC_FUNCTION_NAME, FUNCTION_ATTRIBUTE_START, POST_TYPE_FUNCTION_ATTRIBUTE_START, POST_TYPE_FUNCTION_ATTRIBUTE_SUFFIX, TRAILING_MACRO_ATTRIBUTE_NAME, TRAILING_OBJECT_DECLARATION_START };
|
|
4
4
|
|
|
5
5
|
static bool scan_preproc_tokens(TSLexer *lexer, const bool *valid_symbols);
|
|
6
6
|
|
|
@@ -30,13 +30,27 @@ bool tree_sitter_c_external_scanner_scan(void *payload, TSLexer *lexer, const bo
|
|
|
30
30
|
lexer->result_symbol = PREPROC_FUNCTION_NAME;
|
|
31
31
|
return scan_function_macro_name(lexer, valid_symbols[PRAGMA_OPERATOR], PRAGMA_OPERATOR);
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
if (valid_symbols[PREPROC_LPAREN] || valid_symbols[PREPROC_NEWLINE] ||
|
|
34
|
+
valid_symbols[PREPROC_ARG] || valid_symbols[PREPROC_DIRECTIVE_ARG]) {
|
|
35
|
+
return scan_preproc_tokens(lexer, valid_symbols);
|
|
36
|
+
}
|
|
37
|
+
static const TSSymbol attribute_tokens[] = {
|
|
38
|
+
FUNCTION_ATTRIBUTE_START, POST_TYPE_FUNCTION_ATTRIBUTE_START, POST_TYPE_FUNCTION_ATTRIBUTE_SUFFIX,
|
|
39
|
+
TRAILING_MACRO_ATTRIBUTE_NAME, TRAILING_OBJECT_DECLARATION_START,
|
|
40
|
+
};
|
|
41
|
+
const MacroAttributeSymbols symbols = {
|
|
42
|
+
.pragma = PRAGMA_OPERATOR,
|
|
43
|
+
.object_start = TRAILING_OBJECT_DECLARATION_START,
|
|
44
|
+
.allow_pragma = valid_symbols[PRAGMA_OPERATOR],
|
|
45
|
+
.allow_object_start = valid_symbols[TRAILING_OBJECT_DECLARATION_START],
|
|
46
|
+
};
|
|
47
|
+
for (unsigned i = 0; i < sizeof(attribute_tokens) / sizeof(attribute_tokens[0]); i++) {
|
|
48
|
+
TSSymbol token = attribute_tokens[i];
|
|
49
|
+
if (!valid_symbols[token]) continue;
|
|
50
|
+
lexer->result_symbol = token;
|
|
51
|
+
return scan_function_attribute_guard(lexer,
|
|
52
|
+
token == FUNCTION_ATTRIBUTE_START || token == POST_TYPE_FUNCTION_ATTRIBUTE_START,
|
|
53
|
+
token != FUNCTION_ATTRIBUTE_START, token == TRAILING_MACRO_ATTRIBUTE_NAME, &symbols);
|
|
40
54
|
}
|
|
41
55
|
return scan_preproc_tokens(lexer, valid_symbols);
|
|
42
56
|
}
|
package/tree-sitter-c.wasm
CHANGED
|
Binary file
|