[antlr-interest] Mix Custom and Default error handling...

Tom Goff tom at tomgoff.com
Tue Mar 21 16:30:52 PST 2006


Hello,

I would like to use the default error/exception handling built into antlr
2.7.5, but I would like to add some clean up code before it's executed. For
example,

myRule:
	{
		MyRuleClass rc = null;
	}
	:
	{
		rc = new MyRuleClass();
	}
	RULE
	a:ID { rc.ID = a.getText(); }
	{ this.Rules.Add(rc); }
	;

In this rule, I would like to delete rc if an exception is thrown. I know I
can modify it like so:

myRule:
	{
		MyRuleClass rc = null;
	}
	:
	{
		rc = new MyRuleClass();
	}
	RULE
	a:ID { rc.ID = a.getText(); }
	{ this.Rules.Add(rc); }
	;
	exception // for rule
		catch [RecognitionException ex] {
			if (null == rc)
				delete rc;
		}

But then I lose the call to reportError (which I can easily add) and recover
(which I can't add easily). How can I reproduce or keep the call to recover?
Or is there another easy option?

Any help would be great and thanks,
Tom



More information about the antlr-interest mailing list