/paradise

Implementation of new-style ("inline") macros for scalac

Primary LanguageScalaBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Scalameta Paradise Plugin

Join the chat at https://gitter.im/scalameta/scalameta

This is a prototype of new-style ("inline") macros based on scala.meta. Results can be reproduced with scala.meta 1.0.0 and macro paradise 3.0.0-M3.

$ cat Macros.scala
import scala.meta._

class main extends scala.annotation.StaticAnnotation {
  inline def apply(defn: Any) = meta {
    val q"object $name { ..$stats }" = defn
    val main = q"""
      def main(args: Array[String]): Unit = { ..$stats }
    """
    q"object $name { $main }"
  }
}

$ scalac -cp <scala.meta> -Xplugin:<paradise> Macros.scala

$ cat Test.scala
@main object Test {
  println("hello world")
}

$ scalac -cp . -Xplugin:<paradise> Test.scala && scala Test
hello world

Check out Eugene Burmako's talk at ScalaDays Berlin 2016 to learn more: http://scalamacros.org/paperstalks/2016-06-17-Metaprogramming20.pdf.