Last active
December 13, 2015 23:49
-
-
Save ochafik/4994437 to your computer and use it in GitHub Desktop.
Macro Extensions Plugin Input / Output with macro body
This file contains hidden or 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
@scalaxy.extension[Any] | |
def quoted(quote: String): String = macro { | |
// `c` is defined as the macro Context. | |
// `quote` and `self` are in scope, defined as `c.Expr[Any]` and `c.Expr[String]`. | |
println(s"Currently expanding ${c.prefix}.quoted(${quote.tree})") | |
// `c.universe._` is automatically imported, so `reify` is in scope. | |
reify({ | |
// Make sure we're not evaluating quote twice, in case it's a complex expression! | |
val q = quote.splice | |
q + self.splice + q | |
}) | |
} |
This file contains hidden or 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
// Transformed AST after the `scalaxy-extensions` compilation phase: | |
import scala.language.experimental.macros | |
implicit class scalaxy$extensions$quoted$1(self: Any) { | |
def quoted(quote: String) = macro scalaxy$extensions$quoted$1.quoted | |
} | |
object scalaxy$extensions$quoted$1 { | |
def quoted(c: scala.reflect.macros.Context) | |
(quote: c.Expr[String]): c.Expr[String] = { | |
import c.universe._ | |
val Apply(_, List(selfTree$1)) = c.prefix.tree | |
val self = c.Expr[Any](selfTree$1) | |
reify({ | |
// Make sure we're not evaluating quote twice, in case it's a complex expression! | |
val q = quote.splice | |
q + self.splice + q | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment