GDScript: Be more lenient with identifiers

- Allow identifiers similar to keywords if they are in ASCII range.
- Allow constants to be treated as regular identifiers.
- Allow keywords that can be used as identifiers in expressions.
This commit is contained in:
George Marques 2023-02-09 11:17:37 -03:00
parent d02a7bc00d
commit 03ea77407c
No known key found for this signature in database
GPG key ID: 046BD46A3201E43D
8 changed files with 67 additions and 6 deletions

View file

@ -2145,7 +2145,12 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_precedence(Precedence p_pr
make_completion_context(COMPLETION_IDENTIFIER, nullptr);
GDScriptTokenizer::Token token = current;
ParseFunction prefix_rule = get_rule(token.type)->prefix;
GDScriptTokenizer::Token::Type token_type = token.type;
if (token.is_identifier()) {
// Allow keywords that can be treated as identifiers.
token_type = GDScriptTokenizer::Token::IDENTIFIER;
}
ParseFunction prefix_rule = get_rule(token_type)->prefix;
if (prefix_rule == nullptr) {
// Expected expression. Let the caller give the proper error message.
@ -3010,7 +3015,14 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_get_node(ExpressionNode *p
path_state = PATH_STATE_NODE_NAME;
} else if (current.is_node_name()) {
advance();
get_node->full_path += previous.get_identifier();
String identifier = previous.get_identifier();
#ifdef DEBUG_ENABLED
// Check spoofing.
if (TS->has_feature(TextServer::FEATURE_UNICODE_SECURITY) && TS->spoof_check(identifier)) {
push_warning(get_node, GDScriptWarning::CONFUSABLE_IDENTIFIER, identifier);
}
#endif
get_node->full_path += identifier;
path_state = PATH_STATE_NODE_NAME;
} else if (!check(GDScriptTokenizer::Token::SLASH) && !check(GDScriptTokenizer::Token::PERCENT)) {