Skip to content

Commit 772c288

Browse files
authored
Fix for parsing end in A[x ? y : end] (#136)
Failure due to overeager error detection of `end` keyword.
1 parent 997d964 commit 772c288

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/parser.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ function is_closing_token(ps::ParseState, k)
220220
(k == K"end" && !ps.end_symbol)
221221
end
222222

223+
function is_block_continuation_keyword(ps::ParseState, k)
224+
is_block_continuation_keyword(k) && !(ps.end_symbol && k == K"end")
225+
end
226+
223227
function is_closer_or_newline(ps::ParseState, k)
224228
is_closing_token(ps,k) || k == K"NewlineWs"
225229
end
@@ -658,7 +662,7 @@ function parse_cond(ps::ParseState)
658662

659663
# FIXME: This is a very specific case. Error recovery should be handled more
660664
# generally elsewhere.
661-
if is_block_continuation_keyword(kind(t))
665+
if is_block_continuation_keyword(ps, kind(t))
662666
# a "continuaton keyword" is likely to belong to the surrounding code, so
663667
# we abort early
664668

@@ -669,6 +673,8 @@ function parse_cond(ps::ParseState)
669673
bump_invisible(ps, K"error", TRIVIA_FLAG, error="unexpected `$(kind(t))`")
670674
emit(ps, mark, K"if")
671675
return
676+
else
677+
# A[x ? y : end] ==> (ref A (? x y end))
672678
end
673679
parse_eq_star(ps)
674680
emit(ps, mark, K"?")

test/parser.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ tests = [
6666
"a ? b: c" => "(? a b (error-t) c)"
6767
"a ? b :c" => "(? a b (error-t) c)"
6868
"a ? b c" => "(? a b (error-t) c)"
69+
"A[x ? y : end]" => "(ref A (? x y end))"
6970
],
7071
JuliaSyntax.parse_arrow => [
7172
"x → y" => "(call-i x → y)"

0 commit comments

Comments
 (0)