JuliaTeX / TreeView.jl

Draw Julia syntax trees as a graph
Other
82 stars 15 forks source link

View tree of expression stored in variable #21

Open dpo opened 5 years ago

dpo commented 5 years ago

I'm on Julia 1.0.3, TreeView 0.3.1 in an IJulia notebook:

julia> myexpr = :(1.0 * x[1] + -1.0 * x[2] + -1.0 * x[3])
julia> @tree @eval myexpr
LabelledTree({4, 3} directed simple Int64 graph, Any[:macrocall, Symbol("@eval"), :(#= In[21]:1 =#), :objexpr])

On a side note, it took me a moment to realize that I needed @eval here. If this usage is correct, perhaps there could be an example in the README. This may also be related to #19?!

dpo commented 5 years ago

Sorry; brew install pdf2svg.

dpsanders commented 5 years ago

Please feel free to suggest improvements for the README.

dpo commented 5 years ago

I got confused. The @eval trick doesn't work; it displays something else. How does one display an expression stored in a variable? Just call tree_walk(myexpr)?

dpsanders commented 5 years ago

This is currently not enabled via the macro, though it would be a useful addition, so I've reopened the issue and changed the title.

Indeed just calling the function is a good workaround.

dpo commented 5 years ago

Ok, thank you!

dpsanders commented 5 years ago

The syntax could be @tree $myexpr. This requires explicitly handling the relevant $ syntax in the expression parser and escaping the resulting variable.