Skip to content

Commit e2fe70d

Browse files
authored
Add support for empty nd-array syntax (#4)
1 parent a2a38e0 commit e2fe70d

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/parser.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,13 +2673,13 @@ end
26732673
# power of 0 for whitespace and negative numbers for other separators.
26742674
#
26752675
# FIXME: Error messages for mixed spaces and ;; delimiters
2676-
function parse_array_separator(ps)
2677-
t = peek_token(ps)
2676+
function parse_array_separator(ps; skip_newlines=false)
2677+
t = peek_token(ps; skip_newlines=skip_newlines)
26782678
k = kind(t)
26792679
if k == K";"
26802680
n_semis = 1
26812681
while true
2682-
bump(ps, TRIVIA_FLAG)
2682+
bump(ps, TRIVIA_FLAG; skip_newlines=skip_newlines)
26832683
t = peek_token(ps)
26842684
if kind(t) != K";" || t.had_whitespace
26852685
break
@@ -2722,11 +2722,18 @@ function parse_cat(ps::ParseState, closer, end_is_symbol)
27222722
whitespace_newline=false,
27232723
for_generator=true)
27242724
k = peek(ps, skip_newlines=true)
2725+
mark = position(ps)
27252726
if k == closer
27262727
# [] ==> (vect)
27272728
return parse_vect(ps, closer)
2729+
elseif k == K";"
2730+
# [;;] ==> (ncat 2)
2731+
# [;; \n ] ==> (ncat 2)
2732+
n_semis, _ = parse_array_separator(ps; skip_newlines=true)
2733+
bump_closing_token(ps, closer)
2734+
min_supported_version(v"1.8", ps, mark, "empty multidimensional array syntax")
2735+
return (K"ncat", set_numeric_flags(n_semis))
27282736
end
2729-
mark = position(ps)
27302737
parse_eq_star(ps)
27312738
k = peek(ps, skip_newlines=true)
27322739
if k == K"," || k == closer

test/parser.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,9 @@ tests = [
633633
# Column major
634634
((v=v"1.7",), "[x ; y ;; z ; w ;;; a ; b ;; c ; d]") =>
635635
"(ncat-3 (nrow-2 (nrow-1 x y) (nrow-1 z w)) (nrow-2 (nrow-1 a b) (nrow-1 c d)))"
636+
# Empty nd arrays
637+
((v=v"1.8",), "[;;]") => "(ncat-2)"
638+
((v=v"1.8",), "[\n ;; \n ]") => "(ncat-2)"
636639
],
637640
JuliaSyntax.parse_string => [
638641
"\"a \$(x + y) b\"" => "(string \"a \" (call-i x + y) \" b\")"

0 commit comments

Comments
 (0)