Skip to content

Commit ee82adc

Browse files
committed
Merge pull request #105413 from HolonProduction/gdscript-recover-match
GDScript: Do phrase level recovery for match
2 parents aef0065 + 4a0e40f commit ee82adc

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
@@ -2421,8 +2421,16 @@ GDScriptParser::MatchBranchNode *GDScriptParser::parse_match_branch() {
24212421
}
24222422

24232423
if (!consume(GDScriptTokenizer::Token::COLON, vformat(R"(Expected ":"%s after "match" %s.)", has_guard ? "" : R"( or "when")", has_guard ? "pattern guard" : "patterns"))) {
2424+
branch->block = alloc_recovery_suite();
24242425
complete_extents(branch);
2425-
return nullptr;
2426+
// Consume the whole line and treat the next one as new match branch.
2427+
while (current.type != GDScriptTokenizer::Token::NEWLINE && !is_at_end()) {
2428+
advance();
2429+
}
2430+
if (!is_at_end()) {
2431+
advance();
2432+
}
2433+
return branch;
24262434
}
24272435

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

modules/gdscript/gdscript_parser.h

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

1467+
SuiteNode *alloc_recovery_suite() {
1468+
SuiteNode *suite = alloc_recovery_node<SuiteNode>();
1469+
suite->parent_block = current_suite;
1470+
suite->parent_function = current_function;
1471+
suite->is_in_loop = current_suite->is_in_loop;
1472+
return suite;
1473+
}
1474+
14671475
void clear();
14681476
void push_error(const String &p_message, const Node *p_origin = nullptr);
14691477
#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)