45 lines
1.1 KiB
Scala
45 lines
1.1 KiB
Scala
package wacc
|
|
|
|
import parsley.{Failure, Success}
|
|
import scopt.OParser
|
|
import java.io.File
|
|
|
|
case class CliConfig(
|
|
file: File = new File(".")
|
|
)
|
|
|
|
val cliBuilder = OParser.builder[CliConfig]
|
|
val cliParser = {
|
|
import cliBuilder._
|
|
OParser.sequence(
|
|
programName("wacc-compiler"),
|
|
help('h', "help")
|
|
.text("Prints this help message"),
|
|
arg[File]("<file>")
|
|
.text("Input WACC source file")
|
|
.required()
|
|
.action((f, c) => c.copy(file = f))
|
|
.validate(f =>
|
|
if (!f.exists) failure("File does not exist")
|
|
else if (!f.isFile) failure("File must be a regular file")
|
|
else if (!f.getName.endsWith(".wacc"))
|
|
failure("File must have .wacc extension")
|
|
else success
|
|
)
|
|
)
|
|
}
|
|
|
|
def compile(contents: String): Int = {
|
|
parser.parse(contents) match {
|
|
case Success(x) => 0
|
|
case Failure(msg) => 100
|
|
}
|
|
}
|
|
|
|
def main(args: Array[String]): Unit =
|
|
OParser.parse(cliParser, args, CliConfig()) match {
|
|
case Some(config) =>
|
|
System.exit(scala.util.Random.between(0, 3) * 100)
|
|
case None =>
|
|
}
|