Skip to content

Commit 684e7aa

Browse files
committed
Merge pull request godotengine#89472 from dalexeev/gds-fix-bin-tokenizer-continuation-lines
GDScript: Fix continuation lines in `GDScriptTokenizerBuffer`
2 parents 49dd453 + 02253b6 commit 684e7aa

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

modules/gdscript/gdscript_tokenizer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,10 +1455,11 @@ GDScriptTokenizer::Token GDScriptTokenizerText::scan() {
14551455
if (_peek() != '\n') {
14561456
return make_error("Expected new line after \"\\\".");
14571457
}
1458-
continuation_lines.push_back(line);
14591458
_advance();
14601459
newline(false);
14611460
line_continuation = true;
1461+
_skip_whitespace(); // Skip whitespace/comment lines after `\`. See GH-89403.
1462+
continuation_lines.push_back(line);
14621463
return scan(); // Recurse to get next token.
14631464
}
14641465

modules/gdscript/gdscript_tokenizer_buffer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code,
285285

286286
// Remove continuation lines from map.
287287
for (int line : tokenizer.get_continuation_lines()) {
288-
if (rev_token_lines.has(line + 1)) {
289-
token_lines.erase(rev_token_lines[line + 1]);
290-
token_columns.erase(rev_token_lines[line + 1]);
288+
if (rev_token_lines.has(line)) {
289+
token_lines.erase(rev_token_lines[line]);
290+
token_columns.erase(rev_token_lines[line]);
291291
}
292292
}
293293

modules/gdscript/tests/gdscript_test_runner.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,23 @@ bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) {
300300
#endif
301301

302302
String out_file = next.get_basename() + ".out";
303-
if (!is_generating && !dir->file_exists(out_file)) {
304-
ERR_FAIL_V_MSG(false, "Could not find output file for " + next);
305-
}
306-
GDScriptTest test(current_dir.path_join(next), current_dir.path_join(out_file), source_dir);
307-
if (binary_tokens) {
308-
test.set_tokenizer_mode(GDScriptTest::TOKENIZER_BUFFER);
303+
ERR_FAIL_COND_V_MSG(!is_generating && !dir->file_exists(out_file), false, "Could not find output file for " + next);
304+
305+
if (next.ends_with(".bin.gd")) {
306+
// Test text mode first.
307+
GDScriptTest text_test(current_dir.path_join(next), current_dir.path_join(out_file), source_dir);
308+
tests.push_back(text_test);
309+
// Test binary mode even without `--use-binary-tokens`.
310+
GDScriptTest bin_test(current_dir.path_join(next), current_dir.path_join(out_file), source_dir);
311+
bin_test.set_tokenizer_mode(GDScriptTest::TOKENIZER_BUFFER);
312+
tests.push_back(bin_test);
313+
} else {
314+
GDScriptTest test(current_dir.path_join(next), current_dir.path_join(out_file), source_dir);
315+
if (binary_tokens) {
316+
test.set_tokenizer_mode(GDScriptTest::TOKENIZER_BUFFER);
317+
}
318+
tests.push_back(test);
309319
}
310-
tests.push_back(test);
311320
}
312321
}
313322

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# GH-89403
2+
3+
func test():
4+
var x := 1
5+
if x == 0 \
6+
# Comment.
7+
# Comment.
8+
and (x < 1 or x > 2) \
9+
# Comment.
10+
and x != 3:
11+
pass
12+
print("Ok")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GDTEST_OK
2+
Ok

0 commit comments

Comments
 (0)