Skip to content

Instantly share code, notes, and snippets.

@toivoh
Created August 10, 2012 09:28
Show Gist options
  • Save toivoh/3312906 to your computer and use it in GitHub Desktop.
Save toivoh/3312906 to your computer and use it in GitHub Desktop.
AST pretty printing example
code = quote
function show_body_lines(io::IO, ex)
args = is_expr(ex, :block) ? ex.args : {ex}
for arg in args
if !is_linenumber(arg); print(io, '\n'); end
show(io, arg)
end
end
end
show(code)
@toivoh
Copy link
Author

toivoh commented Aug 15, 2012

Test output:

begin   #  line 2:
    function show_body_lines(io::IO, ex)    #  none, line 3:
        args=if is_expr(ex, :block)
                ex.args
            else 
                {ex}
            end #  line 4:
        for arg=args    #  line 5:
            if !(is_linenumber(arg))    #  line 5:
                begin 
                    print(io, '\n')
                end
            end #  line 6:
            show(io, arg)
        end
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment