Show More
@@ -94,17 +94,17 b' class parser(object):' | |||
|
94 | 94 | return self.eval(t) |
|
95 | 95 | return t |
|
96 | 96 | |
|
97 | def _prettyformat(tree, leafnodes, level, lines): | |
|
98 | if not isinstance(tree, tuple) or tree[0] in leafnodes: | |
|
99 | lines.append((level, str(tree))) | |
|
100 | else: | |
|
101 | lines.append((level, '(%s' % tree[0])) | |
|
102 | for s in tree[1:]: | |
|
103 | _prettyformat(s, leafnodes, level + 1, lines) | |
|
104 | lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')] | |
|
105 | ||
|
97 | 106 | def prettyformat(tree, leafnodes): |
|
98 | def _prettyformat(tree, level, lines): | |
|
99 | if not isinstance(tree, tuple) or tree[0] in leafnodes: | |
|
100 | lines.append((level, str(tree))) | |
|
101 | else: | |
|
102 | lines.append((level, '(%s' % tree[0])) | |
|
103 | for s in tree[1:]: | |
|
104 | _prettyformat(s, level + 1, lines) | |
|
105 | lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')] | |
|
106 | ||
|
107 | 107 | lines = [] |
|
108 | _prettyformat(tree, 0, lines) | |
|
108 | _prettyformat(tree, leafnodes, 0, lines) | |
|
109 | 109 | output = '\n'.join((' ' * l + s) for l, s in lines) |
|
110 | 110 | return output |
General Comments 0
You need to be logged in to leave comments.
Login now