Skip to content

Commit

Permalink
Update show.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
toivoh committed Mar 1, 2016
1 parent 0b6cab6 commit 864cda4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ is_expr(ex, head::Symbol) = (isa(ex, Expr) && (ex.head == head))
is_expr(ex, head::Symbol, n::Int) = is_expr(ex, head) && length(ex.args) == n

is_linenumber(ex::LineNumberNode) = true
is_linenumber(ex::Expr) = (ex.head == :line)
is_linenumber(ex) = false

is_quoted(ex) = false
Expand Down Expand Up @@ -417,7 +418,8 @@ end

emphasize(io, str::AbstractString) = have_color ? print_with_color(:red, io, str) : print(io, uppercase(str))

show_linenumber(io::IO, file, line) = print(io," # ", file,", line ",line,':')
show_linenumber(io::IO, line) = print(io," # line ",line,':')
show_linenumber(io::IO, line, file) = print(io," # ", file,", line ",line,':')

# show a block, e g if/for/etc
function show_block(io::IO, head, args::Vector, body, indent::Int)
Expand Down Expand Up @@ -486,7 +488,7 @@ end
## AST printing ##

show_unquoted(io::IO, sym::Symbol, ::Int, ::Int) = print(io, sym)
show_unquoted(io::IO, ex::LineNumberNode, ::Int, ::Int) = show_linenumber(io, ex.file, ex.line)
show_unquoted(io::IO, ex::LineNumberNode, ::Int, ::Int) = show_linenumber(io, ex.line, ex.file)
show_unquoted(io::IO, ex::LabelNode, ::Int, ::Int) = print(io, ex.label, ": ")
show_unquoted(io::IO, ex::GotoNode, ::Int, ::Int) = print(io, "goto ", ex.label)
show_unquoted(io::IO, ex::TopNode, ::Int, ::Int) = print(io,"top(",ex.name,')')
Expand Down Expand Up @@ -737,6 +739,9 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int)
print(io, "typealias ")
show_list(io, args, ' ', indent)

elseif is(head, :line) && 1 <= nargs <= 2
show_linenumber(io, args...)

elseif is(head, :if) && nargs == 3 # if/else
show_block(io, "if", args[1], args[2], indent)
show_block(io, "else", args[3], indent)
Expand Down

0 comments on commit 864cda4

Please sign in to comment.