I\'m analyzing the AST generated by python code for \"fun and profit\", and I would like to have something more graphical than \"ast.dump\" to actually see the AST generated.
If you look at ast.NodeVisitor, it's a fairly trivial class. You can either subclass it or just reimplement its walking strategy to whatever you need. For instance, keeping references to the parent when nodes are visited is very simple to implement this way, just add a visit
method that also accepts the parent as an argument, and pass that from your own generic_visit
.
P.S. By the way, it appears that NodeVisitor.generic_visit
implements DFS, so all you have to do is add the parent node passing.