Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow ± and ∓ as unary operators #34200

Merged
merged 3 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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