From e81635aa0743104f061fad529aab0d313a6ab5e4 Mon Sep 17 00:00:00 2001 From: simeonschaub Date: Tue, 10 Mar 2020 13:13:59 +0100 Subject: [PATCH] =?UTF-8?q?allow=20=C2=B1=20and=20=E2=88=93=20as=20unary?= =?UTF-8?q?=20operators=20(#34200)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NEWS.md | 4 ++++ src/julia-parser.scm | 5 +++-- test/parse.jl | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 88c87e4ec90b17..60df17954b41d7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,10 @@ New language features * `⨟` is now parsed as a binary operator with times precedence. It can be entered in the REPL with `\bbsemi` followed by TAB ([#34722]). +* `±` and `∓` are now unary operators as well, like `+` or `-`. Attention has to be paid in + macros and matrix constructors, which are whitespace sensitive, because expressions like + `[a ±b]` now get parsed as `[a ±(b)]` instead of `[±(a, b)]`. ([#34200]) + Language changes ---------------- diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 2caac49087d618..7dd18c401070b6 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -102,12 +102,13 @@ 0)) (define unary-ops (append! '(|<:| |>:|) - (add-dots '(+ - ! ~ ¬ √ ∛ ∜ ⋆)))) + (add-dots '(+ - ! ~ ¬ √ ∛ ∜ ⋆ ± ∓)))) (define unary-op? (Set unary-ops)) ; operators that are both unary and binary -(define unary-and-binary-ops '(+ - $ & ~ ⋆ |.+| |.-| |.⋆|)) +(define unary-and-binary-ops (append! '($ & ~) + (add-dots '(+ - ⋆ ± ∓)))) (define unary-and-binary-op? (Set unary-and-binary-ops)) diff --git a/test/parse.jl b/test/parse.jl index 2deeecd516f2a7..93946b603ba019 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -310,3 +310,8 @@ end @test isequal(parse(Float64, s), sign(v)) end end + +@testset "unary ± and ∓" begin + @test Meta.parse("±x") == Expr(:call, :±, :x) + @test Meta.parse("∓x") == Expr(:call, :∓, :x) +end