You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Improve GDScript "unexpected token in class body" parser error
This parser error was misleading. Fixes: 1. Now points at correct line 2. For identifiers, prints out `Identifier "%s"`
This commit is contained in:
@@ -1060,8 +1060,8 @@ void GDScriptParser::parse_class_body(bool p_is_multiline) {
|
|||||||
default:
|
default:
|
||||||
// Display a completion with identifiers.
|
// Display a completion with identifiers.
|
||||||
make_completion_context(COMPLETION_IDENTIFIER, nullptr);
|
make_completion_context(COMPLETION_IDENTIFIER, nullptr);
|
||||||
push_error(vformat(R"(Unexpected "%s" in class body.)", current.get_name()));
|
|
||||||
advance();
|
advance();
|
||||||
|
push_error(vformat(R"(Unexpected %s in class body.)", previous.get_debug_name()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (token.type != GDScriptTokenizer::Token::STATIC) {
|
if (token.type != GDScriptTokenizer::Token::STATIC) {
|
||||||
|
|||||||
@@ -164,6 +164,15 @@ const char *GDScriptTokenizer::Token::get_name() const {
|
|||||||
return token_names[type];
|
return token_names[type];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String GDScriptTokenizer::Token::get_debug_name() const {
|
||||||
|
switch (type) {
|
||||||
|
case IDENTIFIER:
|
||||||
|
return vformat(R"(identifier "%s")", source);
|
||||||
|
default:
|
||||||
|
return vformat(R"("%s")", get_name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool GDScriptTokenizer::Token::can_precede_bin_op() const {
|
bool GDScriptTokenizer::Token::can_precede_bin_op() const {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case IDENTIFIER:
|
case IDENTIFIER:
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ public:
|
|||||||
String source;
|
String source;
|
||||||
|
|
||||||
const char *get_name() const;
|
const char *get_name() const;
|
||||||
|
String get_debug_name() const;
|
||||||
bool can_precede_bin_op() const;
|
bool can_precede_bin_op() const;
|
||||||
bool is_identifier() const;
|
bool is_identifier() const;
|
||||||
bool is_node_name() const;
|
bool is_node_name() const;
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# GH-96792
|
||||||
|
|
||||||
|
var error
|
||||||
|
error = true
|
||||||
|
|
||||||
|
func test():
|
||||||
|
pass
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
GDTEST_PARSER_ERROR
|
||||||
|
Unexpected identifier "error" in class body.
|
||||||
Reference in New Issue
Block a user