Hi Bill,

On Wed, Nov 23, 2011 at 5:41 PM, Bill Andersen <bill.ander...@mac.com>wrote:

> Hi Folks...
>
> Been trying to figure out how to shut off default Lexer behavior to print
> messages to System.err, such as:
>
>        line 2:4 no viable alternative at character ' '
>
> Instead, I'd like to catch these and do something with them.  Overriding
> reportError(RecognitionException) doesn't work and no other option seems
> obvious.


Both the lexer and parser have a `reportError(...)` method, and my guess is
that you did something like this:

@members {
  @Override
  public void reportError(RecognitionException e) ...
}

which is a short-hand for:

@parser::members { // note the `parser::`
  @Override
  public void reportError(RecognitionException e) ...
}

But since a "no viable alternative" error is something that comes from the
lexer, you need to explicitly override the lexer method like this:

@lexer::members {
  @Override
  public void reportError(RecognitionException e) {
    System.out.println("CUSTOM ERROR...");
  }
}

Regards,

Bart.

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to