class ActionParser(Parser): def __init__(self,rule,parent): if not isinstance(rule, Action): raise Exception("Cannot use an ActionParser on a non-Action rule") Parser.__init__(self, rule, parent) self.actioned = False self.active = MakeParser(rule.items, self) def parse(self,token): disp = self.active.parse(token) self.bad = self.active.bad self.done = self.active.done if not self.actioned and not self.bad and self.done: self.rule.func(self) self.actioned = True return disp return '' # The Action's msg should contain at most a single %s, which will be filled # by the display of its sub-parser. It may have other text in its msg which # we'll want to display too. So we let the Rule do the work. def display(self): d = self.active.display() return self.rule.display([d])