[antlr-interest] Customizing error messages

Olivier Lefevre lefevrol at yahoo.com
Thu Feb 21 16:05:03 PST 2008


It seems the standard way to customize error messages is to override
some BaseRecognizer method or methods, which can get rather involved.
In the case where you want the recognizer to exit immediately upon
recognition error, you must override two more methods. Wouldn't it
be a lot simpler to just throw your own Exception within an action
or the method body of a predicate? Just a question; it might not be a
good idea for reasons I don't appreciate.

Incidentally the book is confusing on this topic. In §10.2 (p.246) it
says "To get these rich error messages, override two methods from
BaseRecognizer, displayRecognitionError() and getTokenErrorDisplay()"
but then it goes on to provide an example in which the overridden
methods are actually getErrorMessage() and getTokenErrorDisplay().
Same deal in the §10.3 example, which again overrides getErrorMessage().
So, when might displayRecognitionError() be a useful one to override?

-- O.L.



More information about the antlr-interest mailing list