blob: b623d8820ac6ba9e952d04e5e9032c666d071179 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
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
}
|