Changing the rule for arrow like operators again.

This commit is contained in:
ReneSac 2015-04-10 23:59:17 -03:00
commit 34997292f4
4 changed files with 12 additions and 12 deletions

View file

@ -212,7 +212,7 @@ proc getPrecedence(tok: TToken, strongSpaces: bool): int =
let relevantChar = tok.ident.s[0] let relevantChar = tok.ident.s[0]
# arrow like? # 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) return considerStrongSpaces(1)
template considerAsgn(value: expr) = template considerAsgn(value: expr) =

View file

@ -15,8 +15,8 @@ Associativity
Binary operators whose first character is ``^`` are right-associative, all Binary operators whose first character is ``^`` are right-associative, all
other binary operators are left-associative. other binary operators are left-associative.
Operators whose the first character is either ``-`` or ``=`` and the last Operators ending in either ``->``, ``~>`` or ``=>`` are called
character is ``>`` are called `arrow like`:idx:. `arrow like`:idx:.
Precedence Precedence

View file

@ -73,11 +73,11 @@ echo "all" | tester & " " & args
echo "all"|tester & " " & args echo "all"|tester & " " & args
# Test arrow like operators. See also tests/macros/tclosuremacro.nim # 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 template `===>`(a, b: int): expr = a - b shr 1
echo 3 -+> 2 + 2 and 4 echo 3 +-> 2 + 2 and 4
var arrowed = 3-+>2 + 2 and 4 # arrowed = 4 var arrowed = 3+->2 + 2 and 4 # arrowed = 4
echo arrowed ===> 15 echo arrowed ===> 15
echo (2 * 3-+>2) == (2*3 -+> 2) echo (2 * 3+->2) == (2*3 +-> 2)
echo arrowed ===> 2 + 3-+>2 echo arrowed ===> 2 + 3+->2

View file

@ -34,10 +34,10 @@ News
should be used instead. should be used instead.
- ``nim idetools`` has been replaced by a separate tool `nimsuggest`_. - ``nim idetools`` has been replaced by a separate tool `nimsuggest`_.
- *arrow like* operators are not right associative anymore. - *arrow like* operators are not right associative anymore.
- *arrow like* operators are now required to start with ``=`` or ``-`` in - *arrow like* operators are now required end with either ``->``, ``~>`` or
addition to end with ``>``. Examples of arrow like operators that continue ``=>``, not just ``>``. Examples of operators still considered arrow like:
to work are: ``->``, ``==>``, ``=+>``. On the other hand, the following ``->``, ``==>``, ``+=>``. On the other hand, the following operators are now
operators are now considered regular operators: ``|>``, ``+->``, etc. considered regular operators again: ``|>``, ``-+>``, etc.
- Typeless parameters are now only allowed in templates and macros. The old - Typeless parameters are now only allowed in templates and macros. The old
way turned out to be too error-prone. way turned out to be too error-prone.
- The 'addr' and 'type' operators are now parsed as unary function - The 'addr' and 'type' operators are now parsed as unary function