mirror of
https://github.com/fluencelabs/aqua.git
synced 2025-04-25 06:52:13 +00:00
build jar, generate hll files from dir
This commit is contained in:
parent
232cd0439c
commit
ce049d42ca
@ -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",
|
||||
|
@ -1 +1,2 @@
|
||||
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.6")
|
||||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")
|
56
src/main/scala/aqua/AquaGen.scala
Normal file
56
src/main/scala/aqua/AquaGen.scala
Normal 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() }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -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 {
|
Loading…
x
Reference in New Issue
Block a user