Last active
November 11, 2016 09:39
-
-
Save daniel-trinh/8761259 to your computer and use it in GitHub Desktop.
Pretty Print method for formatting case class (as a string input)
This file contains hidden or 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 | |
case ',' => outputTree += char.toString + "\n" + indents | |
case _ => outputTree += char.toString | |
}} | |
def indents = " " * indentLevel * indentSize | |
outputTree | |
} | |
val asdf = """Argument(Expr(List(EqualsExpr(List(CallExpr(None, Token(VARID, firstGroup2, 34, firstGroup2 ), None, List(), None ) ), Token(EQUALS,=,46,= ), Expr(List(GeneralTokens(List(Token(STRING_LITERAL,"One",48,"One") ) ) ) ) ) ) ) )""" | |
pp(asdf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment