diff options
author | George Marques <george@gmarqu.es> | 2021-09-15 09:56:24 -0300 |
---|---|---|
committer | George Marques <george@gmarqu.es> | 2021-09-15 09:56:24 -0300 |
commit | 5d31ce4b161553e85bbd8397f2ce62cbd213095f (patch) | |
tree | 8c9e186efdd9667bf3c223b29b73dddeca3036f8 /modules/gdscript/gdscript_parser.cpp | |
parent | 32f8f74d8345049e41d1abb7239fcee40ecb2c53 (diff) | |
download | redot-engine-5d31ce4b161553e85bbd8397f2ce62cbd213095f.tar.gz |
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.
Diffstat (limited to 'modules/gdscript/gdscript_parser.cpp')
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
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<LiteralNode *>(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<IdentifierNode *>(key)->name; + if (key->type == Node::IDENTIFIER) { + key->reduced_value = static_cast<IdentifierNode *>(key)->name; + } else if (key->type == Node::LITERAL) { + key->reduced_value = StringName(static_cast<LiteralNode *>(key)->value.operator String()); + } } break; case DictionaryNode::PYTHON_DICT: |