summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/interpreter/IMain.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-08-01 22:45:12 +0000
committerPaul Phillips <paulp@improving.org>2011-08-01 22:45:12 +0000
commit60ee9924b7449ec64cffcecd6accd1a856c4fa3a (patch)
treecbf4fb3bdcae173197389b2a88d45ae64b45e1fe /src/compiler/scala/tools/nsc/interpreter/IMain.scala
parent257b6c91a52dc805dfb413b323a70e52f6499c2e (diff)
downloadscala-60ee9924b7449ec64cffcecd6accd1a856c4fa3a.tar.gz
scala-60ee9924b7449ec64cffcecd6accd1a856c4fa3a.tar.bz2
scala-60ee9924b7449ec64cffcecd6accd1a856c4fa3a.zip
Tired of ugly-printing in the repl, I sort of f...
Tired of ugly-printing in the repl, I sort of finished some old code for pretty printing token streams. It is at least a lot prettier than it once was, and I threw in some power mode helpers. Now you can do this. % scala -Dscala.repl.power Welcome to Scala version 2.10.0.r25427-b20110801144412 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26). // .u turns a string into an URL like .r does into a regex, and .pp pretty prints the url scala> "https://raw.github.com/scalaz/scalaz/master/example/src/main/scala/scal az/example/ExampleIteratee.scala".u.pp package scalaz.example object ExampleIteratee { def main (args: Array[String]) = run import scalaz._ import Scalaz._ import IterV._ [etc it's all there in real life] } No review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/interpreter/IMain.scala')
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/IMain.scala30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/IMain.scala b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
index b84bf178a0..207def1eb2 100644
--- a/src/compiler/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
@@ -19,7 +19,7 @@ import reporters._
import symtab.Flags
import scala.reflect.internal.Names
import scala.tools.util.PathResolver
-import scala.tools.nsc.util.{ ScalaClassLoader, Exceptional }
+import scala.tools.nsc.util.{ ScalaClassLoader, Exceptional, Indenter }
import ScalaClassLoader.URLClassLoader
import Exceptional.unwrap
import scala.collection.{ mutable, immutable }
@@ -1007,11 +1007,20 @@ class IMain(val settings: Settings, protected val out: JPrintWriter) extends Imp
}
}
- private object exprTyper extends { val repl: IMain.this.type = imain } with ExprTyper { }
+ object replTokens extends {
+ val global: imain.global.type = imain.global
+ } with ReplTokens { }
+
+ private object exprTyper extends {
+ val repl: IMain.this.type = imain
+ } with ExprTyper { }
+
def parse(line: String): Option[List[Tree]] = exprTyper.parse(line)
def typeOfExpression(expr: String, silent: Boolean = true): Option[Type] = {
exprTyper.typeOfExpression(expr, silent)
}
+ def prettyPrint(code: String) =
+ replTokens.prettyPrint(exprTyper tokens code)
protected def onlyTerms(xs: List[Name]) = xs collect { case x: TermName => x }
protected def onlyTypes(xs: List[Name]) = xs collect { case x: TypeName => x }
@@ -1090,9 +1099,20 @@ class IMain(val settings: Settings, protected val out: JPrintWriter) extends Imp
/** Secret bookcase entrance for repl debuggers: end the line
* with "// show" and see what's going on.
*/
- if (repllog.isTrace || (code.lines exists (_.trim endsWith "// show"))) {
- echo(code)
- parse(code) foreach (ts => ts foreach (t => withoutUnwrapping(repldbg(asCompactString(t)))))
+ def isShow = code.lines exists (_.trim endsWith "// show")
+ def isShowRaw = code.lines exists (_.trim endsWith "// raw")
+
+ // checking for various debug signals
+ if (isShowRaw)
+ replTokens withRawTokens prettyPrint(code)
+ else if (repllog.isTrace || isShow)
+ prettyPrint(code)
+
+ // old style
+ parse(code) foreach { ts =>
+ ts foreach { t =>
+ withoutUnwrapping(repldbg(asCompactString(t)))
+ }
}
}