@willbooster/tree-sitter-c 23.0.0 → 24.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/grammar.js +43 -5
- package/package.json +1 -1
- package/src/conditionalMacro.h +17 -10
- package/tree-sitter-c.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -62,6 +62,35 @@ const BINARY_OPERATORS = [
|
|
|
62
62
|
|
|
63
63
|
const LINE_SPLICE = /\\(?:\r\n?|\n\r?)/;
|
|
64
64
|
const LINE_COMMENT = seq('/', repeat(LINE_SPLICE), '/', /(\\+(.|\r?\n)|[^\\\n])*/);
|
|
65
|
+
const COMMENT_SPLICES = repeat(seq('\\', /[\r\n]/));
|
|
66
|
+
const COMMENT_ESCAPE = seq('\\', /[^\r\n*]/);
|
|
67
|
+
const BLOCK_COMMENT_STARS = seq(
|
|
68
|
+
'*',
|
|
69
|
+
repeat(
|
|
70
|
+
choice(
|
|
71
|
+
seq(COMMENT_SPLICES, choice('*', String.raw`\*`)),
|
|
72
|
+
seq(COMMENT_SPLICES, '\\\r', '\n'),
|
|
73
|
+
seq(COMMENT_SPLICES, '\\\n', '\r')
|
|
74
|
+
)
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
const BLOCK_COMMENT_NONCLOSING = choice(
|
|
78
|
+
/[^/*\\]/,
|
|
79
|
+
COMMENT_ESCAPE,
|
|
80
|
+
seq(COMMENT_SPLICES, '\\\r', choice(/[^/*\\\n]/, COMMENT_ESCAPE)),
|
|
81
|
+
seq(COMMENT_SPLICES, '\\\n', choice(/[^/*\\\r]/, COMMENT_ESCAPE))
|
|
82
|
+
);
|
|
83
|
+
const BLOCK_COMMENT = seq(
|
|
84
|
+
'/',
|
|
85
|
+
repeat(LINE_SPLICE),
|
|
86
|
+
'*',
|
|
87
|
+
/[^*]*/,
|
|
88
|
+
repeat(seq(BLOCK_COMMENT_STARS, BLOCK_COMMENT_NONCLOSING, /[^*]*/)),
|
|
89
|
+
BLOCK_COMMENT_STARS,
|
|
90
|
+
COMMENT_SPLICES,
|
|
91
|
+
'/'
|
|
92
|
+
);
|
|
93
|
+
const PREPROC_PREFIX = seq('#', repeat(choice(/[ \t\v\f]/, LINE_SPLICE, BLOCK_COMMENT)));
|
|
65
94
|
const PRAGMA_SPACING = repeat(choice(/\s/, /\\(?:\r\n?|\n\r?)/));
|
|
66
95
|
const PREPROC_ARGUMENT = /\S([^/\n]|\/[^*]|\\\r?\n)*/;
|
|
67
96
|
const VA_ARG_KEYWORDS = choice('va_arg', '__builtin_va_arg');
|
|
@@ -627,7 +656,11 @@ module.exports = Object.assign(
|
|
|
627
656
|
|
|
628
657
|
preproc_call: ($) =>
|
|
629
658
|
choice(
|
|
630
|
-
preprocCall(
|
|
659
|
+
preprocCall(
|
|
660
|
+
$,
|
|
661
|
+
alias(preprocessorToken('pragma'), $.preproc_directive),
|
|
662
|
+
choice($._preproc_directive_arg, $.preproc_arg)
|
|
663
|
+
),
|
|
631
664
|
preprocCall($, $.preproc_directive, $._preproc_directive_arg)
|
|
632
665
|
),
|
|
633
666
|
|
|
@@ -659,7 +692,7 @@ module.exports = Object.assign(
|
|
|
659
692
|
preproc_arg: () => token(prec(-1, PREPROC_ARGUMENT)),
|
|
660
693
|
|
|
661
694
|
_preproc_directive_arg: () => token(prec(-2, PREPROC_ARGUMENT)),
|
|
662
|
-
preproc_directive: () =>
|
|
695
|
+
preproc_directive: () => preprocessorToken(/[a-zA-Z0-9]\w*/),
|
|
663
696
|
|
|
664
697
|
_preproc_expression: ($) =>
|
|
665
698
|
choice(
|
|
@@ -2281,7 +2314,7 @@ module.exports = Object.assign(
|
|
|
2281
2314
|
_preproc_number: () =>
|
|
2282
2315
|
/(\d|\.\d)([\p{XID_Continue}.]|[eEpP][+-]|'[_a-zA-Z0-9]|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8})*/u,
|
|
2283
2316
|
|
|
2284
|
-
comment: () => token(choice(LINE_COMMENT,
|
|
2317
|
+
comment: () => token(choice(LINE_COMMENT, BLOCK_COMMENT)),
|
|
2285
2318
|
},
|
|
2286
2319
|
}),
|
|
2287
2320
|
{ PREC, preprocIf, preprocessor, commaSep, commaSep1, declarationSpecifiers }
|
|
@@ -2682,14 +2715,19 @@ function preprocIf(suffix, content, precedence = 0, repeatContent = true) {
|
|
|
2682
2715
|
}
|
|
2683
2716
|
|
|
2684
2717
|
/**
|
|
2685
|
-
* Creates a
|
|
2718
|
+
* Creates a preprocessing directive token.
|
|
2686
2719
|
*
|
|
2687
2720
|
* @param {string} command
|
|
2688
2721
|
*
|
|
2689
2722
|
* @returns {import('./types/treeSitterDsl').AliasRule}
|
|
2690
2723
|
*/
|
|
2691
2724
|
function preprocessor(command) {
|
|
2692
|
-
return alias(
|
|
2725
|
+
return alias(preprocessorToken(command), '#' + command);
|
|
2726
|
+
}
|
|
2727
|
+
|
|
2728
|
+
/** @param {string | RegExp} command */
|
|
2729
|
+
function preprocessorToken(command) {
|
|
2730
|
+
return token(seq(PREPROC_PREFIX, command));
|
|
2693
2731
|
}
|
|
2694
2732
|
|
|
2695
2733
|
/**
|
package/package.json
CHANGED
package/src/conditionalMacro.h
CHANGED
|
@@ -13,7 +13,8 @@ typedef struct {
|
|
|
13
13
|
|
|
14
14
|
static bool conditional_macro_body(TSLexer *lexer, const ConditionalMacroSymbols *symbols, bool *escaped);
|
|
15
15
|
static bool conditional_macro_word(TSLexer *lexer, MacroName *name, bool escaped);
|
|
16
|
-
static bool conditional_macro_spacing(TSLexer *lexer, bool *separated, bool *escaped);
|
|
16
|
+
static bool conditional_macro_spacing(TSLexer *lexer, bool *separated, bool *escaped, bool directive);
|
|
17
|
+
static bool conditional_macro_space(int32_t c, bool directive);
|
|
17
18
|
static bool conditional_macro_next_line(TSLexer *lexer, bool *escaped);
|
|
18
19
|
static bool conditional_macro_directive(TSLexer *lexer, MacroName *name);
|
|
19
20
|
static bool conditional_macro_marker_line(TSLexer *lexer, const ConditionalMacroSymbols *symbols, bool *escaped);
|
|
@@ -50,7 +51,7 @@ static bool scan_conditional_macro(TSLexer *lexer, const ConditionalMacroSymbols
|
|
|
50
51
|
static bool conditional_macro_body(TSLexer *lexer, const ConditionalMacroSymbols *symbols, bool *escaped) {
|
|
51
52
|
bool separated = false;
|
|
52
53
|
MacroName condition = {.ascii = true};
|
|
53
|
-
if (!conditional_macro_spacing(lexer, &separated, escaped) || !separated ||
|
|
54
|
+
if (!conditional_macro_spacing(lexer, &separated, escaped, false) || !separated ||
|
|
54
55
|
!conditional_macro_word(lexer, &condition, *escaped) || !conditional_macro_next_line(lexer, escaped)) return false;
|
|
55
56
|
if (!conditional_macro_marker_line(lexer, symbols, escaped) || !conditional_macro_closing(lexer)) return false;
|
|
56
57
|
return conditional_macro_skip_lines(lexer, escaped) && !lexer->eof(lexer) && lexer->lookahead != '#';
|
|
@@ -63,7 +64,7 @@ static bool conditional_macro_closing(TSLexer *lexer) {
|
|
|
63
64
|
return false;
|
|
64
65
|
bool separated = false;
|
|
65
66
|
bool escaped = false;
|
|
66
|
-
if (!conditional_macro_spacing(lexer, &separated, &escaped)) return false;
|
|
67
|
+
if (!conditional_macro_spacing(lexer, &separated, &escaped, false)) return false;
|
|
67
68
|
return !escaped && (lexer->eof(lexer) || lexer->lookahead == '\n' || lexer->lookahead == '\r');
|
|
68
69
|
}
|
|
69
70
|
|
|
@@ -151,7 +152,7 @@ static bool conditional_macro_skip_lines(TSLexer *lexer, bool *escaped) {
|
|
|
151
152
|
bool separated = false;
|
|
152
153
|
for (;;) {
|
|
153
154
|
*escaped = false;
|
|
154
|
-
if (!conditional_macro_spacing(lexer, &separated, escaped)) return false;
|
|
155
|
+
if (!conditional_macro_spacing(lexer, &separated, escaped, false)) return false;
|
|
155
156
|
if (*escaped || !scan_preproc_newline(lexer, false)) return true;
|
|
156
157
|
}
|
|
157
158
|
}
|
|
@@ -167,25 +168,27 @@ static bool conditional_macro_marker_line(TSLexer *lexer, const ConditionalMacro
|
|
|
167
168
|
static bool conditional_macro_directive(TSLexer *lexer, MacroName *name) {
|
|
168
169
|
if (lexer->lookahead != '#') return false;
|
|
169
170
|
lexer->advance(lexer, false);
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
bool separated = false;
|
|
172
|
+
bool escaped = false;
|
|
173
|
+
return conditional_macro_spacing(lexer, &separated, &escaped, true) && !escaped &&
|
|
174
|
+
conditional_macro_word(lexer, name, false);
|
|
172
175
|
}
|
|
173
176
|
|
|
174
177
|
static bool conditional_macro_next_line(TSLexer *lexer, bool *escaped) {
|
|
175
178
|
bool separated = false;
|
|
176
179
|
*escaped = false;
|
|
177
|
-
if (!conditional_macro_spacing(lexer, &separated, escaped) || *escaped ||
|
|
180
|
+
if (!conditional_macro_spacing(lexer, &separated, escaped, false) || *escaped ||
|
|
178
181
|
!scan_preproc_newline(lexer, false)) return false;
|
|
179
182
|
for (;;) {
|
|
180
|
-
if (!conditional_macro_spacing(lexer, &separated, escaped) || lexer->eof(lexer)) return false;
|
|
183
|
+
if (!conditional_macro_spacing(lexer, &separated, escaped, false) || lexer->eof(lexer)) return false;
|
|
181
184
|
if (*escaped || !scan_preproc_newline(lexer, false)) return true;
|
|
182
185
|
}
|
|
183
186
|
}
|
|
184
187
|
|
|
185
|
-
static bool conditional_macro_spacing(TSLexer *lexer, bool *separated, bool *escaped) {
|
|
188
|
+
static bool conditional_macro_spacing(TSLexer *lexer, bool *separated, bool *escaped, bool directive) {
|
|
186
189
|
while (lexer->lookahead != '\n' && lexer->lookahead != '\r') {
|
|
187
190
|
int32_t c = lexer->lookahead;
|
|
188
|
-
if (
|
|
191
|
+
if (conditional_macro_space(c, directive)) {
|
|
189
192
|
*separated = true;
|
|
190
193
|
lexer->advance(lexer, false);
|
|
191
194
|
continue;
|
|
@@ -204,6 +207,10 @@ static bool conditional_macro_spacing(TSLexer *lexer, bool *separated, bool *esc
|
|
|
204
207
|
return true;
|
|
205
208
|
}
|
|
206
209
|
|
|
210
|
+
static bool conditional_macro_space(int32_t c, bool directive) {
|
|
211
|
+
return directive ? c == ' ' || c == '\t' || c == '\v' || c == '\f' : pragma_space(c);
|
|
212
|
+
}
|
|
213
|
+
|
|
207
214
|
static bool conditional_macro_word(TSLexer *lexer, MacroName *name, bool escaped) {
|
|
208
215
|
bool has_name = escaped;
|
|
209
216
|
if (escaped) {
|
package/tree-sitter-c.wasm
CHANGED
|
Binary file
|