...
Add the following to your grammar to override the default insert/delete behavior:
Code Block |
---|
@members { protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) throws RecognitionException { throw new MismatchedTreeNodeExceptionMismatchedTokenException(ttype, (TreeNodeStream)input); } } |
and now you get
No Format |
---|
line 3:714 extraneousmismatched input '3' expecting ';' tree=(FUNC_DEF (FUNC_HDR int foo) (BLOCK (VAR_DEF int i) (= i 3) <mismatched token: [@19,41:41='3',<12>,3:14], resync=i = 3> 3)) |
ANTLR deleted shows the extraneous token. Later, I'll add an automated way to engage this selectively when it's safe to do so (no refs in code/AST stuff): http://www.antlr.org/browse/ANTLR-213mismatched token in the tree now; it didn't recover as it did before.