mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 07:43:26 +00:00
Unicode Operators are no longer experimental (#20444)
* Unicode Operators are no longer experimental * fixes tests * Update doc/manual.md Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
@@ -70,7 +70,7 @@
|
||||
- Removed two type pragma syntaxes deprecated since 0.20, namely
|
||||
`type Foo = object {.final.}`, and `type Foo {.final.} [T] = object`.
|
||||
|
||||
- [Overloadable enums](https://nim-lang.github.io/Nim/manual.html#types-enumeration-types)
|
||||
- [Overloadable enums](https://nim-lang.github.io/Nim/manual.html#overloadable-enum-value-names) and Unicode Operators
|
||||
are no longer experimental.
|
||||
|
||||
- Removed the `nimIncrSeqV3` define.
|
||||
|
||||
@@ -907,7 +907,7 @@ proc getSymbol(L: var Lexer, tok: var Token) =
|
||||
inc(pos)
|
||||
suspicious = true
|
||||
of '\x80'..'\xFF':
|
||||
if c in UnicodeOperatorStartChars and unicodeOperators in L.config.features and unicodeOprLen(L.buf, pos)[0] != 0:
|
||||
if c in UnicodeOperatorStartChars and unicodeOprLen(L.buf, pos)[0] != 0:
|
||||
break
|
||||
else:
|
||||
h = h !& ord(c)
|
||||
@@ -943,7 +943,7 @@ proc getOperator(L: var Lexer, tok: var Token) =
|
||||
if c in OpChars:
|
||||
h = h !& ord(c)
|
||||
inc(pos)
|
||||
elif c in UnicodeOperatorStartChars and unicodeOperators in L.config.features:
|
||||
elif c in UnicodeOperatorStartChars:
|
||||
let oprLen = unicodeOprLen(L.buf, pos)[0]
|
||||
if oprLen == 0: break
|
||||
for i in 0..<oprLen:
|
||||
@@ -1244,7 +1244,7 @@ proc rawGetTok*(L: var Lexer, tok: var Token) =
|
||||
else:
|
||||
case c
|
||||
of UnicodeOperatorStartChars:
|
||||
if unicodeOperators in L.config.features and unicodeOprLen(L.buf, L.bufpos)[0] != 0:
|
||||
if unicodeOprLen(L.buf, L.bufpos)[0] != 0:
|
||||
getOperator(L, tok)
|
||||
else:
|
||||
getSymbol(L, tok)
|
||||
@@ -1355,7 +1355,7 @@ proc rawGetTok*(L: var Lexer, tok: var Token) =
|
||||
getNumber(L, tok)
|
||||
let c = L.buf[L.bufpos]
|
||||
if c in SymChars+{'_'}:
|
||||
if c in UnicodeOperatorStartChars and unicodeOperators in L.config.features and
|
||||
if c in UnicodeOperatorStartChars and
|
||||
unicodeOprLen(L.buf, L.bufpos)[0] != 0:
|
||||
discard
|
||||
else:
|
||||
@@ -1370,7 +1370,7 @@ proc rawGetTok*(L: var Lexer, tok: var Token) =
|
||||
getNumber(L, tok)
|
||||
let c = L.buf[L.bufpos]
|
||||
if c in SymChars+{'_'}:
|
||||
if c in UnicodeOperatorStartChars and unicodeOperators in L.config.features and
|
||||
if c in UnicodeOperatorStartChars and
|
||||
unicodeOprLen(L.buf, L.bufpos)[0] != 0:
|
||||
discard
|
||||
else:
|
||||
|
||||
@@ -213,9 +213,9 @@ type
|
||||
strictFuncs,
|
||||
views,
|
||||
strictNotNil,
|
||||
overloadableEnums, # not experimental anymore
|
||||
overloadableEnums, # deadcode
|
||||
strictEffects,
|
||||
unicodeOperators,
|
||||
unicodeOperators, # deadcode
|
||||
flexibleOptionalParams
|
||||
|
||||
LegacyFeature* = enum
|
||||
|
||||
@@ -695,6 +695,21 @@ are used for other notational purposes.
|
||||
The `not` keyword is always a unary operator, `a not b` is parsed
|
||||
as `a(not b)`, not as `(a) not (b)`.
|
||||
|
||||
Unicode Operators
|
||||
-----------------
|
||||
|
||||
These Unicode operators are also parsed as operators::
|
||||
|
||||
∙ ∘ × ★ ⊗ ⊘ ⊙ ⊛ ⊠ ⊡ ∩ ∧ ⊓ # same priority as * (multiplication)
|
||||
± ⊕ ⊖ ⊞ ⊟ ∪ ∨ ⊔ # same priority as + (addition)
|
||||
|
||||
|
||||
Unicode operators can be combined with non-Unicode operator
|
||||
symbols. The usual precedence extensions then apply, for example, `⊠=` is an
|
||||
assignment like operator just like `*=` is.
|
||||
|
||||
No Unicode normalization step is performed.
|
||||
|
||||
|
||||
Other tokens
|
||||
------------
|
||||
|
||||
@@ -65,27 +65,6 @@ However, a `void` type cannot be inferred in generic code:
|
||||
The `void` type is only valid for parameters and return types; other symbols
|
||||
cannot have the type `void`.
|
||||
|
||||
|
||||
Unicode Operators
|
||||
=================
|
||||
|
||||
Under the `--experimental:unicodeOperators`:option: switch,
|
||||
these Unicode operators are also parsed as operators::
|
||||
|
||||
∙ ∘ × ★ ⊗ ⊘ ⊙ ⊛ ⊠ ⊡ ∩ ∧ ⊓ # same priority as * (multiplication)
|
||||
± ⊕ ⊖ ⊞ ⊟ ∪ ∨ ⊔ # same priority as + (addition)
|
||||
|
||||
|
||||
If enabled, Unicode operators can be combined with non-Unicode operator
|
||||
symbols. The usual precedence extensions then apply, for example, `⊠=` is an
|
||||
assignment like operator just like `*=` is.
|
||||
|
||||
No Unicode normalization step is performed.
|
||||
|
||||
.. note:: Due to parser limitations one **cannot** enable this feature via a
|
||||
pragma `{.experimental: "unicodeOperators".}` reliably.
|
||||
|
||||
|
||||
Top-down type inference
|
||||
=======================
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
--experimental:unicodeOperators
|
||||
Reference in New Issue
Block a user