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

Allow putting keywords in quotation marks for error messages #262

Open
JojOatXGME opened this issue Apr 4, 2021 · 0 comments
Open

Allow putting keywords in quotation marks for error messages #262

JojOatXGME opened this issue Apr 4, 2021 · 0 comments

Comments

@JojOatXGME
Copy link

JojOatXGME commented Apr 4, 2021

Let's consider the following grammar.

file ::= root
root ::= ID [ 'or' ID ] ';'

And the following input.

id bad

If I follow the tutorial, I get something like the following error message.

MyTokenType.; or MyTokenType.or expected, got 'bad'

I think this is strange to read. In contrast to the tutorial, most plugins I looked at don't override toString(). As a result, we get the following error message.

';' or or expected, got 'bad'

This would look much better if the keyword or had been quoted. GeneratedParserUtilBase.ErrorState.appendExpected(…) does not quote or because it starts like a valid Java identifier (which seems a little arbitrary to me).

I'm currently not aware of any possibility to put or in quotation marks? Do I miss something? If not, I would suggest extending the API to allow to override the text used for a token in error messages. As a positive side effect, this would also allow to decouple the error message from the token name in the PSI structure (where the prefix from the tutorial is actually helpful). What do you think about that?

EDIT: I already thought about prefixing keywords with "\u2060" (Word Joiner) in toString() as a workaround. However, I am not sure if this is appropriate or might cause other problems.

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

1 participant