Changing the rule for arrow like operators again.

This commit is contained in:
ReneSac
2015-04-10 23:59:17 -03:00
parent d71f1b98e0
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]
# 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) =

View File

@@ -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

View File

@@ -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

View File

@@ -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