[antlr-interest] executing actions while recovering from
syntaxerrors
Don Caton
dcaton at shorelinesoftware.com
Sat Apr 9 07:52:55 PDT 2005
Ter:
I generally need to guard actions anyhow, to prevent null pointer exceptions
when a rule doesn't successfully match. So automatic guarding would be
beneficial and simplify action code, at least for me. I'd love to eliminate
the repetitious "if (#x != NULL )" tests I have all over the place.
However, there may be cases where you'd always want to run an action.
Perhaps an option to suppress guarding in that case:
{ options { guarded = false; } : <action code> }
This would also serve to self-document the fact that the action always runs,
even if the rule fails. You could also have a global option to turn it on
or off for the whole grammar, to maintain compatibility with existing
grammar and satisfy everyone's personal preference.
Don
> Anyway, putting a guard around every action looks gross and
> takes time/space (oh, and I guess is no guarantee it's safe):
>
> if ( !recoveryMode ) { action }
>
> Anybody wanna comment? For now, the actions are unguarded.
>
> Ter
> --
> CS Professor & Grad Director, University of San Francisco
> Creator, ANTLR Parser Generator, http://www.antlr.org
> Cofounder, http://www.jguru.com
>
>
>
>
More information about the antlr-interest
mailing list