[antlr-interest] Customizing Error Recovery

Jim Idle jimi at temporal-wave.com
Mon Nov 30 18:38:01 PST 2009


The function has been renamed already, I will double check. The parameter should go as you say, this was taken from the JavaFX compiler.

Err, the point of consuming the tokens is to suppress spurious errors so you can sync back to a decent restart point. Any syntax error in the previous subrule will be caught and displayed because the exception will throw in that rule and you will be back in the class rule, where you want to resync to a good point so you don't drop out of the loop.

Now, if you want to be more clever, then you can see if there were any errors in the previous rule, then if there are spurious tokens after the class member then you can show an error about them. The point is not the actual recovery mechanism you employ, but how to get NATLR to let you do such a thing of course. I will add something to this effect to the article tomorrow.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of David-Sarah Hopwood
> Sent: Monday, November 30, 2009 6:23 PM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Customizing Error Recovery
> 
> Jim Idle wrote:
> > As this subject comes up fairly often, I thought I would write an
> > article showing some of the ways you can influence, hijack, or
> > otherwise coerce the error recovery mechanisms within your parser.
> You
> > can find the article here:
> >
> > http://www.antlr.org/wiki/display/ANTLR3/Custom+Syntax+Error+Recovery
> 
> The '[ListBuffer<JFXTree> mems]' argument to syncClass should be
> removed.
> 
> 'protected void syncToSet(BitSet follow)' should be called
> 'syncToGoodToken' if it's to be consistent with the call in
> 'syncToSet()'.
> 
> A more serious problem is that this code seems to be suppressing
> errors, as opposed to recovering from them. That is, syncToSet will
> just discard invalid tokens, rather than reporting that an invalid
> token was found before syncing to the next good token.
> 
> --
> David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com






More information about the antlr-interest mailing list