blob: b623d8820ac6ba9e952d04e5e9032c666d071179 (
plain) (
tree)
|
|
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.Context
import scala.reflect.macros.ParseException
object Macros {
def impl(c: Context)() = {
import c.universe._
val out = try {
c.parse("foo(bar")
"didn't fail"
} catch {
case e: ParseException =>
s"failed with '${e.pos}' position and '${e.msg}' message"
}
c.Expr[String](Literal(Constant(out)))
}
def foo(): String = macro impl
}
|