Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions servers/rendering/shader_preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,23 @@ char32_t ShaderPreprocessor::Tokenizer::peek() {
return 0;
}

int ShaderPreprocessor::Tokenizer::consume_line_continuations(int p_offset) {
int ShaderPreprocessor::Tokenizer::consume_line_continuations() {
int skips = 0;

for (int i = index + p_offset; i < size; i++) {
char32_t c = code[i];
if (c == '\\') {
if (i + 1 < size && code[i + 1] == '\n') {
// This line ends with "\" and "\n" continuation.
add_generated(Token('\n', line));
line++;
skips++;

i = i + 2;
index = i;
} else {
break;
for (; index < size; index++) {
char32_t c = code[index];
if (c != '\\') {
if (is_whitespace(c)) {
continue;
}
} else if (!is_whitespace(c)) {
break;
}
if (index + 1 < size && code[index + 1] == '\n') {
add_generated(Token('\n', line));
line++;
skips++;
index++;
} else {
break;
}
}
Expand All @@ -106,11 +105,11 @@ LocalVector<ShaderPreprocessor::Token> ShaderPreprocessor::Tokenizer::advance(ch
LocalVector<ShaderPreprocessor::Token> tokens;

while (index < size) {
char32_t c = code[index++];
if (c == '\\' && consume_line_continuations(-1) > 0) {
char32_t c = code[index];
if (c == '\\' && consume_line_continuations() > 0) {
continue;
}

index++;
if (c == '\n') {
add_generated(ShaderPreprocessor::Token('\n', line));
line++;
Expand Down Expand Up @@ -145,7 +144,7 @@ String ShaderPreprocessor::Tokenizer::get_identifier(bool *r_is_cursor, bool p_s

while (true) {
char32_t c = peek();
if (c == '\\' && consume_line_continuations(0) > 0) {
if (c == '\\' && consume_line_continuations() > 0) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion servers/rendering/shader_preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ShaderPreprocessor {
int get_line() const;
int get_index() const;
char32_t peek();
int consume_line_continuations(int p_offset);
int consume_line_continuations();

void get_and_clear_generated(LocalVector<char32_t> *r_out);
void backtrack(char32_t p_what);
Expand Down
Loading