diff options
author | Yuri Sizov <yuris@humnom.net> | 2023-07-31 21:00:57 +0200 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-07-31 21:00:57 +0200 |
commit | 62b4643d854755b36d7c7ace0047d7a40e812f1a (patch) | |
tree | d2b0cc6d03f0ed5b3c2edd7f40c67a52a4416bf4 /modules/gdscript/gdscript_tokenizer.cpp | |
parent | 438d960592d275040686b18674ccf026ef5f4fd3 (diff) | |
parent | f68beeb7faf060c74550e93dccaf27115c60a8ee (diff) | |
download | redot-engine-62b4643d854755b36d7c7ace0047d7a40e812f1a.tar.gz |
Merge pull request #73226 from AThousandShips/gdscript_tok_improvement
Improve GDScript identifier tokenization
Diffstat (limited to 'modules/gdscript/gdscript_tokenizer.cpp')
-rw-r--r-- | modules/gdscript/gdscript_tokenizer.cpp | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp index 3927a4dd3e..4f374b63b0 100644 --- a/modules/gdscript/gdscript_tokenizer.cpp +++ b/modules/gdscript/gdscript_tokenizer.cpp @@ -579,6 +579,24 @@ GDScriptTokenizer::Token GDScriptTokenizer::potential_identifier() { return make_identifier(name); } + if (!only_ascii) { + // Kept here in case the order with push_error matters. + Token id = make_identifier(name); + +#ifdef DEBUG_ENABLED + // Additional checks for identifiers but only in debug and if it's available in TextServer. + if (TS->has_feature(TextServer::FEATURE_UNICODE_SECURITY)) { + int64_t confusable = TS->is_confusable(name, keyword_list); + if (confusable >= 0) { + push_error(vformat(R"(Identifier "%s" is visually similar to the GDScript keyword "%s" and thus not allowed.)", name, keyword_list[confusable])); + } + } +#endif // DEBUG_ENABLED + + // Cannot be a keyword, as keywords are ASCII only. + return id; + } + // Define some helper macros for the switch case. #define KEYWORD_GROUP_CASE(char) \ break; \ @@ -614,19 +632,7 @@ GDScriptTokenizer::Token GDScriptTokenizer::potential_identifier() { } // Not a keyword, so must be an identifier. - Token id = make_identifier(name); - -#ifdef DEBUG_ENABLED - // Additional checks for identifiers but only in debug and if it's available in TextServer. - if (!only_ascii && TS->has_feature(TextServer::FEATURE_UNICODE_SECURITY)) { - int64_t confusable = TS->is_confusable(name, keyword_list); - if (confusable >= 0) { - push_error(vformat(R"(Identifier "%s" is visually similar to the GDScript keyword "%s" and thus not allowed.)", name, keyword_list[confusable])); - } - } -#endif // DEBUG_ENABLED - - return id; + return make_identifier(name); #undef KEYWORD_GROUP_CASE #undef KEYWORD |