|
1 | | -# This module is needed until AbstractTrees.jl#37 is fixed. |
2 | | -# (PR: https://github.com/Keno/AbstractTrees.jl/pull/38) |
3 | | -# because currently `print_tree` does not respect `maxdepth`. |
4 | | -# This just implements the changes in the above PR. |
| 1 | +# This module originally existed for AbstractTrees.jl#37, |
| 2 | +# but has since diverged from the functionality of |
| 3 | +# AbstractTrees.print_tree. It is now a separate implementation |
| 4 | +# of tree printing |
5 | 5 | # Code in this file is modified from AbstractTrees.jl |
6 | 6 | # See LICENSE for a copy of its MIT license. |
7 | 7 | module TreePrint |
8 | 8 |
|
9 | | -using AbstractTrees: printnode, treekind, IndexedTree, children |
| 9 | +using AbstractTrees: children, printnode |
10 | 10 |
|
11 | 11 | # Printing |
12 | 12 | struct TreeCharSet |
@@ -83,19 +83,16 @@ function _print_tree( |
83 | 83 | if withinds |
84 | 84 | printnode(nodebuf, tree, inds) |
85 | 85 | else |
86 | | - tree != roottree && isa(treekind(roottree), IndexedTree) ? |
87 | | - printnode(nodebuf, roottree[tree]) : printnode(nodebuf, tree) |
| 86 | + printnode(nodebuf, tree) |
88 | 87 | end |
89 | 88 | str = String(take!(isa(nodebuf, IOContext) ? nodebuf.io : nodebuf)) |
90 | 89 | for (i, line) in enumerate(split(str, '\n')) |
91 | 90 | i != 1 && print_prefix(io, depth, charset, active_levels) |
92 | 91 | println(io, line) |
93 | 92 | end |
94 | 93 | depth > maxdepth && return |
95 | | - c = |
96 | | - isa(treekind(roottree), IndexedTree) ? childindices(roottree, tree) : |
97 | | - children(roottree, tree) |
98 | | - if c !== () |
| 94 | + c = children(tree) |
| 95 | + if !isempty(c) |
99 | 96 | width = 0 |
100 | 97 | s = Iterators.Stateful( |
101 | 98 | from === nothing ? pairs(c) : Iterators.Rest(pairs(c), from), |
|
0 commit comments