You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
GDScript: Implement pattern guards for match statement
Within a match statement, it is now possible to add guards in each
branch:
var a = 0
match a:
0 when false: print("does not run")
0 when true: print("but this does")
This allows more complex logic for deciding which branch to take.
This commit is contained in:
@@ -99,6 +99,7 @@ static const char *token_names[] = {
|
||||
"pass", // PASS,
|
||||
"return", // RETURN,
|
||||
"match", // MATCH,
|
||||
"when", // WHEN,
|
||||
// Keywords
|
||||
"as", // AS,
|
||||
"assert", // ASSERT,
|
||||
@@ -187,6 +188,7 @@ bool GDScriptTokenizer::Token::is_identifier() const {
|
||||
switch (type) {
|
||||
case IDENTIFIER:
|
||||
case MATCH: // Used in String.match().
|
||||
case WHEN: // New keyword, avoid breaking existing code.
|
||||
// Allow constants to be treated as regular identifiers.
|
||||
case CONST_PI:
|
||||
case CONST_INF:
|
||||
@@ -241,6 +243,7 @@ bool GDScriptTokenizer::Token::is_node_name() const {
|
||||
case VAR:
|
||||
case VOID:
|
||||
case WHILE:
|
||||
case WHEN:
|
||||
case YIELD:
|
||||
return true;
|
||||
default:
|
||||
@@ -531,6 +534,7 @@ GDScriptTokenizer::Token GDScriptTokenizer::annotation() {
|
||||
KEYWORD("void", Token::VOID) \
|
||||
KEYWORD_GROUP('w') \
|
||||
KEYWORD("while", Token::WHILE) \
|
||||
KEYWORD("when", Token::WHEN) \
|
||||
KEYWORD_GROUP('y') \
|
||||
KEYWORD("yield", Token::YIELD) \
|
||||
KEYWORD_GROUP('I') \
|
||||
|
||||
Reference in New Issue
Block a user