Skip to content

Instantly share code, notes, and snippets.

@xeno-by
Created March 18, 2014 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeno-by/9619590 to your computer and use it in GitHub Desktop.
Save xeno-by/9619590 to your computer and use it in GitHub Desktop.
import scala.language.experimental.macros
import scala.reflect.macros.Context
import scala.annotation.StaticAnnotation
class csvTyped(val sample: String)(funcs: (String => Any)*) extends StaticAnnotation {
def macroTransform(annottees: Any*): Any = macro Macros.impl
}
object Macros {
def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
import c.universe._
val Apply(Select(Apply(Apply(_, List(Literal(Constant(macroArgument: String)))), functions), _), _) = c.macroApplication
val types = functions.map(func => c.typeCheck(func, typeOf[String => Any], silent = false, withImplicitViewsDisabled = false, withMacrosDisabled = false).tpe).map {
case TypeRef(_, fn1, _ :: returnType :: Nil) if fn1 == typeOf[Function1[_, _]].typeSymbol => returnType
}
???
}
}
=======
@csvTyped("sample.csv")(_.toDouble)
object Test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment