[antlr-interest] Error recovery contortion

Paul J. Lucas pauljlucas at mac.com
Tue Dec 7 11:09:24 PST 2004


On Tue, 7 Dec 2004, Terence Parr wrote:

> On Dec 2, 2004, at 12:01 PM, Paul J. Lucas wrote:

> > 	OK, so I tried setting defaultErrorHandler=true.  This makes
> > 	the generated AST be fine for errors outside of function
> > 	declarations, but now the problem is that ANTLR recovers all by
> > 	itself while doing enclosedExpr and functionDeclBody above is
> > 	never given the opportunity to catch the exception and do the
> > 	correct recovery.  Hence, this breaks my recovery mechanism.
> 
> Are you sure?

	Yes.

> The following code generates precisely the same output 
> for func() with and without the "defaultErrorHandler=false;".

	For *your* example code, it would work fine because your rule
	contains only tokens, not rules.  If it contains a rule as mine
	does, *that* rule is auto-recovered from by ANTLR so, by the
	time it gets back to the current rule, it's too late.

> > 	One slight problem: reportError() isn't declared to throw any
> > 	exception.  Hence, I created the ANTLR_WorkaroundException class that
> > 	extends RuntimeException to work around this annoyance.
> 
> Only an annoyance, mein herr, because you want reportError to do more 
> than it was meant to ;)

	Which is why I suggested modifying the auto-exception-recovery
	code that ANTLR emits to include a recover() method that is
	declared to throw an exception.

	- Paul



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list