Skip to content

Commit

Permalink
make \cdot and \cdotp equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Aug 5, 2020
1 parent 371bfa8 commit bea33a1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion doc/src/manual/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ Different ways of entering Unicode combining characters (e.g., accents)
are treated as equivalent (specifically, Julia identifiers are [NFC](http://www.macchiato.com/unicode/nfc-faq)-normalized).
The Unicode characters `ɛ` (U+025B: Latin small letter open e)
and `µ` (U+00B5: micro sign) are treated as equivalent to the corresponding
Greek letters, because the former are easily accessible via some input methods.
Greek letters, and the [interpunct](https://en.wikipedia.org/wiki/Interpunct) mark `·` (U+00B7: Middle dot) is treated as the mathematical
dot operator (U+22C5: ``), because the former are easily accessible via some input methods.

## 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 @@ -4,4 +4,5 @@
static const uint32_t charmap[][2] = {
{ 0x025B, 0x03B5 }, // latin small letter open e -> greek small letter epsilon
{ 0x00B5, 0x03BC }, // micro sign -> greek small letter mu
{ 0x00B7, 0x22C5 }, // middot char -> dot operator (#25098)
};
10 changes: 10 additions & 0 deletions src/flisp/julia_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,15 @@ value_t fl_accum_julia_symbol(fl_context_t *fl_ctx, value_t *args, uint32_t narg
return symbol(fl_ctx, allascii ? str.buf : normalize(fl_ctx, str.buf));
}

/* convert a string to a symbol, first applying normalization */
value_t fl_string2normsymbol(fl_context_t *fl_ctx, value_t *args, uint32_t nargs)
{
argcount(fl_ctx, "string->normsymbol", nargs, 1);
if (!fl_isstring(fl_ctx, args[0]))
type_error(fl_ctx, "string->normsymbol", "string", args[0]);
return symbol(fl_ctx, normalize(fl_ctx, (char*)cvalue_data(args[0])));
}

static const builtinspec_t julia_flisp_func_info[] = {
{ "skip-ws", fl_skipws },
{ "accum-julia-symbol", fl_accum_julia_symbol },
Expand All @@ -357,6 +366,7 @@ static const builtinspec_t julia_flisp_func_info[] = {
{ "op-suffix-char?", fl_julia_op_suffix_char },
{ "strip-op-suffix", fl_julia_strip_op_suffix },
{ "underscore-symbol?", fl_julia_underscore_symbolp },
{ "string->normsymbol", fl_string2normsymbol },
{ NULL, NULL }
};

Expand Down
6 changes: 3 additions & 3 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
(define prec-colon (append! '(: |..|) (add-dots '(… ⁝ ⋮ ⋱ ⋰ ⋯))))
(define prec-plus (append! '($)
(add-dots '(+ - |\|| ⊕ ⊖ ⊞ ⊟ |++| ∪ ∨ ⊔ ± ∓ ∔ ∸ ≏ ⊎ ⊻ ⊽ ⋎ ⋓ ⧺ ⧻ ⨈ ⨢ ⨣ ⨤ ⨥ ⨦ ⨧ ⨨ ⨩ ⨪ ⨫ ⨬ ⨭ ⨮ ⨹ ⨺ ⩁ ⩂ ⩅ ⩊ ⩌ ⩏ ⩐ ⩒ ⩔ ⩖ ⩗ ⩛ ⩝ ⩡ ⩢ ⩣))))
(define prec-times (add-dots '(* / ÷ % & ⋅ ∘ × |\\| ∩ ∧ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ ⊓ ∗ ∙ ∤ ⅋ ≀ ⊼ ⋄ ⋆ ⋇ ⋉ ⋊ ⋋ ⋌ ⋏ ⋒ ⟑ ⦸ ⦼ ⦾ ⦿ ⧶ ⧷ ⨇ ⨰ ⨱ ⨲ ⨳ ⨴ ⨵ ⨶ ⨷ ⨸ ⨻ ⨼ ⨽ ⩀ ⩃ ⩄ ⩋ ⩍ ⩎ ⩑ ⩓ ⩕ ⩘ ⩚ ⩜ ⩞ ⩟ ⩠ ⫛ ⊍ ▷ ⨝ ⟕ ⟖ ⟗ ⨟)))
(define prec-times (add-dots '(* / ÷ % & ⋅ · ∘ × |\\| ∩ ∧ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ ⊓ ∗ ∙ ∤ ⅋ ≀ ⊼ ⋄ ⋆ ⋇ ⋉ ⋊ ⋋ ⋌ ⋏ ⋒ ⟑ ⦸ ⦼ ⦾ ⦿ ⧶ ⧷ ⨇ ⨰ ⨱ ⨲ ⨳ ⨴ ⨵ ⨶ ⨷ ⨸ ⨻ ⨼ ⨽ ⩀ ⩃ ⩄ ⩋ ⩍ ⩎ ⩑ ⩓ ⩕ ⩘ ⩚ ⩜ ⩞ ⩟ ⩠ ⫛ ⊍ ▷ ⨝ ⟕ ⟖ ⟗ ⨟)))
(define prec-rational (add-dots '(//)))
(define prec-bitshift (add-dots '(<< >> >>>)))
;; `where`
Expand Down Expand Up @@ -232,7 +232,7 @@
(if (and (eqv? c #\*) (eqv? (peek-char port) #\*))
(error "use \"x^y\" instead of \"x**y\" for exponentiation, and \"x...\" instead of \"**x\" for splatting."))
(if (or (eof-object? (peek-char port)) (not (op-or-sufchar? (peek-char port))))
(symbol (string c)) ; 1-char operator
(string->normsymbol (string c)) ; 1-char operator
(let ((str (let loop ((str (string c))
(c (peek-char port))
(in-suffix? #f))
Expand Down Expand Up @@ -262,7 +262,7 @@
(loop newop (peek-char port) sufchar?))
str))
str))))))
(string->symbol str))))
(string->normsymbol str))))

(define (accum-digits c pred port _-digit-sep)
(let loop ((str '())
Expand Down
5 changes: 4 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
let ε=1, μ=2, x=3, î=4, =5
# issue #5434 (mu vs micro):
@test Meta.parse("\u00b5") === Meta.parse("\u03bc")
@test µ == μ == 2
Expand All @@ -829,6 +829,9 @@ let ε=1, μ=2, x=3, î=4
# latin vs greek ε (#14751)
@test Meta.parse("\u025B") === Meta.parse("\u03B5")
@test ɛ == ε == 1
# middot char · vs math dot operator ⋅ (#25098)
@test Meta.parse("\u00b7") === Meta.parse("\u22c5")
@test (·) == () == 5
end

# issue #8925
Expand Down

0 comments on commit bea33a1

Please sign in to comment.