47 lines
1019 B
Python
47 lines
1019 B
Python
import json
|
|
import parser
|
|
import ast
|
|
from sys import argv
|
|
|
|
|
|
#f = open(argv[1], "r")
|
|
f = open("../test.py", "r")
|
|
source = "".join(x for x in f.readlines())
|
|
#print(parser.suite(source).tolist())
|
|
tree = ast.parse(source)
|
|
#print(ast.dump(tree))
|
|
|
|
#class Tree(ast.NodeTransformer):
|
|
# def __init__(self, source):
|
|
# r = ast.parse(source)
|
|
# self.visit(r)
|
|
# def vist_Str(self, node):
|
|
# print(ast.Str(node.body))
|
|
|
|
a = ast.parse(source)
|
|
#Tree().vist_Str(a)
|
|
def nodes(parsed_source):
|
|
r = []
|
|
for i in ast.walk(parsed_source):
|
|
r.append(i)
|
|
return r
|
|
#print(nodes(a))
|
|
f = open("../test.py", "r")
|
|
linee = f.readlines()
|
|
|
|
# da completare sta puttanata dello strip
|
|
#for i in linee:
|
|
# i = i.rstrip()
|
|
|
|
for i in ast.walk(a):
|
|
try:
|
|
print(str(i.lineno-1) + " " + linee[i.lineno-1])
|
|
except:
|
|
print("SALTATA" + " " + str(i))
|
|
|
|
# Divagazioni notturne importanti
|
|
# Ecco come funziona Visitor
|
|
my_visit = ast.NodeVisitor()
|
|
print(my_visit.visit(a))
|
|
# peccato non stampi nulla
|