diff --git a/src/parser.jl b/src/parser.jl index 4203c40e..e02b2127 100644 --- a/src/parser.jl +++ b/src/parser.jl @@ -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)) @@ -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") diff --git a/test/parser.jl b/test/parser.jl index 4a50b0c8..be7ed72d 100644 --- a/test/parser.jl +++ b/test/parser.jl @@ -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)" @@ -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)"