Created
November 27, 2012 09:51
-
-
Save maxhodak/4153384 to your computer and use it in GitHub Desktop.
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
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