Skip to content

Instantly share code, notes, and snippets.

@hexx
Created February 23, 2013 08:23
Show Gist options
  • Save hexx/5018956 to your computer and use it in GitHub Desktop.
Save hexx/5018956 to your computer and use it in GitHub Desktop.
Making a macro tree using ToolBox.
object Macros {
def tbtest = macro tbtestImpl
def tbtestImpl(c:Context) = {
import c.universe._
import scala.reflect.runtime.{currentMirror => cm}
import scala.reflect.runtime.{universe => ru}
val toolBox = cm.mkToolBox()
val importer = c.universe.mkImporter(ru)
val code = """println("Hello Hogeika!")"""
val tree = importer.importTree(toolBox.parse(code))
c.Expr[Unit](Block(List(tree), Literal(Constant(()))))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment