You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by pa...@apache.org on 2015/06/06 00:39:15 UTC
incubator-groovy git commit: GROOVY-7428: Change precedence priority
of ** compared to pre/post inc/dec and unary plus/minus
Repository: incubator-groovy
Updated Branches:
refs/heads/master 6fe6b3181 -> e874e68a5
GROOVY-7428: Change precedence priority of ** compared to pre/post inc/dec and unary plus/minus
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/e874e68a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/e874e68a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/e874e68a
Branch: refs/heads/master
Commit: e874e68a51a44af6277b5e24146bd90c644a0e8a
Parents: 6fe6b31
Author: Paul King <pa...@asert.com.au>
Authored: Tue May 19 08:04:34 2015 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Sat Jun 6 08:37:01 2015 +1000
----------------------------------------------------------------------
src/main/org/codehaus/groovy/antlr/groovy.g | 32 ++++++--------------
src/spec/doc/core-operators.adoc | 4 +--
.../groovy/operator/PowerOperatorsTest.groovy | 12 +++-----
3 files changed, 15 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/e874e68a/src/main/org/codehaus/groovy/antlr/groovy.g
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/antlr/groovy.g b/src/main/org/codehaus/groovy/antlr/groovy.g
index 2cc12f2..b1ad444 100644
--- a/src/main/org/codehaus/groovy/antlr/groovy.g
+++ b/src/main/org/codehaus/groovy/antlr/groovy.g
@@ -2342,7 +2342,7 @@ commandArgument
// nextHigherPrecedenceExpression
// (OPERATOR nextHigherPrecedenceExpression)*
// which is a standard recursive definition for a parsing an expression.
-// The operators in java have the following precedences:
+// The operators have the following precedences:
// lowest ( 15) = **= *= /= %= += -= <<= >>= >>>= &= ^= |=
// ( 14) ?: (conditional expression and elvis)
// ( 13) ||
@@ -2358,11 +2358,11 @@ commandArgument
// ( 4) * / %
// ( 3) **(power)
// ( 2) ++(pre) --(pre) +(unary) -(unary)
-// ( 1) ~ ! $ (type) ++(post) --(post)
-// . ?. *. (dot -- identifier qualification)
-// [] () (method call) {} (closableBlock) [] (list/map)
-// new () (explicit parenthesis)
-// $x (scope escape)
+// ( 1) ~ ! (type) ++(post) --(post)
+// . (member access) .& (method closure) .@ (field/attribute access)
+// ?. (safe dereference) * *. *: (spread ops)
+// [] (index) () (method call) {} (closableBlock) [] (list/map)
+// new (object creation) () (explicit parenthesis)
//
// the last two are not usually on a precedence chart; I put them in
// to point out that new has a higher precedence than '.', so you
@@ -2833,11 +2833,7 @@ additiveExpression[int lc_stmt]
// multiplication/division/modulo (level 4)
multiplicativeExpression[int lc_stmt]
- : ( INC^ nls! powerExpressionNotPlusMinus[0] ((STAR^ | DIV^ | MOD^ ) nls! powerExpression[0])* )
- | ( DEC^ nls! powerExpressionNotPlusMinus[0] ((STAR^ | DIV^ | MOD^ ) nls! powerExpression[0])* )
- | ( MINUS^ {#MINUS.setType(UNARY_MINUS);} nls! powerExpressionNotPlusMinus[0] ((STAR^ | DIV^ | MOD^ ) nls! powerExpression[0])* )
- | ( PLUS^ {#PLUS.setType(UNARY_PLUS);} nls! powerExpressionNotPlusMinus[0] ((STAR^ | DIV^ | MOD^ ) nls! powerExpression[0])* )
- | ( powerExpressionNotPlusMinus[lc_stmt] ((STAR^ | DIV^ | MOD^ ) nls! powerExpression[0])* )
+ : powerExpression[lc_stmt] ((STAR^ | DIV^ | MOD^ ) nls! powerExpression[0])*
;
// math power operator (**) (level 3)
@@ -2845,14 +2841,6 @@ powerExpression[int lc_stmt]
: unaryExpression[lc_stmt] (STAR_STAR^ nls! unaryExpression[0])*
;
-// math power operator (**) (level 3)
-// (without ++(prefix)/--(prefix)/+(unary)/-(unary))
-// The different rules are needed to avoid ambiguous selection
-// of alternatives.
-powerExpressionNotPlusMinus[int lc_stmt]
- : unaryExpressionNotPlusMinus[lc_stmt] (STAR_STAR^ nls! unaryExpression[0])*
- ;
-
// ++(prefix)/--(prefix)/+(unary)/-(unary) (level 2)
unaryExpression[int lc_stmt]
: INC^ nls! unaryExpression[0]
@@ -2864,9 +2852,7 @@ unaryExpression[int lc_stmt]
// ~(BNOT)/!(LNOT)/(type casting) (level 1)
unaryExpressionNotPlusMinus[int lc_stmt]
- : //BAND^ {#BAND.setType(MEMBER_POINTER_DEFAULT);} nls! namePart
- //|
- BNOT^ nls! unaryExpression[0]
+ : BNOT^ nls! unaryExpression[0]
| LNOT^ nls! unaryExpression[0]
| ( // subrule allows option to shut off warnings
options {
@@ -2894,7 +2880,7 @@ unaryExpressionNotPlusMinus[int lc_stmt]
)
;
-// qualified names, array expressions, method invocation, post inc/dec
+// qualified names, array expressions, method invocation, post inc/dec (level 1)
postfixExpression[int lc_stmt]
:
pathExpression[lc_stmt]
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/e874e68a/src/spec/doc/core-operators.adoc
----------------------------------------------------------------------
diff --git a/src/spec/doc/core-operators.adoc b/src/spec/doc/core-operators.adoc
index 7ab0708..d55f828 100644
--- a/src/spec/doc/core-operators.adoc
+++ b/src/spec/doc/core-operators.adoc
@@ -655,8 +655,8 @@ The table below lists all groovy operators in order of precedence.
| | `?.`   `\*`   `*.`   `*:` | safe dereferencing, spread, spread-dot, spread-map
| | `~`   `!`   `(type)` | bitwise negate/pattern, not, typecast
| | `[]`   `++`   `--` | list/map/array index, post inc/decrement
-| 2 | `**` | power
-| 3 | `++`   `--`   `+`   `-` | pre inc/decrement, unary plus, unary minus
+| 2 | `++`   `--`   `+`   `-` | pre inc/decrement, unary plus, unary minus
+| 3 | `**` | power
| 4 | `*`   `/`   `%` | multiply, div, modulo
| 5 | `+`   `-` | addition, subtraction
| 6 | `<<`   `>>`   `>>>`   `..`   `..<` | left/right (unsigned) shift, inclusive/exclusive range
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/e874e68a/src/test/groovy/operator/PowerOperatorsTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/operator/PowerOperatorsTest.groovy b/src/test/groovy/operator/PowerOperatorsTest.groovy
index 85e81e7..b5138cc 100644
--- a/src/test/groovy/operator/PowerOperatorsTest.groovy
+++ b/src/test/groovy/operator/PowerOperatorsTest.groovy
@@ -20,9 +20,6 @@ package groovy.operator
/**
* Test Math Power Operation in Classic/New Groovy
- *
- * @author Pilho Kim
- * @version $Revision: 4996 $
*/
class PowerOperatorsTest extends GroovyTestCase {
@@ -30,11 +27,11 @@ class PowerOperatorsTest extends GroovyTestCase {
assert 2**5 == 32
assert -2**5 == -32
assert 3**4 == 81
- assert -3**4 == -81
+ assert -3**4 == 81
assert 3**-4 == 3.power(-4)
- assert -3**-4 == -3.power(-4)
+ assert -3**-4 != -3.power(-4)
assert 7**2 - 7*3 + 2 == 30 // 49 - 21 + 2 = 30
- assert -7**2 - 7*3 + 2 == -68 // -49 - 21 + 2 = -68
+ assert -7**2 - 7*3 + 2 == 30 // 49 - 21 + 2 = -68
assert -(7**2) - 7*3 + 2 == -68 // -49 - 21 + 2 = -68
assert (-7)**2 - 7*3 + 2 == 30 // 49 - 21 + 2 = 30
}
@@ -75,8 +72,7 @@ class PowerOperatorsTest extends GroovyTestCase {
x **= 2
assert x == 25
assert x**2 == 625
- assert -x**2 != 625
- assert -x**2 == -625
+ assert -x**2 == 625
}
void testPowerAssignmentOperation() {