1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +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:
JackErb
2024-11-30 14:29:30 -08:00
parent 893bbdfde8
commit 13fcb05e7b
5 changed files with 20 additions and 1 deletions

View File

@@ -1060,8 +1060,8 @@ void GDScriptParser::parse_class_body(bool p_is_multiline) {
default:
// Display a completion with identifiers.
make_completion_context(COMPLETION_IDENTIFIER, nullptr);
push_error(vformat(R"(Unexpected "%s" in class body.)", current.get_name()));
advance();
push_error(vformat(R"(Unexpected %s in class body.)", previous.get_debug_name()));
break;
}
if (token.type != GDScriptTokenizer::Token::STATIC) {

View File

@@ -164,6 +164,15 @@ const char *GDScriptTokenizer::Token::get_name() const {
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 {
switch (type) {
case IDENTIFIER:

View File

@@ -178,6 +178,7 @@ public:
String source;
const char *get_name() const;
String get_debug_name() const;
bool can_precede_bin_op() const;
bool is_identifier() const;
bool is_node_name() const;

View File

@@ -0,0 +1,7 @@
# GH-96792
var error
error = true
func test():
pass

View File

@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Unexpected identifier "error" in class body.