build jar, generate hll files from dir

This commit is contained in:
DieMyst 2021-03-18 15:51:22 +03:00
parent 232cd0439c
commit ce049d42ca
4 changed files with 60 additions and 2 deletions

View File

@ -10,7 +10,8 @@ lazy val root = project
name := "aqua-hll",
version := "0.1.0",
scalaVersion := dottyVersion,
mainClass in (Compile, run) := Some("aqua.Main"),
mainClass in (Compile, run) := Some("aqua.AquaGen"),
mainClass in assembly := Some("aqua.AquaGen"),
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-effect" % "3.0.0-RC2",
"org.typelevel" %% "cats-parse" % "0.3.1",

View File

@ -1 +1,2 @@
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.6")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")

View File

@ -0,0 +1,56 @@
package aqua
import cats.data.Validated
import cats.effect.{ExitCode, IO, IOApp}
import java.io.{File, PrintWriter}
import scala.io.Source
object AquaGen extends IOApp {
override def run(args: List[String]): IO[ExitCode] =
IO {
val error = "There should be two arguments: path/to/input/dir and path/to/output/dir"
val process = for {
input <- args.headOption.toRight(error)
output <- args.lift(1).toRight(error)
inputDir <- {
val inputDir = new File(input)
if (!inputDir.isDirectory && !inputDir.exists()) Left("Input path should be a dir and exists")
else Right(inputDir)
}
outputDir <- {
val outputDir = new File(output)
if (!outputDir.isDirectory && !outputDir.exists()) Left("Output path should be a dir")
else Right(outputDir)
}
_ = convertAqua(inputDir.listFiles().toList, outputDir)
} yield {
}
process.fold(err => {
println(err);
ExitCode.Error
}, _ => ExitCode.Success)
}
def convertAqua(files: List[File], outputDir: File): Unit = {
for {
file <- files
} yield {
val src = Source.fromFile(file)
val lines = try src.mkString finally src.close()
val result = Aqua.generate(lines) match {
case Validated.Valid(v)
v.mkString("\n")
case Validated.Invalid(errs)
errs.map(_.showForConsole(lines)).toList.mkString("\n")
}
new PrintWriter(outputDir.toPath.resolve(file.getName + ".result").toFile.getAbsolutePath) { write(result); close() }
}
}
}

View File

@ -5,7 +5,7 @@ import cats.data.Validated
import scala.io.Source
object Main extends IOApp.Simple {
object Test extends IOApp.Simple {
override def run: IO[Unit] =
IO {