The problem I've experienced is in the latest C# implementation that comes with as a NuGet package Antlr4.Runtime.4.4.1-alpha001 (I haven't tried in previous ones)
I have reduced the grammar to the bare minimum to show the issue that I'm experiencing.
In the grammar below, to try the error recovery, if I parse
:XXXX (which is missing the fieldName) in the error listener that I have added to capture the parser errors I get 1 error
"no viable alternative at input ':'"However, in the parsing tree I get 2 error nodes:
[Antlr4.Runtime.Tree.ErrorNodeImpl] = {:}
[Antlr4.Runtime.Tree.ErrorNodeImpl] = {value}
If I test the same grammar and input using IntelliJIdea ANTLR4 pluggin, I get a different result "extraneous input ':' expecting {'(', Term}"
And the parse tree shows in red the
: token but then it recovers and the second token is displayed as a proper tree using the second field rule
value, which is what I was expecting.
I'm not sure of the reason, but it seems to me that the C# version is not behaving the same as the Java version.
grammar Combined1;
compileUnit : field EOF ;
field:
fieldName ':' value
| value;
fieldName: Term;
value:
'(' value ')'
| Term;
Term: TERM_START_CHAR TERM_CHAR*;
fragment TERM_START_CHAR: ~( ' ' | '\t' | '\n' | '\r' | ':' );
fragment TERM_CHAR : (TERM_START_CHAR | '.' );
WS : [ \t\r\n\f]+ -> skip;