adtdsl
lets yout define your ADTs using the concise syntax of an internal DSL.
Here's a little example of what you can do with it:
adt MyList {
object Nil
class Cons(head: Int, tail: MyList)
}
transforms into
sealed trait MyList
object MyList {
case object Nil extends MyList
case class Cons(head: Int, tail: MyList) extends MyList
}
- Clone this repository
- Run
./sbt publishLocal
in the project folder to build the project and install it to the local repository
Add adtdsl
library as your project dependency:
libraryDependencies += "io.github.maseev" % "adtdsl" % "0.1"
import com.adtdsl.AdtGenerator._
val input =
"""
|adt MyList {
| object Nil
| class Cons(head: Int, tail: MyList)
|}
|""".stripMargin
val scalaCode = generate(input)