From 202e39fa7ebbae90504ebe89416d3a556a7b50d0 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 11 Dec 2018 10:33:31 -0800 Subject: [PATCH] Allow dotted binary tilde The expression `x .~ y` now parses. Currently it's a syntax error. --- NEWS.md | 1 + src/julia-parser.scm | 5 +++-- test/parse.jl | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8ec6cf567e752..9fb48d3a00af9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 ---------------- diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 8cd3564f7869d..37e6a24dde122 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -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 '(?)) @@ -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)) diff --git a/test/parse.jl b/test/parse.jl index 00d6ced46a26c..45e13a95b7f90 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -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