diff --git a/base/show.jl b/base/show.jl index b2a1da33ddceb..4fa8ba2e2cded 100644 --- a/base/show.jl +++ b/base/show.jl @@ -1303,6 +1303,7 @@ const expr_calls = Dict(:call => ('(',')'), :calldecl => ('(',')'), :ref => ('[',']'), :curly => ('{','}'), :(.) => ('(',')')) const expr_parens = Dict(:tuple=>('(',')'), :vcat=>('[',']'), :hcat =>('[',']'), :row =>('[',']'), :vect=>('[',']'), + :ncat =>('[',']'), :nrow =>('[',']'), :braces=>('{','}'), :bracescat=>('{','}')) ## AST decoding helpers ## @@ -1811,14 +1812,16 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In # list-like forms, e.g. "[1, 2, 3]" elseif haskey(expr_parens, head) || # :vcat etc. - head === :typed_vcat || head === :typed_hcat + head === :typed_vcat || head === :typed_hcat || head === :typed_ncat # print the type and defer to the untyped case - if head === :typed_vcat || head === :typed_hcat + if head === :typed_vcat || head === :typed_hcat || head === :typed_ncat show_unquoted(io, args[1], indent, prec, quote_level) if head === :typed_vcat head = :vcat - else + elseif head === :typed_hcat head = :hcat + else + head = :ncat end args = args[2:end] nargs = nargs - 1 @@ -1828,15 +1831,19 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In sep = "; " elseif head === :hcat || head === :row sep = " " + elseif head === :ncat || head === :nrow + sep = ";"^args[1] * " " + args = args[2:end] + nargs = nargs - 1 else sep = ", " end - head !== :row && print(io, op) + head !== :row && head !== :nrow && print(io, op) show_list(io, args, sep, indent, 0, quote_level) - if nargs == 1 && head === :vcat - print(io, ';') + if nargs <= 1 && (head === :vcat || head === :ncat) + print(io, sep[1:end-1]) end - head !== :row && print(io, cl) + head !== :row && head !== :nrow && print(io, cl) # transpose elseif (head === Symbol("'") && nargs == 1) || ( diff --git a/test/show.jl b/test/show.jl index e4bfd3f95af32..c00dcf523898c 100644 --- a/test/show.jl +++ b/test/show.jl @@ -2304,3 +2304,19 @@ end @test replstr([[1;;]]) == "1-element Vector{Matrix{$Int}}:\n [1;;]" @test replstr([[1;;;]]) == "1-element Vector{Array{$Int, 3}}:\n [1;;;]" end + +@testset "ncat and nrow" begin + @test_repr "[1;;]" + @test_repr "[1;;;]" + @test_repr "[1;; 2]" + @test_repr "[1;;; 2]" + @test_repr "[1;;; 2 3;;; 4]" + @test_repr "[1;;; 2;;;; 3;;; 4]" + + @test_repr "T[1;;]" + @test_repr "T[1;;;]" + @test_repr "T[1;; 2]" + @test_repr "T[1;;; 2]" + @test_repr "T[1;;; 2 3;;; 4]" + @test_repr "T[1;;; 2;;;; 3;;; 4]" +end