[antlr-interest] executing actions during backtrack

Kay Roepke kroepke at dolphin-services.de
Tue May 9 18:56:55 PDT 2006


On 10. May 2006, at 3:28 Uhr, Terence Parr wrote:

> The action would be translated to:
>
> undoActions.add(new Action324(scope,$ID.text));
>
> Later we can walk undoActions and undo everything.
>
> Hmm...would this work?  Surely in this case.  The key is passing  
> all necessary data to the undo as evaluated in its original context.

Yes, this should work in the general case, too, since if you supply  
the information and code necessary to undo the actions you have been  
executing,
there are no external dependencies and you're fine. Just hand it the  
proper undo object and call it later on if necessary. We could  
actually skip out
on reparsing and executing actions in this case to make up for the  
hassle you had to go through to set it up in the first place :)

This is exactly how the undo mechanism works in Apple's Cocoa  
framework. Guess it's modeled after the Command Execute pattern, too  
(or predates it or whatever,
who cares, it works...).

I'd like to see a close proximity between plain actions and @undo  
actions though, otherwise more complicated grammars could be pretty  
hard to grok. But maybe
that's simply a requirement for a good editor to visually indicate  
something fancy going on in that rule. I like the @undo name.

-k


More information about the antlr-interest mailing list