@willbooster/tree-sitter-c 45.0.0 → 45.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/package.json +1 -1
- package/src/directiveBuffer.h +1 -1
- package/src/directiveFacts.h +32 -9
- package/src/emptyDirectives.h +1 -1
- package/tree-sitter-c.wasm +0 -0
- package/tree-sitter.json +1 -1
package/package.json
CHANGED
package/src/directiveBuffer.h
CHANGED
|
@@ -27,7 +27,7 @@ typedef struct {
|
|
|
27
27
|
uint64_t recent;
|
|
28
28
|
// Whether the current segment recorded a null directive or a line-end barrier, which the reverse pass carries, and
|
|
29
29
|
// whether the characters stored or scanned hold `pragma_word`.
|
|
30
|
-
bool utf16, encoding_known, failed, carries, pragma;
|
|
30
|
+
bool utf16, encoding_known, failed, carries, pragma, spaced_splices;
|
|
31
31
|
uint8_t classes[UNIT_CLASS_COUNT];
|
|
32
32
|
} DirectiveBuffer;
|
|
33
33
|
|
package/src/directiveFacts.h
CHANGED
|
@@ -33,8 +33,9 @@ typedef struct {
|
|
|
33
33
|
DirectiveSpans line_ends;
|
|
34
34
|
// `anchored` and `ready` belong to the scanner state: whether the token at the start of the input is out, and
|
|
35
35
|
// whether the facts, which `built` says exist, are in use. `pragmas` is the fact that the input read for them holds
|
|
36
|
-
// `pragma_word`, without which no scan has to look for a `_Pragma` operator.
|
|
37
|
-
|
|
36
|
+
// `pragma_word`, without which no scan has to look for a `_Pragma` operator. `spaced_splices` enables C++23
|
|
37
|
+
// `[lex.phases]/2` horizontal-whitespace line splices inside directive universal character names.
|
|
38
|
+
bool built, anchored, ready, pragmas, failed, spaced_splices;
|
|
38
39
|
} EmptyDirectives;
|
|
39
40
|
|
|
40
41
|
typedef struct {
|
|
@@ -44,6 +45,9 @@ typedef struct {
|
|
|
44
45
|
static bool empty_directives_skip_prefix(TSLexer *lexer);
|
|
45
46
|
static bool empty_directives_scan_word_step(TSLexer *lexer, char *word, unsigned capacity, unsigned *length, bool *trailing_splice, TSLexerPosition *position);
|
|
46
47
|
static bool empty_directives_ucn_follows(TSLexer *lexer, bool continuation);
|
|
48
|
+
static bool empty_directives_ucn_follows_splices(TSLexer *lexer, bool continuation, bool spaced_splices);
|
|
49
|
+
static bool empty_directives_skip_splices(TSLexer *lexer, bool spaced_splices);
|
|
50
|
+
static bool empty_directives_skip_line_splice(TSLexer *lexer, bool spaced_splices);
|
|
47
51
|
static inline bool empty_directives_name_character(int32_t c, bool continuation);
|
|
48
52
|
static bool directive_word_continues(DirectiveInput *input, bool number, bool strict_identifier, bool *in_identifier, int32_t *previous);
|
|
49
53
|
static bool directive_consume_ucn(DirectiveInput *input);
|
|
@@ -109,23 +113,42 @@ static bool empty_directives_scan_word_step(TSLexer *lexer, char *word, unsigned
|
|
|
109
113
|
}
|
|
110
114
|
|
|
111
115
|
static bool empty_directives_ucn_follows(TSLexer *lexer, bool continuation) {
|
|
112
|
-
|
|
116
|
+
return empty_directives_ucn_follows_splices(lexer, continuation, false);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static bool empty_directives_ucn_follows_splices(TSLexer *lexer, bool continuation, bool spaced_splices) {
|
|
120
|
+
if (!empty_directives_skip_splices(lexer, spaced_splices)) return false;
|
|
113
121
|
int32_t prefix = lexer->lookahead;
|
|
114
122
|
if (prefix != 'u' && prefix != 'U' && prefix != 'N') return false;
|
|
115
123
|
lexer->advance(lexer, false);
|
|
116
|
-
if (!
|
|
124
|
+
if (!empty_directives_skip_splices(lexer, spaced_splices)) return false;
|
|
117
125
|
bool braced = prefix != 'U' && lexer->lookahead == '{';
|
|
118
126
|
DirectiveUcn ucn;
|
|
119
127
|
if (!directive_ucn_start(&ucn, prefix, braced)) return false;
|
|
120
128
|
if (braced) lexer->advance(lexer, false);
|
|
121
129
|
for (bool done = false;;) {
|
|
122
|
-
if (!
|
|
130
|
+
if (!empty_directives_skip_splices(lexer, spaced_splices)) return false;
|
|
123
131
|
if (!directive_ucn_feed(&ucn, lexer->lookahead, continuation, &done)) return false;
|
|
124
132
|
lexer->advance(lexer, false);
|
|
125
133
|
if (done) return true;
|
|
126
134
|
}
|
|
127
135
|
}
|
|
128
136
|
|
|
137
|
+
static bool empty_directives_skip_splices(TSLexer *lexer, bool spaced_splices) {
|
|
138
|
+
while (lexer->lookahead == '\\') {
|
|
139
|
+
lexer->advance(lexer, false);
|
|
140
|
+
if (!empty_directives_skip_line_splice(lexer, spaced_splices)) return false;
|
|
141
|
+
}
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
static bool empty_directives_skip_line_splice(TSLexer *lexer, bool spaced_splices) {
|
|
146
|
+
if (spaced_splices) {
|
|
147
|
+
while (directive_horizontal(lexer->lookahead)) lexer->advance(lexer, false);
|
|
148
|
+
}
|
|
149
|
+
return scan_preproc_newline(lexer, false);
|
|
150
|
+
}
|
|
151
|
+
|
|
129
152
|
static inline bool empty_directives_name_character(int32_t c, bool continuation) {
|
|
130
153
|
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (continuation && c == '_');
|
|
131
154
|
}
|
|
@@ -408,8 +431,8 @@ static bool directive_consume_ucn(DirectiveInput *input) {
|
|
|
408
431
|
DirectiveInput copy = *input;
|
|
409
432
|
copy.spaced_splice = false;
|
|
410
433
|
directive_next(©);
|
|
411
|
-
if (copy.spaced_splice || !directive_ucn(©, true)) return false;
|
|
412
|
-
copy.spaced_splice = had_spaced;
|
|
434
|
+
if ((!copy.buffer->spaced_splices && copy.spaced_splice) || !directive_ucn(©, true)) return false;
|
|
435
|
+
copy.spaced_splice = had_spaced || copy.spaced_splice;
|
|
413
436
|
*input = copy;
|
|
414
437
|
return true;
|
|
415
438
|
}
|
|
@@ -427,8 +450,8 @@ static bool directive_ucn(DirectiveInput *input, bool continuation) {
|
|
|
427
450
|
if (!directive_ucn_feed(&ucn, directive_next(©), continuation, &done)) return false;
|
|
428
451
|
if (done) break;
|
|
429
452
|
}
|
|
430
|
-
if (copy.spaced_splice) return false;
|
|
431
|
-
copy.spaced_splice = had_spaced;
|
|
453
|
+
if (!copy.buffer->spaced_splices && copy.spaced_splice) return false;
|
|
454
|
+
copy.spaced_splice = had_spaced || copy.spaced_splice;
|
|
432
455
|
*input = copy;
|
|
433
456
|
return true;
|
|
434
457
|
}
|
package/src/emptyDirectives.h
CHANGED
|
@@ -139,7 +139,7 @@ static bool empty_directives_initialize(EmptyDirectives *state, TSLexer *lexer,
|
|
|
139
139
|
static bool empty_directives_build(EmptyDirectives *state, TSLexer *lexer) {
|
|
140
140
|
TSLexerPosition position;
|
|
141
141
|
lexer->get_position(lexer, &position);
|
|
142
|
-
DirectiveBuffer buffer = {.lexer = lexer, .fill_byte = position.bytes};
|
|
142
|
+
DirectiveBuffer buffer = {.lexer = lexer, .fill_byte = position.bytes, .spaced_splices = state->spaced_splices};
|
|
143
143
|
DirectiveInput input = {.buffer = &buffer, .byte = position.bytes};
|
|
144
144
|
// `run` holds the run before a segment's `#`, and `tail` the segment's trailing run.
|
|
145
145
|
DirectiveSpans run = {0}, tail = {0};
|
package/tree-sitter-c.wasm
CHANGED
|
Binary file
|