[antlr-interest] Error Handling.

Adam Connelly adam.rpconnelly at googlemail.com
Wed May 14 15:53:56 PDT 2008


The default behaviour (AFAIK) is simply to print the errors; if you want to
alter this you pretty much have to override emitErrorMessage.  The methods
in BaseRecognizer to look at are:

reportError() [I doubt you'd want to alter this]
getErrorMessage() [defines the text of the message]
getErrorHeader() [defines the start of the error message e.g. "line 30:20"]
emitErrorMessage() [this has the println call]
displayRecognitionError() [calls getErrorMessage(), getErrorHeader() and
then emitErrorMessage()]

The RecognitionException contains the line and charPositionInLine members
that give you the info about where the error occurred, and a token member.
I think if you want to keep track of errors you'd have to override the
method and store the errors yourself.

So if you don't need to alter the text that represents the message, but just
how the message is output, then you just need to look at emitErrorMessage(),
but I think in your case you may wish to override displayRecognitionError()
so you've still got access to the token, etc.

Hope that helps,
Adam

2008/5/13 Miguel Marques <mig.marques at gmail.com>:

> Hello,
>
> After reading the FAQ and googling I could find exactly what I am looking
> for.
> I've generated a lexer+parser with antlr to a DSL and now I'm integrating
> it with the Eclipse Platform as an editor. So I need to be able to run the
> parser and then retrieve the parsing errors. From what I've understood antlr
> generates all the
> try/catch for all parsing exceptions so that it can continue the parsing
> process by guessing the "next" needed token and it prints the error to the
> stderror. Are those errors kept somewhere? Is there any object that keeps
> info on the line it occured and token name rule, etc?
>
> Miguel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080514/20a6b9c9/attachment.html 


More information about the antlr-interest mailing list