Testing grammars with JUnit

If You're Using Version 0.7 or Earlier

Upgrade!

Or, in order for my assertions to work, you need to add this code to each of your grammars. In your lexer, change @members to @lexer::members. If your lexer and parser are in the same file, have both a @members and @lexer::members section.

@members { 
  protected void mismatch(IntStream input, int ttype, BitSet follow) 
    throws RecognitionException { 
    throw new MismatchedTokenException(ttype, input); 
  } 
  public void recoverFromMismatchedSet(
      IntStream input, RecognitionException e, BitSet follow) 
      throws RecognitionException { 
    throw e; 
  } 
} 
@rulecatch { 
  catch (RecognitionException e) { 
    throw e; 
  } 
} 

It's ugly and dumb code. Depending on what version of ANTLR itself you're using, you may have to tweak some of the return types.