Possible Duplicate:
What’s the easiest way to use reify (get an AST of) an expression in Scala?
Inside of a macro definition, I can use c.reify
on the Context
parameter to turn an expression into an AST.
But I'd love to be able to test my macro functions by passing them AST's and seeing what comes out. In other words, given:
def printf(format: String, args: Any*): Unit = macro printf_impl
def printf_impl(c: Context)(format: c.Expr[String], args: Expr[Any]*): c.Expr[Unit] = ....
I'd like to be able to do this to get the AST generated by specific expressions, so I can do unit testing or just informally test at the REPL
printf_impl(c.reify("x%sy", c.reify(4 + 5))
But what should c
be in that expression?