Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ function parse_range(ps::ParseState)
end
n_colons += 1
bump(ps, n_colons == 1 ? EMPTY_FLAGS : TRIVIA_FLAG)
had_newline = peek(ps, skip_newlines=false) == K"NewlineWs"
had_newline = peek(ps) == K"NewlineWs"
t = peek_token(ps)
if is_closing_token(ps, kind(t))
# 1: } ==> (call-i 1 : (error))
Expand All @@ -824,7 +824,8 @@ function parse_range(ps::ParseState)
end
if had_newline
# Error message for people coming from python
# 1:\n2 ==> (call-i 1 : (error))
# 1:\n2 ==> (call-i 1 : (error))
# (1:\n2) ==> (call-i 1 : 2)
emit_diagnostic(ps, whitespace=true,
error="line break after `:` in range expression")
bump_invisible(ps, K"error")
Expand Down
4 changes: 4 additions & 0 deletions test/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ tests = [
"1:2:3" => "(call-i 1 : 2 3)"
"a:b:c:d:e" => "(call-i (call-i a : b c) : d e)"
"a :< b" => "(call-i a (error : <) b)"
"1:\n2" => "(call-i 1 : (error))"
],
JuliaSyntax.parse_range => [
"a..b" => "(call-i a .. b)"
Expand Down Expand Up @@ -561,6 +562,9 @@ tests = [
# Generators
"(x for a in as)" => "(generator x (= a as))"
"(x \n\n for a in as)" => "(generator x (= a as))"
# Range parsing in parens
"(1:\n2)" => "(call-i 1 : 2)"
"(1:2)" => "(call-i 1 : 2)"
],
JuliaSyntax.parse_atom => [
":foo" => "(quote foo)"
Expand Down