diff options
author | Lex Spoon <lex@lexspoon.org> | 2006-03-31 10:13:48 +0000 |
---|---|---|
committer | Lex Spoon <lex@lexspoon.org> | 2006-03-31 10:13:48 +0000 |
commit | 7ff239d7a998fb0ef7443e6c2020b6dcb64dabdd (patch) | |
tree | 4e7202e572e0afaff57db11e01dfdb14bdb5b8ff | |
parent | e9ea3247c61faf1be0c7d659dd03dda24ed7573e (diff) | |
download | scala-7ff239d7a998fb0ef7443e6c2020b6dcb64dabdd.tar.gz scala-7ff239d7a998fb0ef7443e6c2020b6dcb64dabdd.tar.bz2 scala-7ff239d7a998fb0ef7443e6c2020b6dcb64dabdd.zip |
replaying no longer adds to the replay list
-rw-r--r-- | src/compiler/scala/tools/nsc/InterpreterLoop.scala | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/InterpreterLoop.scala b/src/compiler/scala/tools/nsc/InterpreterLoop.scala index 52ecb7a37a..f7b09a16d3 100644 --- a/src/compiler/scala/tools/nsc/InterpreterLoop.scala +++ b/src/compiler/scala/tools/nsc/InterpreterLoop.scala @@ -70,6 +70,7 @@ class InterpreterLoop(in: BufferedReader, out: PrintWriter) { out.println("Type :help to repeat this message later.") } + /** The main read-eval-print loop for the interpereter. It calls command() for each line of input, and stops when command() returns false */ @@ -81,9 +82,12 @@ class InterpreterLoop(in: BufferedReader, out: PrintWriter) { if (line == null) return () // assumes null means EOF - val keepGoing = command(line) + val Pair(keepGoing, shouldReplay) = command(line) + if (!keepGoing) - return () // the evpr function said to stop + return () + if(shouldReplay) + addReplay(line) } } @@ -119,8 +123,10 @@ class InterpreterLoop(in: BufferedReader, out: PrintWriter) { } } - /** run one command submitted by the user */ - def command(line: String): Boolean = { + /** Run one command submitted by the user. Two values are returned: + * (1) whether to keep running, and (2) whether to record the + * command for replay. */ + def command(line: String): Pair[Boolean, Boolean] = { def withFile(command: String)(action: String => Unit): Unit = { val spaceIdx = command.indexOf(' ') if (spaceIdx <= 0) { @@ -142,20 +148,22 @@ class InterpreterLoop(in: BufferedReader, out: PrintWriter) { val loadRegexp = ":l(o(a(d)?)?)?.*" val replayRegexp = ":r(e(p(l(a(y)?)?)?)?)?.*" + var shouldReplay = false + if (line.matches(helpRegexp)) printHelp else if (line.matches(quitRegexp)) - return false + return Pair(false, false) else if (line.matches(compileRegexp)) { withFile(line)(f => { interpreter.compile(f) - addReplay(line) + shouldReplay = true }) } else if (line.matches(loadRegexp)) { withFile(line)(f => { interpretAllFrom(f) - addReplay(line) + shouldReplay = true }) } else if (line.matches(replayRegexp)) @@ -166,9 +174,9 @@ class InterpreterLoop(in: BufferedReader, out: PrintWriter) { () else { if(interpreter.interpret(line)) - addReplay(line) + shouldReplay = true } - true + Pair(true, shouldReplay) } |