-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Report InputMismatchException with original context information #1969
Conversation
@Et999 @michaelpj @PayneSun @marcospassos It should be possible to apply this change to your code by extending int priorState = recognizer.getState();
ParserRuleContext priorContext = recognizer.getContext();
try {
recognizer.setState(nextTokensState);
recognizer._ctx = nextTokensContext;
throw new InputMismatchException(recognizer);
} finally {
recognizer.setState(priorState);
recognizer._ctx = priorContext;
} |
Thanks enormously for looking into this! I'll give this a try and see how it looks. |
278983f
to
9a04d09
Compare
Built locally, tested. Fixes the regressions in 4.7, and actually improves the errors in several other cases. Big 👍 from me. |
9a04d09
to
0803c74
Compare
@Et999 and @marcospassos can you build locally and confirm this works for you? |
@parrt After confirmation, I'll start the work to implement this for other targets. |
I'll test it by tomorrow :) |
@antlr/antlr-targets please note Sam's improvements to the error reporting in this PR. |
ugh. we appear to be getting random travis fluctuations |
@sharwell we caught 160+ tests failing due to the BC break introduced in 4.7, even applying the patch you provided. The errors can be grouped into the following cases:
Besides this, we found several cases where error recovery got worst. Given the following grammar and invalid input, notice how the error recovery produces worst guesses:
Invalid input:
In 4.6, the previously input was recognized as:
While in 4.7 the same input is recognized as:
This difference is probably related to the same issue, right? |
@marcospassos If you are testing error messages, I would not expect this change to reduce the number of "regressing tests", since the messages will still change. Is your project open source so I can help triage the differences? Also, before we go too far we should make sure the change was properly applied since the result discrepancy between @michaelpj and @marcospassos is so large. 💭 I notice that your examples all mention EOF. Do all of your failing tests involve EOF handling? |
@sharwell the project is not open source. However, we're not testing only error messages, but also the generated parse tree. Why don't you consider the error message a BC break? This fix not only changed the error messages but also made the parser produce different parse trees, which is a serious BC break. Btw, is |
@marcospassos I sent you an email 👍 |
After talking with @marcospassos, it appears the negative outcomes from this experiment were likely influenced by uncommon characteristics of the language being parsed. In particular:
For this case, I suggested creating a type derived from |
Thank you @sharwell! |
Ok, sounds like we have no objections to this improvement. |
Thanks, @sharwell !! |
Fixes #1922
📝 This needs more test cases, particularly for LL(k) failures where k>1. However, my current understanding is these cases have been impacted by this bug for much longer (since 4.2.2) than the issue being addressed for the k=1 case.