You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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 messageline 1:4 missing ALNUM at '<EOF>'
, and the RecognitionException is null.When parsing the string
TEST TEST TEST
, the error message isline 1:10 extraneous input 'TEST' expecting <EOF>
, and the RecognitionException is null.But when parsing the string
TEST *
, the error message isline 1:5 mismatched input '*' expecting ALNUM
, and the RecognitionException is a InputMismatchException.It seems like each of these should return an InputMismatchException.
The text was updated successfully, but these errors were encountered: