diff options
author | Martin Odersky <odersky@gmail.com> | 2007-09-10 13:12:27 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2007-09-10 13:12:27 +0000 |
commit | b907c8eb599b53d83b2494e63a928182ec97f2eb (patch) | |
tree | 525ad28a003906f9c493595f84e5ec4a977cfc88 /src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | |
parent | c9e92bfc89083227aa18f88b07688afd625970af (diff) | |
download | scala-b907c8eb599b53d83b2494e63a928182ec97f2eb.tar.gz scala-b907c8eb599b53d83b2494e63a928182ec97f2eb.tar.bz2 scala-b907c8eb599b53d83b2494e63a928182ec97f2eb.zip |
1. added var pattern = expr syntax
2. better error messages in two situations
3. fixed tickets 5, 33, 42
4. changed check files of 3 failing tests
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/parser/Parsers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 38 |
1 files changed, 23 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 04e83a5ebe..a820c985e6 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -1941,7 +1941,7 @@ trait Parsers { case VAL => patDefOrDcl(mods) case VAR => - varDefOrDcl(mods) + patDefOrDcl(mods | Flags.MUTABLE) case DEF => List(funDefOrDcl(mods)) case TYPE => @@ -1955,18 +1955,29 @@ trait Parsers { /** PatDef ::= Pattern2 {`,' Pattern2} [`:' Type] `=' Expr * ValDcl ::= Id {`,' Id} `:' Type + * VarDef ::= PatDef | Id {`,' Id} `:' Type `=' `_' */ def patDefOrDcl(mods: Modifiers): List[Tree] = { var newmods = mods - var lhs = new ListBuffer[Tree] + val lhsBuf = new ListBuffer[Tree] do { inNextToken - lhs += stripParens(pattern2(false)) + val p = pattern2(false) + lhsBuf += stripParens(p) } while (inToken == COMMA) + val lhs = lhsBuf.toList val tp = typedOpt() val rhs = - if (tp.isEmpty || inToken == EQUALS) equalsExpr() - else { + if (tp.isEmpty || inToken == EQUALS) { + accept(EQUALS) + if (!tp.isEmpty && newmods.hasFlag(Flags.MUTABLE) && + (lhs.toList forall (_.isInstanceOf[Ident])) && inToken == USCORE) { + inNextToken + EmptyTree + } else { + expr() + } + } else { newmods = newmods | Flags.DEFERRED EmptyTree } @@ -1979,10 +1990,11 @@ trait Parsers { else Typed(p, tp), rhs.duplicate) map atPos(p.pos) - if (rhs == EmptyTree) { + if (newmods.hasFlag(Flags.DEFERRED)) { trees match { case List(ValDef(_, _, _, EmptyTree)) => - if (mods.hasFlag(Flags.LAZY)) syntaxError(p.pos, "lazy values may not be abstract", false) + if (mods.hasFlag(Flags.LAZY)) + syntaxError(p.pos, "lazy values may not be abstract", false) case _ => syntaxError(p.pos, "pattern definition may not be abstract", false) } } @@ -1991,7 +2003,7 @@ trait Parsers { for (p <- lhs.toList; d <- mkDefs(p)) yield d } - /** VarDef ::= Id {`,' Id} [`:' Type] `=' Expr + /** VarDef ::= PatDef * | Id {`,' Id} `:' Type `=' `_' * VarDcl ::= Id {`,' Id} `:' Type */ @@ -2389,7 +2401,7 @@ trait Parsers { /** BlockStatSeq ::= { BlockStat semi } [ResultExpr] * BlockStat ::= Import * | Annotations [implicit] [lazy] Def - * | LocalModifiers TmplDef + * | Annotations LocalModifiers TmplDef * | Expr1 * | */ @@ -2412,13 +2424,9 @@ trait Parsers { } else if (isExprIntro) { stats += expr(InBlock) if (inToken != RBRACE && inToken != CASE) acceptStatSep() - } else if (isDefIntro) { - localDef(NoMods) - } else if (isLocalModifier || inToken == AT) { + } else if (isDefIntro || isLocalModifier || in.token == AT) { val annots = annotations() - localDef(modifiers() withAnnotations annots) - } else if (!isStatSep) { - localDef(localModifiers()) + localDef(localModifiers() withAnnotations annots) } else if (isStatSep) { inNextToken } else { |