Skip to content

Commit 88a1539

Browse files
committed
Merge pull request scala#2710 from jedesah/repl_load
SI-4829 the :load command now fails if the command ends with a space
2 parents 196444e + 6e37f39 commit 88a1539

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/compiler/scala/tools/nsc/interpreter/ILoop.scala

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import java.io.{ BufferedReader, FileReader }
1111
import java.util.concurrent.locks.ReentrantLock
1212
import scala.sys.process.Process
1313
import session._
14-
import scala.tools.util.{ Signallable, Javap }
14+
import scala.tools.util.{ Signallable, Javap, StringOps }
1515
import scala.annotation.tailrec
1616
import scala.collection.mutable.ListBuffer
1717
import scala.concurrent.ops
@@ -591,31 +591,31 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
591591
}
592592
}
593593

594-
def withFile(filename: String)(action: File => Unit) {
595-
val f = File(filename)
594+
def smartPath(path: String) = if (File(path).exists) path else path.trim
595+
596+
def withPath(path: String)(action: File => Unit) {
597+
val f = File(path)
596598

597599
if (f.exists) action(f)
598-
else echo("That file does not exist")
600+
else echo("The path '" + f + "' doesn't seem to exist.")
599601
}
600602

601603
def loadCommand(arg: String) = {
602604
var shouldReplay: Option[String] = None
603-
withFile(arg)(f => {
605+
withPath(smartPath(arg))(f => {
604606
interpretAllFrom(f)
605607
shouldReplay = Some(":load " + arg)
606608
})
607609
Result(true, shouldReplay)
608610
}
609611

610612
def addClasspath(arg: String): Unit = {
611-
val f = File(arg).normalize
612-
if (f.exists) {
613+
withPath(File(arg).normalize.path)(f => {
613614
addedClasspath = ClassPath.join(addedClasspath, f.path)
614615
val totalClasspath = ClassPath.join(settings.classpath.value, addedClasspath)
615616
echo("Added '%s'. Your new classpath is:\n\"%s\"".format(f.path, totalClasspath))
616617
replay()
617-
}
618-
else echo("The path '" + f + "' doesn't seem to exist.")
618+
})
619619
}
620620

621621
def powerCmd(): Result = {
@@ -641,9 +641,10 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
641641
* if any. */
642642
def command(line: String): Result = {
643643
if (line startsWith ":") {
644-
val cmd = line.tail takeWhile (x => !x.isWhitespace)
644+
val lineNoColon = line.tail
645+
val (cmd, arg) = StringOps.splitLeft(lineNoColon, ' ').getOrElse((lineNoColon, ""))
645646
uniqueCommand(cmd) match {
646-
case Some(lc) => lc(line.tail stripPrefix cmd dropWhile (_.isWhitespace))
647+
case Some(lc) => lc(arg)
647648
case _ => ambiguousError(cmd)
648649
}
649650
}

src/compiler/scala/tools/util/StringOps.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ trait StringOps {
5454
if (idx == -1) None
5555
else Some(str take idx, str drop (if (doDropIndex) idx + 1 else idx))
5656

57+
def splitLeft(str: String, ch: Char): Option[(String, String)] = {
58+
splitAt(str, str.indexOf(ch), true)
59+
}
60+
5761
/** Returns a string meaning "n elements".
5862
*
5963
* @param n ...

0 commit comments

Comments
 (0)