summaryrefslogtreecommitdiff
path: root/modules/gdscript/gdscript_parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript/gdscript_parser.cpp')
-rw-r--r--modules/gdscript/gdscript_parser.cpp562
1 files changed, 321 insertions, 241 deletions
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index f006d50a83..e96bf0238a 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -252,6 +252,16 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
}
}
+ // Check that the next token is not TK_CURSOR and if it is, the offset should be incremented.
+ int next_valid_offset = 1;
+ if (tokenizer->get_token(next_valid_offset) == GDScriptTokenizer::TK_CURSOR) {
+ next_valid_offset++;
+ // There is a chunk of the identifier that also needs to be ignored (not always there!)
+ if (tokenizer->get_token(next_valid_offset) == GDScriptTokenizer::TK_IDENTIFIER) {
+ next_valid_offset++;
+ }
+ }
+
if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_OPEN) {
//subexpression ()
tokenizer->advance();
@@ -504,7 +514,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
Ref<GDScript> gds = res;
if (gds.is_valid() && !gds->is_valid()) {
- _set_error("Could not fully preload the script, possible cyclic reference or compilation error. Use 'load()' instead if a cyclic reference is intended.");
+ _set_error("Couldn't fully preload the script, possible cyclic reference or compilation error. Use \"load()\" instead if a cyclic reference is intended.");
return NULL;
}
@@ -518,7 +528,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
} else if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_YIELD) {
if (!current_function) {
- _set_error("yield() can only be used inside function blocks.");
+ _set_error("\"yield()\" can only be used inside function blocks.");
return NULL;
}
@@ -526,7 +536,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_OPEN) {
- _set_error("Expected '(' after 'yield'");
+ _set_error("Expected \"(\" after \"yield\".");
return NULL;
}
@@ -552,7 +562,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
yield->arguments.push_back(object);
if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
- _set_error("Expected ',' after first argument of 'yield'");
+ _set_error("Expected \",\" after the first argument of \"yield\".");
return NULL;
}
@@ -578,7 +588,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
yield->arguments.push_back(signal);
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
- _set_error("Expected ')' after second argument of 'yield'");
+ _set_error("Expected \")\" after the second argument of \"yield\".");
return NULL;
}
@@ -592,7 +602,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
} else if (tokenizer->get_token() == GDScriptTokenizer::TK_SELF) {
if (p_static) {
- _set_error("'self'' not allowed in static function or constant expression");
+ _set_error("\"self\" isn't allowed in a static function or constant expression.");
return NULL;
}
//constant defined by tokenizer
@@ -613,7 +623,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
if (identifier == StringName()) {
- _set_error("Built-in type constant or static function expected after '.'");
+ _set_error("Built-in type constant or static function expected after \".\".");
return NULL;
}
if (!Variant::has_constant(bi_type, identifier)) {
@@ -668,7 +678,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
expr = cn;
}
- } else if (tokenizer->get_token(1) == GDScriptTokenizer::TK_PARENTHESIS_OPEN && tokenizer->is_token_literal()) {
+ } else if (tokenizer->get_token(next_valid_offset) == GDScriptTokenizer::TK_PARENTHESIS_OPEN && tokenizer->is_token_literal()) {
// We check with is_token_literal, as this allows us to use match/sync/etc. as a name
//function or constructor
@@ -898,6 +908,10 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
} else if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_IS && tokenizer->get_token(1) == GDScriptTokenizer::TK_BUILT_IN_TYPE) {
// 'is' operator with built-in type
+ if (!expr) {
+ _set_error("Expected identifier before 'is' operator");
+ return NULL;
+ }
OperatorNode *op = alloc_node<OperatorNode>();
op->op = OperatorNode::OP_IS_BUILTIN;
op->arguments.push_back(expr);
@@ -1136,10 +1150,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
return NULL; //nothing
}
- if (!expr) {
- ERR_EXPLAIN("GDScriptParser bug, couldn't figure out what expression is...");
- ERR_FAIL_V(NULL);
- }
+ ERR_FAIL_COND_V_MSG(!expr, NULL, "GDScriptParser bug, couldn't figure out what expression is.");
/******************/
/* Parse Indexing */
@@ -2308,7 +2319,7 @@ void GDScriptParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_m
// static type check if possible
if (pattern_type.has_type && to_match_type.has_type) {
if (!_is_type_compatible(to_match_type, pattern_type) && !_is_type_compatible(pattern_type, to_match_type)) {
- _set_error("Pattern type (" + pattern_type.to_string() + ") is not compatible with the type of the value to match (" + to_match_type.to_string() + ").",
+ _set_error("The pattern type (" + pattern_type.to_string() + ") isn't compatible with the type of the value to match (" + to_match_type.to_string() + ").",
p_pattern->line);
return;
}
@@ -2760,24 +2771,24 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
case GDScriptTokenizer::TK_CF_PASS: {
if (tokenizer->get_token(1) != GDScriptTokenizer::TK_SEMICOLON && tokenizer->get_token(1) != GDScriptTokenizer::TK_NEWLINE && tokenizer->get_token(1) != GDScriptTokenizer::TK_EOF) {
- _set_error("Expected ';' or <NewLine>.");
+ _set_error("Expected \";\" or a line break.");
return;
}
_mark_line_as_safe(tokenizer->get_token_line());
tokenizer->advance();
if (tokenizer->get_token() == GDScriptTokenizer::TK_SEMICOLON) {
- // Ignore semicolon after 'pass'
+ // Ignore semicolon after 'pass'.
tokenizer->advance();
}
} break;
case GDScriptTokenizer::TK_PR_VAR: {
- //variale declaration and (eventual) initialization
+ // Variable declaration and (eventual) initialization.
tokenizer->advance();
int var_line = tokenizer->get_token_line();
if (!tokenizer->is_token_literal(0, true)) {
- _set_error("Expected identifier for local variable name.");
+ _set_error("Expected an identifier for the local variable name.");
return;
}
StringName n = tokenizer->get_token_literal();
@@ -2785,7 +2796,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
if (current_function) {
for (int i = 0; i < current_function->arguments.size(); i++) {
if (n == current_function->arguments[i]) {
- _set_error("Variable '" + String(n) + "' already defined in the scope (at line: " + itos(current_function->line) + ").");
+ _set_error("Variable \"" + String(n) + "\" already defined in the scope (at line " + itos(current_function->line) + ").");
return;
}
}
@@ -2793,7 +2804,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
BlockNode *check_block = p_block;
while (check_block) {
if (check_block->variables.has(n)) {
- _set_error("Variable '" + String(n) + "' already defined in the scope (at line: " + itos(check_block->variables[n]->line) + ").");
+ _set_error("Variable \"" + String(n) + "\" already defined in the scope (at line " + itos(check_block->variables[n]->line) + ").");
return;
}
check_block = check_block->parent_block;
@@ -2815,7 +2826,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
#endif
tokenizer->advance();
} else if (!_parse_type(lv->datatype)) {
- _set_error("Expected type for variable.");
+ _set_error("Expected a type for the variable.");
return;
}
}
@@ -2864,7 +2875,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
lv->assign = assigned;
if (!_end_statement()) {
- _set_error("Expected end of statement (var)");
+ _set_error("Expected end of statement (\"var\").");
return;
}
@@ -2893,7 +2904,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
p_block->sub_blocks.push_back(cf_if->body);
if (!_enter_indent_block(cf_if->body)) {
- _set_error("Expected indented block after 'if'");
+ _set_error("Expected an indented block after \"if\".");
p_block->end_line = tokenizer->get_token_line();
return;
}
@@ -2923,7 +2934,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
if (tab_level.back()->get() > indent_level) {
- _set_error("Invalid indent");
+ _set_error("Invalid indentation.");
return;
}
@@ -2954,7 +2965,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
p_block->sub_blocks.push_back(cf_if->body);
if (!_enter_indent_block(cf_if->body)) {
- _set_error("Expected indented block after 'elif'");
+ _set_error("Expected an indented block after \"elif\".");
p_block->end_line = tokenizer->get_token_line();
return;
}
@@ -2970,7 +2981,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
} else if (tokenizer->get_token() == GDScriptTokenizer::TK_CF_ELSE) {
if (tab_level.back()->get() > indent_level) {
- _set_error("Invalid indent");
+ _set_error("Invalid indentation.");
return;
}
@@ -2980,7 +2991,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
p_block->sub_blocks.push_back(cf_if->body_else);
if (!_enter_indent_block(cf_if->body_else)) {
- _set_error("Expected indented block after 'else'");
+ _set_error("Expected an indented block after \"else\".");
p_block->end_line = tokenizer->get_token_line();
return;
}
@@ -3025,7 +3036,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
p_block->sub_blocks.push_back(cf_while->body);
if (!_enter_indent_block(cf_while->body)) {
- _set_error("Expected indented block after 'while'");
+ _set_error("Expected an indented block after \"while\".");
p_block->end_line = tokenizer->get_token_line();
return;
}
@@ -3044,7 +3055,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
if (!tokenizer->is_token_literal(0, true)) {
- _set_error("identifier expected after 'for'");
+ _set_error("Identifier expected after \"for\".");
}
IdentifierNode *id = alloc_node<IdentifierNode>();
@@ -3053,7 +3064,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_OP_IN) {
- _set_error("'in' expected after identifier");
+ _set_error("\"in\" expected after identifier.");
return;
}
@@ -3143,7 +3154,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
p_block->sub_blocks.push_back(cf_for->body);
if (!_enter_indent_block(cf_for->body)) {
- _set_error("Expected indented block after 'for'");
+ _set_error("Expected indented block after \"for\".");
p_block->end_line = tokenizer->get_token_line();
return;
}
@@ -3170,23 +3181,25 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
} break;
case GDScriptTokenizer::TK_CF_CONTINUE: {
+ _mark_line_as_safe(tokenizer->get_token_line());
tokenizer->advance();
ControlFlowNode *cf_continue = alloc_node<ControlFlowNode>();
cf_continue->cf_type = ControlFlowNode::CF_CONTINUE;
p_block->statements.push_back(cf_continue);
if (!_end_statement()) {
- _set_error("Expected end of statement (continue)");
+ _set_error("Expected end of statement (\"continue\").");
return;
}
} break;
case GDScriptTokenizer::TK_CF_BREAK: {
+ _mark_line_as_safe(tokenizer->get_token_line());
tokenizer->advance();
ControlFlowNode *cf_break = alloc_node<ControlFlowNode>();
cf_break->cf_type = ControlFlowNode::CF_BREAK;
p_block->statements.push_back(cf_break);
if (!_end_statement()) {
- _set_error("Expected end of statement (break)");
+ _set_error("Expected end of statement (\"break\").");
return;
}
} break;
@@ -3240,7 +3253,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
match_node->val_to_match = val_to_match;
if (!_enter_indent_block()) {
- _set_error("Expected indented pattern matching block after 'match'");
+ _set_error("Expected indented pattern matching block after \"match\".");
return;
}
@@ -3279,7 +3292,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
p_block->statements.push_back(an);
if (!_end_statement()) {
- _set_error("Expected end of statement after assert.");
+ _set_error("Expected end of statement after \"assert\".");
return;
}
} break;
@@ -3290,7 +3303,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
p_block->statements.push_back(bn);
if (!_end_statement()) {
- _set_error("Expected end of statement after breakpoint.");
+ _set_error("Expected end of statement after \"breakpoint\".");
return;
}
} break;
@@ -3322,7 +3335,7 @@ bool GDScriptParser::_parse_newline() {
int current_indent = tab_level.back()->get();
if (indent > current_indent) {
- _set_error("Unexpected indent.");
+ _set_error("Unexpected indentation.");
return false;
}
@@ -3332,7 +3345,7 @@ bool GDScriptParser::_parse_newline() {
//exit block
if (tab_level.size() == 1) {
- _set_error("Invalid indent. BUG?");
+ _set_error("Invalid indentation. Bug?");
return false;
}
@@ -3359,13 +3372,13 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) {
if (p_class->extends_used) {
- _set_error("'extends' already used for this class.");
+ _set_error("\"extends\" can only be present once per script.");
return;
}
- if (!p_class->constant_expressions.empty() || !p_class->subclasses.empty() || !p_class->functions.empty() || !p_class->variables.empty() || p_class->classname_used) {
+ if (!p_class->constant_expressions.empty() || !p_class->subclasses.empty() || !p_class->functions.empty() || !p_class->variables.empty()) {
- _set_error("'extends' must be used before anything else.");
+ _set_error("\"extends\" must be used before anything else.");
return;
}
@@ -3385,7 +3398,7 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) {
Variant constant = tokenizer->get_token_constant();
if (constant.get_type() != Variant::STRING) {
- _set_error("'extends' constant must be a string.");
+ _set_error("\"extends\" constant must be a string.");
return;
}
@@ -3420,7 +3433,7 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) {
default: {
- _set_error("Invalid 'extends' syntax, expected string constant (path) and/or identifier (parent class).");
+ _set_error("Invalid \"extends\" syntax, expected string constant (path) and/or identifier (parent class).");
return;
}
}
@@ -3480,28 +3493,29 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (error_set)
return;
if (!_end_statement()) {
- _set_error("Expected end of statement after extends");
+ _set_error("Expected end of statement after \"extends\".");
return;
}
} break;
case GDScriptTokenizer::TK_PR_CLASS_NAME: {
+ _mark_line_as_safe(tokenizer->get_token_line());
if (p_class->owner) {
- _set_error("'class_name' is only valid for the main class namespace.");
+ _set_error("\"class_name\" is only valid for the main class namespace.");
return;
}
if (self_path.begins_with("res://") && self_path.find("::") != -1) {
- _set_error("'class_name' not allowed in built-in scripts.");
+ _set_error("\"class_name\" isn't allowed in built-in scripts.");
return;
}
if (tokenizer->get_token(1) != GDScriptTokenizer::TK_IDENTIFIER) {
- _set_error("'class_name' syntax: 'class_name <UniqueName>'");
+ _set_error("\"class_name\" syntax: \"class_name <UniqueName>\"");
return;
}
if (p_class->classname_used) {
- _set_error("'class_name' already used for this class.");
+ _set_error("\"class_name\" can only be present once per script.");
return;
}
@@ -3510,12 +3524,12 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
p_class->name = tokenizer->get_token_identifier(1);
if (self_path != String() && ScriptServer::is_global_class(p_class->name) && ScriptServer::get_global_class_path(p_class->name) != self_path) {
- _set_error("Unique global class '" + p_class->name + "' already exists at path: " + ScriptServer::get_global_class_path(p_class->name));
+ _set_error("Unique global class \"" + p_class->name + "\" already exists at path: " + ScriptServer::get_global_class_path(p_class->name));
return;
}
if (ClassDB::class_exists(p_class->name)) {
- _set_error("Class '" + p_class->name + "' shadows a native class.");
+ _set_error("The class \"" + p_class->name + "\" shadows a native class.");
return;
}
@@ -3542,12 +3556,12 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
} else {
- _set_error("Optional parameter after 'class_name' must be a string constant file path to an icon.");
+ _set_error("The optional parameter after \"class_name\" must be a string constant file path to an icon.");
return;
}
} else if (tokenizer->get_token() == GDScriptTokenizer::TK_CONSTANT) {
- _set_error("Class icon must be separated by a comma.");
+ _set_error("The class icon must be separated by a comma.");
return;
}
@@ -3556,7 +3570,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (p_class->tool) {
- _set_error("tool used more than once");
+ _set_error("The \"tool\" keyword can only be present once per script.");
return;
}
@@ -3571,7 +3585,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token(1) != GDScriptTokenizer::TK_IDENTIFIER) {
- _set_error("'class' syntax: 'class <Name>:' or 'class <Name> extends <BaseClass>:'");
+ _set_error("\"class\" syntax: \"class <Name>:\" or \"class <Name> extends <BaseClass>:\"");
return;
}
name = tokenizer->get_token_identifier(1);
@@ -3579,23 +3593,23 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
// Check if name is shadowing something else
if (ClassDB::class_exists(name) || ClassDB::class_exists("_" + name.operator String())) {
- _set_error("Class '" + String(name) + "' shadows a native class.");
+ _set_error("The class \"" + String(name) + "\" shadows a native class.");
return;
}
if (ScriptServer::is_global_class(name)) {
- _set_error("Can't override name of unique global class '" + name + "' already exists at path: " + ScriptServer::get_global_class_path(p_class->name));
+ _set_error("Can't override name of the unique global class \"" + name + "\". It already exists at: " + ScriptServer::get_global_class_path(p_class->name));
return;
}
ClassNode *outer_class = p_class;
while (outer_class) {
for (int i = 0; i < outer_class->subclasses.size(); i++) {
if (outer_class->subclasses[i]->name == name) {
- _set_error("Another class named '" + String(name) + "' already exists in this scope (at line " + itos(outer_class->subclasses[i]->line) + ").");
+ _set_error("Another class named \"" + String(name) + "\" already exists in this scope (at line " + itos(outer_class->subclasses[i]->line) + ").");
return;
}
}
if (outer_class->constant_expressions.has(name)) {
- _set_error("A constant named '" + String(name) + "' already exists in the outer class scope (at line" + itos(outer_class->constant_expressions[name].expression->line) + ").");
+ _set_error("A constant named \"" + String(name) + "\" already exists in the outer class scope (at line" + itos(outer_class->constant_expressions[name].expression->line) + ").");
return;
}
@@ -3639,7 +3653,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) {
- _set_error("Expected 'func'.");
+ _set_error("Expected \"func\".");
return;
}
@@ -3663,18 +3677,18 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (name == StringName()) {
- _set_error("Expected identifier after 'func' (syntax: 'func <identifier>([arguments]):' ).");
+ _set_error("Expected an identifier after \"func\" (syntax: \"func <identifier>([arguments]):\").");
return;
}
for (int i = 0; i < p_class->functions.size(); i++) {
if (p_class->functions[i]->name == name) {
- _set_error("Function '" + String(name) + "' already exists in this class (at line: " + itos(p_class->functions[i]->line) + ").");
+ _set_error("The function \"" + String(name) + "\" already exists in this class (at line " + itos(p_class->functions[i]->line) + ").");
}
}
for (int i = 0; i < p_class->static_functions.size(); i++) {
if (p_class->static_functions[i]->name == name) {
- _set_error("Function '" + String(name) + "' already exists in this class (at line: " + itos(p_class->static_functions[i]->line) + ").");
+ _set_error("The function \"" + String(name) + "\" already exists in this class (at line " + itos(p_class->static_functions[i]->line) + ").");
}
}
@@ -3696,7 +3710,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_OPEN) {
- _set_error("Expected '(' after identifier (syntax: 'func <identifier>([arguments]):' ).");
+ _set_error("Expected \"(\" after the identifier (syntax: \"func <identifier>([arguments]):\" ).");
return;
}
@@ -3728,7 +3742,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (!tokenizer->is_token_literal(0, true)) {
- _set_error("Expected identifier for argument.");
+ _set_error("Expected an identifier for an argument.");
return;
}
@@ -3746,7 +3760,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
argtype.infer_type = true;
tokenizer->advance();
} else if (!_parse_type(argtype)) {
- _set_error("Expected type for argument.");
+ _set_error("Expected a type for an argument.");
return;
}
}
@@ -3795,7 +3809,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
continue;
} else if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
- _set_error("Expected ',' or ')'.");
+ _set_error("Expected \",\" or \")\".");
return;
}
@@ -3824,7 +3838,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (name == "_init") {
if (_static) {
- _set_error("Constructor cannot be static.");
+ _set_error("The constructor cannot be static.");
return;
}
@@ -3841,7 +3855,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() == GDScriptTokenizer::TK_PERIOD) {
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_OPEN) {
- _set_error("expected '(' for parent constructor arguments.");
+ _set_error("Expected \"(\" for parent constructor arguments.");
return;
}
tokenizer->advance();
@@ -3861,7 +3875,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
continue;
} else if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
- _set_error("Expected ',' or ')'.");
+ _set_error("Expected \",\" or \")\".");
return;
}
@@ -3886,7 +3900,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() == GDScriptTokenizer::TK_FORWARD_ARROW) {
if (!_parse_type(return_type, true)) {
- _set_error("Expected return type for function.");
+ _set_error("Expected a return type for the function.");
return;
}
}
@@ -3916,7 +3930,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (!tokenizer->is_token_literal()) {
- _set_error("Expected identifier after 'signal'.");
+ _set_error("Expected an identifier after \"signal\".");
return;
}
@@ -3940,7 +3954,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
}
if (!tokenizer->is_token_literal(0, true)) {
- _set_error("Expected identifier in signal argument.");
+ _set_error("Expected an identifier in a \"signal\" argument.");
return;
}
@@ -3954,7 +3968,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) {
tokenizer->advance();
} else if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
- _set_error("Expected ',' or ')' after signal parameter identifier.");
+ _set_error("Expected \",\" or \")\" after a \"signal\" parameter identifier.");
return;
}
}
@@ -3963,7 +3977,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
p_class->_signals.push_back(sig);
if (!_end_statement()) {
- _set_error("Expected end of statement (signal)");
+ _set_error("Expected end of statement (\"signal\").");
return;
}
} break;
@@ -4018,12 +4032,11 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
- ERR_EXPLAIN("Exporting bit flags hint requires string constants.");
- WARN_DEPRECATED;
+ WARN_DEPRECATED_MSG("Exporting bit flags hint requires string constants.");
break;
}
if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
- _set_error("Expected ',' in bit flags hint.");
+ _set_error("Expected \",\" in the bit flags hint.");
return;
}
@@ -4035,7 +4048,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) {
current_export = PropertyInfo();
- _set_error("Expected a string constant in named bit flags hint.");
+ _set_error("Expected a string constant in the named bit flags hint.");
return;
}
@@ -4053,7 +4066,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
current_export = PropertyInfo();
- _set_error("Expected ')' or ',' in named bit flags hint.");
+ _set_error("Expected \")\" or \",\" in the named bit flags hint.");
return;
}
tokenizer->advance();
@@ -4066,7 +4079,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
- _set_error("Expected ')' in layers 2D render hint.");
+ _set_error("Expected \")\" in the layers 2D render hint.");
return;
}
current_export.hint = PROPERTY_HINT_LAYERS_2D_RENDER;
@@ -4077,7 +4090,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
- _set_error("Expected ')' in layers 2D physics hint.");
+ _set_error("Expected \")\" in the layers 2D physics hint.");
return;
}
current_export.hint = PROPERTY_HINT_LAYERS_2D_PHYSICS;
@@ -4088,7 +4101,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
- _set_error("Expected ')' in layers 3D render hint.");
+ _set_error("Expected \")\" in the layers 3D render hint.");
return;
}
current_export.hint = PROPERTY_HINT_LAYERS_3D_RENDER;
@@ -4099,7 +4112,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
- _set_error("Expected ')' in layers 3D physics hint.");
+ _set_error("Expected \")\" in the layers 3D physics hint.");
return;
}
current_export.hint = PROPERTY_HINT_LAYERS_3D_PHYSICS;
@@ -4115,7 +4128,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) {
current_export = PropertyInfo();
- _set_error("Expected a string constant in enumeration hint.");
+ _set_error("Expected a string constant in the enumeration hint.");
return;
}
@@ -4133,7 +4146,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
current_export = PropertyInfo();
- _set_error("Expected ')' or ',' in enumeration hint.");
+ _set_error("Expected \")\" or \",\" in the enumeration hint.");
return;
}
@@ -4151,7 +4164,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
current_export.hint = PROPERTY_HINT_EXP_EASING;
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
- _set_error("Expected ')' in hint.");
+ _set_error("Expected \")\" in the hint.");
return;
}
break;
@@ -4166,7 +4179,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE)
break;
else if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
- _set_error("Expected ')' or ',' in exponential range hint.");
+ _set_error("Expected \")\" or \",\" in the exponential range hint.");
return;
}
tokenizer->advance();
@@ -4182,7 +4195,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) {
current_export = PropertyInfo();
- _set_error("Expected a range in numeric hint.");
+ _set_error("Expected a range in the numeric hint.");
return;
}
@@ -4197,7 +4210,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
current_export = PropertyInfo();
- _set_error("Expected ',' or ')' in numeric range hint.");
+ _set_error("Expected \",\" or \")\" in the numeric range hint.");
return;
}
@@ -4212,7 +4225,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) {
current_export = PropertyInfo();
- _set_error("Expected a number as upper bound in numeric range hint.");
+ _set_error("Expected a number as upper bound in the numeric range hint.");
return;
}
@@ -4225,7 +4238,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
current_export = PropertyInfo();
- _set_error("Expected ',' or ')' in numeric range hint.");
+ _set_error("Expected \",\" or \")\" in the numeric range hint.");
return;
}
@@ -4239,7 +4252,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) {
current_export = PropertyInfo();
- _set_error("Expected a number as step in numeric range hint.");
+ _set_error("Expected a number as step in the numeric range hint.");
return;
}
@@ -4258,7 +4271,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) {
current_export = PropertyInfo();
- _set_error("Expected a string constant in enumeration hint.");
+ _set_error("Expected a string constant in the enumeration hint.");
return;
}
@@ -4275,7 +4288,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
current_export = PropertyInfo();
- _set_error("Expected ')' or ',' in enumeration hint.");
+ _set_error("Expected \")\" or \",\" in the enumeration hint.");
return;
}
tokenizer->advance();
@@ -4295,7 +4308,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_IDENTIFIER || !(tokenizer->get_token_identifier() == "GLOBAL")) {
- _set_error("Expected 'GLOBAL' after comma in directory hint.");
+ _set_error("Expected \"GLOBAL\" after comma in the directory hint.");
return;
}
if (!p_class->tool) {
@@ -4306,11 +4319,11 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
- _set_error("Expected ')' in hint.");
+ _set_error("Expected \")\" in the hint.");
return;
}
} else {
- _set_error("Expected ')' or ',' in hint.");
+ _set_error("Expected \")\" or \",\" in the hint.");
return;
}
break;
@@ -4339,7 +4352,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA)
tokenizer->advance();
else {
- _set_error("Expected ')' or ',' in hint.");
+ _set_error("Expected \")\" or \",\" in the hint.");
return;
}
}
@@ -4347,9 +4360,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) {
if (current_export.hint == PROPERTY_HINT_GLOBAL_FILE)
- _set_error("Expected string constant with filter");
+ _set_error("Expected string constant with filter.");
else
- _set_error("Expected 'GLOBAL' or string constant with filter");
+ _set_error("Expected \"GLOBAL\" or string constant with filter.");
return;
}
current_export.hint_string = tokenizer->get_token_constant();
@@ -4357,7 +4370,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
}
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
- _set_error("Expected ')' in hint.");
+ _set_error("Expected \")\" in the hint.");
return;
}
break;
@@ -4368,7 +4381,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
current_export.hint = PROPERTY_HINT_MULTILINE_TEXT;
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
- _set_error("Expected ')' in hint.");
+ _set_error("Expected \")\" in the hint.");
return;
}
break;
@@ -4379,7 +4392,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_IDENTIFIER) {
current_export = PropertyInfo();
- _set_error("Color type hint expects RGB or RGBA as hints");
+ _set_error("Color type hint expects RGB or RGBA as hints.");
return;
}
@@ -4390,7 +4403,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
//none
} else {
current_export = PropertyInfo();
- _set_error("Color type hint expects RGB or RGBA as hints");
+ _set_error("Color type hint expects RGB or RGBA as hints.");
return;
}
tokenizer->advance();
@@ -4399,7 +4412,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
default: {
current_export = PropertyInfo();
- _set_error("Type '" + Variant::get_type_name(type) + "' can't take hints.");
+ _set_error("Type \"" + Variant::get_type_name(type) + "\" can't take hints.");
return;
} break;
}
@@ -4437,7 +4450,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
} else {
current_export = PropertyInfo();
- _set_error("Export hint not a resource type.");
+ _set_error("The export hint isn't a resource type.");
}
} else if (constant.get_type() == Variant::DICTIONARY) {
// Enumeration
@@ -4451,7 +4464,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
} else {
current_export = PropertyInfo();
- _set_error("Expected 'FLAGS' after comma.");
+ _set_error("Expected \"FLAGS\" after comma.");
}
}
@@ -4488,7 +4501,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
current_export = PropertyInfo();
- _set_error("Expected ')' or ',' after export hint.");
+ _set_error("Expected \")\" or \",\" after the export hint.");
return;
}
@@ -4508,7 +4521,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_ONREADY && tokenizer->get_token() != GDScriptTokenizer::TK_PR_REMOTE && tokenizer->get_token() != GDScriptTokenizer::TK_PR_MASTER && tokenizer->get_token() != GDScriptTokenizer::TK_PR_PUPPET && tokenizer->get_token() != GDScriptTokenizer::TK_PR_SYNC && tokenizer->get_token() != GDScriptTokenizer::TK_PR_REMOTESYNC && tokenizer->get_token() != GDScriptTokenizer::TK_PR_MASTERSYNC && tokenizer->get_token() != GDScriptTokenizer::TK_PR_PUPPETSYNC && tokenizer->get_token() != GDScriptTokenizer::TK_PR_SLAVE) {
current_export = PropertyInfo();
- _set_error("Expected 'var', 'onready', 'remote', 'master', 'puppet', 'sync', 'remotesync', 'mastersync', 'puppetsync'.");
+ _set_error("Expected \"var\", \"onready\", \"remote\", \"master\", \"puppet\", \"sync\", \"remotesync\", \"mastersync\", \"puppetsync\".");
return;
}
@@ -4519,7 +4532,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
//may be fallthrough from export, ignore if so
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR) {
- _set_error("Expected 'var'.");
+ _set_error("Expected \"var\".");
return;
}
@@ -4531,13 +4544,13 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (current_export.type) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR) {
- _set_error("Expected 'var'.");
+ _set_error("Expected \"var\".");
return;
}
} else {
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) {
- _set_error("Expected 'var' or 'func'.");
+ _set_error("Expected \"var\" or \"func\".");
return;
}
}
@@ -4551,13 +4564,13 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (current_export.type) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR) {
- _set_error("Expected 'var'.");
+ _set_error("Expected \"var\".");
return;
}
} else {
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) {
- _set_error("Expected 'var' or 'func'.");
+ _set_error("Expected \"var\" or \"func\".");
return;
}
}
@@ -4576,13 +4589,13 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (current_export.type) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR) {
- _set_error("Expected 'var'.");
+ _set_error("Expected \"var\".");
return;
}
} else {
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) {
- _set_error("Expected 'var' or 'func'.");
+ _set_error("Expected \"var\" or \"func\".");
return;
}
}
@@ -4597,9 +4610,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) {
if (current_export.type)
- _set_error("Expected 'var'.");
+ _set_error("Expected \"var\".");
else
- _set_error("Expected 'var' or 'func'.");
+ _set_error("Expected \"var\" or \"func\".");
return;
}
@@ -4612,9 +4625,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) {
if (current_export.type)
- _set_error("Expected 'var'.");
+ _set_error("Expected \"var\".");
else
- _set_error("Expected 'var' or 'func'.");
+ _set_error("Expected \"var\" or \"func\".");
return;
}
@@ -4627,9 +4640,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) {
if (current_export.type)
- _set_error("Expected 'var'.");
+ _set_error("Expected \"var\".");
else
- _set_error("Expected 'var' or 'func'.");
+ _set_error("Expected \"var\" or \"func\".");
return;
}
@@ -4652,7 +4665,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (!tokenizer->is_token_literal(0, true)) {
- _set_error("Expected identifier for member variable name.");
+ _set_error("Expected an identifier for the member variable name.");
return;
}
@@ -4668,14 +4681,14 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
#endif
if (current_class->constant_expressions.has(member.identifier)) {
- _set_error("A constant named '" + String(member.identifier) + "' already exists in this class (at line: " +
+ _set_error("A constant named \"" + String(member.identifier) + "\" already exists in this class (at line: " +
itos(current_class->constant_expressions[member.identifier].expression->line) + ").");
return;
}
for (int i = 0; i < current_class->variables.size(); i++) {
if (current_class->variables[i].identifier == member.identifier) {
- _set_error("Variable '" + String(member.identifier) + "' already exists in this class (at line: " +
+ _set_error("Variable \"" + String(member.identifier) + "\" already exists in this class (at line: " +
itos(current_class->variables[i].line) + ").");
return;
}
@@ -4683,7 +4696,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
for (int i = 0; i < current_class->subclasses.size(); i++) {
if (current_class->subclasses[i]->name == member.identifier) {
- _set_error("A class named '" + String(member.identifier) + "' already exists in this class (at line " + itos(current_class->subclasses[i]->line) + ").");
+ _set_error("A class named \"" + String(member.identifier) + "\" already exists in this class (at line " + itos(current_class->subclasses[i]->line) + ").");
return;
}
}
@@ -4713,7 +4726,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
#endif
tokenizer->advance();
} else if (!_parse_type(member.data_type)) {
- _set_error("Expected type for class variable.");
+ _set_error("Expected a type for the class variable.");
return;
}
}
@@ -4741,7 +4754,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
IdentifierNode *id = static_cast<IdentifierNode *>(op->arguments[1]);
if (id->name == "get_node") {
- _set_error("Use 'onready var " + String(member.identifier) + " = get_node(..)' instead");
+ _set_error("Use \"onready var " + String(member.identifier) + " = get_node(...)\" instead.");
return;
}
}
@@ -4769,7 +4782,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
Object *obj = cn->value;
Resource *res = Object::cast_to<Resource>(obj);
if (res == NULL) {
- _set_error("Exported constant not a type or resource.");
+ _set_error("The exported constant isn't a type or resource.");
return;
}
member._export.hint = PROPERTY_HINT_RESOURCE_TYPE;
@@ -4787,7 +4800,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
const Variant *args = &cn->value;
cn->value = Variant::construct(member._export.type, &args, 1, err);
} else {
- _set_error("Cannot convert the provided value to the export type.");
+ _set_error("Can't convert the provided value to the export type.");
return;
}
}
@@ -4885,7 +4898,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
//just comma means using only getter
if (!tokenizer->is_token_literal()) {
- _set_error("Expected identifier for setter function after 'setget'.");
+ _set_error("Expected an identifier for the setter function after \"setget\".");
}
member.setter = tokenizer->get_token_literal();
@@ -4898,7 +4911,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (!tokenizer->is_token_literal()) {
- _set_error("Expected identifier for getter function after ','.");
+ _set_error("Expected an identifier for the getter function after \",\".");
}
member.getter = tokenizer->get_token_literal();
@@ -4909,7 +4922,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
p_class->variables.push_back(member);
if (!_end_statement()) {
- _set_error("Expected end of statement (continue)");
+ _set_error("Expected end of statement (\"continue\").");
return;
}
} break;
@@ -4921,7 +4934,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
if (!tokenizer->is_token_literal(0, true)) {
- _set_error("Expected name (identifier) for constant.");
+ _set_error("Expected an identifier for the constant.");
return;
}
@@ -4929,14 +4942,14 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
int line = tokenizer->get_token_line();
if (current_class->constant_expressions.has(const_id)) {
- _set_error("Constant '" + String(const_id) + "' already exists in this class (at line: " +
+ _set_error("Constant \"" + String(const_id) + "\" already exists in this class (at line " +
itos(current_class->constant_expressions[const_id].expression->line) + ").");
return;
}
for (int i = 0; i < current_class->variables.size(); i++) {
if (current_class->variables[i].identifier == const_id) {
- _set_error("A variable named '" + String(const_id) + "' already exists in this class (at line: " +
+ _set_error("A variable named \"" + String(const_id) + "\" already exists in this class (at line " +
itos(current_class->variables[i].line) + ").");
return;
}
@@ -4944,7 +4957,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
for (int i = 0; i < current_class->subclasses.size(); i++) {
if (current_class->subclasses[i]->name == const_id) {
- _set_error("A class named '" + String(const_id) + "' already exists in this class (at line " + itos(current_class->subclasses[i]->line) + ").");
+ _set_error("A class named \"" + String(const_id) + "\" already exists in this class (at line " + itos(current_class->subclasses[i]->line) + ").");
return;
}
}
@@ -4959,13 +4972,13 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
#endif
tokenizer->advance();
} else if (!_parse_type(constant.type)) {
- _set_error("Expected type for class constant.");
+ _set_error("Expected a type for the class constant.");
return;
}
}
if (tokenizer->get_token() != GDScriptTokenizer::TK_OP_ASSIGN) {
- _set_error("Constant expects assignment.");
+ _set_error("Constants must be assigned immediately.");
return;
}
@@ -4980,7 +4993,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
}
if (subexpr->type != Node::TYPE_CONSTANT) {
- _set_error("Expected constant expression", line);
+ _set_error("Expected a constant expression.", line);
return;
}
subexpr->line = line;
@@ -4989,7 +5002,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
p_class->constant_expressions.insert(const_id, constant);
if (!_end_statement()) {
- _set_error("Expected end of statement (constant)", line);
+ _set_error("Expected end of statement (constant).", line);
return;
}
@@ -5006,14 +5019,14 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
enum_name = tokenizer->get_token_literal();
if (current_class->constant_expressions.has(enum_name)) {
- _set_error("A constant named '" + String(enum_name) + "' already exists in this class (at line: " +
+ _set_error("A constant named \"" + String(enum_name) + "\" already exists in this class (at line " +
itos(current_class->constant_expressions[enum_name].expression->line) + ").");
return;
}
for (int i = 0; i < current_class->variables.size(); i++) {
if (current_class->variables[i].identifier == enum_name) {
- _set_error("A variable named '" + String(enum_name) + "' already exists in this class (at line: " +
+ _set_error("A variable named \"" + String(enum_name) + "\" already exists in this class (at line " +
itos(current_class->variables[i].line) + ").");
return;
}
@@ -5021,7 +5034,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
for (int i = 0; i < current_class->subclasses.size(); i++) {
if (current_class->subclasses[i]->name == enum_name) {
- _set_error("A class named '" + String(enum_name) + "' already exists in this class (at line " + itos(current_class->subclasses[i]->line) + ").");
+ _set_error("A class named \"" + String(enum_name) + "\" already exists in this class (at line " + itos(current_class->subclasses[i]->line) + ").");
return;
}
}
@@ -5029,7 +5042,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
}
if (tokenizer->get_token() != GDScriptTokenizer::TK_CURLY_BRACKET_OPEN) {
- _set_error("Expected '{' in enum declaration");
+ _set_error("Expected \"{\" in the enum declaration.");
return;
}
tokenizer->advance();
@@ -5047,7 +5060,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() == GDScriptTokenizer::TK_EOF) {
_set_error("Unexpected end of file.");
} else {
- _set_error(String("Unexpected ") + GDScriptTokenizer::get_token_name(tokenizer->get_token()) + ", expected identifier");
+ _set_error(String("Unexpected ") + GDScriptTokenizer::get_token_name(tokenizer->get_token()) + ", expected an identifier.");
}
return;
@@ -5070,14 +5083,14 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
}
if (subexpr->type != Node::TYPE_CONSTANT) {
- _set_error("Expected constant expression");
+ _set_error("Expected a constant expression.");
return;
}
enum_value_expr = static_cast<ConstantNode *>(subexpr);
if (enum_value_expr->value.get_type() != Variant::INT) {
- _set_error("Expected an int value for enum");
+ _set_error("Expected an integer value for \"enum\".");
return;
}
@@ -5093,7 +5106,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) {
tokenizer->advance();
} else if (tokenizer->is_token_literal(0, true)) {
- _set_error("Unexpected identifier");
+ _set_error("Unexpected identifier.");
return;
}
@@ -5101,14 +5114,14 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
enum_dict[const_id] = enum_value_expr->value;
} else {
if (current_class->constant_expressions.has(const_id)) {
- _set_error("A constant named '" + String(const_id) + "' already exists in this class (at line: " +
+ _set_error("A constant named \"" + String(const_id) + "\" already exists in this class (at line " +
itos(current_class->constant_expressions[const_id].expression->line) + ").");
return;
}
for (int i = 0; i < current_class->variables.size(); i++) {
if (current_class->variables[i].identifier == const_id) {
- _set_error("A variable named '" + String(const_id) + "' already exists in this class (at line: " +
+ _set_error("A variable named \"" + String(const_id) + "\" already exists in this class (at line " +
itos(current_class->variables[i].line) + ").");
return;
}
@@ -5116,7 +5129,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
for (int i = 0; i < current_class->subclasses.size(); i++) {
if (current_class->subclasses[i]->name == const_id) {
- _set_error("A class named '" + String(const_id) + "' already exists in this class (at line " + itos(current_class->subclasses[i]->line) + ").");
+ _set_error("A class named \"" + String(const_id) + "\" already exists in this class (at line " + itos(current_class->subclasses[i]->line) + ").");
return;
}
}
@@ -5143,7 +5156,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
}
if (!_end_statement()) {
- _set_error("Expected end of statement (enum)");
+ _set_error("Expected end of statement (\"enum\").");
return;
}
@@ -5189,19 +5202,19 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive
String base = base_path;
if (base == "" || base.is_rel_path()) {
- _set_error("Could not resolve relative path for parent class: " + path, p_class->line);
+ _set_error("Couldn't resolve relative path for the parent class: " + path, p_class->line);
return;
}
path = base.plus_file(path).simplify_path();
}
script = ResourceLoader::load(path);
if (script.is_null()) {
- _set_error("Could not load base class: " + path, p_class->line);
+ _set_error("Couldn't load the base class: " + path, p_class->line);
return;
}
if (!script->is_valid()) {
- _set_error("Script not fully loaded (cyclic preload?): " + path, p_class->line);
+ _set_error("Script isn't fully loaded (cyclic preload?): " + path, p_class->line);
return;
}
@@ -5216,7 +5229,7 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive
script = subclass;
} else {
- _set_error("Could not find subclass: " + sub, p_class->line);
+ _set_error("Couldn't find the subclass: " + sub, p_class->line);
return;
}
}
@@ -5238,10 +5251,35 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive
if (ScriptServer::is_global_class(base)) {
base_script = ResourceLoader::load(ScriptServer::get_global_class_path(base));
if (!base_script.is_valid()) {
- _set_error("Class '" + base + "' could not be fully loaded (script error or cyclic dependency).", p_class->line);
+ _set_error("The class \"" + base + "\" couldn't be fully loaded (script error or cyclic dependency).", p_class->line);
return;
}
p = NULL;
+ } else {
+ List<PropertyInfo> props;
+ ProjectSettings::get_singleton()->get_property_list(&props);
+ for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
+ String s = E->get().name;
+ if (!s.begins_with("autoload/")) {
+ continue;
+ }
+ String name = s.get_slice("/", 1);
+ if (name == base) {
+ String singleton_path = ProjectSettings::get_singleton()->get(s);
+ if (singleton_path.begins_with("*")) {
+ singleton_path = singleton_path.right(1);
+ }
+ if (!singleton_path.begins_with("res://")) {
+ singleton_path = "res://" + singleton_path;
+ }
+ base_script = ResourceLoader::load(singleton_path);
+ if (!base_script.is_valid()) {
+ _set_error("Class '" + base + "' could not be fully loaded (script error or cyclic inheritance).", p_class->line);
+ return;
+ }
+ p = NULL;
+ }
+ }
}
while (p) {
@@ -5279,13 +5317,13 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive
if (p->constant_expressions.has(base)) {
if (p->constant_expressions[base].expression->type != Node::TYPE_CONSTANT) {
- _set_error("Could not resolve constant '" + base + "'.", p_class->line);
+ _set_error("Couldn't resolve the constant \"" + base + "\".", p_class->line);
return;
}
const ConstantNode *cn = static_cast<const ConstantNode *>(p->constant_expressions[base].expression);
base_script = cn->value;
if (base_script.is_null()) {
- _set_error("Constant is not a class: " + base, p_class->line);
+ _set_error("Constant isn't a class: " + base, p_class->line);
return;
}
break;
@@ -5312,13 +5350,13 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive
Ref<GDScript> new_base_class = base_script->get_constants()[subclass];
if (new_base_class.is_null()) {
- _set_error("Constant is not a class: " + ident, p_class->line);
+ _set_error("Constant isn't a class: " + ident, p_class->line);
return;
}
find_subclass = new_base_class;
} else {
- _set_error("Could not find subclass: " + ident, p_class->line);
+ _set_error("Couldn't find the subclass: " + ident, p_class->line);
return;
}
}
@@ -5329,13 +5367,13 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive
if (p_class->extends_class.size() > 1) {
- _set_error("Invalid inheritance (unknown class + subclasses)", p_class->line);
+ _set_error("Invalid inheritance (unknown class + subclasses).", p_class->line);
return;
}
//if not found, try engine classes
if (!GDScriptLanguage::get_singleton()->get_global_map().has(base)) {
- _set_error("Unknown class: '" + base + "'", p_class->line);
+ _set_error("Unknown class: \"" + base + "\"", p_class->line);
return;
}
@@ -5357,7 +5395,7 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive
p_class->base_type.kind = DataType::NATIVE;
p_class->base_type.native_type = native;
} else {
- _set_error("Could not determine inheritance", p_class->line);
+ _set_error("Couldn't determine inheritance.", p_class->line);
return;
}
@@ -5502,7 +5540,7 @@ bool GDScriptParser::_parse_type(DataType &r_type, bool p_can_be_void) {
switch (tokenizer->get_token()) {
case GDScriptTokenizer::TK_PERIOD: {
if (!can_index) {
- _set_error("Unexpected '.'.");
+ _set_error("Unexpected \".\".");
return false;
}
can_index = false;
@@ -5533,7 +5571,7 @@ bool GDScriptParser::_parse_type(DataType &r_type, bool p_can_be_void) {
}
if (tokenizer->get_token(-1) == GDScriptTokenizer::TK_PERIOD) {
- _set_error("Expected subclass identifier.");
+ _set_error("Expected a subclass identifier.");
return false;
}
@@ -5571,7 +5609,7 @@ GDScriptParser::DataType GDScriptParser::_resolve_type(const DataType &p_source,
Ref<GDScript> gds = script;
if (gds.is_valid()) {
if (!gds->is_valid()) {
- _set_error("Class '" + id + "' could not be fully loaded (script error or cyclic dependency).", p_line);
+ _set_error("The class \"" + id + "\" couldn't be fully loaded (script error or cyclic dependency).", p_line);
return DataType();
}
result.kind = DataType::GDSCRIPT;
@@ -5580,15 +5618,55 @@ GDScriptParser::DataType GDScriptParser::_resolve_type(const DataType &p_source,
result.kind = DataType::SCRIPT;
result.script_type = script;
} else {
- _set_error("Class '" + id + "' was found in global scope but its script could not be loaded.", p_line);
+ _set_error("The class \"" + id + "\" was found in global scope, but its script couldn't be loaded.", p_line);
return DataType();
}
}
name_part++;
continue;
- } else {
- p = current_class;
}
+ List<PropertyInfo> props;
+ ProjectSettings::get_singleton()->get_property_list(&props);
+ String singleton_path;
+ for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
+ String s = E->get().name;
+ if (!s.begins_with("autoload/")) {
+ continue;
+ }
+ String name = s.get_slice("/", 1);
+ if (name == id) {
+ singleton_path = ProjectSettings::get_singleton()->get(s);
+ if (singleton_path.begins_with("*")) {
+ singleton_path = singleton_path.right(1);
+ }
+ if (!singleton_path.begins_with("res://")) {
+ singleton_path = "res://" + singleton_path;
+ }
+ break;
+ }
+ }
+ if (!singleton_path.empty()) {
+ Ref<Script> script = ResourceLoader::load(singleton_path);
+ Ref<GDScript> gds = script;
+ if (gds.is_valid()) {
+ if (!gds->is_valid()) {
+ _set_error("Class '" + id + "' could not be fully loaded (script error or cyclic inheritance).", p_line);
+ return DataType();
+ }
+ result.kind = DataType::GDSCRIPT;
+ result.script_type = gds;
+ } else if (script.is_valid()) {
+ result.kind = DataType::SCRIPT;
+ result.script_type = script;
+ } else {
+ _set_error("Couldn't fully load singleton script '" + id + "' (possible cyclic reference or parse error).", p_line);
+ return DataType();
+ }
+ name_part++;
+ continue;
+ }
+
+ p = current_class;
} else if (base_type.kind == DataType::CLASS) {
p = base_type.class_type;
}
@@ -5681,8 +5759,8 @@ GDScriptParser::DataType GDScriptParser::_resolve_type(const DataType &p_source,
} else {
base = result.to_string();
}
- _set_error("Identifier '" + String(id) + "' is not a valid type (not a script or class), or could not be found on base '" +
- base + "'.",
+ _set_error("The identifier \"" + String(id) + "\" isn't a valid type (not a script or class), or couldn't be found on base \"" +
+ base + "\".",
p_line);
return DataType();
}
@@ -5760,7 +5838,7 @@ GDScriptParser::DataType GDScriptParser::_type_from_gdtype(const GDScriptDataTyp
switch (p_gdtype.kind) {
case GDScriptDataType::UNINITIALIZED: {
- ERR_EXPLAIN("Uninitialized datatype. Please report a bug.");
+ ERR_PRINT("Uninitialized datatype. Please report a bug.");
} break;
case GDScriptDataType::BUILTIN: {
result.kind = DataType::BUILTIN;
@@ -6146,8 +6224,8 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
}
if (!valid) {
- _set_error("Invalid cast. Cannot convert from '" + source_type.to_string() +
- "' to '" + cn->cast_type.to_string() + "'.",
+ _set_error("Invalid cast. Cannot convert from \"" + source_type.to_string() +
+ "\" to \"" + cn->cast_type.to_string() + "\".",
cn->line);
return DataType();
}
@@ -6176,11 +6254,11 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
DataType signal_type = _reduce_node_type(op->arguments[1]);
// TODO: Check if signal exists when it's a constant
if (base_type.has_type && base_type.kind == DataType::BUILTIN && base_type.builtin_type != Variant::NIL && base_type.builtin_type != Variant::OBJECT) {
- _set_error("First argument of 'yield()' must be an object.", op->line);
+ _set_error("The first argument of \"yield()\" must be an object.", op->line);
return DataType();
}
if (signal_type.has_type && (signal_type.kind != DataType::BUILTIN || signal_type.builtin_type != Variant::STRING)) {
- _set_error("Second argument of 'yield()' must be a string.", op->line);
+ _set_error("The second argument of \"yield()\" must be a string.", op->line);
return DataType();
}
}
@@ -6200,15 +6278,15 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
if (check_types && type_type.has_type) {
if (!type_type.is_meta_type && (type_type.kind != DataType::NATIVE || !ClassDB::is_parent_class(type_type.native_type, "Script"))) {
- _set_error("Invalid 'is' test: right operand is not a type (not a native type nor a script).", op->line);
+ _set_error("Invalid \"is\" test: the right operand isn't a type (neither a native type nor a script).", op->line);
return DataType();
}
type_type.is_meta_type = false; // Test the actual type
if (!_is_type_compatible(type_type, value_type) && !_is_type_compatible(value_type, type_type)) {
if (op->op == OperatorNode::OP_IS) {
- _set_error("A value of type '" + value_type.to_string() + "' will never be an instance of '" + type_type.to_string() + "'.", op->line);
+ _set_error("A value of type \"" + value_type.to_string() + "\" will never be an instance of \"" + type_type.to_string() + "\".", op->line);
} else {
- _set_error("A value of type '" + value_type.to_string() + "' will never be of type '" + type_type.to_string() + "'.", op->line);
+ _set_error("A value of type \"" + value_type.to_string() + "\" will never be of type \"" + type_type.to_string() + "\".", op->line);
}
return DataType();
}
@@ -6236,8 +6314,8 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
node_type = _get_operation_type(var_op, argument_type, argument_type, valid);
if (check_types && !valid) {
- _set_error("Invalid operand type ('" + argument_type.to_string() +
- "') to unary operator '" + Variant::get_operator_name(var_op) + "'.",
+ _set_error("Invalid operand type (\"" + argument_type.to_string() +
+ "\") to unary operator \"" + Variant::get_operator_name(var_op) + "\".",
op->line, op->column);
return DataType();
}
@@ -6281,8 +6359,8 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
node_type = _get_operation_type(var_op, argument_a_type, argument_b_type, valid);
if (check_types && !valid) {
- _set_error("Invalid operand types ('" + argument_a_type.to_string() + "' and '" +
- argument_b_type.to_string() + "') to operator '" + Variant::get_operator_name(var_op) + "'.",
+ _set_error("Invalid operand types (\"" + argument_a_type.to_string() + "\" and \"" +
+ argument_b_type.to_string() + "\") to operator \"" + Variant::get_operator_name(var_op) + "\".",
op->line, op->column);
return DataType();
}
@@ -6297,7 +6375,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
// Ternary operators
case OperatorNode::OP_TERNARY_IF: {
if (op->arguments.size() != 3) {
- _set_error("Parser bug: ternary operation without 3 arguments");
+ _set_error("Parser bug: ternary operation without 3 arguments.");
ERR_FAIL_V(DataType());
}
@@ -6330,7 +6408,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
case OperatorNode::OP_ASSIGN_BIT_XOR:
case OperatorNode::OP_INIT_ASSIGN: {
- _set_error("Assignment inside expression is not allowed (parser bug?).", op->line);
+ _set_error("Assignment inside an expression isn't allowed (parser bug?).", op->line);
return DataType();
} break;
@@ -6366,8 +6444,8 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
if (valid) {
result = _type_from_variant(res);
} else if (check_types) {
- _set_error("Can't get index '" + String(member_id->name.operator String()) + "' on base '" +
- base_type.to_string() + "'.",
+ _set_error("Can't get index \"" + String(member_id->name.operator String()) + "\" on base \"" +
+ base_type.to_string() + "\".",
op->line);
return DataType();
}
@@ -6459,7 +6537,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
}
}
if (error) {
- _set_error("Invalid index type (" + index_type.to_string() + ") for base '" + base_type.to_string() + "'.",
+ _set_error("Invalid index type (" + index_type.to_string() + ") for base \"" + base_type.to_string() + "\".",
op->line);
return DataType();
}
@@ -6492,8 +6570,8 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
node_type = _type_from_variant(res);
node_type.is_constant = false;
} else if (check_types) {
- _set_error("Can't get index '" + String(cn->value) + "' on base '" +
- base_type.to_string() + "'.",
+ _set_error("Can't get index \"" + String(cn->value) + "\" on base \"" +
+ base_type.to_string() + "\".",
op->line);
return DataType();
}
@@ -6503,11 +6581,11 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
_mark_line_as_unsafe(op->line);
}
} else if (!for_completion && (index_type.kind != DataType::BUILTIN || index_type.builtin_type != Variant::STRING)) {
- _set_error("Only strings can be used as index in the base type '" + base_type.to_string() + "'.", op->line);
+ _set_error("Only strings can be used as an index in the base type \"" + base_type.to_string() + "\".", op->line);
return DataType();
}
}
- if (check_types && !node_type.has_type) {
+ if (check_types && !node_type.has_type && base_type.kind == DataType::BUILTIN) {
// Can infer indexing type for some variant types
DataType result;
result.has_type = true;
@@ -6520,7 +6598,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
case Variant::REAL:
case Variant::NODE_PATH:
case Variant::_RID: {
- _set_error("Can't index on a value of type '" + base_type.to_string() + "'.", op->line);
+ _set_error("Can't index on a value of type \"" + base_type.to_string() + "\".", op->line);
return DataType();
} break;
// Return int
@@ -6694,8 +6772,7 @@ bool GDScriptParser::_get_function_signature(DataType &p_base_type, const String
}
if (!ClassDB::class_exists(native)) {
if (!check_types) return false;
- ERR_EXPLAIN("Parser bug: Class '" + String(native) + "' not found.");
- ERR_FAIL_V(false);
+ ERR_FAIL_V_MSG(false, "Parser bug: Class '" + String(native) + "' not found.");
}
MethodBind *method = ClassDB::get_method(native, p_function);
@@ -6919,7 +6996,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat
if (check_types) {
if (!tmp.has_method(callee_name)) {
- _set_error("Method '" + callee_name + "' is not declared on base '" + base_type.to_string() + "'.", p_call->line);
+ _set_error("The method \"" + callee_name + "\" isn't declared on base \"" + base_type.to_string() + "\".", p_call->line);
return DataType();
}
@@ -6979,7 +7056,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat
if (!valid) {
#ifdef DEBUG_ENABLED
if (p_call->arguments[0]->type == Node::TYPE_SELF) {
- _set_error("Method '" + callee_name + "' is not declared in the current class.", p_call->line);
+ _set_error("The method \"" + callee_name + "\" isn't declared in the current class.", p_call->line);
return DataType();
}
DataType tmp_type;
@@ -7004,7 +7081,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat
}
if (check_types && !is_static && !is_initializer && base_type.is_meta_type) {
- _set_error("Non-static function '" + String(callee_name) + "' can only be called from an instance.", p_call->line);
+ _set_error("Non-static function \"" + String(callee_name) + "\" can only be called from an instance.", p_call->line);
return DataType();
}
@@ -7029,11 +7106,11 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat
}
if (arg_count < arg_types.size() - default_args_count) {
- _set_error("Too few arguments for '" + callee_name + "()' call. Expected at least " + itos(arg_types.size() - default_args_count) + ".", p_call->line);
+ _set_error("Too few arguments for \"" + callee_name + "()\" call. Expected at least " + itos(arg_types.size() - default_args_count) + ".", p_call->line);
return return_type;
}
if (!is_vararg && arg_count > arg_types.size()) {
- _set_error("Too many arguments for '" + callee_name + "()' call. Expected at most " + itos(arg_types.size()) + ".", p_call->line);
+ _set_error("Too many arguments for \"" + callee_name + "()\" call. Expected at most " + itos(arg_types.size()) + ".", p_call->line);
return return_type;
}
@@ -7055,7 +7132,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat
} else if (!_is_type_compatible(arg_types[i - arg_diff], par_type, true)) {
// Supertypes are acceptable for dynamic compliance
if (!_is_type_compatible(par_type, arg_types[i - arg_diff])) {
- _set_error("At '" + callee_name + "()' call, argument " + itos(i - arg_diff + 1) + ". Assigned type (" +
+ _set_error("At \"" + callee_name + "()\" call, argument " + itos(i - arg_diff + 1) + ". Assigned type (" +
par_type.to_string() + ") doesn't match the function argument's type (" +
arg_types[i - arg_diff].to_string() + ").",
p_call->line);
@@ -7203,8 +7280,7 @@ bool GDScriptParser::_get_member_type(const DataType &p_base_type, const StringN
}
if (!ClassDB::class_exists(native)) {
if (!check_types) return false;
- ERR_EXPLAIN("Parser bug: Class '" + String(native) + "' not found.");
- ERR_FAIL_V(false);
+ ERR_FAIL_V_MSG(false, "Parser bug: Class \"" + String(native) + "\" not found.");
}
bool valid = false;
@@ -7374,7 +7450,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_identifier_type(const DataType
Ref<GDScript> gds = scr;
if (gds.is_valid()) {
if (!gds->is_valid()) {
- _set_error("Class '" + p_identifier + "' could not be fully loaded (script error or cyclic dependency).");
+ _set_error("The class \"" + p_identifier + "\" couldn't be fully loaded (script error or cyclic dependency).");
return DataType();
}
result.kind = DataType::GDSCRIPT;
@@ -7383,7 +7459,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_identifier_type(const DataType
}
return result;
}
- _set_error("Class '" + p_identifier + "' was found in global scope but its script could not be loaded.");
+ _set_error("The class \"" + p_identifier + "\" was found in global scope, but its script couldn't be loaded.");
return DataType();
}
@@ -7426,7 +7502,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_identifier_type(const DataType
Ref<GDScript> gds = singleton;
if (gds.is_valid()) {
if (!gds->is_valid()) {
- _set_error("Couldn't fully load singleton script '" + p_identifier + "' (possible cyclic reference or parse error).", p_line);
+ _set_error("Couldn't fully load the singleton script \"" + p_identifier + "\" (possible cyclic reference or parse error).", p_line);
return DataType();
}
result.kind = DataType::GDSCRIPT;
@@ -7438,7 +7514,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_identifier_type(const DataType
}
// This means looking in the current class, which type is always known
- _set_error("Identifier '" + p_identifier.operator String() + "' is not declared in the current scope.", p_line);
+ _set_error("The identifier \"" + p_identifier.operator String() + "\" isn't declared in the current scope.", p_line);
}
#ifdef DEBUG_ENABLED
@@ -7470,7 +7546,7 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
DataType expr = _resolve_type(c.expression->get_datatype(), c.expression->line);
if (check_types && !_is_type_compatible(cont, expr)) {
- _set_error("Constant value type (" + expr.to_string() + ") is not compatible with declared type (" + cont.to_string() + ").",
+ _set_error("The constant value type (" + expr.to_string() + ") isn't compatible with declared type (" + cont.to_string() + ").",
c.expression->line);
return;
}
@@ -7481,7 +7557,7 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
DataType tmp;
if (_get_member_type(p_class->base_type, E->key(), tmp)) {
- _set_error("Member '" + String(E->key()) + "' already exists in parent class.", c.expression->line);
+ _set_error("The member \"" + String(E->key()) + "\" already exists in a parent class.", c.expression->line);
return;
}
}
@@ -7503,7 +7579,7 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
DataType tmp;
if (_get_member_type(p_class->base_type, v.identifier, tmp)) {
- _set_error("Member '" + String(v.identifier) + "' already exists in parent class.", v.line);
+ _set_error("The member \"" + String(v.identifier) + "\" already exists in a parent class.", v.line);
return;
}
@@ -7520,7 +7596,7 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
} else {
// Try with implicit conversion
if (v.data_type.kind != DataType::BUILTIN || !_is_type_compatible(v.data_type, expr_type, true)) {
- _set_error("Assigned expression type (" + expr_type.to_string() + ") doesn't match the variable's type (" +
+ _set_error("The assigned expression's type (" + expr_type.to_string() + ") doesn't match the variable's type (" +
v.data_type.to_string() + ").",
v.line);
return;
@@ -7549,7 +7625,7 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
if (v.data_type.infer_type) {
if (!expr_type.has_type) {
- _set_error("Assigned value does not have a set type, variable type cannot be inferred.", v.line);
+ _set_error("The assigned value doesn't have a set type; the variable type can't be inferred.", v.line);
return;
}
v.data_type = expr_type;
@@ -7561,7 +7637,7 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
if (v.data_type.has_type && v._export.type != Variant::NIL) {
DataType export_type = _type_from_property(v._export);
if (!_is_type_compatible(v.data_type, export_type, true)) {
- _set_error("Export hint type (" + export_type.to_string() + ") doesn't match the variable's type (" +
+ _set_error("The export hint's type (" + export_type.to_string() + ") doesn't match the variable's type (" +
v.data_type.to_string() + ").",
v.line);
return;
@@ -7580,15 +7656,15 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
if (setter->get_required_argument_count() != 1 &&
!(setter->get_required_argument_count() == 0 && setter->default_values.size() > 0)) {
- _set_error("Setter function needs to receive exactly 1 argument. See '" + setter->name +
- "()' definition at line " + itos(setter->line) + ".",
+ _set_error("The setter function needs to receive exactly 1 argument. See \"" + setter->name +
+ "()\" definition at line " + itos(setter->line) + ".",
v.line);
return;
}
if (!_is_type_compatible(v.data_type, setter->argument_types[0])) {
- _set_error("Setter argument type (" + setter->argument_types[0].to_string() +
- ") doesn't match the variable's type (" + v.data_type.to_string() + "). See '" +
- setter->name + "()' definition at line " + itos(setter->line) + ".",
+ _set_error("The setter argument's type (" + setter->argument_types[0].to_string() +
+ ") doesn't match the variable's type (" + v.data_type.to_string() + "). See \"" +
+ setter->name + "()\" definition at line " + itos(setter->line) + ".",
v.line);
return;
}
@@ -7599,15 +7675,15 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
FunctionNode *getter = p_class->functions[j];
if (getter->get_required_argument_count() != 0) {
- _set_error("Getter function can't receive arguments. See '" + getter->name +
- "()' definition at line " + itos(getter->line) + ".",
+ _set_error("The getter function can't receive arguments. See \"" + getter->name +
+ "()\" definition at line " + itos(getter->line) + ".",
v.line);
return;
}
if (!_is_type_compatible(v.data_type, getter->get_datatype())) {
- _set_error("Getter return type (" + getter->get_datatype().to_string() +
+ _set_error("The getter return type (" + getter->get_datatype().to_string() +
") doesn't match the variable's type (" + v.data_type.to_string() +
- "). See '" + getter->name + "()' definition at line " + itos(getter->line) + ".",
+ "). See \"" + getter->name + "()\" definition at line " + itos(getter->line) + ".",
v.line);
return;
}
@@ -7621,23 +7697,23 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
for (int j = 0; j < p_class->static_functions.size(); j++) {
if (v.setter == p_class->static_functions[j]->name) {
FunctionNode *setter = p_class->static_functions[j];
- _set_error("Setter can't be a static function. See '" + setter->name + "()' definition at line " + itos(setter->line) + ".", v.line);
+ _set_error("The setter can't be a static function. See \"" + setter->name + "()\" definition at line " + itos(setter->line) + ".", v.line);
return;
}
if (v.getter == p_class->static_functions[j]->name) {
FunctionNode *getter = p_class->static_functions[j];
- _set_error("Getter can't be a static function. See '" + getter->name + "()' definition at line " + itos(getter->line) + ".", v.line);
+ _set_error("The getter can't be a static function. See \"" + getter->name + "()\" definition at line " + itos(getter->line) + ".", v.line);
return;
}
}
if (!found_setter && v.setter != StringName()) {
- _set_error("Setter function is not defined.", v.line);
+ _set_error("The setter function isn't defined.", v.line);
return;
}
if (!found_getter && v.getter != StringName()) {
- _set_error("Getter function is not defined.", v.line);
+ _set_error("The getter function isn't defined.", v.line);
return;
}
}
@@ -7684,7 +7760,7 @@ void GDScriptParser::_check_function_types(FunctionNode *p_function) {
if (!_is_type_compatible(p_function->argument_types[i], def_type, true)) {
String arg_name = p_function->arguments[i];
_set_error("Value type (" + def_type.to_string() + ") doesn't match the type of argument '" +
- arg_name + "' (" + p_function->arguments[i] + ")",
+ arg_name + "' (" + p_function->arguments[i] + ").",
p_function->line);
}
}
@@ -7747,21 +7823,21 @@ void GDScriptParser::_check_function_types(FunctionNode *p_function) {
}
}
parent_signature += ")";
- _set_error("Function signature doesn't match the parent. Parent signature is: '" + parent_signature + "'.", p_function->line);
+ _set_error("The function signature doesn't match the parent. Parent signature is: \"" + parent_signature + "\".", p_function->line);
return;
}
}
#endif // DEBUG_ENABLED
} else {
if (p_function->return_type.has_type && (p_function->return_type.kind != DataType::BUILTIN || p_function->return_type.builtin_type != Variant::NIL)) {
- _set_error("Constructor cannot return a value.", p_function->line);
+ _set_error("The constructor can't return a value.", p_function->line);
return;
}
}
if (p_function->return_type.has_type && (p_function->return_type.kind != DataType::BUILTIN || p_function->return_type.builtin_type != Variant::NIL)) {
if (!p_function->body->has_return) {
- _set_error("Non-void function must return a value in all possible paths.", p_function->line);
+ _set_error("A non-void function must return a value in all possible paths.", p_function->line);
return;
}
}
@@ -7892,7 +7968,7 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
} else {
// Try implicit conversion
if (lv->datatype.kind != DataType::BUILTIN || !_is_type_compatible(lv->datatype, assign_type, true)) {
- _set_error("Assigned value type (" + assign_type.to_string() + ") doesn't match the variable's type (" +
+ _set_error("The assigned value type (" + assign_type.to_string() + ") doesn't match the variable's type (" +
lv->datatype.to_string() + ").",
lv->line);
return;
@@ -7924,7 +8000,7 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
}
if (lv->datatype.infer_type) {
if (!assign_type.has_type) {
- _set_error("Assigned value does not have a set type, variable type cannot be inferred.", lv->line);
+ _set_error("The assigned value doesn't have a set type; the variable type can't be inferred.", lv->line);
return;
}
lv->datatype = assign_type;
@@ -7975,7 +8051,7 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
}
}
if (lh_type.is_constant) {
- _set_error("Cannot assign a new value to a constant.", op->line);
+ _set_error("Can't assign a new value to a constant.", op->line);
return;
}
}
@@ -7994,8 +8070,8 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
rh_type = _get_operation_type(oper, lh_type, arg_type, valid);
if (check_types && !valid) {
- _set_error("Invalid operand types ('" + lh_type.to_string() + "' and '" + arg_type.to_string() +
- "') to assignment operator '" + Variant::get_operator_name(oper) + "'.",
+ _set_error("Invalid operand types (\"" + lh_type.to_string() + "\" and \"" + arg_type.to_string() +
+ "\") to assignment operator \"" + Variant::get_operator_name(oper) + "\".",
op->line);
return;
}
@@ -8023,7 +8099,7 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
} else {
// Try implicit conversion
if (lh_type.kind != DataType::BUILTIN || !_is_type_compatible(lh_type, rh_type, true)) {
- _set_error("Assigned value type (" + rh_type.to_string() + ") doesn't match the variable's type (" +
+ _set_error("The assigned value's type (" + rh_type.to_string() + ") doesn't match the variable's type (" +
lh_type.to_string() + ").",
op->line);
return;
@@ -8108,18 +8184,18 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
if (function_type.kind == DataType::BUILTIN && function_type.builtin_type == Variant::NIL) {
// Return void, should not have arguments
if (cf->arguments.size() > 0) {
- _set_error("Void function cannot return a value.", cf->line, cf->column);
+ _set_error("A void function cannot return a value.", cf->line, cf->column);
return;
}
} else {
// Return something, cannot be empty
if (cf->arguments.size() == 0) {
- _set_error("Non-void function must return a value.", cf->line, cf->column);
+ _set_error("A non-void function must return a value.", cf->line, cf->column);
return;
}
if (!_is_type_compatible(function_type, ret_type)) {
- _set_error("Returned value type (" + ret_type.to_string() + ") doesn't match the function return type (" +
+ _set_error("The returned value type (" + ret_type.to_string() + ") doesn't match the function return type (" +
function_type.to_string() + ").",
cf->line, cf->column);
return;
@@ -8256,6 +8332,10 @@ int GDScriptParser::get_error_column() const {
return error_column;
}
+bool GDScriptParser::has_error() const {
+ return error_set;
+}
+
Error GDScriptParser::_parse(const String &p_base_path) {
base_path = p_base_path;
@@ -8272,7 +8352,7 @@ Error GDScriptParser::_parse(const String &p_base_path) {
if (tokenizer->get_token() == GDScriptTokenizer::TK_ERROR) {
error_set = false;
- _set_error("Parse Error: " + tokenizer->get_token_error());
+ _set_error("Parse error: " + tokenizer->get_token_error());
}
if (error_set && !for_completion) {