Created
June 24, 2015 19:49
-
-
Save dozed/ed5c3b2bc727ca752d68 to your computer and use it in GitHub Desktop.
This file contains 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 scala.language.experimental.macros | |
object implicit_dsls extends App { | |
trait DSLImpl { | |
def getImpl(route: String)(action: => Any): Unit | |
} | |
object MacroDSL { | |
import scala.reflect.macros.blackbox.Context | |
def getImplM(c: Context)(route: c.Expr[String])(action: c.Expr[Any]): c.Expr[Unit] = { | |
c.universe.reify { | |
println("macro get") | |
} | |
} | |
implicit val macroDSLImpl = new DSLImpl { | |
// macros cant implement abstract methods | |
// | |
// def getImpl(route: String)(action: => Any): Unit = macro getImplM | |
def getImpl(route: String)(action: => Any): Unit = {} | |
} | |
} | |
object DefaultDSL { | |
implicit val defaultDSLImpl = new DSLImpl { | |
def getImpl(route: String)(action: => Any): Unit = { | |
println("default get") | |
} | |
} | |
} | |
trait DSL | |
object DSL extends DSL { | |
def get(route: String)(action: => Any)(implicit dslImpl: DSLImpl) = dslImpl.getImpl(route)(action) | |
} | |
// import DefaultDSL._ | |
import MacroDSL._ | |
DSL.get("/foo") { | |
"ok" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment