Skip to content

Commit

Permalink
Allow dotted binary tilde (JuliaLang#30351)
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 authored and StefanKarpinski committed Dec 12, 2018
1 parent 891e2ab commit 8965a81
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
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
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -742,7 +743,7 @@
ex
(begin
(take-token s)
(cond ((eq? t '~) ;; ~ is the only non-syntactic assignment-precedence operators
(cond ((or (eq? t '~) (eq? t '|.~|)) ;; ~ is the only non-syntactic assignment-precedence operators
(if (and space-sensitive (ts:space? s)
(not (space-before-next-token? s)))
(begin (ts:put-back! s t (ts:space? s))
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(:call, :.~, :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 8965a81

Please sign in to comment.