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
9 changes: 5 additions & 4 deletions JuliaSyntax/src/julia/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ function parse_assignment_with_initial_ex(ps::ParseState, mark, down::T) where {
# is_short_form_func is true, to prevent `f() = 1 = 2` from parsing.
parse_assignment(ps, down)
emit(ps, mark,
is_short_form_func ? K"function" : (isdot ? dotted(k) : k),
is_short_form_func ? K"function" : (isdot ? dotted(ps, k) : k),
is_short_form_func ? SHORT_FORM_FUNCTION_FLAG : flags(t))
end
end
Expand Down Expand Up @@ -750,7 +750,7 @@ function parse_arrow(ps::ParseState)
end
end

function dotted(k)
function dotted(ps::ParseState, k)
if k == K"||"
return K".||"
elseif k == K"&&"
Expand All @@ -760,7 +760,8 @@ function dotted(k)
elseif k == K"op="
return K".op="
else
error("Unexpected dotted operator: $k")
emit_diagnostic(ps, error = "Operator is invalid for broadcasting")
return K"error"
end
end

Expand All @@ -773,7 +774,7 @@ function parse_lazy_cond(ps::ParseState, down, is_op, self)
if is_op(k)
bump_dotted(ps, isdot, TRIVIA_FLAG)
self(ps)
emit(ps, mark, isdot ? dotted(k) : k, flags(t))
emit(ps, mark, isdot ? dotted(ps, k) : k, flags(t))
if isdot
min_supported_version(v"1.7", ps, mark, "dotted operators `.||` and `.&&`")
end
Expand Down
7 changes: 7 additions & 0 deletions JuliaSyntax/test/parser_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@
@test parseshow("'abc'", ignore_errors=true) == "(char (ErrorOverLongCharacter))"
@test parseshow("1e1000", ignore_errors=true) == "(ErrorNumericOverflow)"
@test parseshow("1f1000", ignore_errors=true) == "(ErrorNumericOverflow)"
@testset "raise = false with invalid dotted operators" begin
result = Meta.parse("a .:= b"; raise = false)
@test Meta.isexpr(result, :error)

result2 = Meta.parse("a .= b"; raise = false)
@test result2 == :(a .= b)
end
end
end

Expand Down