The dotty version of paradise to interface with scala.meta.
NOTE: Before the PR is merged into Dotty, the following instructions only make sense to our clone of the Dotty compiler. Check the build setting for the macros
project for more details.
Download the latest assembly here, then compile with the assembly in class path:
./bin/dotc -classpath path/to/eden-assembly.jar macros.scala
Add Eden as a dependency:
libraryDependencies += "me.fengy" % "eden_2.11" % "0.1.2"
More examples can be found below:
Note: macro definitions have to be compiled before usage.
Definition:
import scala.annotation.StaticAnnotation
import scala.meta._
import scala.meta.dialects.Dotty
import scala.collection.immutable.Seq
class main extends StaticAnnotation {
inline def apply(defn: Any): Any = meta {
val q"object $name { ..$stats }" = defn
val main = q"""
def stub(args: Any): Any = { ..$stats }
"""
q"object $name { $main }"
}
}
Usage:
@main object Test {
"hello world!"
}
Definition:
class plus {
inline def apply(a: Any, b: Any): Any = meta {
q"$a + $b"
}
}
Usage:
val p = new plus
assert(p(3, 5) == 8)