This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pp(tree: String, indentSize: Int = 2): String = { | |
var indentLevel = 0 | |
var outputTree = "" | |
tree foreach { char => char match { | |
case '(' => | |
indentLevel += 1 | |
outputTree += char.toString+'\n'+indents | |
case ')' => | |
indentLevel -= 1 | |
outputTree += "\n" + indents + char.toString |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//quick hack to pretty-print some text: | |
"((hi)(bye(yeah))((x)))".foldLeft(0){ | |
(a,b)=> { | |
var indent=a; | |
b match { | |
case '('=> println("("); indent=a+2; print(" "*indent); | |
case ')'=>println;indent=a-2;println(" "*indent + ")");print(" "*indent) | |
case x => print(x); |
NewerOlder