Ejemplo n.º 1
0
def main(infilename, outfilename):
    node = ast.parse(open(infilename).read())
    node = transformers.ParentChildNodeTransformer().visit(node)
    visitor = visitors.GraphNodeVisitor()
    visitor.visit(node)
    visitor.graph.write_png(outfilename)
    os.system('open ' + outfilename)
Ejemplo n.º 2
0
def ast_playing(source_code):
    node = ast.parse(source_code)
    node = transformers.ParentChildNodeTransformer().visit(node)
    visitor = visitors.GraphNodeVisitor()
    visitor.visit(node)
    for n in ast.walk(node):
        print(type(n))
    visitor.graph.write_png('graph_1.png')
Ejemplo n.º 3
0
def __tests():
    import ast
    with open('tests/function_def_test.py') as test_code:
        test_node = ast.parse(test_code.read())
        node = transformers.ParentNodeTransformer().visit(test_node)
        visitor = visitors.GraphNodeVisitor()
        visitor.visit(node)

        visitor.graph.write_png('graph.png')
Ejemplo n.º 4
0
 def dump_ast(mod, name):
     if IMPORT_ASTMONKEY:
         mod = deepcopy(mod)
         mod = transformers.ParentChildNodeTransformer().visit(deepcopy(mod))
         visitor = visitors.GraphNodeVisitor()
         visitor.visit(mod)
         visitor.graph.write_png(name + '.png')
         print("\033[1;32;40mAST visualization saved as \033[94m%s.png\033[0m" % name)
     else:
         print("\033[93mInstall astmonkey for visualization.\033[0m")
Ejemplo n.º 5
0
def main():
    code = ''
    for line in sys.stdin:
        code += line
        print(line)
    node = ast.parse(code)
    node = transformers.ParentChildNodeTransformer().visit(node)
    visitor = visitors.GraphNodeVisitor()
    visitor.visit(node)

    visitor.graph.write_png('src/main/resources/graph.png')
Ejemplo n.º 6
0
 def setUp(self):
     self.visitor = visitors.GraphNodeVisitor()
Ejemplo n.º 7
0
 def visitor(self):
     return visitors.GraphNodeVisitor()
Ejemplo n.º 8
0
import ast
from astmonkey import visitors, transformers

node = ast.parse('def foo(x):\n\treturn x + 1')
node = transformers.ParentNodeTransformer().visit(node)
visitor = visitors.GraphNodeVisitor()
visitor.visit(node)

visitor.graph.write_png('graph.png')