julianpeeters / dc10-scala   0.9.0

Apache License 2.0 GitHub

A definitional compiler for generating Scala code.

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

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

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, Tuple2[Set[LibDep], List[Statement]], Tuple2[Set[LibDep], List[Statement]], Unit] = cats.data.IndexedStateT@3ef0c214

Use the compiler impl to check and render code toString or virtualFile:

import dc10.scala.compiler.{compile, string}
import dc10.scala.version.`3.3.4`

val result: String = snippet.compile.string
// result: String = """val str: String = "hello, world"
// val msg: String = str"""

Libraries