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:
parent
65c2518d5c
commit
a8cc5d1379
6 changed files with 23 additions and 30 deletions
|
|
@ -70,7 +70,7 @@
|
||||||
- Removed two type pragma syntaxes deprecated since 0.20, namely
|
- Removed two type pragma syntaxes deprecated since 0.20, namely
|
||||||
`type Foo = object {.final.}`, and `type Foo {.final.} [T] = object`.
|
`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.
|
are no longer experimental.
|
||||||
|
|
||||||
- Removed the `nimIncrSeqV3` define.
|
- Removed the `nimIncrSeqV3` define.
|
||||||
|
|
|
||||||
|
|
@ -907,7 +907,7 @@ proc getSymbol(L: var Lexer, tok: var Token) =
|
||||||
inc(pos)
|
inc(pos)
|
||||||
suspicious = true
|
suspicious = true
|
||||||
of '\x80'..'\xFF':
|
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
|
break
|
||||||
else:
|
else:
|
||||||
h = h !& ord(c)
|
h = h !& ord(c)
|
||||||
|
|
@ -943,7 +943,7 @@ proc getOperator(L: var Lexer, tok: var Token) =
|
||||||
if c in OpChars:
|
if c in OpChars:
|
||||||
h = h !& ord(c)
|
h = h !& ord(c)
|
||||||
inc(pos)
|
inc(pos)
|
||||||
elif c in UnicodeOperatorStartChars and unicodeOperators in L.config.features:
|
elif c in UnicodeOperatorStartChars:
|
||||||
let oprLen = unicodeOprLen(L.buf, pos)[0]
|
let oprLen = unicodeOprLen(L.buf, pos)[0]
|
||||||
if oprLen == 0: break
|
if oprLen == 0: break
|
||||||
for i in 0..<oprLen:
|
for i in 0..<oprLen:
|
||||||
|
|
@ -1244,7 +1244,7 @@ proc rawGetTok*(L: var Lexer, tok: var Token) =
|
||||||
else:
|
else:
|
||||||
case c
|
case c
|
||||||
of UnicodeOperatorStartChars:
|
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)
|
getOperator(L, tok)
|
||||||
else:
|
else:
|
||||||
getSymbol(L, tok)
|
getSymbol(L, tok)
|
||||||
|
|
@ -1355,7 +1355,7 @@ proc rawGetTok*(L: var Lexer, tok: var Token) =
|
||||||
getNumber(L, tok)
|
getNumber(L, tok)
|
||||||
let c = L.buf[L.bufpos]
|
let c = L.buf[L.bufpos]
|
||||||
if c in SymChars+{'_'}:
|
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:
|
unicodeOprLen(L.buf, L.bufpos)[0] != 0:
|
||||||
discard
|
discard
|
||||||
else:
|
else:
|
||||||
|
|
@ -1370,7 +1370,7 @@ proc rawGetTok*(L: var Lexer, tok: var Token) =
|
||||||
getNumber(L, tok)
|
getNumber(L, tok)
|
||||||
let c = L.buf[L.bufpos]
|
let c = L.buf[L.bufpos]
|
||||||
if c in SymChars+{'_'}:
|
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:
|
unicodeOprLen(L.buf, L.bufpos)[0] != 0:
|
||||||
discard
|
discard
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -213,9 +213,9 @@ type
|
||||||
strictFuncs,
|
strictFuncs,
|
||||||
views,
|
views,
|
||||||
strictNotNil,
|
strictNotNil,
|
||||||
overloadableEnums, # not experimental anymore
|
overloadableEnums, # deadcode
|
||||||
strictEffects,
|
strictEffects,
|
||||||
unicodeOperators,
|
unicodeOperators, # deadcode
|
||||||
flexibleOptionalParams
|
flexibleOptionalParams
|
||||||
|
|
||||||
LegacyFeature* = enum
|
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
|
The `not` keyword is always a unary operator, `a not b` is parsed
|
||||||
as `a(not b)`, not as `(a) not (b)`.
|
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
|
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
|
The `void` type is only valid for parameters and return types; other symbols
|
||||||
cannot have the type `void`.
|
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
|
Top-down type inference
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
--experimental:unicodeOperators
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue