summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-09-17 21:20:56 +0000
committerPaul Phillips <paulp@improving.org>2010-09-17 21:20:56 +0000
commit513fd181bc99263c92f759c4e17889dcb8da53f0 (patch)
tree1622666cd62bd160b68bc0205de6db4317c6026a /src/compiler
parentab8f20c1f7cb13f4c9a7bac88ebb82a5ce89e6d9 (diff)
downloadscala-513fd181bc99263c92f759c4e17889dcb8da53f0.tar.gz
scala-513fd181bc99263c92f759c4e17889dcb8da53f0.tar.bz2
scala-513fd181bc99263c92f759c4e17889dcb8da53f0.zip
Restoring negative literal parsing behavior to ...
Restoring negative literal parsing behavior to what should be the least surprising option. Thanks much to Johannes Rudolph for identifying the bug in the bytecode generator which needed addressing for us to arrive at proper -0.0 behavior, and for writing the majority of this patch. A '-' followed immediately by either a number or a period should now always be treated as a single numeric literal, which means the minus binds more tightly than anything else. A specific example of how this differs from 2.8 final is: -5.+(10) == 5.0 // and not -15.0 The full range of potentially ambiguous parses involving prefix operators, numbers, and dots is quite large and still needs to be completely and clearly specified. Closes #2378 and #3657, review by odersky, jrudolph.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 61d45114a9..e44806139e 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -453,6 +453,15 @@ self =>
case _ => false
}
+ def isNumericLit: Boolean = in.token match {
+ case INTLIT | LONGLIT | FLOATLIT | DOUBLELIT => true
+ case _ => false
+ }
+ def isUnaryOp: Boolean = isIdent && (in.name match {
+ case MINUS | PLUS | TILDE | BANG => true
+ case _ => false
+ })
+
def isIdent = in.token == IDENTIFIER || in.token == BACKQUOTED_IDENT
def isExprIntroToken(token: Int): Boolean = token match {
@@ -1241,24 +1250,14 @@ self =>
/** PrefixExpr ::= [`-' | `+' | `~' | `!' | `&'] SimpleExpr
*/
def prefixExpr(): Tree = {
- def unaryOp(): Name = "unary_" + ident()
- if (isIdent && in.name == MINUS) {
- atPos(in.offset) {
- val name = unaryOp()
- in.token match {
- // Don't include double and float here else we lose -0.0
- case INTLIT | LONGLIT => literal(true)
- case _ => Select(stripParens(simpleExpr()), name)
- }
- }
- } else if (isIdent && (in.name == PLUS || in.name == TILDE || in.name == BANG)) {
+ if (isUnaryOp) {
atPos(in.offset) {
- val name = unaryOp()
- Select(stripParens(simpleExpr()), name)
+ val name: Name = "unary_" + ident()
+ if (in.name == MINUS && isNumericLit) simpleExprRest(atPos(in.offset)(literal(true)), true)
+ else Select(stripParens(simpleExpr()), name)
}
- } else {
- simpleExpr()
}
+ else simpleExpr()
}
def xmlLiteral(): Tree