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

ErrorListener shouldn't receive a null RecognitionException #949

Open
PaulJuliusMartinez opened this issue Jul 2, 2015 · 2 comments
Open

Comments

@PaulJuliusMartinez
Copy link

I'm trying to write a basic auto-completion tool using ANTLR. In order to determine what types of things to suggest, I'm parsing everything before the cursor and catching the syntax error passed to an error listener to get the expected tokens from the RecognitionException that is passed along to the syntax error.

However, according to the docs, "the RecognitionException is non-null for all syntax errors except when we discover mismatched token errors that we can recover from in-line, without returning from the surrounding rule (via the single token insertion and deletion mechanism)."

I'd argue that this is undesirable behavior because there is no way to get the expected tokens in this case, even though the generated error message passed in the msg parameter lists them. I think in these cases it would still be acceptable to throw a InputMismatchException. Consider the following case of a grammar that just excepts two text tokens separated by whitespace:

start : ALNUM ALNUM EOF

where ALNUM is a string of alphanumeric characters.

When parsing the string TEST, the default error listener emits the message line 1:4 missing ALNUM at '<EOF>', and the RecognitionException is null.

When parsing the string TEST TEST TEST, the error message is line 1:10 extraneous input 'TEST' expecting <EOF>, and the RecognitionException is null.

But when parsing the string TEST *, the error message is line 1:5 mismatched input '*' expecting ALNUM, and the RecognitionException is a InputMismatchException.

It seems like each of these should return an InputMismatchException.

@RutgerRauws
Copy link

I am also writing an auto-completion tool for a grammar I defined in ANTLR and am facing the exact same issue as you are.

I guess I could work around this by just parsing the msg parameter but I would rather not. Is there a specific reason why this issue was not picked up, @parrt? (i.e. a design decision) Otherwise I might look into it.

@parrt
Copy link
Member

parrt commented Oct 6, 2017

I believe that sometimes null is allowed by the API... sorry but I will be back to ANTLR stuff for another month or so.

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

3 participants