summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-03-29 20:22:53 +0000
committerPaul Phillips <paulp@improving.org>2011-03-29 20:22:53 +0000
commitb34ef21d7104a0878976c3027a910654e7e853ed (patch)
tree4ea041964dcea94a33755ed200eb7202c7ab2ac0 /src
parent21432085e182ff01ec339ae63031408d5a0ade81 (diff)
downloadscala-b34ef21d7104a0878976c3027a910654e7e853ed.tar.gz
scala-b34ef21d7104a0878976c3027a910654e7e853ed.tar.bz2
scala-b34ef21d7104a0878976c3027a910654e7e853ed.zip
Transcript pastes now work with leading whitesp...
Transcript pastes now work with leading whitespace (such as my commit message in r24624), no review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ILoop.scala2
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/IMain.scala8
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Pasted.scala21
3 files changed, 23 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala
index 8972bb6420..787502498a 100644
--- a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala
@@ -649,7 +649,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: PrintWriter)
* and avoid the interpreter, as it's likely not valid scala code.
*/
if (code == "") None
- else if (!paste.running && code.startsWith(PromptString)) {
+ else if (!paste.running && code.trim.startsWith(PromptString)) {
paste.transcript(code)
None
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/IMain.scala b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
index 5681196ef1..0dfc5f4483 100644
--- a/src/compiler/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
@@ -922,7 +922,13 @@ class IMain(val settings: Settings, protected val out: PrintWriter) {
execution.state match {
case Done => ("" + execution.get(), true)
- case Threw => if (bindLastException) handleException(execution.caught()) else throw execution.caught()
+ case Threw =>
+ val ex = execution.caught()
+ if (isReplDebug)
+ ex.printStackTrace()
+
+ if (bindLastException) handleException(ex)
+ else throw ex
case Cancelled => ("Execution interrupted by signal.\n", false)
case Running => ("Execution still running! Seems impossible.", false)
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/Pasted.scala b/src/compiler/scala/tools/nsc/interpreter/Pasted.scala
index e605bb010d..df106e1f00 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Pasted.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Pasted.scala
@@ -15,6 +15,18 @@ abstract class Pasted {
def PromptString: String
def interpret(line: String): Unit
+ private def matchesString(line: String, target: String): Boolean = (
+ (line startsWith target) ||
+ (line.nonEmpty && " \t".toSet(line.head) && matchesString(line.tail, target))
+ )
+ private def stripString(line: String, target: String) = line indexOf target match {
+ case -1 => line
+ case idx => line drop (idx + target.length)
+ }
+
+ def matchesPrompt(line: String) = matchesString(line, PromptString)
+ def matchesContinue(line: String) = matchesString(line, ContinueString)
+
private var isRunning = false
def running = isRunning
@@ -32,12 +44,9 @@ abstract class Pasted {
finally isRunning = false
}
- private def isPrompted(line: String) = line startsWith PromptString
- private def isContinuation(line: String) = line startsWith ContinueString
-
private def append(code: String, line: String): String =
- if (isPrompted(line)) code + "\n" + line
- else if (isContinuation(line)) code + "\n" + line.stripPrefix(ContinueString)
+ if (matchesPrompt(line)) code + "\n" + line
+ else if (matchesContinue(line)) code + "\n" + stripString(line, ContinueString)
else fixResRefs(code, line)
/** If the line looks like
@@ -49,7 +58,7 @@ abstract class Pasted {
*
* In all other cases, discard the line.
*/
- private val resRegex = """^(res\d+):.*""".r
+ private val resRegex = """^\s*(res\d+):.*""".r
private def fixResRefs(code: String, line: String) = line match {
case resRegex(resName) if code contains PromptString =>
val (str1, str2) = code splitAt code.lastIndexOf(PromptString) + PromptString.length