Created
December 2, 2012 12:39
-
-
Save aztek/4188468 to your computer and use it in GitHub Desktop.
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
import language.experimental.macros | |
import reflect.macros.Context | |
object WeirdMacro { | |
def show_structure(something: Any): String = macro show_structure_impl | |
def show_structure_impl(c: Context)(something: c.Expr[Any]): c.Expr[String] = { | |
import c.universe._ | |
c.Expr[String](Literal(Constant(something.tree.toString))) | |
} | |
} |
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
import WeirdMacro._ | |
object WeirdMacroTest extends App { | |
val expr = show_structure { | |
a -> b | |
} | |
println(expr) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@macro def show_structure(something: Any): String = q"${something.toString}"