Skip to content

Instantly share code, notes, and snippets.

@daniel-trinh
Last active November 11, 2016 09:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniel-trinh/8761259 to your computer and use it in GitHub Desktop.
Save daniel-trinh/8761259 to your computer and use it in GitHub Desktop.
Pretty Print method for formatting case class (as a string input)
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