Scala - how to print case classes like (pretty printed) tree

前端 未结 10 1877
情歌与酒
情歌与酒 2020-12-07 22:35

I\'m making a parser with Scala Combinators. It is awesome. What I end up with is a long list of entagled case classes, like: ClassDecl(Complex,List(VarDecl(Real,float

10条回答
  •  忘掉有多难
    2020-12-07 23:02

    Use the com.lihaoyi.pprint library.

    libraryDependencies += "com.lihaoyi" %% "pprint" % "0.4.1"
    
    val data = ...
    
    val str = pprint.tokenize(data).mkString
    println(str)
    

    you can also configure width, height, indent and colors:

    pprint.tokenize(data, width = 80).mkString
    

    Docs: http://www.lihaoyi.com/PPrint/

提交回复
热议问题