summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/list/library.lst3
-rw-r--r--config/list/runtime.lst4
-rw-r--r--doc/reference/reference.verb.tex137
-rw-r--r--sources/meta/scalac/ast/Tree.java23
-rw-r--r--sources/scala/Except.scala10
-rw-r--r--sources/scala/Monitor.scala3
-rw-r--r--sources/scala/Predef.scala23
-rw-r--r--sources/scala/runtime/NativeLoop.java (renamed from sources/scala/NativeLoop.java)2
-rw-r--r--sources/scala/runtime/NativeMonitor.java (renamed from sources/scala/NativeMonitor.java)2
-rw-r--r--sources/scala/runtime/ScalaRunTime.scala35
-rw-r--r--sources/scalac/ast/parser/Parser.java106
-rw-r--r--sources/scalac/ast/parser/Scanner.java7
-rw-r--r--sources/scalac/ast/parser/Tokens.java6
-rw-r--r--sources/scalac/util/Names.java6
-rw-r--r--support/latex/verbfilterScala.java14
-rw-r--r--test/files/pos/cours2c.scala6
-rw-r--r--test/files/pos/exceptions.scala5
-rw-r--r--test/files/run/Course-2002-08.scala6
-rw-r--r--test/files/run/Course-2002-13.scala4
-rw-r--r--test/files/run/mics1.scala2
-rw-r--r--test/files/run/queens.scala4
-rw-r--r--test/pos/cours2c.scala6
-rw-r--r--test/pos/exceptions.scala5
23 files changed, 275 insertions, 144 deletions
diff --git a/config/list/library.lst b/config/list/library.lst
index db01c106d2..8e2557bd61 100644
--- a/config/list/library.lst
+++ b/config/list/library.lst
@@ -6,7 +6,6 @@
$colon$colon.scala
BufferedIterator.scala
Cell.scala
-Except.scala
Iterable.scala
Iterator.scala
Labelled.scala
@@ -79,6 +78,8 @@ concurrent/SyncVar.scala
concurrent/TIMEOUT.scala
concurrent/ops.scala
+runtime/ScalaRunTime.scala
+
xml/Element.scala
xml/javaAdapter/HashMap.scala
diff --git a/config/list/runtime.lst b/config/list/runtime.lst
index ee90d9d4c2..a1bf30537a 100644
--- a/config/list/runtime.lst
+++ b/config/list/runtime.lst
@@ -23,14 +23,14 @@ Function9.java
Int.java
Long.java
MatchError.java
-NativeMonitor.java
-NativeLoop.java
Object.java
Ref.java
Short.java
Unit.java
runtime/InterpreterSupport.java
+runtime/NativeLoop.java
+runtime/NativeMonitor.java
runtime/ResultOrException.java
runtime/RunTime.java
diff --git a/doc/reference/reference.verb.tex b/doc/reference/reference.verb.tex
index fbd2cbdd57..026b2e95ac 100644
--- a/doc/reference/reference.verb.tex
+++ b/doc/reference/reference.verb.tex
@@ -1527,8 +1527,7 @@ classes to arbitrary types following the definitions of
If two types in the base class sequence of a template refer to the
same class definition, then that definition must define a trait
(\sref{sec:traits}), and the type that comes later in the sequence must
-conform to the type that comes first. Furthermore, a base class
-sequence may not contain two different case classes
+conform to the type that comes first.
\sref{sec:case-classes}.
\subsection{Evaluation}
@@ -1819,79 +1818,75 @@ object; it is not possible for clients to create objects of class
\label{sec:classes}
\syntax\begin{verbatim}
- PureDef \=::= \= $\CLASS$ ClassDef {`,' ClassDef}
- ClassDef \>::= \> Id ParamSig ClassTemplate
- ClassTemplate \>::=\> extends Constr {with Constr} [with `{' {TemplateStat `;'} `}']
- \> |\> with `{' {TemplateStat `;'} `}'
+ ClsDef \=::=\= class ClassDef {`,' ClassDef}
+ ClassDef \=::=\= Id [TypeParamClause] [ParamClause] [`:' SimpleType] ClassTemplate
+ ClassTemplate \>::=\> extends Template
+ \> |\> TemplateBody
+ \> |\>
\end{verbatim}
-The most general form of class definition is $\CLASS;c[tps](ps_1)
-\ldots (ps_m);\EXTENDS;t$. Here,
+The most general form of class definition is
+\verb@class c[tps](ps): s extends t@.
+Here,
\begin{itemize}
\item[]
-$c$ is the name of the class to be defined.
+\verb@c@ is the name of the class to be defined.
\item[]
-$tps$ is a non-empty list of type parameters of the class being
+\verb@tps@ is a non-empty list of type parameters of the class being
defined. The scope of a type parameter is the whole class definition,
including the type parameter section itself. It is illegal to define
two type parameters with the same name. The type parameter section
-$[tps]$ may be omitted. A class with a type parameter section is
+\verb@[tps]@ may be omitted. A class with a type parameter section is
called {\em polymorphic}, otherwise it is called {\em monomorphic}.
-\item[] $ps_1 \commadots ps_m$ are parameter clauses for the {\em primary
-constructor} of the class. The scope of a formal parameter defined in
-section $ps_i$ includes all parameter sections $ps_j$ for $j > i$ as
-well as the statements $stats$. It is illegal to define two formal
-parameters with the same name. The formal
-parameter clauses are omitted for interface classes (\sref{sec:interfaces}).
-\item[] $t$ is a
+\item[]
+\verb@ps@ is a formal parameter clause for the {\em primary
+constructor} of the class. The scope of a formal parameter includes
+the template \verb@t@. It is illegal to define two formal parameters
+with the same name. The formal parameter section \verb@(ps)@ may be omitted
+in which case an empty parameter section \verb@()@ is assumed.
+\item[]
+\verb@s@ is the {\em self type} of the class. Inside the
+class, the type of \verb@this@ is assumed to be \verb@s@. The self
+type must conform to the self types of all classes which are inherited
+by the template \verb@t@. The self type declaration \verb@:s@ may be
+omitted, in which case the self type of the class is assumed to be
+equal to \verb@c[tps]@.
+\item[]
+\verb@t@ is a
template (\sref{sec:templates}) of the form
-$sc;\WITH;mc_1;\WITH;\ldots;\WITH;mc_n;\WITH;(stats)$
+\verb@sc with mc$_1$ with ... with mc$_n$ { stats }@
which defines the base classes, behavior and initial state of objects of
-the class. The extends clause $\EXTENDS;sc$ can be omitted, in which case
+the class. The extends clause \verb@extends sc with ... with mc$_n$@
+can be omitted, in which case
\verb@extends scala.Object@ is assumed. The class body
-$\WITH;(stats)$ may also be omitted, in which case the empty body
-$\WITH;\{\}$ is assumed.
+\verb@{stats}@ may also be omitted, in which case the empty body
+\verb@{}@ is assumed.
\end{itemize}
-This definition is conceptually equivalent to
-\begin{itemize}
-\item[]
-A definition of a new type $c[tps]$ which is a subtype of the types of
-$sc, mc_1 \commadots mc_n$, which defines the
-members of the template $t$ and which also carries the information
-whether the class is \verb@final@, and whether it defines a case class
-(\sref{sec:datadef}).
-\item[]
-A definition of a final constructor function with signature
-\begin{verbatim}
-def c[tps](ps$_1$)$\ldots$(ps$_n$):class c[tps] ,
-\end{verbatim}
+This class definition defines both a type \verb@c[tps]@ and a constructor
+with signature \verb@constr c[tps](ps)@
which when applied
-initializes members of its result type by evaluating the template $t$.
-\end{itemize}
-Both the type and the constructor definition inherit any
-\verb@private@ or \verb@protected@ modifiers present in the class
-definition.
+initializes instances of \verb@c[tps]@ type by evaluating the template \verb@t@.
-\section{Case Classes}
-\label{sec:datadef}
+\subsection{Case Classes}
+\label{sec:case-classes}
\syntax\begin{verbatim}
- PureDef \=::= \= $\CASE$ $\CLASS$ ClassDef {`,' ClassDef}
+ ClsDef \=::=\= case class ClassDef {`,' ClassDef}
\end{verbatim}
If a class definition is prefixed with \verb@case@, the class is said
to be a {\em case class}. The primary constructor of a case class may
-be used in a constructor pattern (\sref{sec:patterns}). Case classes
-may not have abstract members, and none of the base classes of a case
-class may be a case class. Furthermore, no type may have two different
-case classes among its basetypes.
+be used in a constructor pattern (\sref{sec:patterns}). None of the
+base classes of a case class may be a case class. Furthermore, no type
+may have two different case classes among its basetypes.
-A case class definition of $c[tps](ps_1)\ldots(ps_n)$ with type
-parameters $tps$ and value parameters $(ps_1)\ldots(ps_n)$ implicitly
+A case class definition of \verb@c[tps](ps)@ with type
+parameters \verb@tps@ and value parameters \verb@ps@ implicitly
generates the function definition
-$$\DEF;c[tps](ps_1)\ldots(ps_n): c[tps] = \NEW;c[tps](ps_1)\ldots(ps_n)
-$$
-following the class definition itself. Also implicity defined are
+\begin{verbatim}
+def c[tps](ps): c[tps] = new c[tps](ps)
+\end{verbatim}
+together with the class definition itself. Also implicity defined are
accessor member definitions in the class that return its value
parameters. Every binding \verb@x: T@ in the parameter section leads
to a value definition of \verb@x@ that defines \verb@x@
@@ -1902,14 +1897,17 @@ The case class may not contain a directly bound member with the same
simple name as one of its value parameters.
Every case class implicitly overrides some method definitions of class
-\verb@Object@ (\sref{sec:cls-object}). In particular:
+\verb@Object@ (\sref{sec:cls-object}) unless a definition of the same
+method is already given in the case class itself or a non-abstract
+definition of the same method is given in some base class of the case
+class different from \verb@Object@. In particular:
\begin{itemize}
-\item[] Method \verb@==@ is structural equality, where two
+\item[] Method \verb@equals@ is structural equality, where two
instances are equal if they belong to the same class and
-have equal (wrt \verb@==@) primary constructor arguments.
+have equal (wrt \verb@equals@) primary constructor arguments.
\item[] Method \verb@hashCode@ computes a hash-code
depending on the data structure in a way which maps equal (wrt
-\verb@==@) values to equal hash-codes.
+\verb@equals@) values to equal hash-codes.
\item[] Method \verb@toString@ returns a string representation which
contains the name of the class and its primary constructor arguments.
\end{itemize}
@@ -1918,7 +1916,7 @@ contains the name of the class and its primary constructor arguments.
calculus:
\begin{verbatim}
-class Expr
+class Expr;
case class
Var (x: String) extends Expr,
Apply (f: Expr, e: Expr) extends Expr,
@@ -1929,17 +1927,16 @@ This defines a class \verb@Expr@ with case classes
expressions could then be written as follows.
\begin{verbatim}
-type Env = (String)Value;
+type Env = String => Value;
case class Value(e: Expr, env: Env);
def eval(e: Expr, env: Env): Value = e match {
case Var (x) =>
env(x)
- case Apply(f, g) => {
+ case Apply(f, g) =>
val Value(Lambda (x, e1), env1) = eval(f, env);
val v = eval(g, env);
eval (e1, (y => if (y == x) v else env1(y)))
- }
case Lambda(_, _) =>
Value(e, env)
}
@@ -1951,6 +1948,8 @@ It is possible to define further case classes that extend type
case class Number(x: Int) extends Expr;
\end{verbatim}
+This form of extensibility can be excluded by declaring the case class \verb@sealed@; in this case, only
+
\section{Interface Classes}
\label{sec:interfaces}
@@ -1998,16 +1997,16 @@ abstract class Comparable[a] with {
ModuleDef \=::= \= Id [`:' Type] ClassTemplate
\end{verbatim}
-A module definition is of the form $\MODULE;m;\EXTENDS;t$ where $t$ is
+A module definition is of the form \verb@\MODULE;m;\EXTENDS;t@ where \verb@t@ is
a template (\sref{sec:templates})
-$sc;\WITH;mc_1;\WITH;\ldots;\WITH;mc_n;\WITH;(stats)$. The extends
-clause $\EXTENDS;sc$ can be omitted, in which case
+\verb@sc;\WITH;mc_1;\WITH;\ldots;\WITH;mc_n;\WITH;(stats)@. The extends
+clause \verb@\EXTENDS;sc@ can be omitted, in which case
\verb@extends scala.Object@ is assumed.
-The module body $\WITH;(stats)$ may also be omitted, in which case the
-empty body $\WITH;\{\}$ is assumed.
+The module body \verb@\WITH;(stats)@ may also be omitted, in which case the
+empty body \verb@\WITH;\{\}@ is assumed.
The module definition defines a single object conforming to the
-template $t$. It is almost equivalent to a triple of a class
+template \verb@t@. It is almost equivalent to a triple of a class
definition,
a type definition and a value definition that creates an object of the class:
\begin{verbatim}
@@ -4169,8 +4168,8 @@ grammar.
CaseClause \>::=\> case Pattern [`if' PostfixExpr] `=>' Block
Constr \>::=\> StableId [TypeArgs] [`(' [Exprs] `)']
- ConstrExpr \>::=\> Constr
- \> |\> `{' {BlockStat `;'} Constr `}'
+ ConstrExpr \>::=\> this [ArgumentExpr]
+ \> |\> `{' {BlockStat `;'} this [ArgumentExpr] `}'
Pattern \>::=\> varid `:' Type1
\> |\> `_' `:' Type1
@@ -4236,7 +4235,7 @@ grammar.
VarDef \>::=\> Id [`:' Type] `=' Expr
\> |\> Id `:' Type `=' `_'
FunDef \>::=\> Id [FunTypeParamClause] {ParamClause} [`:' Type] `=' Expr
- ConstrDef \>::=\> Id [FunTypeParamClause] [ParamClause] [`:' Type] `=' ConstrExpr
+ ConstrDef \>::=\> this [ParamClause] `=' ConstrExpr
TypeDef \>::=\> Id `=' Type
ClsDef \>::=\> ([case] class | trait) ClassDef {`,' ClassDef}
\> |\> [case] object ObjectDef {`,' ObjectDef}
diff --git a/sources/meta/scalac/ast/Tree.java b/sources/meta/scalac/ast/Tree.java
index 7d6568cbe6..9f0af9759a 100644
--- a/sources/meta/scalac/ast/Tree.java
+++ b/sources/meta/scalac/ast/Tree.java
@@ -102,7 +102,10 @@ public class Tree {
n_SelectFromType = node("SelectFromType", Type, HasSym),
n_FunType = node("FunType" , Type, NoSym),
n_CompoundType = node("CompoundType" , Type, NoSym),
- n_AppliedType = node("AppliedType" , Type, NoSym);
+ n_AppliedType = node("AppliedType" , Type, NoSym),
+ n_Try = node("Try" , Term, NoSym),
+ n_While = node("While" , Term, NoSym),
+ n_DoUntil = node("DoUntil" , Term, NoSym);
public final TreeNode[] nodes;
public int arrays;
@@ -336,6 +339,24 @@ public class Tree {
addField(t_TypeTree, "tpe").
addField(t_TypeTrees, "args");
+ n_Try.
+ setDescription("Try Expression").
+ setRange(Phase.PARSER, Phase.END).
+ addField(t_TermTree, "block").
+ addField(t_TermTree, "catcher").
+ addField(t_TermTree, "finalizer");
+
+ n_While.
+ setDescription("While Loop").
+ setRange(Phase.PARSER, Phase.END).
+ addField(t_TermTree, "cond").
+ addField(t_TermTree, "block");
+
+ n_DoUntil.
+ setDescription("Do-Until Loop").
+ setRange(Phase.PARSER, Phase.END).
+ addField(t_TermTree, "block").
+ addField(t_TermTree, "cond");
}
//########################################################################
diff --git a/sources/scala/Except.scala b/sources/scala/Except.scala
deleted file mode 100644
index ce73a35e9c..0000000000
--- a/sources/scala/Except.scala
+++ /dev/null
@@ -1,10 +0,0 @@
-package scala;
-
-class Except[a](r: scala.runtime.ResultOrException[a]) {
- def except[b >: a](handler: PartialFunction[Throwable, b]): b =
- if (r.exc == null) r.result as b
- else if (handler isDefinedAt r.exc) handler(r.exc)
- else r.exc.throw;
- def finally(def handler: Unit): a =
- if (r.exc == null) r.result as a else { handler; r.exc.throw }
-}
diff --git a/sources/scala/Monitor.scala b/sources/scala/Monitor.scala
index 168f72a6ca..08e6201612 100644
--- a/sources/scala/Monitor.scala
+++ b/sources/scala/Monitor.scala
@@ -11,7 +11,8 @@ package scala;
trait Monitor {
- def synchronized[a](def p: a): a = NativeMonitor.synchronised(this, p);
+ def synchronized[a](def p: a): a =
+ scala.runtime.NativeMonitor.synchronised(this, p);
def await(def cond: Boolean) = while (!cond) { this.wait() }
}
diff --git a/sources/scala/Predef.scala b/sources/scala/Predef.scala
index 218b5d926e..db81ed9576 100644
--- a/sources/scala/Predef.scala
+++ b/sources/scala/Predef.scala
@@ -33,27 +33,8 @@ object Predef {
def exit: scala.Unit = System.exit(0);
- def synchronized[A](obj: AnyRef)(def body: A) = NativeMonitor.synchronised(obj, body);
-
- def try[a](def block: a): Except[a] =
- new Except(scala.runtime.ResultOrException.tryBlock(block));
-
- def while(def cond: Boolean)(def body: Unit): Unit = NativeLoop.loopWhile(cond, body);
- /* if (cond) {
- body; while(cond)(body)
- } */
-
- trait Until {
- def until(def condition: Boolean): Unit
- }
-
- def repeat(def command: Unit): Until =
- new Until {
- def until(def condition: Boolean): Unit = {
- command ;
- if (condition) {} else until(condition)
- }
- }
+ def synchronized[A](obj: AnyRef)(def body: A) =
+ scala.runtime.NativeMonitor.synchronised(obj, body);
type Pair = Tuple2;
def Pair[a, b](x: a, y: b) = Tuple2(x, y);
diff --git a/sources/scala/NativeLoop.java b/sources/scala/runtime/NativeLoop.java
index 921259b90b..b849bd222d 100644
--- a/sources/scala/NativeLoop.java
+++ b/sources/scala/runtime/NativeLoop.java
@@ -7,7 +7,7 @@
** $Id$
\* */
-package scala;
+package scala.runtime;
public class NativeLoop {
diff --git a/sources/scala/NativeMonitor.java b/sources/scala/runtime/NativeMonitor.java
index ade1a10110..0afda00674 100644
--- a/sources/scala/NativeMonitor.java
+++ b/sources/scala/runtime/NativeMonitor.java
@@ -7,7 +7,7 @@
** $Id$
\* */
-package scala;
+package scala.runtime;
public class NativeMonitor {
diff --git a/sources/scala/runtime/ScalaRunTime.scala b/sources/scala/runtime/ScalaRunTime.scala
new file mode 100644
index 0000000000..18bbcb27a7
--- /dev/null
+++ b/sources/scala/runtime/ScalaRunTime.scala
@@ -0,0 +1,35 @@
+package scala.runtime;
+
+object ScalaRunTime {
+
+ class Try[a](r: scala.runtime.ResultOrException[a]) {
+ def Catch[b >: a](handler: PartialFunction[Throwable, b]): b =
+ if (r.exc == null)
+ r.result as b
+ else if (/*!(r.exc is NonLocalReturn) && */handler isDefinedAt r.exc)
+ handler(r.exc)
+ else
+ r.exc.throw;
+
+ def Finally(handler: Unit): a =
+ if (r.exc == null) r.result as a else r.exc.throw;
+ }
+
+ def Try[a](def block: a): Try[a] =
+ new Try(ResultOrException.tryBlock(block));
+
+ def While(def cond: Boolean)(def body: Unit): Unit =
+ NativeLoop.loopWhile(cond, body);
+
+ trait DoWhile {
+ def While(def condition: Boolean): Unit;
+ }
+
+ def Do(def command: Unit): DoWhile =
+ new DoWhile {
+ def While(def condition: Boolean): Unit = {
+ command;
+ NativeLoop.loopWhile(condition, command);
+ }
+ }
+}
diff --git a/sources/scalac/ast/parser/Parser.java b/sources/scalac/ast/parser/Parser.java
index 87c8989f33..1f6c7e31f8 100644
--- a/sources/scalac/ast/parser/Parser.java
+++ b/sources/scalac/ast/parser/Parser.java
@@ -153,6 +153,7 @@ public class Parser implements Tokens {
case SYMBOLLIT: case TRUE: case FALSE: case NULL: case IDENTIFIER:
case THIS: case SUPER: case IF:
case FOR: case NEW: case USCORE:
+ case TRY: case WHILE: case DO:
case LPAREN: case LBRACE:
return true;
default:
@@ -199,6 +200,14 @@ public class Parser implements Tokens {
return make.Select(pos, make.Ident(pos, Names.scala), name);
}
+ Tree scalaRuntimeDot(int pos, Name name) {
+ return make.Select(pos, scalaDot(pos, Names.runtime), name);
+ }
+
+ Tree ScalaRunTimeDot(int pos, Name name) {
+ return make.Select(pos, scalaRuntimeDot(pos, Names.ScalaRunTime), name);
+ }
+
Tree scalaBooleanDot(int pos, Name name) {
return make.Select(pos, scalaDot(pos, Names.Boolean), name);
}
@@ -253,6 +262,54 @@ public class Parser implements Tokens {
return make.Apply(pos, make.Select(pos, rhs, name), new Tree[]{cont});
}
+ Tree makeTry(int pos, Tree body, Tree catcher, Tree finalizer) {
+ Tree t = body;
+ if (catcher != Tree.Empty)
+ t =
+ make.Apply(
+ pos,
+ make.Select(
+ pos,
+ make.Apply(
+ pos, ScalaRunTimeDot(pos, Names.Try), new Tree[]{t}),
+ Names.Catch),
+ new Tree[]{catcher});
+ if (finalizer != Tree.Empty)
+ t =
+ make.Apply(
+ pos,
+ make.Select(
+ pos,
+ make.Apply(
+ pos, ScalaRunTimeDot(pos, Names.Try), new Tree[]{t}),
+ Names.Finally),
+ new Tree[]{finalizer});
+ return t;
+ }
+
+ Tree makeWhile(int pos, Tree cond, Tree body) {
+ return
+ make.Apply(
+ pos,
+ make.Apply(
+ pos, ScalaRunTimeDot(pos, Names.While), new Tree[]{cond}),
+ new Tree[]{body});
+ }
+
+ Tree makeDoWhile(int pos, Tree body, Tree cond) {
+ return
+ make.Apply(
+ pos,
+ make.Select(
+ pos,
+ make.Apply(
+ pos,
+ ScalaRunTimeDot(pos, Names.Do),
+ new Tree[]{body}),
+ Names.While),
+ new Tree[]{cond});
+ }
+
/** Convert tree to formal parameter list
*/
ValDef[] convertToParams(Tree t) {
@@ -674,6 +731,9 @@ public class Parser implements Tokens {
/** Expr ::= Bindings `=>' Expr
* | if `(' Expr `)' Expr [[`;'] else Expr]
+ * | try `{' block `}' [catch Expr] [finally Expr]
+ * | while `(' Expr `)' Expr
+ * | do Expr [`;'] while `(' Expr `)'
* | for `(' Enumerators `)' (do | yield) Expr
* | [SimpleExpr `.'] Id `=' Expr
* | SimpleExpr ArgumentExprs `=' Expr
@@ -696,19 +756,45 @@ public class Parser implements Tokens {
} else {
elsep = Tree.Empty;
}
- return make.If(pos, cond, thenp, elsep) ;
+ return make.If(pos, cond, thenp, elsep);
+ } else if (s.token == TRY) {
+ int pos = s.skipToken();
+ accept(LBRACE);
+ Tree body = block(pos);
+ accept(RBRACE);
+ Tree catcher = Tree.Empty;
+ if (s.token == CATCH) {
+ s.nextToken();
+ catcher = expr();
+ }
+ Tree finalizer = Tree.Empty;
+ if (s.token == FINALLY) {
+ s.nextToken();
+ finalizer = expr();
+ }
+ return makeTry(pos, body, catcher, finalizer);
+ } else if (s.token == WHILE) {
+ int pos = s.skipToken();
+ accept(LPAREN);
+ Tree cond = expr();
+ accept(RPAREN);
+ Tree body = expr();
+ return makeWhile(pos, cond, body);
+ } else if (s.token == DO) {
+ int pos = s.skipToken();
+ Tree body = expr();
+ if (s.token == SEMI) s.nextToken();
+ accept(WHILE);
+ accept(LPAREN);
+ Tree cond = expr();
+ accept(RPAREN);
+ return makeDoWhile(pos, body, cond);
} else if (s.token == FOR) {
s.nextToken();
Tree[] enums;
- if (s.token == LBRACE) {
- accept(LBRACE);
- enums = enumerators();
- accept(RBRACE);
- } else {
- accept(LPAREN);
- enums = enumerators();
- accept(RPAREN);
- }
+ accept(LPAREN);
+ enums = enumerators();
+ accept(RPAREN);
if (s.token == DO) {
return makeFor(s.skipToken(), enums, Names.foreach, Names.foreach, expr());
} else if (s.token == YIELD) {
diff --git a/sources/scalac/ast/parser/Scanner.java b/sources/scalac/ast/parser/Scanner.java
index 5573ce3e05..da022bd953 100644
--- a/sources/scalac/ast/parser/Scanner.java
+++ b/sources/scalac/ast/parser/Scanner.java
@@ -115,7 +115,7 @@ public class Scanner extends TokenData {
fetchToken();
switch (token) {
case ELSE: case EXTENDS: case WITH:
- case YIELD: case DO:
+ case YIELD: case CATCH: case FINALLY:
case COMMA: case SEMI: case DOT:
case COLON: case EQUALS: case ARROW:
case LARROW: case SUBTYPE: case SUPERTYPE:
@@ -798,6 +798,7 @@ public class Scanner extends TokenData {
enterKeyword("as", AS);
enterKeyword("case", CASE);
enterKeyword("class", CLASS);
+ enterKeyword("catch", CATCH);
enterKeyword("constr", CONSTR);
enterKeyword("def", DEF);
enterKeyword("do", DO);
@@ -805,6 +806,7 @@ public class Scanner extends TokenData {
enterKeyword("extends", EXTENDS);
enterKeyword("false", FALSE);
enterKeyword("final", FINAL);
+ enterKeyword("finally", FINALLY);
enterKeyword("for", FOR);
enterKeyword("if", IF);
enterKeyword("import", IMPORT);
@@ -816,15 +818,18 @@ public class Scanner extends TokenData {
enterKeyword("package", PACKAGE);
enterKeyword("private", PRIVATE);
enterKeyword("protected", PROTECTED);
+ enterKeyword("return", RETURN);
enterKeyword("sealed", SEALED);
enterKeyword("super", SUPER);
enterKeyword("this", THIS);
enterKeyword("trait", TRAIT);
enterKeyword("true", TRUE);
+ enterKeyword("try", TRY);
enterKeyword("type", TYPE);
enterKeyword("val", VAL);
enterKeyword("var", VAR);
enterKeyword("with", WITH);
+ enterKeyword("while", WHILE);
enterKeyword("yield", YIELD);
enterKeyword(".", DOT);
enterKeyword("_", USCORE);
diff --git a/sources/scalac/ast/parser/Tokens.java b/sources/scalac/ast/parser/Tokens.java
index f2e3bc39ad..9ec7878918 100644
--- a/sources/scalac/ast/parser/Tokens.java
+++ b/sources/scalac/ast/parser/Tokens.java
@@ -61,6 +61,12 @@ public interface Tokens {
DO = 51,
TRAIT = 52,
SEALED = 53,
+ /* THROW = 54, */
+ TRY = 55,
+ CATCH = 56,
+ FINALLY = 57,
+ WHILE = 58,
+ RETURN = 59,
/* special symbols */
COMMA = 61,
diff --git a/sources/scalac/util/Names.java b/sources/scalac/util/Names.java
index 1c394a8ba2..069fafbbad 100644
--- a/sources/scalac/util/Names.java
+++ b/sources/scalac/util/Names.java
@@ -37,9 +37,12 @@ public class Names {
public static final Name AnyRef = Name.fromString("AnyRef");
public static final Name Array = Name.fromString("Array");
public static final Name Byte = Name.fromString("Byte");
+ public static final Name Catch = Name.fromString("Catch");
public static final Name Char = Name.fromString("Char");
public static final Name Boolean = Name.fromString("Boolean");
+ public static final Name Do = Name.fromString("Do");
public static final Name Double = Name.fromString("Double");
+ public static final Name Finally = Name.fromString("Finally");
public static final Name Float = Name.fromString("Float");
public static final Name Function = Name.fromString("Function");
public static final Name Int = Name.fromString("Int");
@@ -50,13 +53,16 @@ public class Names {
public static final Name Object = Name.fromString("Object");
public static final Name PartialFunction = Name.fromString("PartialFunction");
public static final Name Predef = Name.fromString("Predef");
+ public static final Name ScalaRunTime = Name.fromString("ScalaRunTime");
public static final Name Seq = Name.fromString("Seq");
public static final Name Short = Name.fromString("Short");
public static final Name String = Name.fromString("String");
public static final Name Symbol = Name.fromString("Symbol");
public static final Name Throwable = Name.fromString("Throwable");
+ public static final Name Try = Name.fromString("Try");
public static final Name Tuple = Name.fromString("Tuple");
public static final Name Unit = Name.fromString("Unit");
+ public static final Name While = Name.fromString("While");
public static final Name apply = Name.fromString("apply");
public static final Name as = Name.fromString("as");
public static final Name box = Name.fromString("box");
diff --git a/support/latex/verbfilterScala.java b/support/latex/verbfilterScala.java
index b8db2fb6e9..d71b6b9d3f 100644
--- a/support/latex/verbfilterScala.java
+++ b/support/latex/verbfilterScala.java
@@ -5,12 +5,14 @@ import java.io.*;
public class verbfilterScala {
static String[] reserved = {
- "abstract", "as", "case", "class", "constr", "def", "do", "else",
- "extends", "false", "final", "for", "if", "import",
- "is", "new", "null", "object", "override", "package",
- "private", "protected", "sealed", "super", "this",
- "trait", "true", "type", "val", "var",
- "with", "yield"};
+ "abstract", "as", "case", "catch", "class",
+ "def", "do", "else", "extends", "false",
+ "final", "finally", "for", "if", "import",
+ "is", "new", "null", "object", "override",
+ "package", "private", "protected", "return",
+ "sealed", "super", "this", "trait", "try",
+ "true", "type", "val", "var", "with",
+ "while", "yield"};
static final int TABINC = 8;
diff --git a/test/files/pos/cours2c.scala b/test/files/pos/cours2c.scala
index 776469e1bb..e3917e43eb 100644
--- a/test/files/pos/cours2c.scala
+++ b/test/files/pos/cours2c.scala
@@ -32,12 +32,12 @@ object m2 {
def average(x: Double, y: Double) = (x + y)/2;
def fixedPoint(f: Double => Double, firstGuess: Double) = {
- def try(guess: Double): Double = {
+ def Try(guess: Double): Double = {
val next = f(guess);
if (isCloseEnough(guess, next)) next
- else try(next)
+ else Try(next)
}
- try(firstGuess);
+ Try(firstGuess);
}
def sin(x: Double): Double = x;
diff --git a/test/files/pos/exceptions.scala b/test/files/pos/exceptions.scala
index c47b0e4785..f28a10d367 100644
--- a/test/files/pos/exceptions.scala
+++ b/test/files/pos/exceptions.scala
@@ -4,7 +4,7 @@ object test {
//def error[a](x: String):a = new java.lang.RuntimeException(x) throw;
- def main(): Unit = {
+ def main(args: Array[String]): Unit = {
try {
try {
System.out.println("hi!");
@@ -12,11 +12,10 @@ object test {
} finally {
System.out.println("ho!")
}
- } except {
+ } catch {
case ex: IOException => System.out.println("io exception!");
case ex => System.out.println(ex);
}
}
- main();
}
diff --git a/test/files/run/Course-2002-08.scala b/test/files/run/Course-2002-08.scala
index b821caa140..f94b42ebc0 100644
--- a/test/files/run/Course-2002-08.scala
+++ b/test/files/run/Course-2002-08.scala
@@ -89,16 +89,16 @@ object M1 {
object M2 {
- def while(def condition: Boolean)(def command: Unit): Unit =
+ def While(def condition: Boolean)(def command: Unit): Unit =
if (condition) {
- command; while(condition)(command)
+ command; While(condition)(command)
} else {
}
def power (x: Double, exp: Int): Double = {
var r = 1.0;
var i = exp;
- while (i > 0) { r = r * x; i = i - 1 }
+ While (i > 0) { r = r * x; i = i - 1 }
r
}
diff --git a/test/files/run/Course-2002-13.scala b/test/files/run/Course-2002-13.scala
index ebdde8bf86..541008bb1b 100644
--- a/test/files/run/Course-2002-13.scala
+++ b/test/files/run/Course-2002-13.scala
@@ -50,14 +50,14 @@ class Interpreter {
}
}
loop;
- } except ({
+ } catch {
case (exception: FileNotFoundException) =>
System.out.println("not found: " + filename);
"";
case (exception: IOException) =>
System.out.println("can't read: " + filename);
"";
- })
+ }
}
def run(prompt: String)(process: String => Unit): Unit = {
diff --git a/test/files/run/mics1.scala b/test/files/run/mics1.scala
index 8d5cecf043..b3673dd5e0 100644
--- a/test/files/run/mics1.scala
+++ b/test/files/run/mics1.scala
@@ -16,7 +16,7 @@ object Test {
System.out.print("lookup(" + key + ") = ");
try {
System.out.println(map.lookup(key));
- } except {
+ } catch {
case e => System.out.println(e.getMessage());
}
}
diff --git a/test/files/run/queens.scala b/test/files/run/queens.scala
index 4daa702e29..ba812f5971 100644
--- a/test/files/run/queens.scala
+++ b/test/files/run/queens.scala
@@ -21,11 +21,11 @@ object M0 {
abs(col - p.head) != delta &&
isSafe(col, p.tail, delta + 1));
- for {
+ for (
val placement <- placeQueens(row - 1);
val col <- columns;
isSafe(col, placement, 1)
- } yield {
+ ) yield {
col :: placement
}
}
diff --git a/test/pos/cours2c.scala b/test/pos/cours2c.scala
index 776469e1bb..e3917e43eb 100644
--- a/test/pos/cours2c.scala
+++ b/test/pos/cours2c.scala
@@ -32,12 +32,12 @@ object m2 {
def average(x: Double, y: Double) = (x + y)/2;
def fixedPoint(f: Double => Double, firstGuess: Double) = {
- def try(guess: Double): Double = {
+ def Try(guess: Double): Double = {
val next = f(guess);
if (isCloseEnough(guess, next)) next
- else try(next)
+ else Try(next)
}
- try(firstGuess);
+ Try(firstGuess);
}
def sin(x: Double): Double = x;
diff --git a/test/pos/exceptions.scala b/test/pos/exceptions.scala
index c47b0e4785..f28a10d367 100644
--- a/test/pos/exceptions.scala
+++ b/test/pos/exceptions.scala
@@ -4,7 +4,7 @@ object test {
//def error[a](x: String):a = new java.lang.RuntimeException(x) throw;
- def main(): Unit = {
+ def main(args: Array[String]): Unit = {
try {
try {
System.out.println("hi!");
@@ -12,11 +12,10 @@ object test {
} finally {
System.out.println("ho!")
}
- } except {
+ } catch {
case ex: IOException => System.out.println("io exception!");
case ex => System.out.println(ex);
}
}
- main();
}