From 34997292f48d40e8ed49d84c999b6d32afa3b044 Mon Sep 17 00:00:00 2001 From: ReneSac Date: Fri, 10 Apr 2015 23:59:17 -0300 Subject: [PATCH] Changing the rule for arrow like operators again. --- compiler/parser.nim | 2 +- doc/manual/syntax.txt | 4 ++-- tests/parser/tstrongspaces.nim | 10 +++++----- web/news.txt | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/compiler/parser.nim b/compiler/parser.nim index f195892eb4..2d363638fc 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -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) = diff --git a/doc/manual/syntax.txt b/doc/manual/syntax.txt index 0f2208d300..f6fe0652db 100644 --- a/doc/manual/syntax.txt +++ b/doc/manual/syntax.txt @@ -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 diff --git a/tests/parser/tstrongspaces.nim b/tests/parser/tstrongspaces.nim index eaf4d908c9..e70b91988c 100644 --- a/tests/parser/tstrongspaces.nim +++ b/tests/parser/tstrongspaces.nim @@ -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 diff --git a/web/news.txt b/web/news.txt index c515e2ec2c..b5b897c1ab 100644 --- a/web/news.txt +++ b/web/news.txt @@ -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