Emit an AST as Julia code?

By “AST”, do you mean an Expr?

If so, simply printing an Expr displays it the form of Julia code:

julia> a = quote
         println("hello world!")
       end
quote
    #= REPL[1]:2 =#
    println("hello world!")
end

julia> println(a)
begin
    #= REPL[1]:2 =#
    println("hello world!")
end

For prettier printing, you can get rid of the line annotations using MacroTools.striplines:

julia> using MacroTools


julia> MacroTools.striplines(a) |> println
begin
    println("hello world!")
end
4 Likes