summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-03-13 16:48:57 +0000
committerPaul Phillips <paulp@improving.org>2009-03-13 16:48:57 +0000
commita7ea09750252edb05465232db0ee2e4ed8ac4039 (patch)
tree3d46560182bbe932da980e9ae879c9d0af9ad2f8 /src
parent5f0edd35f0264789c3b5200f3cf7ec1b95335837 (diff)
downloadscala-a7ea09750252edb05465232db0ee2e4ed8ac4039.tar.gz
scala-a7ea09750252edb05465232db0ee2e4ed8ac4039.tar.bz2
scala-a7ea09750252edb05465232db0ee2e4ed8ac4039.zip
Modifies try/catch/finally to allow arbitrary e...
Modifies try/catch/finally to allow arbitrary expressions for try. Formerly { ... } was required for try. Now expressions like: val x = try Integer.parseInt("xx") catch { case e => 10 } work as one would hope.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index ed8a5d1a35..c1c5e26d3d 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -956,7 +956,7 @@ trait Parsers extends NewScanners with MarkupParsers {
* ResultExpr ::= (Bindings | Id `:' CompoundType) `=>' Block
* | Expr1
* Expr1 ::= if `(' Expr `)' {nl} Expr [[semi] else Expr]
- * | try `{' Block `}' [catch `{' CaseClauses `}'] [finally Expr]
+ * | try (`{' Block `}' | Expr) [catch `{' CaseClauses `}'] [finally Expr]
* | while `(' Expr `)' {nl} Expr
* | do Expr [semi] while `(' Expr `)'
* | for (`(' Enumerators `)' | '{' Enumerators '}') {nl} [yield] Expr
@@ -997,13 +997,16 @@ trait Parsers extends NewScanners with MarkupParsers {
atPos(pos) { If(cond, thenp, elsep) }
case TRY =>
atPos(inSkipToken) {
- val body = surround(LBRACE,RBRACE)(block(), Literal(()))
+ val body =
+ if (inToken == LBRACE) surround(LBRACE, RBRACE)(block(), Literal(()))
+ else if (inToken == LPAREN) surround(LPAREN, RPAREN)(expr(), Literal(()))
+ else expr()
val catches =
if (inToken == CATCH) {
inNextToken
val cases = surround(LBRACE,RBRACE)(caseClauses(), Nil)
cases
- } else List()
+ } else Nil
val finalizer =
if (inToken == FINALLY) { inNextToken; expr() }
else EmptyTree