Skip to content

Commit

Permalink
allow ± and ∓ as unary operators (#34200)
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonschaub authored and KristofferC committed Apr 11, 2020
1 parent 8f93ded commit e81635a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <kbd>TAB</kbd> ([#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
----------------

Expand Down
5 changes: 3 additions & 2 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
5 changes: 5 additions & 0 deletions test/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e81635a

Please sign in to comment.