[antlr-interest] Calling code at rule exit
David Ray
ray at soartech.com
Wed Nov 16 11:21:13 PST 2005
Thanks for the suggestion. AOP is a little overkill though :)
After thinking a little more the solution I came up with is just a
simple sub-rule. It's a little annoying, but not too bad:
rule:
...
{ pushScope(); }
ruleScope /* actual rule that may fail */
{ popScope(); }
;
This isn't totally exception-safe, but seems like it will work for the
time being. Unit tests pass anyway.
Thanks,
Dave
Akhilesh Mritunjai wrote:
> I know its like using an elephant gun to kill a
> cockroach, but have you given a thought in using AOP
> frameworks like AspectJ and kins.
>
> I believe ANTLR gives options to add exception
> handlers, but dunno about finalizers... and even they
> don't apply to complete method body, afaik. AOP hacks
> are only things guaranteed to work.
>
> - Akhilesh
>
>
> --- David Ray <ray at soartech.com> wrote:
>
>
>>Hello,
>>
>>I have some code that I would like to be called
>>whenever a rule exits
>>whether it exits normally or due to an error (I'm
>>using the default
>>error handler, so reportError() is called and the
>>exception never
>>actually leaves the method). I'm maintaining a
>>variable scope stack and
>>I need to push/pop it in rules that introduce a new
>>scope. Right now, if
>>an error occurs, the pop is never called and my
>>stack is left in a bad
>>state.
>>
>>If this were C++, I'd just make a sentry object and
>>call pop in the
>>destructor, but since I'm doing this in Java I'm not
>>sure if there is a
>>good way to do that. Does anyone know of a Java
>>equivalent to C++
>>sentry objects, or some way I can do this in ANTLR?
>>
>>Thanks,
>>Dave Ray
>>ray at soartech.com
>>
>
>
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
More information about the antlr-interest
mailing list