Skip to content

Commit

Permalink
Unicode Operators are no longer experimental (nim-lang#20444)
Browse files Browse the repository at this point in the history
* Unicode Operators are no longer experimental

* fixes tests

* Update doc/manual.md

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
  • Loading branch information
2 people authored and capocasa committed Mar 31, 2023
1 parent e36bc31 commit 7147f18
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 30 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions compiler/lexer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ type
strictFuncs,
views,
strictNotNil,
overloadableEnums, # not experimental anymore
overloadableEnums, # deadcode
strictEffects,
unicodeOperators,
unicodeOperators, # deadcode
flexibleOptionalParams

LegacyFeature* = enum
Expand Down
15 changes: 15 additions & 0 deletions doc/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand Down
21 changes: 0 additions & 21 deletions doc/manual_experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======================

Expand Down
1 change: 0 additions & 1 deletion tests/lexer/nim.cfg

This file was deleted.

0 comments on commit 7147f18

Please sign in to comment.