title: Force semantic error (failed predicate) in ANTLR4
body: <p>Basically, I've extended the BaseErrorListener, and I need to know when the error is semantic and when it's syntactic. So I want the following to give me a failed predicate exception, but I'm getting a <code>NoViableAltException</code> instead (I know the counting is working, because I can print out the value of <code>things</code>, and it's correct). Is there a way I can re-work it to do what I want? In my example below, I want there to be a failed predicate exception if we don't end up with 6 <code>things</code>.</p>
  
  <pre><code>grammar Test;
  
  @parser::members {
      int things = 0;
  }
  .
  .
  .
  samplerule : THING { things++; } ;
  .
  .
  .
  // Want this to be a failed predicate instead of NoViableAltException
  anotherrule : ENDTOKEN { things == 6 }? ;
  .
  .
  .
  </code></pre>
  
  <hr>
  
  <p>I'm already properly getting failed predicate exceptions with the following (for a different scenario):</p>
  
  <pre><code>somerule : { Integer.valueOf(getCurrentToken().getText()) &lt; 256 }? NUMBER ;
  .
  .
  .
  NUMBER : [0-9]+ ;
  </code></pre>