summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-01-23 15:54:05 +0000
committermichelou <michelou@epfl.ch>2007-01-23 15:54:05 +0000
commitcfe333853f15ccfe84eca657900e700341ffa832 (patch)
tree44ec284188ca75abf3b8d8bc0cc77a93efa116bb
parent8acb41bd0a4dc1a6a6e6c20f48cb1c508470551a (diff)
downloadscala-cfe333853f15ccfe84eca657900e700341ffa832.tar.gz
scala-cfe333853f15ccfe84eca657900e700341ffa832.tar.bz2
scala-cfe333853f15ccfe84eca657900e700341ffa832.zip
updated some commments in interpreter
-rw-r--r--src/compiler/scala/tools/nsc/Interpreter.scala22
-rw-r--r--src/compiler/scala/tools/nsc/InterpreterLoop.scala40
-rw-r--r--src/compiler/scala/tools/nsc/InterpreterResults.scala19
-rw-r--r--src/compiler/scala/tools/nsc/MainInterpreter.scala4
4 files changed, 50 insertions, 35 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala
index 30fcb998ad..f9d082fdc5 100644
--- a/src/compiler/scala/tools/nsc/Interpreter.scala
+++ b/src/compiler/scala/tools/nsc/Interpreter.scala
@@ -232,7 +232,14 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
def compileString(code: String): Boolean =
compileSources(List(new SourceFile("<script>", code.toCharArray)))
- /** build a request from the user. "trees" is "line" after being parsed. */
+ /** Build a request from the user. <code>trees</code> is <code>line</code>
+ * after being parsed.
+ *
+ * @param trees ..
+ * @param line ..
+ * @param lineName ..
+ * @return ..
+ */
private def buildRequest(trees: List[Tree], line: String, lineName: String): Request =
trees match {
/* This case for assignments is more specialized than desirable: it only
@@ -262,12 +269,13 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
* reporter. Values defined are available for future interpreted
* strings.
* </p>
- *
* <p>
* The return value is whether the line was interpreter successfully,
* e.g. that there were no parse errors.
* </p>
*
+ * @param line ...
+ * @return ...
*/
def interpret(line: String): IR.Result = {
// parse
@@ -301,7 +309,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
if (succeeded)
prevRequests += req
- if(succeeded) IR.Success else IR.Error
+ if (succeeded) IR.Success else IR.Error
}
/** A counter used for numbering objects created by bind() */
@@ -367,8 +375,8 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
Interpreter.deleteRecursively(classfilePath)
/** A traverser that finds all mentioned identifiers, i.e. things
- that need to be imported.
- It might return extra names. */
+ * that need to be imported. It might return extra names.
+ */
private class ImportVarsTraverser(definedVars: List[Name]) extends Traverser {
val importVars = new HashSet[Name]()
@@ -671,8 +679,8 @@ object Interpreter {
*/
def deleteRecursively(path: File): Unit = {
path match {
- case _ if (!path.exists) => ()
- case _ if (path.isDirectory) =>
+ case _ if !path.exists => {}
+ case _ if path.isDirectory =>
for (val p <- path.listFiles)
deleteRecursively(p)
path.delete
diff --git a/src/compiler/scala/tools/nsc/InterpreterLoop.scala b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
index 6cc2fd27f3..84f7fc224a 100644
--- a/src/compiler/scala/tools/nsc/InterpreterLoop.scala
+++ b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
@@ -73,7 +73,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
}
/** print a friendly help message */
- def printHelp = {
+ def printHelp {
out.println("This is an interpreter for Scala.")
out.println("Type in expressions to have them evaluated.")
out.println("Type :compile followed by a filename to compile a complete Scala file.")
@@ -84,7 +84,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
}
/** Print a welcome message */
- def printWelcome = {
+ def printWelcome {
out.println("This is an interpreter for Scala.")
out.println("Type in expressions to have them evaluated.")
out.println("Type :help for more information.")
@@ -92,15 +92,15 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
/** The main read-eval-print loop for the interpereter. It calls
* <code>command()</code> for each line of input, and stops when
- * <code>command()</code> returns false.
+ * <code>command()</code> returns <code>false</code>.
*/
- def repl(): Unit = {
+ def repl {
var firstTime = true
- while(true) {
- if(interactive) {
+ while (true) {
+ if (interactive) {
out.print("\nscala> ")
out.flush
- if(firstTime) {
+ if (firstTime) {
interpreter.prime
firstTime = false
}
@@ -112,7 +112,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
val Pair(keepGoing, finalLineMaybe) = command(line)
if (!keepGoing)
- return ()
+ return
finalLineMaybe match {
case Some(finalLine) => addReplay(finalLine)
@@ -122,13 +122,13 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
}
/** interpret all lines from a specified file */
- def interpretAllFrom(filename: String): Unit = {
+ def interpretAllFrom(filename: String) {
val fileIn = try {
new FileReader(filename)
} catch {
case _:IOException =>
out.println("Error opening file: " + filename)
- return ()
+ return
}
val oldIn = in
val oldInteractive = interactive
@@ -137,7 +137,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
interactive = false
out.println("Loading " + filename + "...")
out.flush
- repl()
+ repl
} finally {
in = oldIn
interactive = oldInteractive
@@ -146,7 +146,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
}
/** create a new interpreter and replay all commands so far */
- def replay = {
+ def replay {
closeInterpreter
createInterpreter
for (val cmd <- replayCommands) {
@@ -219,22 +219,21 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
interpreter.interpret(code) match {
case IR.Success => Some(code)
case IR.Error => None
- case IR.Incomplete => {
- if(interactive && code.endsWith("\n\n")) {
+ case IR.Incomplete =>
+ if (interactive && code.endsWith("\n\n")) {
out.println("Two blank lines seen. Aborting this expression.")
None
} else {
- if(interactive) {
+ if (interactive) {
out.print(" | ")
out.flush
}
val nextLine = in.readLine
- if(nextLine == null)
+ if (nextLine == null)
None // end of file
else
interpretStartingWith(code + "\n" + nextLine)
}
- }
}
}
@@ -259,7 +258,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
}
/** process command-line arguments and do as they request */
- def main(args: Array[String]): unit = {
+ def main(args: Array[String]) {
def error1(msg: String): Unit = out.println("scala: " + msg)
val command = new InterpreterCommand(List.fromArray(args), error1)
@@ -268,9 +267,8 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
// explicitly requested a help listing
out.println(command.usageMsg)
out.flush
- return ()
}
-
- main(command.settings)
+ else
+ main(command.settings)
}
}
diff --git a/src/compiler/scala/tools/nsc/InterpreterResults.scala b/src/compiler/scala/tools/nsc/InterpreterResults.scala
index 9ae055abbf..41c738611e 100644
--- a/src/compiler/scala/tools/nsc/InterpreterResults.scala
+++ b/src/compiler/scala/tools/nsc/InterpreterResults.scala
@@ -1,16 +1,25 @@
+/* NSC -- new Scala compiler
+ * Copyright 2005-2007 LAMP/EPFL
+ * @author Martin Odersky
+ */
+// $Id: $
+
package scala.tools.nsc
object InterpreterResults {
- /** A result from interpreting one line of input */
+
+ /** A result from interpreting one line of input. */
abstract sealed class Result
- /** The line was interpreted successfully */
+ /** The line was interpreted successfully. */
case object Success extends Result
- /** The line was erroneous in some way */
+ /** The line was erroneous in some way. */
case object Error extends Result
/** The input was incomplete. The caller should request more
- * input. */
+ * input.
+ */
case object Incomplete extends Result
-} \ No newline at end of file
+
+}
diff --git a/src/compiler/scala/tools/nsc/MainInterpreter.scala b/src/compiler/scala/tools/nsc/MainInterpreter.scala
index 190088e48f..e4544c2550 100644
--- a/src/compiler/scala/tools/nsc/MainInterpreter.scala
+++ b/src/compiler/scala/tools/nsc/MainInterpreter.scala
@@ -1,5 +1,5 @@
/* NSC -- new Scala compiler
- * Copyright 2005-2006 LAMP/EPFL
+ * Copyright 2005-2007 LAMP/EPFL
* @author Lex Spoon
*/
// $Id$
@@ -8,7 +8,7 @@ package scala.tools.nsc
/** A command-line wrapper for the interpreter */
object MainInterpreter {
- def main(args: Array[String]): Unit = {
+ def main(args: Array[String]) {
(new InterpreterLoop).main(args)
}
}