mirror of
https://github.com/godotengine/godot
synced 2024-09-05 17:59:56 +00:00
made _ a special token in GDScript
This commit is contained in:
parent
72a0255585
commit
c24c739da5
|
@ -1704,7 +1704,7 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (token) {
|
switch (token) {
|
||||||
// dictionary
|
// array
|
||||||
case GDTokenizer::TK_BRACKET_OPEN: {
|
case GDTokenizer::TK_BRACKET_OPEN: {
|
||||||
tokenizer->advance();
|
tokenizer->advance();
|
||||||
pattern->pt_type = GDParser::PatternNode::PT_ARRAY;
|
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();
|
pattern->bind = tokenizer->get_token_identifier();
|
||||||
tokenizer->advance();
|
tokenizer->advance();
|
||||||
} break;
|
} break;
|
||||||
// array
|
// dictionary
|
||||||
case GDTokenizer::TK_CURLY_BRACKET_OPEN: {
|
case GDTokenizer::TK_CURLY_BRACKET_OPEN: {
|
||||||
tokenizer->advance();
|
tokenizer->advance();
|
||||||
pattern->pt_type = GDParser::PatternNode::PT_DICTIONARY;
|
pattern->pt_type = GDParser::PatternNode::PT_DICTIONARY;
|
||||||
|
@ -1826,17 +1826,16 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
case GDTokenizer::TK_WILDCARD: {
|
||||||
|
tokenizer->advance();
|
||||||
|
pattern->pt_type = PatternNode::PT_WILDCARD;
|
||||||
|
} break;
|
||||||
// all the constants like strings and numbers
|
// all the constants like strings and numbers
|
||||||
default: {
|
default: {
|
||||||
Node *value = _parse_and_reduce_expression(pattern, p_static);
|
Node *value = _parse_and_reduce_expression(pattern, p_static);
|
||||||
if (error_set) {
|
if (error_set) {
|
||||||
return NULL;
|
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) {
|
if (value->type != Node::TYPE_IDENTIFIER && value->type != Node::TYPE_CONSTANT) {
|
||||||
_set_error("Only constant expressions or variables allowed in a pattern");
|
_set_error("Only constant expressions or variables allowed in a pattern");
|
||||||
|
|
|
@ -119,6 +119,7 @@ const char* GDTokenizer::token_names[TK_MAX]={
|
||||||
"':'",
|
"':'",
|
||||||
"'\\n'",
|
"'\\n'",
|
||||||
"PI",
|
"PI",
|
||||||
|
"_",
|
||||||
"Error",
|
"Error",
|
||||||
"EOF",
|
"EOF",
|
||||||
"Cursor"};
|
"Cursor"};
|
||||||
|
@ -899,6 +900,7 @@ void GDTokenizerText::_advance() {
|
||||||
{TK_CF_PASS,"pass"},
|
{TK_CF_PASS,"pass"},
|
||||||
{TK_SELF,"self"},
|
{TK_SELF,"self"},
|
||||||
{TK_CONST_PI,"PI"},
|
{TK_CONST_PI,"PI"},
|
||||||
|
{TK_WILDCARD,"_"},
|
||||||
{TK_ERROR,NULL}
|
{TK_ERROR,NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -127,6 +127,7 @@ public:
|
||||||
TK_DOLLAR,
|
TK_DOLLAR,
|
||||||
TK_NEWLINE,
|
TK_NEWLINE,
|
||||||
TK_CONST_PI,
|
TK_CONST_PI,
|
||||||
|
TK_WILDCARD,
|
||||||
TK_ERROR,
|
TK_ERROR,
|
||||||
TK_EOF,
|
TK_EOF,
|
||||||
TK_CURSOR, //used for code completion
|
TK_CURSOR, //used for code completion
|
||||||
|
|
Loading…
Reference in a new issue