Skip to content

Commit

Permalink
make \minus equivalent to - operator #26193 (#40948)
Browse files Browse the repository at this point in the history
* make \minus equivalent to - operator #26193
  • Loading branch information
epithet authored May 27, 2021
1 parent 7edd190 commit 3cdf6a3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Language changes

* `macroexpand`, `@macroexpand`, and `@macroexpand1` no longer wrap errors in a `LoadError`. To reduce breakage, `@test_throws` has been modified so that many affected tests will still pass ([#38379]].
* The middle dot `·` (`\cdotp` U+00b7) and the Greek interpunct `·` (U+0387) are now treated as equivalent to the dot operator `` (`\cdot` U+22c5) (#25157).
* The minus sign `` (`\minus` U+2212) is now treated as equivalent to the hyphen-minus sign `-` (U+002d).

Compiler/Runtime improvements
-----------------------------
Expand Down
1 change: 1 addition & 0 deletions doc/src/manual/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ are treated as equivalent to the corresponding Greek letters. The middle dot
`·` (U+00B7) and the Greek
[interpunct](https://en.wikipedia.org/wiki/Interpunct) `·` (U+0387) are both
treated as the mathematical dot operator `` (U+22C5).
The minus sign `` (U+2212) is treated as equivalent to the hyphen-minus sign `-` (U+002D).

## Stylistic Conventions

Expand Down
1 change: 1 addition & 0 deletions src/flisp/julia_charmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ static const uint32_t charmap[][2] = {
{ 0x00B5, 0x03BC }, // micro sign -> greek small letter mu
{ 0x00B7, 0x22C5 }, // middot char -> dot operator (#25098)
{ 0x0387, 0x22C5 }, // Greek interpunct -> dot operator (#25098)
{ 0x2212, 0x002D }, // minus -> hyphen-minus (#26193)
};
14 changes: 9 additions & 5 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(define (add-dots ops) (append! ops (map (lambda (op) (symbol (string "." op))) ops)))

(define prec-assignment
(append! (add-dots '(= += -= *= /= //= |\\=| ^= ÷= %= <<= >>= >>>= |\|=| &= ⊻= ≔ ⩴ ≕))
(append! (add-dots '(= += -= −= *= /= //= |\\=| ^= ÷= %= <<= >>= >>>= |\|=| &= ⊻= ≔ ⩴ ≕))
(add-dots '(~))
'(:= $=)))
;; comma - higher than assignment outside parentheses, lower when inside
Expand All @@ -20,7 +20,7 @@
(define prec-pipe> '(|.\|>| |\|>|))
(define prec-colon (append! '(: |..|) (add-dots '(… ⁝ ⋮ ⋱ ⋰ ⋯))))
(define prec-plus (append! '($)
(add-dots '(+ - ¦ |\|| ⊕ ⊖ ⊞ ⊟ |++| ∪ ∨ ⊔ ± ∓ ∔ ∸ ≏ ⊎ ⊻ ⊽ ⋎ ⋓ ⧺ ⧻ ⨈ ⨢ ⨣ ⨤ ⨥ ⨦ ⨧ ⨨ ⨩ ⨪ ⨫ ⨬ ⨭ ⨮ ⨹ ⨺ ⩁ ⩂ ⩅ ⩊ ⩌ ⩏ ⩐ ⩒ ⩔ ⩖ ⩗ ⩛ ⩝ ⩡ ⩢ ⩣))))
(add-dots '(+ - ¦ |\|| ⊕ ⊖ ⊞ ⊟ |++| ∪ ∨ ⊔ ± ∓ ∔ ∸ ≏ ⊎ ⊻ ⊽ ⋎ ⋓ ⧺ ⧻ ⨈ ⨢ ⨣ ⨤ ⨥ ⨦ ⨧ ⨨ ⨩ ⨪ ⨫ ⨬ ⨭ ⨮ ⨹ ⨺ ⩁ ⩂ ⩅ ⩊ ⩌ ⩏ ⩐ ⩒ ⩔ ⩖ ⩗ ⩛ ⩝ ⩡ ⩢ ⩣))))
(define prec-times (add-dots '(* / ⌿ ÷ % & · · ⋅ ∘ × |\\| ∩ ∧ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ ⊓ ∗ ∙ ∤ ⅋ ≀ ⊼ ⋄ ⋆ ⋇ ⋉ ⋊ ⋋ ⋌ ⋏ ⋒ ⟑ ⦸ ⦼ ⦾ ⦿ ⧶ ⧷ ⨇ ⨰ ⨱ ⨲ ⨳ ⨴ ⨵ ⨶ ⨷ ⨸ ⨻ ⨼ ⨽ ⩀ ⩃ ⩄ ⩋ ⩍ ⩎ ⩑ ⩓ ⩕ ⩘ ⩚ ⩜ ⩞ ⩟ ⩠ ⫛ ⊍ ▷ ⨝ ⟕ ⟖ ⟗ ⨟)))
(define prec-rational (add-dots '(//)))
(define prec-bitshift (add-dots '(<< >> >>>)))
Expand Down Expand Up @@ -377,13 +377,17 @@
(and (eq? pred char-hex?) ispP)
(memv c '(#\e #\E #\f)))
(begin (read-char port)
(let ((d (peek-char port)))
(let* ((d (peek-char port))
(is-minus-sign (or (eqv? d #\-) (eqv? d #\u2212))))
(if (and (not (eof-object? d))
(or (char-numeric? d) (eqv? d #\+) (eqv? d #\-)))
(or (char-numeric? d) (eqv? d #\+) is-minus-sign))
(begin (set! is-float32-literal (eqv? c #\f))
(set! is-hex-float-literal ispP)
(write-char c str)
(write-char (read-char port) str)
(if is-minus-sign
(begin (read-char port)
(write-char #\- str))
(write-char (read-char port) str))
(read-digs #t #f)
(disallow-dot))
(io.ungetc port c)))))
Expand Down
13 changes: 12 additions & 1 deletion test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ let f = function (x; kw...)
end

# normalization of Unicode symbols (#19464)
let ε=1, μ=2, x=3, î=4, =5
let ε=1, μ=2, x=3, î=4, =5, (-)=6
# issue #5434 (mu vs micro):
@test Meta.parse("\u00b5") === Meta.parse("\u03bc")
@test µ == μ == 2
Expand All @@ -832,6 +832,17 @@ let ε=1, μ=2, x=3, î=4, ⋅=5
# middot char · or · vs math dot operator ⋅ (#25098)
@test Meta.parse("\u00b7") === Meta.parse("\u0387") === Meta.parse("\u22c5")
@test (·) == (·) == () == 5
# minus − vs hyphen-minus - (#26193)
@test Meta.parse("\u2212") === Meta.parse("-")
@test Meta.parse("\u221242") === Meta.parse("-42")
@test Meta.parse("\u2212 42") == Meta.parse("- 42")
@test Meta.parse("\u2212x") == Meta.parse("-x")
@test Meta.parse("x \u2212 42") == Meta.parse("x - 42")
@test Meta.parse("x \u2212= 42") == Meta.parse("x -= 42")
@test Meta.parse("100.0e\u22122") === Meta.parse("100.0E\u22122") === Meta.parse("100.0e-2")
@test Meta.parse("100.0f\u22122") === Meta.parse("100.0f-2")
@test Meta.parse("0x100p\u22128") === Meta.parse("0x100P\u22128") === Meta.parse("0x100p-8")
@test () == (-) == 6
end

# issue #8925
Expand Down

0 comments on commit 3cdf6a3

Please sign in to comment.