From c73ab4525e402cbbc0fd745a34c453520c87564c Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 30 Jan 2010 06:30:57 +0000 Subject: A compact tree printer, for primitives like mys... A compact tree printer, for primitives like myself who do all their debugging in the console and need extraneous information filtered out. New option: -Ycompact-trees. Supply that in conjunction with -Xprint:all and suddenly the output is a (relative) masterpiece of concision. Review by anyone who is game to review such a thing. Community? --- test/files/run/treePrint.scala | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/files/run/treePrint.scala (limited to 'test/files/run/treePrint.scala') diff --git a/test/files/run/treePrint.scala b/test/files/run/treePrint.scala new file mode 100644 index 0000000000..ffe9a392d4 --- /dev/null +++ b/test/files/run/treePrint.scala @@ -0,0 +1,40 @@ +/** Testing compact tree printers. + */ +object Test { + import scala.tools.nsc._ + import java.io.{ OutputStream, BufferedReader, StringReader, PrintWriter, Writer, OutputStreamWriter} + + val code = """ + def foo = { + var q: Boolean = false + val x = if (true) { + if (true) { + if (true) { + 5 + } + else if (true) { + 5 + } else { + 10 + } + } + else 20 + } + else 30 + + (x == 5) || !q || true + } + """ + + class NullOutputStream extends OutputStream { def write(b: Int) { } } + + def main(args: Array[String]) { + val settings = new Settings + settings.classpath.value = System.getProperty("java.class.path") + settings.Ycompacttrees.value = true + + val repl = new Interpreter(settings, new PrintWriter(new NullOutputStream)) + repl.interpret("""def initialize = "Have to interpret something or we get errors." """) + println(repl mkTree code) + } +} -- cgit v1.2.3