From cd5cd762649facb15960da46a8e38f8197a41289 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sat, 22 Feb 2014 16:36:01 -0500 Subject: [PATCH] fix regression in expression printing (ref #5879) fix #5898, showing 1-arg form of kw expr (used internally) add prettyprinting of string interpolation without this, test-show fails on my fix to #5879, which helps explain why things were that way --- base/show.jl | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/base/show.jl b/base/show.jl index 7472b6f13dac9..33c6416c8b7bd 100644 --- a/base/show.jl +++ b/base/show.jl @@ -491,20 +491,33 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int) show(io, args[1]) elseif is(head, :null) print(io, "nothing") - elseif is(head, :kw) + elseif is(head, :kw) && length(args)==2 show_unquoted(io, args[1], indent+indent_width) print(io, '=') show_unquoted(io, args[2], indent+indent_width) + elseif is(head, :string) + a = map(args) do x + if !isa(x,String) + if isa(x,Symbol) && !(x in quoted_syms) + string("\$", x) + else + string("\$(", sprint(show_unquoted,x), ")") + end + else + sprint(print_escaped, x, "\"\$") + end + end + print(io, '"', a..., '"') # print anything else as "Expr(head, args...)" else - print(io, "Expr(") - show_unquoted(io, ex.head, indent) + print(io, "\$(Expr(") + show(io, ex.head) for arg in args print(io, ", ") - show_unquoted(io, arg, indent) + show(io, arg) end - print(io, ")") + print(io, "))") end show_expr_type(io, ex.typ)