From 5d31ce4b161553e85bbd8397f2ce62cbd213095f Mon Sep 17 00:00:00 2001 From: George Marques Date: Wed, 15 Sep 2021 09:56:24 -0300 Subject: GDScript: Allow string keys on Lua-style dictionaries Which is useful when the key isn't a valid identifier, such as keys with spaces or numeric keys. --- modules/gdscript/gdscript_parser.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'modules/gdscript/gdscript_parser.cpp') diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 19584ce194..42c06d8161 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -2472,8 +2472,13 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_dictionary(ExpressionNode switch (dictionary->style) { case DictionaryNode::LUA_TABLE: - if (key != nullptr && key->type != Node::IDENTIFIER) { - push_error("Expected identifier as LUA-style dictionary key."); + if (key != nullptr && key->type != Node::IDENTIFIER && key->type != Node::LITERAL) { + push_error("Expected identifier or string as LUA-style dictionary key."); + advance(); + break; + } + if (key != nullptr && key->type == Node::LITERAL && static_cast(key)->value.get_type() != Variant::STRING) { + push_error("Expected identifier or string as LUA-style dictionary key."); advance(); break; } @@ -2487,7 +2492,11 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_dictionary(ExpressionNode } if (key != nullptr) { key->is_constant = true; - key->reduced_value = static_cast(key)->name; + if (key->type == Node::IDENTIFIER) { + key->reduced_value = static_cast(key)->name; + } else if (key->type == Node::LITERAL) { + key->reduced_value = StringName(static_cast(key)->value.operator String()); + } } break; case DictionaryNode::PYTHON_DICT: -- cgit v1.2.3