summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2008-05-31 10:48:59 +0000
committerMartin Odersky <odersky@gmail.com>2008-05-31 10:48:59 +0000
commite8eb3647f6720951caf0a1387b149d0b1485749f (patch)
treea49f394722fd863813ddd3c556d288fe76933f17 /src
parent35bb651843dd0b03861a5410b426e16e9e1838cb (diff)
downloadscala-e8eb3647f6720951caf0a1387b149d0b1485749f.tar.gz
scala-e8eb3647f6720951caf0a1387b149d0b1485749f.tar.bz2
scala-e8eb3647f6720951caf0a1387b149d0b1485749f.zip
Fixed #971
Diffstat (limited to 'src')
-rwxr-xr-xsrc/compiler/scala/tools/nsc/javac/JavaParsers.scala33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
index 9bcaf4476a..3d6c752128 100755
--- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
+++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
@@ -548,11 +548,42 @@ trait JavaParsers extends JavaScanners {
}
}
+ /** Parse a sequence of field declarations, separated by commas.
+ * This one is tricky because a comma might also appear in an
+ * initializer. Since we don't parse initializers we don't know
+ * what the comma signifies.
+ * We solve this with a second list buffer `maybe' which contains
+ * potential variable definitions.
+ * Once we have reached the end of the statement, we know whether
+ * these potential definitions are real or not.
+ */
def fieldDecls(pos: Position, mods: Modifiers, tpt: Tree, name: Name): List[Tree] = {
val buf = new ListBuffer[Tree] + varDecl(pos, mods, tpt, name)
+ val maybe = new ListBuffer[Tree] // potential variable definitions.
while (in.token == COMMA) {
in.nextToken
- buf += varDecl(in.currentPos, mods, tpt.duplicate, ident())
+ if (in.token == IDENTIFIER) { // if there's an ident after the comma ...
+ val name = ident()
+ in.nextToken
+ if (in.token == ASSIGN) { // ... followed by an `=', we know it's a real variable definition
+ buf ++= maybe
+ buf += varDecl(in.currentPos, mods, tpt.duplicate, name)
+ maybe.clear()
+ } else if (in.token == COMMA) { // ... if there's a comma after the ident, it could be a real vardef or not.
+ maybe += varDecl(in.currentPos, mods, tpt.duplicate, name)
+ } else { // ... if there's something else we were still in the initializer of the
+ // previous var def; skip to next comma or semicolon.
+ skipTo(COMMA, SEMI)
+ maybe.clear()
+ }
+ } else { // ... if there's no ident following the comma we were still in the initializer of the
+ // previous var def; skip to next comma or semicolon.
+ skipTo(COMMA, SEMI)
+ maybe.clear()
+ }
+ }
+ if (in.token == SEMI) {
+ buf ++= maybe // every potential vardef that survived until here is real.
}
buf.toList
}