Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve misleading GDScript parser error #99887

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JackErb
Copy link

@JackErb JackErb commented Nov 30, 2024

This parser error was misleading.

Fixes:

  1. Now points at correct line
  2. Now prints out the raw token source (e.g. "variable_name" instead of "<Identifier>")

====

With Change:

image

Without Change (misleading):

image

@JackErb JackErb requested a review from a team as a code owner November 30, 2024 22:39
@JackErb JackErb changed the title Improve GDScript "unexpected token in class body" parser error Improve misleading GDScript parser error Nov 30, 2024
@JackErb JackErb requested a review from a team as a code owner December 1, 2024 05:50
advance();
push_error(vformat(R"(Unexpected "%s" in class body.)", previous.source));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the token source code in the error message is debatable, since tokens can be multiline or unreadable (LITERAL, NEWLINE, INDENT, DEDENT). I think we should use something like:

const String token_name = previous.is_identifier() ? previous.get_identifier() : previous.get_name();

Or maybe add a new method to GDScriptTokenizer::Token.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this change and made a new test to verify it's on the proper line.

@dalexeev dalexeev added this to the 4.4 milestone Dec 1, 2024
@dalexeev
Copy link
Member

dalexeev commented Dec 1, 2024

This parser error was misleading.

Fixes:
1. Now points at correct line
2. Now prints out the raw token source (e.g. "variable_name" instead of "<Identifier>")
@JackErb
Copy link
Author

JackErb commented Dec 1, 2024

@JackErb JackErb requested a review from dalexeev December 1, 2024 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants