From 4d929158efa9a6e95df14c399091a0f213aebf2d Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 20 Jun 2006 16:34:51 +0000 Subject: Fixed parsing problem for closures --- .../scala/tools/nsc/ast/parser/Parsers.scala | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/compiler/scala/tools/nsc/ast/parser/Parsers.scala') diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 5107db14ee..ce885459a9 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -608,9 +608,9 @@ trait Parsers requires SyntaxAnalyzer { ts.toList } - /** Expr ::= Bindings `=>' Expr + /** Expr ::= (Bindings | Id) `=>' Expr * | Expr1 - * ResultExpr ::= Bindings `=>' Block + * ResultExpr ::= (Bindings | Id `:' Type1) `=>' Block * | Expr1 * Expr1 ::= if (' Expr `)' [NewLine] Expr [[`;'] else Expr] * | try `{' block `}' [catch `{' caseClauses `}'] [finally Expr] @@ -625,8 +625,7 @@ trait Parsers requires SyntaxAnalyzer { * | PostfixExpr [`:' Type1] * | PostfixExpr match `{' CaseClauses `}' * | MethodClosure - * Bindings ::= Id [`:' Type1] - * | `(' [Binding {`,' Binding}] `)' + * Bindings ::= `(' [Binding {`,' Binding}] `)' * Binding ::= Id [`:' Type] */ def expr(): Tree = @@ -726,7 +725,19 @@ trait Parsers requires SyntaxAnalyzer { syntaxError(in.currentPos, "`*' expected", true); } } else { - t = atPos(pos) { Typed(t, type1()) } + t = atPos(pos) { Typed(t, if (isInBlock) type1() else typ()) } + if (isInBlock && in.token == COMMA) { + val vdefs = new ListBuffer[ValDef]; + while (in.token == COMMA) { + in.nextToken(); + vdefs += ValDef(Modifiers(Flags.PARAM), ident(), typedOpt(), EmptyTree) + } + if (in.token == ARROW) { + t = atPos(in.skipToken()) { + Function(convertToParams(t) ::: vdefs.toList, block()) + } + } else syntaxError(in.currentPos, "`=>' expected", true) + } } } else if (in.token == MATCH) { t = atPos(in.skipToken()) { -- cgit v1.2.3