As I found somewhere on them internets, you can use Base.show_unquoted
to convert any Expr
to a string of valid Julia code:
julia> Base.show_unquoted(stdout, :(import Woof; import Bowow))
begin
import Woof
#= REPL[5]:1 =#
import Bowow
end
To convert to a string, use IOBuffer
, or write to a file:
julia> buf = IOBuffer();
julia> Base.show_unquoted(buf, :(import Woof; import Bowow))
julia> String(take!(buf))
"begin\n import Woof\n #= REPL[11]:1 =#\n import Bowow\nend"