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

Include token type in unexpected token error message #265

Open
andremarianiello opened this issue Sep 9, 2022 · 3 comments
Open

Include token type in unexpected token error message #265

andremarianiello opened this issue Sep 9, 2022 · 3 comments

Comments

@andremarianiello
Copy link

Sometimes I get an unexpected parsing error like

unexpected token \"group\"

and I get confused because group should be a valid next token in my grammar. However, it turns out that group is a Keyword token in my lexer, not an Identifier token like I wanted. Upon realizing that the token was of the wrong type, the error makes sense now. However, realizing that the token type was the problem can take a while, especially if the lexer is complicated or contains overlapping rules, because the error message doesn't give any indication of the types of the tokens involved (found OR expected). I think that including the token types in the error message would help people facing this issue solve it much more quickly.

@alecthomas
Copy link
Owner

I think it would be good to add the token type if you'd like to send a PR.

@alecthomas
Copy link
Owner

Maybe something like unexpected token "group" of type keyword

@alecthomas
Copy link
Owner

I had a bit of a dig into this and unfortunately it would not be straightforward to fix this. The human-readable token names are contained in the lexer.Definition, but these errors come from locations that don't have access to that type. I don't have any good ideas for this at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants