A Definitional Compiler for generating Scala code.
- Library for Scala 3 (JS, JVM, and Native platforms)
- Generates code for Scala 3
"com.julianpeeters" %% "dc10-scala" % "0.7.1"
Use the dsl
to define Scala code (see available libraries):
import dc10.scala.dsl.{*, given}
import scala.language.implicitConversions // for literals, e.g. "hello, world"
val snippet =
for
s <- VAL("str", STRING, "hello, world")
_ <- VAL("msg", STRING, s)
yield ()
// snippet: IndexedStateT[ErrorF, List[Statement], List[Statement], Unit] = cats.data.IndexedStateT@79ece636
Use the compiler
impl to check and render code toString
or toVirtualFile
:
import dc10.scala.compiler.{compile, toString}
import dc10.scala.version.`3.4.0`
val result: String = snippet.compile.toString["scala-3.4.0"]
// result: String = """val str: String = "hello, world"
// val msg: String = str"""