[antlr-interest] Customizing Error Recovery
David-Sarah Hopwood
david-sarah at jacaranda.org
Mon Nov 30 20:04:36 PST 2009
Jim Idle wrote:
> 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.
I may be misunderstanding somthing, but it doesn't look to me as though
syntax errors due to spurious tokens will cause exceptions or be displayed.
For example, suppose that '=' is not a valid starting token for a
declaration. Then for the input
class Foo {
=
int validDeclaration;
}
syncToSet will skip the '=' token without reporting an error, even though
a syntax error should have been reported.
> 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
... or before the first class member ...
> then you can show an error about them.
Well, then I suppose my point is that you should always do this -- it's
not a matter of being clever, but of being minimally correct.
--
David-Sarah Hopwood ⚥ http://davidsarah.livejournal.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 292 bytes
Desc: OpenPGP digital signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20091201/9e17416b/attachment.bin
More information about the antlr-interest
mailing list