mirror of
https://github.com/fluencelabs/aqua.git
synced 2024-12-04 22:50:18 +00:00
commit
6c4bea84ed
@ -1,4 +1,4 @@
|
||||
version = 2.5.0
|
||||
version = 2.7.5
|
||||
|
||||
docstrings = JavaDoc
|
||||
|
||||
|
@ -10,13 +10,16 @@ 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",
|
||||
"org.typelevel" %% "cats-free" % catsV,
|
||||
"com.github.julien-truffaut" %% "monocle-core" % monocleV,
|
||||
"com.github.julien-truffaut" %% "monocle-macro" % monocleV
|
||||
"com.github.julien-truffaut" %% "monocle-macro" % monocleV,
|
||||
"co.fs2" %% "fs2-core" % "3.0.0-M7",
|
||||
"co.fs2" %% "fs2-io" % "3.0.0-M7"
|
||||
),
|
||||
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.5" % Test
|
||||
)
|
||||
|
@ -1 +1,2 @@
|
||||
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.6")
|
||||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")
|
72
src/main/scala/aqua/AquaGen.scala
Normal file
72
src/main/scala/aqua/AquaGen.scala
Normal file
@ -0,0 +1,72 @@
|
||||
package aqua
|
||||
|
||||
import cats.data.Validated
|
||||
import cats.effect.{ExitCode, IO, IOApp}
|
||||
import fs2.io.file.Files
|
||||
import fs2.{text, Stream}
|
||||
import cats.implicits._
|
||||
|
||||
import java.io.{File, PrintWriter}
|
||||
import scala.io.Source
|
||||
import java.nio.file.{Path, Paths}
|
||||
|
||||
final case class ParseArgsException(private val message: String, private val cause: Throwable = None.orNull)
|
||||
extends Exception(message, cause)
|
||||
|
||||
object AquaGen extends IOApp {
|
||||
|
||||
override def run(args: List[String]): IO[ExitCode] = {
|
||||
val io = for {
|
||||
args <- IO.fromEither(parseArgs(args))
|
||||
(input, output) = args
|
||||
_ <- convertAqua(input, output)
|
||||
} yield {}
|
||||
io.map(_ => ExitCode.Success)
|
||||
.handleErrorWith(err => {
|
||||
println(err)
|
||||
IO(ExitCode.Error)
|
||||
})
|
||||
}
|
||||
|
||||
def parseArgs(args: List[String]): Either[ParseArgsException, (List[File], Path)] = {
|
||||
val error = ParseArgsException("There should be two arguments: path/to/input/dir and path/to/output/dir")
|
||||
for {
|
||||
input <- args.headOption.toRight(error)
|
||||
output <- args.lift(1).toRight(error)
|
||||
inputDir <- {
|
||||
val inputDir = new File(input)
|
||||
if (!inputDir.isDirectory && !inputDir.exists())
|
||||
Left(ParseArgsException("Input path should be a dir and exists"))
|
||||
else Right(inputDir)
|
||||
}
|
||||
outputDir <- {
|
||||
val outputDir = new File(output)
|
||||
if (!outputDir.isDirectory && !outputDir.exists()) Left(ParseArgsException("Output path should be a dir"))
|
||||
else Right(outputDir)
|
||||
}
|
||||
|
||||
} yield (inputDir.listFiles().toList, outputDir.toPath)
|
||||
}
|
||||
|
||||
def convertAqua(files: List[File], outputDir: Path): IO[List[Unit]] = {
|
||||
(for {
|
||||
file <- files
|
||||
} yield {
|
||||
Files[IO]
|
||||
.readAll(file.toPath, 4096)
|
||||
.through(text.utf8Decode)
|
||||
.map(text =>
|
||||
Aqua.generate(text) match {
|
||||
case Validated.Valid(v) ⇒
|
||||
v.mkString("\n")
|
||||
case Validated.Invalid(errs) ⇒
|
||||
errs.map(_.showForConsole(text)).toList.mkString("\n")
|
||||
}
|
||||
)
|
||||
.through(text.utf8Encode)
|
||||
.through(Files[IO].writeAll(outputDir.resolve(file.getName + ".result")))
|
||||
.compile
|
||||
.drain
|
||||
}).sequence
|
||||
}
|
||||
}
|
@ -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…
Reference in New Issue
Block a user