diff --git a/NEWS.md b/NEWS.md index 27074440b3b49..f36e8bff553d0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 ----------------------------- diff --git a/doc/src/manual/variables.md b/doc/src/manual/variables.md index 4461ee5c32afe..004efb92dc0e5 100644 --- a/doc/src/manual/variables.md +++ b/doc/src/manual/variables.md @@ -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 diff --git a/src/flisp/julia_charmap.h b/src/flisp/julia_charmap.h index 7384df0c7f506..59f408ce012c9 100644 --- a/src/flisp/julia_charmap.h +++ b/src/flisp/julia_charmap.h @@ -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) }; diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 1f594ff0a1414..f68e0d2c4ebb5 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -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 @@ -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 '(<< >> >>>))) @@ -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))))) diff --git a/test/syntax.jl b/test/syntax.jl index d7e136f92dfcc..5771fcee00e6c 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -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 @@ -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