Skip to content

Commit e41b785

Browse files
committed
Fix let block parsing in comprehension
1 parent bfc4161 commit e41b785

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/components/lists.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ function parse_array_outer(ps::ParseState, trivia, isref)
118118
max_bp = -typemax(Int)
119119
is_start = true
120120
while kindof(ps.nt) !== Tokens.RSQUARE && kindof(ps.nt) !== Tokens.ENDMARKER
121-
a = @nocloser ps :newline @nocloser ps :newline @closesquare ps @closer ps :insquare @closer ps :ws @closer ps :wsop @closer ps :comma parse_expression(ps)
122-
121+
a = @nocloser ps :semicolon @nocloser ps :newline @closesquare ps @closer ps :insquare @closer ps :ws @closer ps :wsop @closer ps :comma parse_expression(ps)
123122
if is_start
124123
args = EXPR[]
125124
if isref && _do_kw_convert(ps, a)

test/parser.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ end
522522
@test "[x;;; y;;;z]'" |> test_expr
523523
@test "[1 2; 3 4]" |> test_expr
524524
@test "[1;2;;3;4;;5;6;;;;9]" |> test_expr
525+
@test "[let; x; end;; y]" |> test_expr
526+
@test "[let; x; end;;;; y]" |> test_expr
525527
end
526528

527529
@testset "typed_ncat" begin
@@ -534,20 +536,34 @@ end
534536
@test "t[x;;\ny]" |> test_expr
535537
@test "t[x y;;\nz a]" |> test_expr
536538
@test "t[x y;;\nz a]'" |> test_expr
539+
@test "t[let; x; end;; y]" |> test_expr
540+
@test "t[let; x; end;;;; y]" |> test_expr
537541
end
538542
end
539543

540544
@testset "hcat" begin
541545
@test "[x y]" |> test_expr
546+
@test "[let; x; end y]" |> test_expr
547+
@test "[let; x; end; y]" |> test_expr
542548
end
543549

544550
@testset "typed_hcat" begin
545551
@test "t[x y]" |> test_expr
552+
@test "t[let; x; end y]" |> test_expr
553+
@test "t[let; x; end; y]" |> test_expr
546554
end
547555

548556
@testset "Comprehension" begin
549557
@test "[i for i = 1:10]" |> test_expr
550558
@test "Int[i for i = 1:10]" |> test_expr
559+
@test """[
560+
[
561+
let l = min((d-k),k);
562+
binomial(d-l,l);
563+
end; for k in 1:d-1
564+
] for d in 2:9
565+
]
566+
""" |> test_expr
551567
end
552568
end
553569

0 commit comments

Comments
 (0)