Skip to content

Commit 4a0e40f

Browse files
GDScript: Do phrase level recovery for match
1 parent e5ccaa7 commit 4a0e40f

File tree

16 files changed

+100
-1
lines changed

16 files changed

+100
-1
lines changed

modules/gdscript/gdscript_parser.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2359,8 +2359,16 @@ GDScriptParser::MatchBranchNode *GDScriptParser::parse_match_branch() {
23592359
}
23602360

23612361
if (!consume(GDScriptTokenizer::Token::COLON, vformat(R"(Expected ":"%s after "match" %s.)", has_guard ? "" : R"( or "when")", has_guard ? "pattern guard" : "patterns"))) {
2362+
branch->block = alloc_recovery_suite();
23622363
complete_extents(branch);
2363-
return nullptr;
2364+
// Consume the whole line and treat the next one as new match branch.
2365+
while (current.type != GDScriptTokenizer::Token::NEWLINE && !is_at_end()) {
2366+
advance();
2367+
}
2368+
if (!is_at_end()) {
2369+
advance();
2370+
}
2371+
return branch;
23642372
}
23652373

23662374
SuiteNode *suite = alloc_node<SuiteNode>();

modules/gdscript/gdscript_parser.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,14 @@ class GDScriptParser {
14631463
return node;
14641464
}
14651465

1466+
SuiteNode *alloc_recovery_suite() {
1467+
SuiteNode *suite = alloc_recovery_node<SuiteNode>();
1468+
suite->parent_block = current_suite;
1469+
suite->parent_function = current_function;
1470+
suite->is_in_loop = current_suite->is_in_loop;
1471+
return suite;
1472+
}
1473+
14661474
void clear();
14671475
void push_error(const String &p_message, const Node *p_origin = nullptr);
14681476
#ifdef DEBUG_ENABLED
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[output]
2+
include=[
3+
{"display": "AUTO_TRANSLATE_MODE_INHERIT"},
4+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extends Node
2+
3+
var t
4+
5+
func test():
6+
match t:
7+
AutoTranslateMode.➡
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[output]
2+
include=[
3+
{"display": "VALUE"},
4+
]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extends Node
2+
3+
enum TestEnum {
4+
VALUE,
5+
}
6+
7+
var t
8+
9+
func test():
10+
match t:
11+
TestEnum.➡ where
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[output]
2+
include=[
3+
{"display": "VALUE"},
4+
]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extends Node
2+
3+
enum TestEnum {
4+
VALUE,
5+
}
6+
7+
var t
8+
9+
func test():
10+
match t:
11+
TestEnum.➡:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[output]
2+
include=[
3+
{"display": "AUTO_TRANSLATE_MODE_INHERIT"},
4+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extends Node
2+
3+
func test():
4+
match AutoTranslateMode.➡

0 commit comments

Comments
 (0)