Skip to content

Commit 56aa403

Browse files
authored
Trailing linebreak is not significant in hcat (#169)
In the reference parser, `[a b\n\n]` parses as `(hcat a b)`, not vcat with a single row.
1 parent d09245b commit 56aa403

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/parser.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,10 +2882,16 @@ function parse_array_separator(ps, array_order)
28822882
k = kind(t)
28832883
if k == K"NewlineWs"
28842884
bump_trivia(ps)
2885-
# Treat a linebreak prior to a value as a semicolon (ie, separator for
2886-
# the first dimension) if no previous semicolons observed
2887-
# [a \n b] ==> (vcat a b)
2888-
return (1, -1)
2885+
if peek(ps) == K"]"
2886+
# Linebreaks not significant before closing `]`
2887+
# [a b\n\n] ==> (hcat a b)
2888+
return (typemin(Int), typemin(Int))
2889+
else
2890+
# Treat a linebreak prior to a value as a semicolon (ie, separator
2891+
# for the first dimension) if no previous semicolons observed
2892+
# [a \n b] ==> (vcat a b)
2893+
return (1, -1)
2894+
end
28892895
elseif k == K","
28902896
# Treat `,` as semicolon for the purposes of recovery
28912897
# [a; b, c] ==> (vcat a b (error-t) c)

test/parser.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,8 @@ tests = [
799799
((v=v"1.7",), "[a b \n ;; c]") => "(ncat-2 (row a b (error-t)) c)"
800800
# Can't mix spaces and multiple ;'s
801801
((v=v"1.7",), "[a b ;; c]") => "(ncat-2 (row a b (error-t)) c)"
802+
# Linebreaks not significant before closing `]`
803+
"[a b\n\n]" => "(hcat a b)"
802804
# Treat a linebreak prior to a value as a semicolon (ie, separator for
803805
# the first dimension) if no previous semicolons observed
804806
"[a \n b]" => "(vcat a b)"

0 commit comments

Comments
 (0)