diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/gd_parser.cpp | 27 | ||||
-rw-r--r-- | modules/gdscript/gd_parser.h | 1 | ||||
-rw-r--r-- | modules/gdscript/gd_script.cpp | 22 |
3 files changed, 36 insertions, 14 deletions
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index c4175e048d..b6e8478846 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -283,13 +283,23 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ return NULL; } tokenizer->advance(); - if (tokenizer->get_token()!=GDTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type()!=Variant::STRING) { - _set_error("Expected string constant as 'preload' argument."); + + String path; + bool valid = false; + Node *subexpr = _parse_and_reduce_expression(p_parent, p_static); + if (subexpr) { + if (subexpr->type == Node::TYPE_CONSTANT) { + ConstantNode *cn = static_cast<ConstantNode*>(subexpr); + if (cn->value.get_type() == Variant::STRING) { + valid = true; + path = (String) cn->value; + } + } + } + if (!valid) { + _set_error("expected string constant as 'preload' argument."); return NULL; } - - - String path = tokenizer->get_token_constant(); if (!path.is_abs_path() && base_path!="") path=base_path+"/"+path; path = path.replace("///","//").simplify_path(); @@ -322,8 +332,6 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ } } - tokenizer->advance(); - if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected ')' after 'preload' path"); return NULL; @@ -3145,6 +3153,11 @@ Error GDParser::parse(const String& p_code, const String& p_base_path, bool p_ju return ret; } +bool GDParser::is_tool_script() const { + + return (head && head->type==Node::TYPE_CLASS && static_cast<const ClassNode*>(head)->tool); +} + const GDParser::Node *GDParser::get_parse_tree() const { return head; diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h index 9ad8633968..6c49c1df52 100644 --- a/modules/gdscript/gd_parser.h +++ b/modules/gdscript/gd_parser.h @@ -454,6 +454,7 @@ public: Error parse(const String& p_code, const String& p_base_path="", bool p_just_validate=false,const String& p_self_path="",bool p_for_completion=false); Error parse_bytecode(const Vector<uint8_t> &p_bytecode,const String& p_base_path="",const String& p_self_path=""); + bool is_tool_script() const; const Node *get_parse_tree() const; //completion info diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 9a3f50d3b8..62c5eb735a 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -1874,19 +1874,27 @@ Error GDScript::reload() { if (ScriptDebugger::get_singleton()) { GDScriptLanguage::get_singleton()->debug_break_parse(get_path(),parser.get_error_line(),"Parser Error: "+parser.get_error()); } - _err_print_error("GDScript::reload",path.empty()?"built-in":(const char*)path.utf8().get_data(),parser.get_error_line(),("Parse Error: "+parser.get_error()).utf8().get_data()); + _err_print_error("GDScript::reload",path.empty()?"built-in":(const char*)path.utf8().get_data(),parser.get_error_line(),("Parse Error: "+parser.get_error()).utf8().get_data(),ERR_HANDLER_SCRIPT); ERR_FAIL_V(ERR_PARSE_ERROR); } + + bool can_run = ScriptServer::is_scripting_enabled() || parser.is_tool_script(); + GDCompiler compiler; err = compiler.compile(&parser,this); if (err) { - if (ScriptDebugger::get_singleton()) { - GDScriptLanguage::get_singleton()->debug_break_parse(get_path(),compiler.get_error_line(),"Parser Error: "+compiler.get_error()); + + if (can_run) { + if (ScriptDebugger::get_singleton()) { + GDScriptLanguage::get_singleton()->debug_break_parse(get_path(),compiler.get_error_line(),"Parser Error: "+compiler.get_error()); + } + _err_print_error("GDScript::reload",path.empty()?"built-in":(const char*)path.utf8().get_data(),compiler.get_error_line(),("Compile Error: "+compiler.get_error()).utf8().get_data(),ERR_HANDLER_SCRIPT); + ERR_FAIL_V(ERR_COMPILATION_FAILED); + } else { + return err; } - _err_print_error("GDScript::reload",path.empty()?"built-in":(const char*)path.utf8().get_data(),compiler.get_error_line(),("Compile Error: "+compiler.get_error()).utf8().get_data()); - ERR_FAIL_V(ERR_COMPILATION_FAILED); } valid=true; @@ -2053,7 +2061,7 @@ Error GDScript::load_byte_code(const String& p_path) { GDParser parser; Error err = parser.parse_bytecode(bytecode,basedir,get_path()); if (err) { - _err_print_error("GDScript::load_byte_code",path.empty()?"built-in":(const char*)path.utf8().get_data(),parser.get_error_line(),("Parse Error: "+parser.get_error()).utf8().get_data()); + _err_print_error("GDScript::load_byte_code",path.empty()?"built-in":(const char*)path.utf8().get_data(),parser.get_error_line(),("Parse Error: "+parser.get_error()).utf8().get_data(),ERR_HANDLER_SCRIPT); ERR_FAIL_V(ERR_PARSE_ERROR); } @@ -2061,7 +2069,7 @@ Error GDScript::load_byte_code(const String& p_path) { err = compiler.compile(&parser,this); if (err) { - _err_print_error("GDScript::load_byte_code",path.empty()?"built-in":(const char*)path.utf8().get_data(),compiler.get_error_line(),("Compile Error: "+compiler.get_error()).utf8().get_data()); + _err_print_error("GDScript::load_byte_code",path.empty()?"built-in":(const char*)path.utf8().get_data(),compiler.get_error_line(),("Compile Error: "+compiler.get_error()).utf8().get_data(),ERR_HANDLER_SCRIPT); ERR_FAIL_V(ERR_COMPILATION_FAILED); } |