@staticmethod
def extract(stack, value, before=None):
    """
        Returns the respective stack nodes of a rule 'value' seen
        by looking backwards at the stack. An optional 'before' rule
        can be required to be seen first.
        """
    seen = before is None
    for node in reversed(stack):
        from_rule = node.dfa.from_rule
        if not seen:
            if from_rule == before:
                seen = True
        elif from_rule == value:
            return node.nodes
    assert 0, stack
