def generic_visit(self, node): # label this node out_string = 'n%s [label="%s"];\n' % (id(node), self.label(node)) # edges to children for fieldname, fieldvalue in ast.iter_fields(node): for index, child in enumerate_flatten(fieldvalue): if isinstance(child, ast.AST): suffix = "".join(["[%d]" % i for i in index]) out_string += 'n{} -> n{} [label="{}{}"];\n'.format( id(node), id(child), fieldname, suffix) out_string += self.visit(child) return out_string
def generic_visit(self, node): # label this node out_string = 'n%s [label="%s"];\n' % (id(node), self.label(node)) # edge to parent if hasattr(node, 'parent') and node.parent is not None: out_string += 'n%s -> n%s [label="parent",style=dotted];\n' % ( id(node), id(node.parent)) # edges to children for fieldname, fieldvalue in ast.iter_fields(node): for index, child in enumerate_flatten(fieldvalue): if isinstance(child, ast.AST): suffix = "".join(["[%d]" % i for i in index]) out_string += 'n%d -> n%d [label="%s%s"];\n' % ( id(node), id(child), fieldname, suffix) out_string += _to_dot(child) return out_string
def generic_visit(self, node): # abort if visited if node in self._visited: return "" else: self._visited.append(node) # label this node out_string = 'n%s [label="%s"];\n' % (id(node), self.label(node)) # edges to children for fieldname, fieldvalue in ast.iter_fields(node): for index, child in enumerate_flatten(fieldvalue): if isinstance(child, ast.AST): suffix = "".join(["[%d]" % i for i in index]) out_string += 'n%d -> n%d [label="%s%s"];\n' % (id(node), id(child), fieldname, suffix) out_string += self.visit(child) return out_string
def generic_visit(self, node): # abort if visited if node in self._visited: return "" else: self._visited.append(node) # label this node out_string = 'n%s [label="%s"];\n' % (id(node), self.label(node)) # edges to children for fieldname, fieldvalue in ast.iter_fields(node): for index, child in enumerate_flatten(fieldvalue): if isinstance(child, ast.AST): suffix = "".join(["[%d]" % i for i in index]) out_string += 'n%d -> n%d [label="%s%s"];\n' % ( id(node), id(child), fieldname, suffix) out_string += self.visit(child) return out_string
def _check(self, nested, exp_indices): act_indices, values = zip(*enumerate_flatten(nested)) for actual, expected in zip(act_indices, exp_indices): self.assertTupleEqual(actual, expected)