summaryrefslogtreecommitdiff
path: root/modules/gdscript
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gdscript_parser.cpp42
-rw-r--r--modules/gdscript/register_types.cpp44
2 files changed, 77 insertions, 9 deletions
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index 36ae61e388..8c110143b8 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -597,12 +597,36 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
OperatorNode *op = alloc_node<OperatorNode>();
op->op = OperatorNode::OP_CALL;
+ //Do a quick Array and Dictionary Check. Replace if either require no arguments.
+ bool replaced = false;
+
if (tokenizer->get_token() == GDScriptTokenizer::TK_BUILT_IN_TYPE) {
+ Variant::Type ct = tokenizer->get_token_type();
+ if (p_parsing_constant == false) {
+ if (ct == Variant::ARRAY) {
+ if (tokenizer->get_token(2) == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
+ ArrayNode *arr = alloc_node<ArrayNode>();
+ expr = arr;
+ replaced = true;
+ tokenizer->advance(3);
+ }
+ }
+ if (ct == Variant::DICTIONARY) {
+ if (tokenizer->get_token(2) == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
+ DictionaryNode *dict = alloc_node<DictionaryNode>();
+ expr = dict;
+ replaced = true;
+ tokenizer->advance(3);
+ }
+ }
+ }
- TypeNode *tn = alloc_node<TypeNode>();
- tn->vtype = tokenizer->get_token_type();
- op->arguments.push_back(tn);
- tokenizer->advance(2);
+ if (!replaced) {
+ TypeNode *tn = alloc_node<TypeNode>();
+ tn->vtype = tokenizer->get_token_type();
+ op->arguments.push_back(tn);
+ tokenizer->advance(2);
+ }
} else if (tokenizer->get_token() == GDScriptTokenizer::TK_BUILT_IN_FUNC) {
BuiltInFunctionNode *bn = alloc_node<BuiltInFunctionNode>();
@@ -628,11 +652,11 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
_make_completable_call(0);
completion_node = op;
}
- if (!_parse_arguments(op, op->arguments, p_static, true))
- return NULL;
-
- expr = op;
-
+ if (!replaced) {
+ if (!_parse_arguments(op, op->arguments, p_static, true))
+ return NULL;
+ expr = op;
+ }
} else if (tokenizer->is_token_literal(0, true)) {
// We check with is_token_literal, as this allows us to use match/sync/etc. as a name
//identifier (reference)
diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp
index 1e007ddb0f..e707032ed8 100644
--- a/modules/gdscript/register_types.cpp
+++ b/modules/gdscript/register_types.cpp
@@ -30,6 +30,7 @@
#include "register_types.h"
#include "gdscript.h"
+#include "gdscript_tokenizer.h"
#include "io/file_access_encrypted.h"
#include "io/resource_loader.h"
#include "os/file_access.h"
@@ -38,6 +39,45 @@ GDScriptLanguage *script_language_gd = NULL;
ResourceFormatLoaderGDScript *resource_loader_gd = NULL;
ResourceFormatSaverGDScript *resource_saver_gd = NULL;
+#ifdef TOOLS_ENABLED
+
+#include "editor/editor_export.h"
+#include "editor/editor_node.h"
+#include "editor/editor_settings.h"
+
+class EditorExportGDScript : public EditorExportPlugin {
+
+ GDCLASS(EditorExportGDScript, EditorExportPlugin);
+
+public:
+ virtual void _export_file(const String &p_path, const String &p_type, const Set<String> &p_features) {
+
+ if (!p_path.ends_with(".gd"))
+ return;
+
+ Vector<uint8_t> file = FileAccess::get_file_as_array(p_path);
+ if (file.empty())
+ return;
+ String txt;
+ txt.parse_utf8((const char *)file.ptr(), file.size());
+ file = GDScriptTokenizerBuffer::parse_code_string(txt);
+
+ if (file.empty())
+ return;
+
+ add_file(p_path.get_basename() + ".gdc", file, true);
+ }
+};
+
+static void _editor_init() {
+
+ Ref<EditorExportGDScript> gd_export;
+ gd_export.instance();
+ EditorExport::get_singleton()->add_export_plugin(gd_export);
+}
+
+#endif
+
void register_gdscript_types() {
ClassDB::register_class<GDScript>();
@@ -49,6 +89,10 @@ void register_gdscript_types() {
ResourceLoader::add_resource_format_loader(resource_loader_gd);
resource_saver_gd = memnew(ResourceFormatSaverGDScript);
ResourceSaver::add_resource_format_saver(resource_saver_gd);
+
+#ifdef TOOLS_ENABLED
+ EditorNode::add_init_callback(_editor_init);
+#endif
}
void unregister_gdscript_types() {