liufengyun / eden   0.1

BSD 3-clause "New" or "Revised" License Website GitHub

[deprecated]dotty version of paradise for interfacing with scala.meta

Scala versions: 2.11

Eden Build Status

The dotty version of paradise to interface with scala.meta.

Usage

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.

Command Line Usage

Download the latest assembly here, then compile with the assembly in class path:

./bin/dotc -classpath path/to/eden-assembly.jar macros.scala

Sbt Usage

Add Eden as a dependency:

libraryDependencies += "me.fengy" % "eden_2.11" % "0.1.2"

Macros

More examples can be found below:

Note: macro definitions have to be compiled before usage.

Annotation Macros

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!"
}

Def Macros

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)