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

Unexpected token reported as expected token #257

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

Unexpected token reported as expected token #257

JojOatXGME opened this issue Feb 13, 2021 · 0 comments

Comments

@JojOatXGME
Copy link

JojOatXGME commented Feb 13, 2021

I run into the issue that Grammar-Kit reports the unexpected token as also being expected. After some debugging, I was able to create a small example that demonstrates the issue.

file ::= root
root ::=
    parens AFTER
  | parens
parens ::= '(' content ')' { pin=1 }
content ::= A B { pin=1 recoverWhile=parens_recover }
private parens_recover ::= !')'

I created a GitHub repository for reproduction. The error message for the input (A) is

')' or B expected, got ')'

It looks like the following requirements must be met to make Grammar-Kit report expected tokens incorrectly.

  1. You need a choice expression with two (or more) choices. (i.e. root)
  2. The first (or at least not last) choice must have two nested pinned expressions. (i.e. parens and content)
  3. The second pinned expressions must fail after it has been pinned but before the last token has been consumed. (i.e. content)
  4. The second choice must fail at the same token as the previous choice.

The problem is that parens adds ) to ErrorState.variants while evaluating the first choice. Since the error message has already been generated for the current frame, the error message is not yet affected. When evaluating the second choice, the parser runs into the exact same error but with ) still being saved as a variant. Since we are outside the frame of the first choice, the parser will override the error reported previously but acknowledge the incorrect variant ).

@JojOatXGME JojOatXGME changed the title Unexpected token reportet as expected token Unexpected token reported as expected token Feb 14, 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