summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/interactive/REPL.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2011-07-04 09:19:14 +0000
committerMartin Odersky <odersky@gmail.com>2011-07-04 09:19:14 +0000
commit9b3c49a171ae32c5f2471dbf7f4b622d6ad42798 (patch)
treed90bb35ee13ee409cae059e68e4b785e5dd058aa /src/compiler/scala/tools/nsc/interactive/REPL.scala
parent54b26beb2c9a82fc5a1b3a66f11ed763bfad39be (diff)
downloadscala-9b3c49a171ae32c5f2471dbf7f4b622d6ad42798.tar.gz
scala-9b3c49a171ae32c5f2471dbf7f4b622d6ad42798.tar.bz2
scala-9b3c49a171ae32c5f2471dbf7f4b622d6ad42798.zip
Towards a scratchpad functionality for the IDE
Diffstat (limited to 'src/compiler/scala/tools/nsc/interactive/REPL.scala')
-rw-r--r--src/compiler/scala/tools/nsc/interactive/REPL.scala15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/interactive/REPL.scala b/src/compiler/scala/tools/nsc/interactive/REPL.scala
index 7545a2f714..f5b536a3f4 100644
--- a/src/compiler/scala/tools/nsc/interactive/REPL.scala
+++ b/src/compiler/scala/tools/nsc/interactive/REPL.scala
@@ -89,6 +89,7 @@ object REPL {
val completeResult = new Response[List[comp.Member]]
val typedResult = new Response[comp.Tree]
val structureResult = new Response[comp.Tree]
+ val instrumentedResult = new Response[(String, SourceFile)]
def makePos(file: String, off1: String, off2: String) = {
val source = toSourceFile(file)
@@ -111,6 +112,11 @@ object REPL {
show(structureResult)
}
+ def formatInstrumented(r: (String, SourceFile)) = {
+ val (name, source) = r
+ "toplevel object = "+name+", contents = \n"+source.content.mkString
+ }
+
loop { line =>
(line split " ").toList match {
case "reload" :: args =>
@@ -132,6 +138,11 @@ object REPL {
doComplete(makePos(file, off1, off2))
case List("complete", file, off1) =>
doComplete(makePos(file, off1, off1))
+ case List("instrument", file) =>
+ val source = toSourceFile(file)
+ comp.askReload(List(source), reloadResult)
+ comp.askInstrumented(source, instrumentedResult)
+ show(instrumentedResult, formatInstrumented)
case List("quit") =>
comp.askShutdown()
// deleted sys. as this has to run on 2.8 also
@@ -146,9 +157,9 @@ object REPL {
def toSourceFile(name: String) = new BatchSourceFile(new PlainFile(new java.io.File(name)))
- def show[T](svar: Response[T]) {
+ def show[T](svar: Response[T], transform: T => Any = (x: T) => x) {
svar.get match {
- case Left(result) => println("==> "+result)
+ case Left(result) => println("==> "+transform(result))
case Right(exc) => exc.printStackTrace; println("ERROR: "+exc)
}
svar.clear()