def node_throw(node): ''' Raise an error, if one exists in the results (AST trees are traversed). Otherwise, the results are returned (invoke with ``>>``). ''' for child in postorder(node, Node): if isinstance(child, Exception): raise child return node
def test_postorder(self): ''' At first I was surprised about this (compare with SimpleNode results above), but these are leaf nodes, so postorder doesn't change anything (there's no difference between "before visiting" and "after visiting" a leaf). ''' g = [1, [11, [111, 112], 12]] result = [node for node in postorder(g, list) if isinstance(node, int)] assert result == [1, 11, 111, 112, 12], result
def test_postorder(self): result = [ node.label for node in postorder(graph(), SimpleNode, exclude=LEAF) ] assert result == [111, 112, 11, 12, 1], result
def test_postorder(self): result = [node.label for node in postorder(graph(), SimpleNode, exclude=LEAF)] assert result == [111, 112, 11, 12, 1], result