@willbooster/tree-sitter-c 18.0.1 → 18.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/grammar.js +5 -0
- package/package.json +1 -1
- package/queries/highlights.scm +1 -0
- package/src/conditionalMacro.h +37 -21
- package/src/keywords.h +1 -0
- package/src/node-types.json +32 -0
- package/tree-sitter-c.wasm +0 -0
- package/tree-sitter.json +9 -2
package/grammar.js
CHANGED
|
@@ -1174,6 +1174,7 @@ module.exports = Object.assign(
|
|
|
1174
1174
|
$.compound_statement,
|
|
1175
1175
|
$.expression_statement,
|
|
1176
1176
|
$.if_statement,
|
|
1177
|
+
$.defer_statement,
|
|
1177
1178
|
$.switch_statement,
|
|
1178
1179
|
$.do_statement,
|
|
1179
1180
|
$.while_statement,
|
|
@@ -1194,6 +1195,7 @@ module.exports = Object.assign(
|
|
|
1194
1195
|
$.compound_statement,
|
|
1195
1196
|
alias($._top_level_expression_statement, $.expression_statement),
|
|
1196
1197
|
$.if_statement,
|
|
1198
|
+
$.defer_statement,
|
|
1197
1199
|
$.switch_statement,
|
|
1198
1200
|
$.do_statement,
|
|
1199
1201
|
$.while_statement,
|
|
@@ -1226,6 +1228,8 @@ module.exports = Object.assign(
|
|
|
1226
1228
|
)
|
|
1227
1229
|
),
|
|
1228
1230
|
|
|
1231
|
+
defer_statement: ($) => seq('_Defer', field('body', $._single_statement)),
|
|
1232
|
+
|
|
1229
1233
|
else_clause: ($) => seq('else', $._single_statement),
|
|
1230
1234
|
|
|
1231
1235
|
switch_statement: ($) =>
|
|
@@ -1254,6 +1258,7 @@ module.exports = Object.assign(
|
|
|
1254
1258
|
$.seh_leave_statement,
|
|
1255
1259
|
alias($._single_labeled_statement, $.labeled_statement),
|
|
1256
1260
|
$.if_statement,
|
|
1261
|
+
$.defer_statement,
|
|
1257
1262
|
$.while_statement,
|
|
1258
1263
|
$.do_statement,
|
|
1259
1264
|
$.for_statement
|
package/package.json
CHANGED
package/queries/highlights.scm
CHANGED
package/src/conditionalMacro.h
CHANGED
|
@@ -3,22 +3,27 @@
|
|
|
3
3
|
|
|
4
4
|
#include "functionMacro.h"
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
typedef struct {
|
|
7
|
+
TSSymbol ifdef, ifndef, leading_ifdef, leading_ifndef;
|
|
8
|
+
// Optional, unordered ASCII words of at most FUNCTION_MACRO_KEYWORD_MAX_LENGTH bytes.
|
|
9
|
+
// Excludes unknown type aliases and marker names; recognized C type/modifier prefixes are unchanged.
|
|
10
|
+
const char *const *reserved_words;
|
|
11
|
+
unsigned reserved_word_count;
|
|
12
|
+
} ConditionalMacroSymbols;
|
|
13
|
+
|
|
14
|
+
static bool conditional_macro_body(TSLexer *lexer, const ConditionalMacroSymbols *symbols, bool *escaped);
|
|
7
15
|
static bool conditional_macro_word(TSLexer *lexer, MacroName *name, bool escaped);
|
|
8
16
|
static bool conditional_macro_spacing(TSLexer *lexer, bool *separated, bool *escaped);
|
|
9
17
|
static bool conditional_macro_next_line(TSLexer *lexer, bool *escaped);
|
|
10
18
|
static bool conditional_macro_directive(TSLexer *lexer, MacroName *name);
|
|
11
|
-
static bool conditional_macro_marker_line(TSLexer *lexer, bool *escaped);
|
|
19
|
+
static bool conditional_macro_marker_line(TSLexer *lexer, const ConditionalMacroSymbols *symbols, bool *escaped);
|
|
12
20
|
static bool conditional_macro_closing(TSLexer *lexer);
|
|
13
|
-
static bool conditional_macro_type_prefix(TSLexer *lexer, bool escaped);
|
|
21
|
+
static bool conditional_macro_type_prefix(TSLexer *lexer, const ConditionalMacroSymbols *symbols, bool escaped);
|
|
14
22
|
static bool conditional_macro_skip_lines(TSLexer *lexer, bool *escaped);
|
|
23
|
+
static bool conditional_macro_reserved_word(const ConditionalMacroSymbols *symbols, const char *word);
|
|
15
24
|
static bool conditional_macro_modifier_group(TSLexer *lexer, const char *word, bool *escaped);
|
|
16
25
|
static bool conditional_macro_attribute_declaration(TSLexer *lexer, bool *escaped);
|
|
17
26
|
|
|
18
|
-
typedef struct {
|
|
19
|
-
TSSymbol ifdef, ifndef, leading_ifdef, leading_ifndef;
|
|
20
|
-
} ConditionalMacroSymbols;
|
|
21
|
-
|
|
22
27
|
static bool scan_conditional_macro(TSLexer *lexer, const ConditionalMacroSymbols *symbols, const bool *valid_symbols) {
|
|
23
28
|
char directive[7] = {0};
|
|
24
29
|
MacroName command = {.word = directive, .capacity = sizeof(directive) - 1, .ascii = true};
|
|
@@ -33,8 +38,8 @@ static bool scan_conditional_macro(TSLexer *lexer, const ConditionalMacroSymbols
|
|
|
33
38
|
lexer->mark_end(lexer);
|
|
34
39
|
|
|
35
40
|
bool escaped = false;
|
|
36
|
-
if (!conditional_macro_body(lexer, &escaped)) return false;
|
|
37
|
-
if (leading && conditional_macro_type_prefix(lexer, escaped)) {
|
|
41
|
+
if (!conditional_macro_body(lexer, symbols, &escaped)) return false;
|
|
42
|
+
if (leading && conditional_macro_type_prefix(lexer, symbols, escaped)) {
|
|
38
43
|
lexer->result_symbol = leading_symbol;
|
|
39
44
|
return true;
|
|
40
45
|
}
|
|
@@ -42,12 +47,12 @@ static bool scan_conditional_macro(TSLexer *lexer, const ConditionalMacroSymbols
|
|
|
42
47
|
return generic;
|
|
43
48
|
}
|
|
44
49
|
|
|
45
|
-
static bool conditional_macro_body(TSLexer *lexer, bool *escaped) {
|
|
50
|
+
static bool conditional_macro_body(TSLexer *lexer, const ConditionalMacroSymbols *symbols, bool *escaped) {
|
|
46
51
|
bool separated = false;
|
|
47
52
|
MacroName condition = {.ascii = true};
|
|
48
53
|
if (!conditional_macro_spacing(lexer, &separated, escaped) || !separated ||
|
|
49
54
|
!conditional_macro_word(lexer, &condition, *escaped) || !conditional_macro_next_line(lexer, escaped)) return false;
|
|
50
|
-
if (!conditional_macro_marker_line(lexer, escaped) || !conditional_macro_closing(lexer)) return false;
|
|
55
|
+
if (!conditional_macro_marker_line(lexer, symbols, escaped) || !conditional_macro_closing(lexer)) return false;
|
|
51
56
|
return conditional_macro_skip_lines(lexer, escaped) && !lexer->eof(lexer) && lexer->lookahead != '#';
|
|
52
57
|
}
|
|
53
58
|
|
|
@@ -68,14 +73,14 @@ typedef enum {
|
|
|
68
73
|
CONDITIONAL_INVALID,
|
|
69
74
|
} ConditionalMacroPrefix;
|
|
70
75
|
|
|
71
|
-
static ConditionalMacroPrefix conditional_macro_prefix_kind(const MacroName *name, const char *word);
|
|
76
|
+
static ConditionalMacroPrefix conditional_macro_prefix_kind(const ConditionalMacroSymbols *symbols, const MacroName *name, const char *word);
|
|
72
77
|
|
|
73
|
-
static ConditionalMacroPrefix conditional_macro_prefix(TSLexer *lexer, bool *escaped);
|
|
78
|
+
static ConditionalMacroPrefix conditional_macro_prefix(TSLexer *lexer, const ConditionalMacroSymbols *symbols, bool *escaped);
|
|
74
79
|
|
|
75
|
-
static bool conditional_macro_type_prefix(TSLexer *lexer, bool escaped) {
|
|
80
|
+
static bool conditional_macro_type_prefix(TSLexer *lexer, const ConditionalMacroSymbols *symbols, bool escaped) {
|
|
76
81
|
ConditionalMacroPrefix kind;
|
|
77
82
|
do {
|
|
78
|
-
kind = conditional_macro_prefix(lexer, &escaped);
|
|
83
|
+
kind = conditional_macro_prefix(lexer, symbols, &escaped);
|
|
79
84
|
} while (kind == CONDITIONAL_MODIFIER);
|
|
80
85
|
if (kind == CONDITIONAL_TYPE) return true;
|
|
81
86
|
if (kind != CONDITIONAL_ALIAS) return false;
|
|
@@ -84,14 +89,14 @@ static bool conditional_macro_type_prefix(TSLexer *lexer, bool escaped) {
|
|
|
84
89
|
return conditional_macro_word(lexer, &declarator, escaped);
|
|
85
90
|
}
|
|
86
91
|
|
|
87
|
-
static ConditionalMacroPrefix conditional_macro_prefix(TSLexer *lexer, bool *escaped) {
|
|
92
|
+
static ConditionalMacroPrefix conditional_macro_prefix(TSLexer *lexer, const ConditionalMacroSymbols *symbols, bool *escaped) {
|
|
88
93
|
if (lexer->lookahead == '[') {
|
|
89
94
|
return conditional_macro_attribute_declaration(lexer, escaped) ? CONDITIONAL_MODIFIER : CONDITIONAL_INVALID;
|
|
90
95
|
}
|
|
91
96
|
char word[FUNCTION_MACRO_KEYWORD_MAX_LENGTH + 1] = {0};
|
|
92
97
|
MacroName type = {.word = word, .capacity = sizeof(word) - 1, .ascii = true};
|
|
93
98
|
if (!conditional_macro_word(lexer, &type, *escaped)) return CONDITIONAL_INVALID;
|
|
94
|
-
ConditionalMacroPrefix kind = conditional_macro_prefix_kind(&type, word);
|
|
99
|
+
ConditionalMacroPrefix kind = conditional_macro_prefix_kind(symbols, &type, word);
|
|
95
100
|
if (kind == CONDITIONAL_TYPE) return kind;
|
|
96
101
|
if (!conditional_macro_skip_lines(lexer, escaped)) return CONDITIONAL_INVALID;
|
|
97
102
|
if (kind == CONDITIONAL_TYPE_MODIFIER && lexer->lookahead == '(') return CONDITIONAL_TYPE;
|
|
@@ -101,9 +106,12 @@ static ConditionalMacroPrefix conditional_macro_prefix(TSLexer *lexer, bool *esc
|
|
|
101
106
|
return kind;
|
|
102
107
|
}
|
|
103
108
|
|
|
104
|
-
static ConditionalMacroPrefix conditional_macro_prefix_kind(const MacroName *name, const char *word) {
|
|
109
|
+
static ConditionalMacroPrefix conditional_macro_prefix_kind(const ConditionalMacroSymbols *symbols, const MacroName *name, const char *word) {
|
|
105
110
|
if (name->ascii && strcmp(word, pragma_word) == 0) return CONDITIONAL_MODIFIER;
|
|
106
|
-
if (!name->ascii
|
|
111
|
+
if (!name->ascii) return CONDITIONAL_ALIAS;
|
|
112
|
+
if (!function_macro_keyword(word)) {
|
|
113
|
+
return conditional_macro_reserved_word(symbols, word) ? CONDITIONAL_RESERVED : CONDITIONAL_ALIAS;
|
|
114
|
+
}
|
|
107
115
|
bool type = function_macro_word_in(word, function_macro_type_keywords,
|
|
108
116
|
sizeof(function_macro_type_keywords) / sizeof(function_macro_type_keywords[0]));
|
|
109
117
|
bool modifier = (!type && function_macro_object_prefix_keyword(word)) ||
|
|
@@ -113,6 +121,14 @@ static ConditionalMacroPrefix conditional_macro_prefix_kind(const MacroName *nam
|
|
|
113
121
|
return modifier ? CONDITIONAL_MODIFIER : CONDITIONAL_RESERVED;
|
|
114
122
|
}
|
|
115
123
|
|
|
124
|
+
static bool conditional_macro_reserved_word(const ConditionalMacroSymbols *symbols, const char *word) {
|
|
125
|
+
if (!symbols->reserved_words) return false;
|
|
126
|
+
for (unsigned i = 0; i < symbols->reserved_word_count; i++) {
|
|
127
|
+
if (strcmp(word, symbols->reserved_words[i]) == 0) return true;
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
|
|
116
132
|
static bool conditional_macro_modifier_group(TSLexer *lexer, const char *word, bool *escaped) {
|
|
117
133
|
bool grouped = strcmp(word, pragma_word) == 0 || function_macro_word_in(word, function_macro_group_modifiers,
|
|
118
134
|
sizeof(function_macro_group_modifiers) / sizeof(function_macro_group_modifiers[0]));
|
|
@@ -140,11 +156,11 @@ static bool conditional_macro_skip_lines(TSLexer *lexer, bool *escaped) {
|
|
|
140
156
|
}
|
|
141
157
|
}
|
|
142
158
|
|
|
143
|
-
static bool conditional_macro_marker_line(TSLexer *lexer, bool *escaped) {
|
|
159
|
+
static bool conditional_macro_marker_line(TSLexer *lexer, const ConditionalMacroSymbols *symbols, bool *escaped) {
|
|
144
160
|
char word[FUNCTION_MACRO_KEYWORD_MAX_LENGTH + 1] = {0};
|
|
145
161
|
MacroName marker = {.word = word, .capacity = sizeof(word) - 1, .ascii = true};
|
|
146
162
|
if (!conditional_macro_word(lexer, &marker, *escaped) ||
|
|
147
|
-
(marker.ascii && function_macro_keyword(word))) return false;
|
|
163
|
+
(marker.ascii && (function_macro_keyword(word) || conditional_macro_reserved_word(symbols, word)))) return false;
|
|
148
164
|
return conditional_macro_next_line(lexer, escaped);
|
|
149
165
|
}
|
|
150
166
|
|
package/src/keywords.h
CHANGED
package/src/node-types.json
CHANGED
|
@@ -261,6 +261,10 @@
|
|
|
261
261
|
"type": "continue_statement",
|
|
262
262
|
"named": true
|
|
263
263
|
},
|
|
264
|
+
{
|
|
265
|
+
"type": "defer_statement",
|
|
266
|
+
"named": true
|
|
267
|
+
},
|
|
264
268
|
{
|
|
265
269
|
"type": "do_statement",
|
|
266
270
|
"named": true
|
|
@@ -1511,6 +1515,10 @@
|
|
|
1511
1515
|
"type": "declaration",
|
|
1512
1516
|
"named": true
|
|
1513
1517
|
},
|
|
1518
|
+
{
|
|
1519
|
+
"type": "defer_statement",
|
|
1520
|
+
"named": true
|
|
1521
|
+
},
|
|
1514
1522
|
{
|
|
1515
1523
|
"type": "do_statement",
|
|
1516
1524
|
"named": true
|
|
@@ -1606,6 +1614,22 @@
|
|
|
1606
1614
|
]
|
|
1607
1615
|
}
|
|
1608
1616
|
},
|
|
1617
|
+
{
|
|
1618
|
+
"type": "defer_statement",
|
|
1619
|
+
"named": true,
|
|
1620
|
+
"fields": {
|
|
1621
|
+
"body": {
|
|
1622
|
+
"multiple": false,
|
|
1623
|
+
"required": true,
|
|
1624
|
+
"types": [
|
|
1625
|
+
{
|
|
1626
|
+
"type": "statement",
|
|
1627
|
+
"named": true
|
|
1628
|
+
}
|
|
1629
|
+
]
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
},
|
|
1609
1633
|
{
|
|
1610
1634
|
"type": "do_statement",
|
|
1611
1635
|
"named": true,
|
|
@@ -4297,6 +4321,10 @@
|
|
|
4297
4321
|
"type": "declaration",
|
|
4298
4322
|
"named": true
|
|
4299
4323
|
},
|
|
4324
|
+
{
|
|
4325
|
+
"type": "defer_statement",
|
|
4326
|
+
"named": true
|
|
4327
|
+
},
|
|
4300
4328
|
{
|
|
4301
4329
|
"type": "do_statement",
|
|
4302
4330
|
"named": true
|
|
@@ -4991,6 +5019,10 @@
|
|
|
4991
5019
|
"type": "_Countof",
|
|
4992
5020
|
"named": false
|
|
4993
5021
|
},
|
|
5022
|
+
{
|
|
5023
|
+
"type": "_Defer",
|
|
5024
|
+
"named": false
|
|
5025
|
+
},
|
|
4994
5026
|
{
|
|
4995
5027
|
"type": "_Generic",
|
|
4996
5028
|
"named": false
|
package/tree-sitter-c.wasm
CHANGED
|
Binary file
|
package/tree-sitter.json
CHANGED
|
@@ -12,11 +12,18 @@
|
|
|
12
12
|
],
|
|
13
13
|
"highlights": "queries/highlights.scm",
|
|
14
14
|
"tags": "queries/tags.scm",
|
|
15
|
-
"injection-regex": "^(c|h)$"
|
|
15
|
+
"injection-regex": "^(c|h)$",
|
|
16
|
+
"external-files": [
|
|
17
|
+
"src/pragma.h",
|
|
18
|
+
"src/identifier.h",
|
|
19
|
+
"src/keywords.h",
|
|
20
|
+
"src/functionMacro.h",
|
|
21
|
+
"src/conditionalMacro.h"
|
|
22
|
+
]
|
|
16
23
|
}
|
|
17
24
|
],
|
|
18
25
|
"metadata": {
|
|
19
|
-
"version": "18.0
|
|
26
|
+
"version": "18.2.0",
|
|
20
27
|
"license": "MIT",
|
|
21
28
|
"description": "C grammar for tree-sitter",
|
|
22
29
|
"authors": [
|