diff options
author | Paul Phillips <paulp@improving.org> | 2009-05-03 15:37:20 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-05-03 15:37:20 +0000 |
commit | e8cdd793c538a020d279723e942c226072be7894 (patch) | |
tree | 0ee65f9422a9f49daf4ddce5854b7ef2771652a8 /src/compiler | |
parent | 2bb5db8e23f54ecea3bc82c48d408ec61c3cd25b (diff) | |
download | scala-e8cdd793c538a020d279723e942c226072be7894.tar.gz scala-e8cdd793c538a020d279723e942c226072be7894.tar.bz2 scala-e8cdd793c538a020d279723e942c226072be7894.zip |
caught corner case for interpreter commands.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/InterpreterLoop.scala | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/InterpreterLoop.scala b/src/compiler/scala/tools/nsc/InterpreterLoop.scala index 944a978ec7..ff74d5177b 100644 --- a/src/compiler/scala/tools/nsc/InterpreterLoop.scala +++ b/src/compiler/scala/tools/nsc/InterpreterLoop.scala @@ -274,18 +274,23 @@ class InterpreterLoop(in0: Option[BufferedReader], out: PrintWriter) { out println msg Result(true, None) } + def ambiguous(cmds: List[Command]) = "Ambiguous: did you mean " + cmds.map(":" + _.name).mkString(" or ") + "?" // not a command if (!line.startsWith(":")) return Result(true, interpretStartingWith(line)) - // this lets us add commands willy-nilly and only requires enough command to disambiguate - val (x :: args) = line.substring(1).split("""\s+""").toList + val tokens = line.substring(1).split("""\s+""").toList + if (tokens.isEmpty) + return withError(ambiguous(commands)) + + val (cmd :: args) = tokens - commands.filter(_.name startsWith x) match { + // this lets us add commands willy-nilly and only requires enough command to disambiguate + commands.filter(_.name startsWith cmd) match { case List(x) => x(args) case Nil => withError("Unknown command. Type :help for help.") - case xs => withError("Ambiguous: did you mean " + xs.map(":" + _.name).mkString(" or ") + "?") + case xs => withError(ambiguous(xs)) } } |