recover method

void recover(
  1. RecognitionException<IntStream> re
)
inherited

Lexers can normally match any char in it's vocabulary after matching a token, so do the easy thing and just kill a character and hope it all works out. You can instead use the rule invocation stack to do sophisticated error recovery if you are in a fragment rule.

Implementation

void recover(RecognitionException re) {
  if (re is LexerNoViableAltException) {
    if (_input.LA(1) != IntStream.EOF) {
      // skip a char and try again
      interpreter!.consume(_input);
    }
  } else {
    //System.out.println("consuming char "+(char)input.LA(1)+" during recovery");
    //re.printStackTrace();
    // TODO: Do we lose character or line position information?
    _input.consume();
  }
}