Skip to content

Commit dcb7f37

Browse files
committed
allow identifiers to start with category No (Number, other)
1 parent 9a239ec commit dcb7f37

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ New language features
4646

4747
* Keyword arguments can be required: if a default value is omitted, then an
4848
exception is thrown if the caller does not assign the keyword a value ([#25830]).
49+
50+
* Identifiers can now start with numeric symbols in category
51+
[No: Number, other](http://www.fileformat.info/info/unicode/category/No/list.htm),
52+
allowing you to have variables with names like `⅓x` or `¹x₂` ([#20278]).
4953

5054
Language changes
5155
----------------

doc/src/manual/variables.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ ERROR: cannot assign variable Base.sqrt from module Main
9494

9595
Variable names must begin with a letter (A-Z or a-z), underscore, or a subset of Unicode code
9696
points greater than 00A0; in particular, [Unicode character categories](http://www.fileformat.info/info/unicode/category/index.htm)
97-
Lu/Ll/Lt/Lm/Lo/Nl (letters), Sc/So (currency and other symbols), and a few other letter-like characters
97+
Lu/Ll/Lt/Lm/Lo/Nl/No (letters and certain numeric symbols), Sc/So (currency and other symbols), and a few other letter-like characters
9898
(e.g. a subset of the Sm math symbols) are allowed. Subsequent characters may also include ! and
99-
digits (0-9 and other characters in categories Nd/No), as well as other Unicode code points: diacritics
99+
digits (0-9 and other decimal digits in category Nd), as well as other Unicode code points: diacritics
100100
and other modifying marks (categories Mn/Mc/Me/Sk), some punctuation connectors (category Pc),
101101
primes, and a few other characters.
102102

src/flisp/julia_extensions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ static int is_wc_cat_id_start(uint32_t wc, utf8proc_category_t cat)
6060
{
6161
return (cat == UTF8PROC_CATEGORY_LU || cat == UTF8PROC_CATEGORY_LL ||
6262
cat == UTF8PROC_CATEGORY_LT || cat == UTF8PROC_CATEGORY_LM ||
63-
cat == UTF8PROC_CATEGORY_LO || cat == UTF8PROC_CATEGORY_NL ||
63+
cat == UTF8PROC_CATEGORY_LO ||
64+
cat == UTF8PROC_CATEGORY_NL || cat == UTF8PROC_CATEGORY_NO ||
6465
cat == UTF8PROC_CATEGORY_SC || // allow currency symbols
6566
// other symbols, but not arrows
6667
(cat == UTF8PROC_CATEGORY_SO && !(wc >= 0x2190 && wc <= 0x21FF)) ||
@@ -131,7 +132,6 @@ JL_DLLEXPORT int jl_id_char(uint32_t wc)
131132
if (cat == UTF8PROC_CATEGORY_MN || cat == UTF8PROC_CATEGORY_MC ||
132133
cat == UTF8PROC_CATEGORY_ND || cat == UTF8PROC_CATEGORY_PC ||
133134
cat == UTF8PROC_CATEGORY_SK || cat == UTF8PROC_CATEGORY_ME ||
134-
cat == UTF8PROC_CATEGORY_NO ||
135135
// primes (single, double, triple, their reverses, and quadruple)
136136
(wc >= 0x2032 && wc <= 0x2037) || (wc == 0x2057) ||
137137
// Other_ID_Continue

test/parse.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ end
255255
@test_throws ArgumentError parse(Complex{Int}, "3 + 4.2im")
256256
end
257257

258+
# identifiers starting with category No:
259+
let ½x = 1/2, ¹x = 12
260+
@test ½x === 1/2
261+
@test ¹x === 12
262+
end
263+
258264
# added ⟂ to operator precedence (#24404)
259265
@test Meta.parse("a ⟂ b ⟂ c") == Expr(:comparison, :a, :, :b, :, :c)
260266
@test Meta.parse("a ⟂ b ∥ c") == Expr(:comparison, :a, :, :b, :, :c)

0 commit comments

Comments
 (0)