more clearer unexpected statement end error messages
(cherry picked from commit 5758d87f09
)
This commit is contained in:
parent
7111aa0688
commit
6b0cfc87af
|
@ -72,6 +72,16 @@ bool GDScriptParser::_end_statement() {
|
|||
return false;
|
||||
}
|
||||
|
||||
void GDScriptParser::_set_end_statement_error(String p_name) {
|
||||
String error_msg;
|
||||
if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER) {
|
||||
error_msg = vformat("Expected end of statement (\"%s\"), got %s (\"%s\") instead.", p_name, tokenizer->get_token_name(tokenizer->get_token()), tokenizer->get_token_identifier());
|
||||
} else {
|
||||
error_msg = vformat("Expected end of statement (\"%s\"), got %s instead.", p_name, tokenizer->get_token_name(tokenizer->get_token()));
|
||||
}
|
||||
_set_error(error_msg);
|
||||
}
|
||||
|
||||
bool GDScriptParser::_enter_indent_block(BlockNode *p_block) {
|
||||
|
||||
if (tokenizer->get_token() != GDScriptTokenizer::TK_COLON) {
|
||||
|
@ -2923,7 +2933,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_end_statement_error("var");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -3234,7 +3244,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
|
|||
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_end_statement_error("continue");
|
||||
return;
|
||||
}
|
||||
} break;
|
||||
|
@ -3246,7 +3256,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
|
|||
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_end_statement_error("break");
|
||||
return;
|
||||
}
|
||||
} break;
|
||||
|
@ -3275,7 +3285,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
|
|||
cf_return->arguments.push_back(retexpr);
|
||||
p_block->statements.push_back(cf_return);
|
||||
if (!_end_statement()) {
|
||||
_set_error("Expected end of statement after return expression.");
|
||||
_set_end_statement_error("return");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -3363,7 +3373,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\".", assert_line);
|
||||
_set_end_statement_error("assert");
|
||||
return;
|
||||
}
|
||||
} break;
|
||||
|
@ -3374,7 +3384,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_end_statement_error("breakpoint");
|
||||
return;
|
||||
}
|
||||
} break;
|
||||
|
@ -3393,7 +3403,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
|
|||
if (tokenizer->get_token() == GDScriptTokenizer::TK_COLON && tokenizer->get_token(1) == GDScriptTokenizer::TK_OP_ASSIGN) {
|
||||
_set_error("Unexpected ':=', use '=' instead. Expected end of statement after expression.");
|
||||
} else {
|
||||
_set_error(String() + "Expected end of statement after expression, got " + tokenizer->get_token_name(tokenizer->get_token()) + " instead");
|
||||
_set_error(vformat("Expected end of statement after expression, got %s instead.", tokenizer->get_token_name(tokenizer->get_token())));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -3582,7 +3592,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
|
|||
if (error_set)
|
||||
return;
|
||||
if (!_end_statement()) {
|
||||
_set_error("Expected end of statement after \"extends\".");
|
||||
_set_end_statement_error("extends");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -4087,7 +4097,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_end_statement_error("signal");
|
||||
return;
|
||||
}
|
||||
} break;
|
||||
|
@ -5038,7 +5048,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_end_statement_error("var");
|
||||
return;
|
||||
}
|
||||
} break;
|
||||
|
@ -5118,7 +5128,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_end_statement_error("const");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -5272,7 +5282,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
|
|||
}
|
||||
|
||||
if (!_end_statement()) {
|
||||
_set_error("Expected end of statement (\"enum\").");
|
||||
_set_end_statement_error("enum");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -624,6 +624,7 @@ private:
|
|||
void _parse_extends(ClassNode *p_class);
|
||||
void _parse_class(ClassNode *p_class);
|
||||
bool _end_statement();
|
||||
void _set_end_statement_error(String p_name);
|
||||
|
||||
void _determine_inheritance(ClassNode *p_class, bool p_recursive = true);
|
||||
bool _parse_type(DataType &r_type, bool p_can_be_void = false);
|
||||
|
|
Loading…
Reference in New Issue