Skip to content

Commit 8965a81

Browse files
ararslanStefanKarpinski
authored andcommitted
Allow dotted binary tilde (#30351)
The expression `x .~ y` now parses. Currently it's a syntax error.
1 parent 891e2ab commit 8965a81

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ New language features
99
the experimental function `Base.catch_stack` ([#28878]).
1010
* The experimental macro `Base.@locals` returns a dictionary of current local variable names
1111
and values ([#29733]).
12+
* Binary `~` can now be dotted, as in `x .~ y` ([#30341]).
1213

1314
Language changes
1415
----------------

src/julia-parser.scm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
;; be an operator.
99
(define prec-assignment
1010
(append! (add-dots '(= += -= *= /= //= |\\=| ^= ÷= %= <<= >>= >>>= |\|=| &= ⊻= ≔ ⩴ ≕))
11-
'(:= ~ $=)))
11+
(add-dots '(~))
12+
'(:= $=)))
1213
;; comma - higher than assignment outside parentheses, lower when inside
1314
(define prec-pair (add-dots '(=>)))
1415
(define prec-conditional '(?))
@@ -742,7 +743,7 @@
742743
ex
743744
(begin
744745
(take-token s)
745-
(cond ((eq? t '~) ;; ~ is the only non-syntactic assignment-precedence operators
746+
(cond ((or (eq? t '~) (eq? t '|.~|)) ;; ~ is the only non-syntactic assignment-precedence operators
746747
(if (and space-sensitive (ts:space? s)
747748
(not (space-before-next-token? s)))
748749
(begin (ts:put-back! s t (ts:space? s))

test/parse.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,9 @@ end
332332
@test_throws ArgumentError parse(Bool, "2")
333333
@test_throws ArgumentError parse(Bool, "02")
334334
end
335+
336+
@testset "issue #30341" begin
337+
@test Meta.parse("x .~ y") == Expr(:call, :.~, :x, :y)
338+
# Ensure dotting binary doesn't break dotting unary
339+
@test Meta.parse(".~[1,2]") == Expr(:call, :.~, Expr(:vect, 1, 2))
340+
end

0 commit comments

Comments
 (0)