title: Is there a way to easily adapt the error messages of ANTLR4?
body: <p>Currenlty I'm working on my own grammar and I would like to have specific error messages on <code>NoViableAlternative</code>, <code>InputMismatch</code>, <code>UnwantedToken</code>, <code>MissingToken</code> and <code>LexerNoViableAltException</code>.</p>
  
  <p>I already extended the <code>Lexer.class</code> and have overridden the <code>notifyListeners</code> to change the default error message <code>token recognition error at:</code> to my own one. As well I extended the <code>DefaultErrorStrategy</code> and have overridden all report methods, like <code>reportNoViableAlternative</code>, <code>reportInputMismatch</code>, <code>reportUnwantedToken</code>, <code>reportMissingToken</code>.</p>
  
  <p>The purpose of all that is to change the messages, which will be passed to the <code>syntaxError()</code> method of the listener <code>ANTLRErrorListener</code>.</p>
  
  <p>Here's a small example of the extended <code>Lexer.class</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>    @Override
      public void notifyListeners(LexerNoViableAltException lexerNoViableAltException) {
          String text = this._input.getText(Interval.of(this._tokenStartCharIndex, this._input.index()));
          String msg = "Operator " + this.getErrorDisplay(text) + " is unkown.";
          ANTLRErrorListener listener = this.getErrorListenerDispatch();
          listener.syntaxError(this, null, this._tokenStartLine, this._tokenStartCharPositionInLine, msg,
              lexerNoViableAltException);
      }
  </code></pre>
  
  <p>Or for the <code>DefaultErrorStrategy</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>    @Override
      protected void reportNoViableAlternative(Parser recognizer, NoViableAltException noViableAltException) {
          TokenStream tokens = recognizer.getInputStream();
          String input;
          if (tokens != null) {
              if (noViableAltException.getStartToken().getType() == -1) {
                  input = "&lt;EOF&gt;";
              } else {
                  input = tokens.getText(noViableAltException.getStartToken(), noViableAltException.getOffendingToken());
              }
          } else {
              input = "&lt;unknown input&gt;";
          }
  
          String msg = "Invalid operation " + input + ".";
          recognizer.notifyErrorListeners(noViableAltException.getOffendingToken(), msg, noViableAltException);
      }
  </code></pre>
  
  <p>So I read this thread <a href="https://stackoverflow.com/questions/18132078/handling-errors-in-antlr4">Handling errors in ANTLR4</a>
  and was wondering if there's no easier solution when it comes to the point of customising?</p>