diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-07-15 14:16:07 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-07-15 14:16:07 -0700 |
commit | 88a1539c68241b1b1f17194d8adf08811cf8c398 (patch) | |
tree | e7b4eefd9fb9d27f26681ac3de30e248b9bdd966 | |
parent | 196444e42950ba9c06d2ec7cb37cc751e8f949f2 (diff) | |
parent | 6e37f39bcc1294143078db60d58020653947504b (diff) | |
download | scala-2.9.x.tar.gz scala-2.9.x.tar.bz2 scala-2.9.x.zip |
Merge pull request #2710 from jedesah/repl_load2.9.x
SI-4829 the :load command now fails if the command ends with a space
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/ILoop.scala | 23 | ||||
-rw-r--r-- | src/compiler/scala/tools/util/StringOps.scala | 4 |
2 files changed, 16 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala index d38f42f609..c7eecc0940 100644 --- a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala +++ b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala @@ -11,7 +11,7 @@ import java.io.{ BufferedReader, FileReader } import java.util.concurrent.locks.ReentrantLock import scala.sys.process.Process import session._ -import scala.tools.util.{ Signallable, Javap } +import scala.tools.util.{ Signallable, Javap, StringOps } import scala.annotation.tailrec import scala.collection.mutable.ListBuffer import scala.concurrent.ops @@ -591,16 +591,18 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter) } } - def withFile(filename: String)(action: File => Unit) { - val f = File(filename) + def smartPath(path: String) = if (File(path).exists) path else path.trim + + def withPath(path: String)(action: File => Unit) { + val f = File(path) if (f.exists) action(f) - else echo("That file does not exist") + else echo("The path '" + f + "' doesn't seem to exist.") } def loadCommand(arg: String) = { var shouldReplay: Option[String] = None - withFile(arg)(f => { + withPath(smartPath(arg))(f => { interpretAllFrom(f) shouldReplay = Some(":load " + arg) }) @@ -608,14 +610,12 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter) } def addClasspath(arg: String): Unit = { - val f = File(arg).normalize - if (f.exists) { + withPath(File(arg).normalize.path)(f => { addedClasspath = ClassPath.join(addedClasspath, f.path) val totalClasspath = ClassPath.join(settings.classpath.value, addedClasspath) echo("Added '%s'. Your new classpath is:\n\"%s\"".format(f.path, totalClasspath)) replay() - } - else echo("The path '" + f + "' doesn't seem to exist.") + }) } def powerCmd(): Result = { @@ -641,9 +641,10 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter) * if any. */ def command(line: String): Result = { if (line startsWith ":") { - val cmd = line.tail takeWhile (x => !x.isWhitespace) + val lineNoColon = line.tail + val (cmd, arg) = StringOps.splitLeft(lineNoColon, ' ').getOrElse((lineNoColon, "")) uniqueCommand(cmd) match { - case Some(lc) => lc(line.tail stripPrefix cmd dropWhile (_.isWhitespace)) + case Some(lc) => lc(arg) case _ => ambiguousError(cmd) } } diff --git a/src/compiler/scala/tools/util/StringOps.scala b/src/compiler/scala/tools/util/StringOps.scala index 65ff582011..25ea401eb7 100644 --- a/src/compiler/scala/tools/util/StringOps.scala +++ b/src/compiler/scala/tools/util/StringOps.scala @@ -54,6 +54,10 @@ trait StringOps { if (idx == -1) None else Some(str take idx, str drop (if (doDropIndex) idx + 1 else idx)) + def splitLeft(str: String, ch: Char): Option[(String, String)] = { + splitAt(str, str.indexOf(ch), true) + } + /** Returns a string meaning "n elements". * * @param n ... |