julianpeeters / dc10-scala   0.7.1

Apache License 2.0 GitHub

A definitional compiler for generating Scala code.

Scala versions: 3.x
Scala.js versions: 1.x
Scala Native versions: 0.4

dc10-scala

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"

dc10-scala

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

Libraries