Skip to content

Commit

Permalink
Allow dotted binary tilde
Browse files Browse the repository at this point in the history
The expression `x .~ y` now parses. Currently it's a syntax error.
  • Loading branch information
ararslan committed Dec 11, 2018
1 parent 5b2e3e7 commit 423543a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ New language features
the experimental function `Base.catch_stack` ([#28878]).
* The experimental macro `Base.@locals` returns a dictionary of current local variable names
and values ([#29733]).
* Binary `~` can now be dotted, as in `x .~ y` ([#30341]).

Language changes
----------------
Expand Down
3 changes: 2 additions & 1 deletion src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
;; be an operator.
(define prec-assignment
(append! (add-dots '(= += -= *= /= //= |\\=| ^= ÷= %= <<= >>= >>>= |\|=| &= ⊻= ≔ ⩴ ≕))
'(:= ~ $=)))
(add-dots '(~))
'(:= $=)))
;; comma - higher than assignment outside parentheses, lower when inside
(define prec-pair (add-dots '(=>)))
(define prec-conditional '(?))
Expand Down
6 changes: 6 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,9 @@ end
@test_throws ArgumentError parse(Bool, "2")
@test_throws ArgumentError parse(Bool, "02")
end

@testset "issue #30341" begin
@test Meta.parse("x .~ y") == Expr(:.~, :x, :y)
# Ensure dotting binary doesn't break dotting unary
@test Meta.parse(".~[1,2]") == Expr(:call, :.~, Expr(:vect, 1, 2))
end

0 comments on commit 423543a

Please sign in to comment.