mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-09 21:28:13 +00:00
Changing the rule for arrow like operators again.
This commit is contained in:
@@ -212,7 +212,7 @@ proc getPrecedence(tok: TToken, strongSpaces: bool): int =
|
||||
let relevantChar = tok.ident.s[0]
|
||||
|
||||
# arrow like?
|
||||
if L > 1 and tok.ident.s[L-1] == '>' and tok.ident.s[0] in {'-', '='}:
|
||||
if L > 1 and tok.ident.s[^1] == '>' and tok.ident.s[^2] in {'-', '~', '='}:
|
||||
return considerStrongSpaces(1)
|
||||
|
||||
template considerAsgn(value: expr) =
|
||||
|
||||
@@ -15,8 +15,8 @@ Associativity
|
||||
Binary operators whose first character is ``^`` are right-associative, all
|
||||
other binary operators are left-associative.
|
||||
|
||||
Operators whose the first character is either ``-`` or ``=`` and the last
|
||||
character is ``>`` are called `arrow like`:idx:.
|
||||
Operators ending in either ``->``, ``~>`` or ``=>`` are called
|
||||
`arrow like`:idx:.
|
||||
|
||||
|
||||
Precedence
|
||||
|
||||
@@ -73,11 +73,11 @@ echo "all" | tester & " " & args
|
||||
echo "all"|tester & " " & args
|
||||
|
||||
# Test arrow like operators. See also tests/macros/tclosuremacro.nim
|
||||
proc `-+>`(a, b: int): int = a + b*4
|
||||
proc `+->`(a, b: int): int = a + b*4
|
||||
template `===>`(a, b: int): expr = a - b shr 1
|
||||
|
||||
echo 3 -+> 2 + 2 and 4
|
||||
var arrowed = 3-+>2 + 2 and 4 # arrowed = 4
|
||||
echo 3 +-> 2 + 2 and 4
|
||||
var arrowed = 3+->2 + 2 and 4 # arrowed = 4
|
||||
echo arrowed ===> 15
|
||||
echo (2 * 3-+>2) == (2*3 -+> 2)
|
||||
echo arrowed ===> 2 + 3-+>2
|
||||
echo (2 * 3+->2) == (2*3 +-> 2)
|
||||
echo arrowed ===> 2 + 3+->2
|
||||
|
||||
@@ -34,10 +34,10 @@ News
|
||||
should be used instead.
|
||||
- ``nim idetools`` has been replaced by a separate tool `nimsuggest`_.
|
||||
- *arrow like* operators are not right associative anymore.
|
||||
- *arrow like* operators are now required to start with ``=`` or ``-`` in
|
||||
addition to end with ``>``. Examples of arrow like operators that continue
|
||||
to work are: ``->``, ``==>``, ``=+>``. On the other hand, the following
|
||||
operators are now considered regular operators: ``|>``, ``+->``, etc.
|
||||
- *arrow like* operators are now required end with either ``->``, ``~>`` or
|
||||
``=>``, not just ``>``. Examples of operators still considered arrow like:
|
||||
``->``, ``==>``, ``+=>``. On the other hand, the following operators are now
|
||||
considered regular operators again: ``|>``, ``-+>``, etc.
|
||||
- Typeless parameters are now only allowed in templates and macros. The old
|
||||
way turned out to be too error-prone.
|
||||
- The 'addr' and 'type' operators are now parsed as unary function
|
||||
|
||||
Reference in New Issue
Block a user