Created
February 23, 2013 08:23
-
-
Save hexx/5018956 to your computer and use it in GitHub Desktop.
Making a macro tree using ToolBox.
This file contains 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
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