summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-08-23 08:05:52 +0200
committerGitHub <noreply@github.com>2017-08-23 08:05:52 +0200
commit1ad68c946eaac6f501a66b5157c0bc4c08a25024 (patch)
tree9cbdae825960add04df678d72d8f3b5e9fcce65d
parenteb238a04dacae397db393cbce74891cf90405a67 (diff)
parent57654d4b950d2bbb9e3cb28721aeb3f4499ea2f9 (diff)
Merge pull request #10542 from karroffel/gdscript-match-index
support enums and nested constants in match statement
-rw-r--r--modules/gdscript/gd_parser.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp
index 7d3857266e..b349b6b9a8 100644
--- a/modules/gdscript/gd_parser.cpp
+++ b/modules/gdscript/gd_parser.cpp
@@ -1894,7 +1894,26 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) {
return NULL;
}
- if (value->type != Node::TYPE_IDENTIFIER && value->type != Node::TYPE_CONSTANT) {
+ if (value->type == Node::TYPE_OPERATOR) {
+ // Maybe it's SomeEnum.VALUE
+ Node *current_value = value;
+
+ while (current_value->type == Node::TYPE_OPERATOR) {
+ OperatorNode *op_node = static_cast<OperatorNode *>(current_value);
+
+ if (op_node->op != OperatorNode::OP_INDEX_NAMED) {
+ _set_error("Invalid operator in pattern. Only index (`A.B`) is allowed");
+ return NULL;
+ }
+ current_value = op_node->arguments[0];
+ }
+
+ if (current_value->type != Node::TYPE_IDENTIFIER) {
+ _set_error("Only constant expression or variables allowed in a pattern");
+ return NULL;
+ }
+
+ } else if (value->type != Node::TYPE_IDENTIFIER && value->type != Node::TYPE_CONSTANT) {
_set_error("Only constant expressions or variables allowed in a pattern");
return NULL;
}