Walk the tree in roughly 'preorder' (a bit of a lie explained below). For each node with typestring name *name* if the node has a method called n_*name*, call that before walking children. In typical use a node with children can call "preorder" in any order i
(self, node=None)
| 87 | maybe_show_tree(self, tree) |
| 88 | |
| 89 | def preorder(self, node=None): |
| 90 | """Walk the tree in roughly 'preorder' (a bit of a lie explained below). |
| 91 | For each node with typestring name *name* if the |
| 92 | node has a method called n_*name*, call that before walking |
| 93 | children. |
| 94 | |
| 95 | In typical use a node with children can call "preorder" in any |
| 96 | order it wants which may skip children or order then in ways |
| 97 | other than first to last. In fact, this this happens. So in |
| 98 | this sense this function not strictly preorder. |
| 99 | """ |
| 100 | if node is None: |
| 101 | node = self.ast |
| 102 | |
| 103 | try: |
| 104 | name = "n_" + self.typestring(node) |
| 105 | if hasattr(self, name): |
| 106 | func = getattr(self, name) |
| 107 | node = func(node) |
| 108 | except GenericASTTraversalPruningException: |
| 109 | return |
| 110 | |
| 111 | for i, kid in enumerate(node): |
| 112 | node[i] = self.preorder(kid) |
| 113 | return node |
| 114 | |
| 115 | def n_mkfunc(self, node): |
| 116 | """If the function has a docstring (this is found in the code |