Scala:如何在宏实现中访问宏注释的相关参数值?

时间:2019-04-03 14:09:07

标签: scala macros annotations arguments scala-macro-paradise

我正在使用属于Scala宏天堂的宏注释(link)。

在他们的示例中,他们使用名为$ echo '"HI:"Hola!""' | perl -lne 'print $& if /\w+(?=:)/' HI 的宏注释,该注释不带参数。但是,我尝试实现的宏注释确实需要一个参数:

identity

我的问题:如何在实现@compileTimeOnly("enable macro paradise to expand macro annotations") class f(id: String) extends StaticAnnotation { def macroTransform(annottees: Any*) = macro identityMacro.impl } object identityMacro extends App { def impl(c: Context)(annottees: c.Expr[Any]*) = { import c.universe._ // how to access id here? } } 的宏中访问id的值?我尝试将其作为附加参数传递给identityMacro.impl,但这不起作用。我假设我必须通过上下文访问它?

0 个答案:

没有答案
相关问题