Skip to content

Commit 025b4e4

Browse files
committed
Added -d argument to dump AST node visits
1 parent 426857d commit 025b4e4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

minpy.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def __init__(self):
201201
self.__star_imports = []
202202
self.__function_name = None
203203
self.__kwargs = []
204+
self.__depth = 0
204205

205206
def modules(self):
206207
return self.__modules
@@ -243,9 +244,11 @@ def __member_mod_visited(self, member):
243244
return False
244245

245246
def generic_visit(self, node):
247+
self.__depth += 1
246248
if PRINT_VISITS:
247-
nprint("{}: {}".format(type(node).__name__, ast.dump(node)))
249+
nprint("| " * self.__depth + ast.dump(node))
248250
super(SourceVisitor, self).generic_visit(node)
251+
self.__depth -= 1
249252

250253
def visit_Import(self, node):
251254
self.__import = True
@@ -536,6 +539,7 @@ def print_usage():
536539
print(" -i Ignore incompatible version warnings.")
537540
print(" -p=X Use X concurrent processes to analyze files (defaults to all cores = {})."
538541
.format(cpu_count()))
542+
print(" -d Dump AST node visits.")
539543

540544
def parse_args():
541545
if len(sys.argv) < 2:
@@ -568,6 +572,10 @@ def parse_args():
568572
if processes <= 0:
569573
print("Non-positive number: {}".format(processes))
570574
sys.exit(-1)
575+
elif arg == "-d":
576+
global PRINT_VISITS
577+
PRINT_VISITS = True
578+
path_pos += 1
571579

572580
if QUIET and VERBOSE > 0:
573581
print("Cannot use quiet and verbose modes together!")

0 commit comments

Comments
 (0)