Created
November 20, 2012 09:46
-
-
Save toivoh/4117023 to your computer and use it in GitHub Desktop.
simple lispy AST printer for julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
show_sexpr(ex) = show_sexpr(OUTPUT_STREAM, ex) | |
show_sexpr(io::IO, ex) = show_sexpr(io, ex, 0) | |
show_sexpr(io::IO, ex, indent::Int) = show(io, ex) | |
const sexpr_indent_width = 2 | |
function show_sexpr(io::IO, ex::Expr, indent::Int) | |
inner = indent + sexpr_indent_width | |
if (ex.head === :block) inter, post = ("\n"*" "^inner, "\n"*" "^indent) | |
else inter, post = (" ", "") | |
end | |
print(io, '(') | |
show(io, ex.head) | |
for arg in ex.args | |
print(io, inter) | |
show_sexpr(io, arg, inner) | |
end | |
print(io, post, ')') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is meant for viewing the internal structure of an AST.
Example:
show_sexpr
applied to its own code