Skip to content

Commit

Permalink
Merge pull request #85 from jlumpe/misc-fixes
Browse files Browse the repository at this point in the history
Miscellaneous fixes
  • Loading branch information
jlumpe authored Sep 2, 2021
2 parents 5c01ee5 + b463a85 commit 087ce85
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions docs/src/implementing.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ tree = MyNode(1, [
# output
7-element Array{Int64,1}:
7-element Vector{Int64}:
3
4
2
Expand Down Expand Up @@ -99,9 +99,9 @@ if possible:

## Printing

[`print_tree`](@ref) calls the [`printnode`](@ref) function to display the representation of each
node in the tree. The default implementation uses the output of `Base.show` (with an appropriate
`IOContext`). You may override this to customize how your tree is printed:
[`print_tree`](@ref) calls the [`AbstractTrees.printnode`](@ref) function to display the
representation of each node in the tree. The default implementation uses the output of `Base.show`
(with an appropriate `IOContext`). You may override this to customize how your tree is printed:

```jldoctest mynode
AbstractTrees.printnode(io::IO, node::MyNode) = print(io, "MyNode($(node.data))")
Expand Down
12 changes: 6 additions & 6 deletions src/builtins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ children(x::AbstractString) = ()
children(x::Expr) = x.args

function printnode(io::IO, x::Expr)
print(io, "Expr(")
show(io, x.head)
print(io, ")")
print(io, "Expr(")
show(io, x.head)
print(io, ")")
end


Expand All @@ -27,7 +27,7 @@ children(kv::Pair{K,V}) where {K,V} = (kv[2],)
printnode(io::IO, ::T) where T <: Union{AbstractArray, AbstractDict} = print(io, T)

if isdefined(Core.Compiler, :Timings)
children(t::Core.Compiler.Timings.Timing) = t.children
printnode(io::IO, t::Core.Compiler.Timings.Timing) = print(io, t.time/10^6, "ms: ", t.mi_info)
nodetype(t::Core.Compiler.Timings.Timing) = Core.Compiler.Timings.Timing
children(t::Core.Compiler.Timings.Timing) = t.children
printnode(io::IO, t::Core.Compiler.Timings.Timing) = print(io, t.time/10^6, "ms: ", t.mi_info)
nodetype(t::Core.Compiler.Timings.Timing) = Core.Compiler.Timings.Timing
end
22 changes: 11 additions & 11 deletions src/printing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,44 @@ Print a text representation of `tree` to the given `io` object.
julia> tree = [1:3, "foo", [[[4, 5], 6, 7], 8]];
julia> print_tree(tree)
Array{Any,1}
Vector{Any}
├─ UnitRange{Int64}
│ ├─ 1
│ ├─ 2
│ └─ 3
├─ "foo"
└─ Array{Any,1}
├─ Array{Any,1}
│ ├─ Array{Int64,1}
└─ Vector{Any}
├─ Vector{Any}
│ ├─ Vector{Int64}
│ │ ├─ 4
│ │ └─ 5
│ ├─ 6
│ └─ 7
└─ 8
julia> print_tree(tree, maxdepth=2)
Array{Any,1}
Vector{Any}
├─ UnitRange{Int64}
│ ├─ 1
│ ├─ 2
│ └─ 3
├─ "foo"
└─ Array{Any,1}
├─ Array{Any,1}
└─ Vector{Any}
├─ Vector{Any}
│ ⋮
└─ 8
julia> print_tree(tree, charset=AbstractTrees.ASCII_CHARSET)
Array{Any,1}
Vector{Any}
+-- UnitRange{Int64}
| +-- 1
| +-- 2
| \\-- 3
+-- "foo"
\\-- Array{Any,1}
+-- Array{Any,1}
| +-- Array{Int64,1}
\\-- Vector{Any}
+-- Vector{Any}
| +-- Vector{Int64}
| | +-- 4
| | \\-- 5
| +-- 6
Expand Down

0 comments on commit 087ce85

Please sign in to comment.