@@ -64,7 +64,7 @@ object Worksheet {
6464 private def execute (evaluator : Evaluator , tree : Tree , sourcefile : SourceFile ): (Int , String ) = {
6565 val source = sourcefile.content.slice(tree.pos.start, tree.pos.end).mkString
6666 val line = sourcefile.offsetToLine(tree.pos.end)
67- (line, evaluator.eval(source))
67+ (line, evaluator.eval(source).getOrElse( " " ) )
6868 }
6969
7070 private def encode (message : String , line : Int ): String =
@@ -155,10 +155,10 @@ private class Evaluator private (javaExec: String,
155155 * @param command The command to evaluate.
156156 * @return The result from the REPL.
157157 */
158- def eval (command : String ): String = {
158+ def eval (command : String ): Option [ String ] = {
159159 processInput.println(command)
160160 processInput.flush()
161- processOutput.next().trim
161+ processOutput.next().map(_. trim)
162162 }
163163
164164 /**
@@ -212,6 +212,7 @@ private class ReplReader(stream: InputStream) extends Thread {
212212 private val in = new InputStreamReader (stream)
213213
214214 private [this ] var output : Option [String ] = None
215+ private [this ] var closed : Boolean = false
215216
216217 override def run (): Unit = synchronized {
217218 val prompt = " scala> "
@@ -228,18 +229,18 @@ private class ReplReader(stream: InputStream) extends Thread {
228229 wait()
229230 }
230231 }
231- output = Some ( " " )
232+ closed = true
232233 notify()
233234 }
234235
235236 /** Block until the next message is ready. */
236- def next (): String = synchronized {
237+ def next (): Option [ String ] = synchronized {
237238
238- while (output.isEmpty) {
239+ while (! closed && output.isEmpty) {
239240 wait()
240241 }
241242
242- val result = output.get
243+ val result = output
243244 notify()
244245 output = None
245246 result
0 commit comments