Skip to content

Instantly share code, notes, and snippets.

@maxhodak
Created November 27, 2012 09:51
Show Gist options
  • Save maxhodak/4153384 to your computer and use it in GitHub Desktop.
Save maxhodak/4153384 to your computer and use it in GitHub Desktop.
import scala.tools.nsc._
import io._
object MkTree {
object Compiler extends Global(new Settings()) {
new Run() // have to initialize the compiler
def parse(code: String) = {
val bfs = new util.BatchSourceFile("<parse>", code)
val unit = new CompilationUnit(new util.ScriptSourceFile(bfs, code.toArray, 0))
val scanner = new syntaxAnalyzer.UnitParser(unit)
scanner.templateStatSeq(false)._2
}
def print(t: Tree) = println(newStandardTreePrinter() printRaw t)
}
def main(args: Array[String]): Unit = {
val data = scala.io.Source.fromFile(args(0)).mkString
val ts = Compiler.parse(data)
ts map Compiler.nodeToString foreach println
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment