[antlr-interest] Cust error recovery

Bryan Ewbank ewbank at gmail.com
Wed Jul 27 03:45:35 PDT 2005


On 7/26/05, Martin Olsson <mnemo at minimum.se> wrote:
> Hi (again :o),
> 
> When ANTLR runs into a parse error I would like it to skip chars/tokens
> until a specific char/token is seen. After digging a while in the ANTLR
> source I noticed that there is a method called consumeUntil() which seems
> to do what I what.

Do you really want to do this, or do you want to have only certain
productions be the "stopping point" for error recovery?

For example, do you want to "skip to semicolon", or "recover at
<statement>"?  The first is somewhat complex in ANTLR, the second is
very straightforward using options in the parser section to disable
default error recovery, and in particular rules to enable default
error recovery.

What I've done is disable everything, then recover at <statement> and
a few others - don't have the grammar in front of me - because that
way I don't have to worry about follow sets, and so on.  I just let
ANTLR to it's thing.

- B


More information about the antlr-interest mailing list