Skip to content

Instantly share code, notes, and snippets.

@aztek
Created December 2, 2012 12:39
Show Gist options
  • Save aztek/4188468 to your computer and use it in GitHub Desktop.
Save aztek/4188468 to your computer and use it in GitHub Desktop.
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)))
}
}
import WeirdMacro._
object WeirdMacroTest extends App {
val expr = show_structure {
a -> b
}
println(expr)
}
@xeno-by
Copy link

xeno-by commented Dec 2, 2012

@macro def show_structure(something: Any): String = q"${something.toString}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment