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

Misleading second error when recovery consumes more than one token #260

Open
JojOatXGME opened this issue Feb 21, 2021 · 0 comments
Open

Comments

@JojOatXGME
Copy link

JojOatXGME commented Feb 21, 2021

When my error recovery consumes more than one token through recoverWhile, I get a second misleading error message. For example with the following grammar.

file ::= root
root ::= 'kw' content ';' { pin=1 }
content ::= 'valid' { recoverWhile=kw_recover }
private kw_recover ::= !';'

And the following input.

kw invalid invalid ;

I get two errors.

  1. On the first occurrence of invalid:

    valid expected, got 'invalid'

  2. On the semicolon (;):

    ';' unexpected

This does not happen when there is only one invalid token. For the following input, only the first error is reported.

kw invalid ;

A workaround for this issue is to use recoverWhile with rules which do never fail (i.e. empty rules).

file ::= root
root ::= 'kw' content recover_kw ';' { pin=1 }
content ::= 'valid'
private recover_kw ::= { recoverWhile=kw_recover }
private kw_recover ::= !';'

Unfortunately, this solution has the problem that some errors are reported twice. For the same input as above, we get the first error two times. The first time, the error is reported at (2, 2) (after kw), the second time the error is reported at (3, 10) (the first occurrence of invalid).

Am I doing something wrong or is there a better way? Is this considered to be a bug of Grammar-Kit? I think ideally, both cases should not report more than one error. I pushed a project to reproduce the issue to this branch. A "working" solution seems to be making content optional. However, this will obviously no longer report an error when the content is missing. Should recoverWhile only be used on rules which are always optional?

@JojOatXGME JojOatXGME changed the title Misleading second error when recovery consumes more then one token Misleading second error when recovery consumes more than one token Apr 5, 2021
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