diff options
Diffstat (limited to 'src/repl')
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/ILoop.scala | 28 | ||||
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/IMain.scala | 1 | ||||
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/PresentationCompilation.scala | 7 |
3 files changed, 20 insertions, 16 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/ILoop.scala b/src/repl/scala/tools/nsc/interpreter/ILoop.scala index f934bbe46c..f844029b64 100644 --- a/src/repl/scala/tools/nsc/interpreter/ILoop.scala +++ b/src/repl/scala/tools/nsc/interpreter/ILoop.scala @@ -764,7 +764,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter) * read, go ahead and interpret it. Return the full string * to be recorded for replay, if any. */ - @tailrec final def interpretStartingWith(code: String): Option[String] = { + final def interpretStartingWith(code: String): Option[String] = { // signal completion non-completion input has been received in.completion.resetVerbosity() @@ -791,17 +791,21 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter) case IR.Incomplete if in.interactive && code.endsWith("\n\n") => echo("You typed two blank lines. Starting a new command.") None - case IR.Incomplete => in.readLine(paste.ContinuePrompt) match { - case null => - // we know compilation is going to fail since we're at EOF and the - // parser thinks the input is still incomplete, but since this is - // a file being read non-interactively we want to fail. So we send - // it straight to the compiler for the nice error message. - intp.compileString(code) - None - - case line => interpretStartingWith(s"$code\n$line") - } + case IR.Incomplete => + val saved = intp.partialInput + intp.partialInput = code + "\n" + try { + in.readLine(paste.ContinuePrompt) match { + case null => + // we know compilation is going to fail since we're at EOF and the + // parser thinks the input is still incomplete, but since this is + // a file being read non-interactively we want to fail. So we send + // it straight to the compiler for the nice error message. + intp.compileString(code) + None + case line => interpretStartingWith(s"$code\n$line") + } + } finally intp.partialInput = saved } } } diff --git a/src/repl/scala/tools/nsc/interpreter/IMain.scala b/src/repl/scala/tools/nsc/interpreter/IMain.scala index 2085fd4e50..f6f391600b 100644 --- a/src/repl/scala/tools/nsc/interpreter/IMain.scala +++ b/src/repl/scala/tools/nsc/interpreter/IMain.scala @@ -80,6 +80,7 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set private var _isInitialized: Future[Boolean] = null // set up initialization future private var bindExceptions = true // whether to bind the lastException variable private var _executionWrapper = "" // code to be wrapped around all lines + var partialInput: String = "" // code accumulated in multi-line REPL input /** We're going to go to some trouble to initialize the compiler asynchronously. * It's critical that nothing call into it until it's been initialized or we will diff --git a/src/repl/scala/tools/nsc/interpreter/PresentationCompilation.scala b/src/repl/scala/tools/nsc/interpreter/PresentationCompilation.scala index 81c4fb0b70..3a2177a4cb 100644 --- a/src/repl/scala/tools/nsc/interpreter/PresentationCompilation.scala +++ b/src/repl/scala/tools/nsc/interpreter/PresentationCompilation.scala @@ -28,10 +28,9 @@ trait PresentationCompilation { // // scala> 1 // scala> .toInt - val line1 = if (Completion.looksLikeInvocation(line)) { - self.mostRecentVar + line - } else line - + // + // and for multi-line input. + val line1 = partialInput + (if (Completion.looksLikeInvocation(line)) { self.mostRecentVar + line } else line) val compiler = newPresentationCompiler() val trees = compiler.newUnitParser(line1).parseStats() val importer = global.mkImporter(compiler) |