dc10.scala.compiler.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dc10-scala_3 Show documentation
Show all versions of dc10-scala_3 Show documentation
A definitional compiler for generating Scala code.
package dc10.scala
import cats.data.StateT
import dc10.compile.{Compiler, Renderer, VirtualFile}
import dc10.scala.ast.{ScalaFile, Statement}
import dc10.scala.error.{CompileError, ErrorF}
implicit object compiler extends Compiler[
ErrorF,
List,
CompileError,
Statement,
ScalaFile
]:
type Ctx[F[_], L, A] = StateT[F, L, A]
extension [C, D] (ast: StateT[ErrorF, List[D], C])
def compile: ErrorF[List[D]] =
ast.runEmptyS
extension (res: ErrorF[List[Statement]])
def toString[V](
using R: Renderer[V, CompileError, List[Statement]]
): String =
res.fold(R.renderErrors, R.render)
extension (res: ErrorF[List[Statement]])
def toStringOrError[V](
using R: Renderer[V, CompileError, List[Statement]]
): ErrorF[String] =
res.map(R.render)
extension (res: ErrorF[List[ScalaFile]])
def toVirtualFile[V](
using R: Renderer[V, CompileError, List[Statement]]
): ErrorF[List[VirtualFile]] =
for
fds <- res
yield fds.map(fileDef =>
VirtualFile(
fileDef.path,
R.render(fileDef.contents)
)
)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy