diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-01-23 07:55:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-23 07:55:11 +0100 |
commit | 5027799c13d9b38b55b2184bca997632339651d8 (patch) | |
tree | 75b487bdd76c08366ecb0895ef82a3096e0e188d /modules/gdscript | |
parent | cff80bb1cc0aa5a548254b9c89d0fab28982b504 (diff) | |
parent | c24c739da54225dd5090e82c8d0a34f8bbe0724a (diff) |
Merge pull request #7583 from karroffel/wildcard
made _ a special token in GDScript
Diffstat (limited to 'modules/gdscript')
-rw-r--r-- | modules/gdscript/gd_parser.cpp | 13 | ||||
-rw-r--r-- | modules/gdscript/gd_tokenizer.cpp | 2 | ||||
-rw-r--r-- | modules/gdscript/gd_tokenizer.h | 1 |
3 files changed, 9 insertions, 7 deletions
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 70659326e5..34c39c8024 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -1704,7 +1704,7 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) } switch (token) { - // dictionary + // array case GDTokenizer::TK_BRACKET_OPEN: { tokenizer->advance(); pattern->pt_type = GDParser::PatternNode::PT_ARRAY; @@ -1759,7 +1759,7 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) pattern->bind = tokenizer->get_token_identifier(); tokenizer->advance(); } break; - // array + // dictionary case GDTokenizer::TK_CURLY_BRACKET_OPEN: { tokenizer->advance(); pattern->pt_type = GDParser::PatternNode::PT_DICTIONARY; @@ -1826,17 +1826,16 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) } } } break; + case GDTokenizer::TK_WILDCARD: { + tokenizer->advance(); + pattern->pt_type = PatternNode::PT_WILDCARD; + } break; // all the constants like strings and numbers default: { Node *value = _parse_and_reduce_expression(pattern, p_static); if (error_set) { return NULL; } - if (value->type == Node::TYPE_IDENTIFIER && static_cast<IdentifierNode*>(value)->name == "_") { - // wildcard pattern - pattern->pt_type = PatternNode::PT_WILDCARD; - break; - } if (value->type != Node::TYPE_IDENTIFIER && value->type != Node::TYPE_CONSTANT) { _set_error("Only constant expressions or variables allowed in a pattern"); diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index 70fc991bcc..5be2a2beae 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -119,6 +119,7 @@ const char* GDTokenizer::token_names[TK_MAX]={ "':'", "'\\n'", "PI", +"_", "Error", "EOF", "Cursor"}; @@ -899,6 +900,7 @@ void GDTokenizerText::_advance() { {TK_CF_PASS,"pass"}, {TK_SELF,"self"}, {TK_CONST_PI,"PI"}, + {TK_WILDCARD,"_"}, {TK_ERROR,NULL} }; diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gd_tokenizer.h index 9a6f4df9c4..5d955ff1ae 100644 --- a/modules/gdscript/gd_tokenizer.h +++ b/modules/gdscript/gd_tokenizer.h @@ -127,6 +127,7 @@ public: TK_DOLLAR, TK_NEWLINE, TK_CONST_PI, + TK_WILDCARD, TK_ERROR, TK_EOF, TK_CURSOR, //used for code completion |