[antlr-interest] executing actions while recovering from
syntaxerrors
Terence Parr
parrt at cs.usfca.edu
Sat Apr 9 16:15:39 PDT 2005
On Apr 9, 2005, at 7:52 AM, Don Caton wrote:
> 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.
Interesting...now that you mention it, it would be pretty groovy to
have a guard around all actions so that you could dynamically turn them
all off after any syntax error (if you wanted to). Hmm...
> 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> }
True. Normally we use init actions for that. I think my new syntax is:
( init {do me always} : ... )
in this case ... would be empty.
> 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.
Thanks for the good thoughts Don :)
Ter
>
> 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
>>
>>
>>
>>
>
>
>
--
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