From 9ecd042e785198fcad3847463aff345bf996a640 Mon Sep 17 00:00:00 2001 From: George Marques Date: Mon, 17 Aug 2020 20:14:46 -0300 Subject: GDScript: Allow "match" to be used as an identifier This is needed to call the String.match() function. --- modules/gdscript/gdscript_tokenizer.cpp | 12 ++++++++++++ modules/gdscript/gdscript_tokenizer.h | 5 ++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp index 7a4bdd88ba..8ced06e2fd 100644 --- a/modules/gdscript/gdscript_tokenizer.cpp +++ b/modules/gdscript/gdscript_tokenizer.cpp @@ -156,6 +156,18 @@ const char *GDScriptTokenizer::Token::get_name() const { return token_names[type]; } +bool GDScriptTokenizer::Token::is_identifier() const { + // Note: Most keywords should not be recognized as identifiers. + // These are only exceptions for stuff that already is on the engine's API. + switch (type) { + case IDENTIFIER: + case MATCH: // Used in String.match(). + return true; + default: + return false; + } +} + String GDScriptTokenizer::get_token_name(Token::Type p_token_type) { ERR_FAIL_INDEX_V_MSG(p_token_type, Token::TK_MAX, "", "Using token type out of the enum."); return token_names[p_token_type]; diff --git a/modules/gdscript/gdscript_tokenizer.h b/modules/gdscript/gdscript_tokenizer.h index 059a226924..956530341c 100644 --- a/modules/gdscript/gdscript_tokenizer.h +++ b/modules/gdscript/gdscript_tokenizer.h @@ -168,9 +168,8 @@ public: String source; const char *get_name() const; - // TODO: Allow some keywords as identifiers? - bool is_identifier() const { return type == IDENTIFIER; } - StringName get_identifier() const { return literal; } + bool is_identifier() const; + StringName get_identifier() const { return source; } Token(Type p_type) { type = p_type; -- cgit v1.2.3