Skip to content
Open
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
7 changes: 4 additions & 3 deletions src/julia/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -686,19 +686,20 @@ function parse_cond(ps::ParseState)
end
parse_eq_star(ParseState(ps, range_colon_enabled=false))
t = peek_token(ps)
if !preceding_whitespace(t)
had_colon = kind(t) == K":"
if had_colon && !preceding_whitespace(t)
# a ? b: c ==> (? a b (error-t) c)
bump_invisible(ps, K"error", TRIVIA_FLAG,
error="space required before `:` in `?` expression")
end
if kind(t) == K":"
if had_colon
bump(ps, TRIVIA_FLAG)
else
# a ? b c ==> (? a b (error-t) c)
bump_invisible(ps, K"error", TRIVIA_FLAG, error="`:` expected in `?` expression")
end
t = peek_token(ps; skip_newlines = true)
if !preceding_whitespace(t)
if had_colon && !preceding_whitespace(t)
# a ? b :c ==> (? a b (error-t) c)
bump_invisible(ps, K"error", TRIVIA_FLAG,
error="space required after `:` in `?` expression")
Expand Down
1 change: 1 addition & 0 deletions test/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ tests = [
"a ? b: c" => "(? a b (error-t) c)"
"a ? b :c" => "(? a b (error-t) c)"
"a ? b c" => "(? a b (error-t) c)"
"a ? b)" => "(? a b (error-t) (error))"
"A[x ? y : end]" => "(ref A (? x y end))"
],
JuliaSyntax.parse_arrow => [
Expand Down
Loading