fix: convert parser to use FParsley

This commit is contained in:
2025-03-13 13:26:35 +00:00
parent 3fff9d3825
commit 5141a2369f
2 changed files with 59 additions and 38 deletions

View File

@@ -18,6 +18,7 @@ import org.typelevel.log4cats.Logger
import assemblyIR as asm
import cats.data.ValidatedNel
import java.io.File
/*
TODO:
@@ -68,11 +69,12 @@ val outputOpt: Opts[Option[Path]] =
.orNone
def frontend(
contents: String
contents: String, file: File
): Either[NonEmptyList[Error], microWacc.Program] =
parser.parse(contents) match {
case Failure(msg) => Left(NonEmptyList.one(Error.SyntaxError(msg)))
case Success(ast.PartialProgram(_, prog)) =>
case Success(fn) =>
val ast.PartialProgram(_, prog) = fn(file)
given errors: mutable.Builder[Error, List[Error]] = List.newBuilder
val (names, funcs) = renamer.rename(prog)
@@ -105,8 +107,8 @@ def compile(
writer.writeTo(backend(typedProg), outputPath) *>
logger.info(s"Success: ${outputPath.toAbsolutePath}")
def processProgram(contents: String, outDir: Path): IO[Int] =
frontend(contents) match {
def processProgram(contents: String, file: File, outDir: Path): IO[Int] =
frontend(contents, file) match {
case Left(errors) =>
val code = errors.map(err => err.exitCode).toList.min
given errorContent: String = contents
@@ -127,7 +129,7 @@ def compile(
for {
contents <- readSourceFile
_ <- logAction(s"Compiling file: ${filePath.toAbsolutePath}")
exitCode <- processProgram(contents, outputDir.getOrElse(filePath.getParent))
exitCode <- processProgram(contents, filePath.toFile, outputDir.getOrElse(filePath.getParent))
} yield exitCode
}