-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from UQ-PAC/staging
Merge staging into main
- Loading branch information
Showing
85 changed files
with
8,992 additions
and
1,165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.11.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//package net.mlbox.millantlr | ||
// https://github.com/da-tubi/antlr4-scala-example/blob/master/antlr.sc | ||
import mill._ | ||
import mill.define._ | ||
import mill.scalalib._ | ||
import $ivy.`org.antlr:antlr4:4.9.3` | ||
import org.antlr.v4.tool.{ANTLRMessage, ANTLRToolListener} | ||
|
||
import scala.collection.mutable | ||
|
||
trait AntlrModule extends JavaModule { | ||
def antlrGrammarSources: mill.define.Target[Seq[mill.api.PathRef]] | ||
def antlrPackage: Option[String] = None | ||
def antlrGenerateVisitor: Boolean = false | ||
def antlrGenerateListener: Boolean = false | ||
|
||
def antlrGrammarSourceFiles = T { | ||
antlrGrammarSources().flatMap { source => | ||
if (os.isDir(source.path)) { | ||
os.walk(source.path) | ||
} else { | ||
Seq(source.path) | ||
} | ||
}.filter { path => | ||
os.isFile(path) && path.ext == "g4" | ||
}.map(PathRef(_)) | ||
} | ||
|
||
def antlrGenerate = T { | ||
val antlrToolArgs = mutable.ArrayBuffer.empty[String] | ||
|
||
antlrToolArgs.appendAll(antlrGrammarSourceFiles().map(_.path.relativeTo(os.pwd).toString)) | ||
antlrToolArgs.append("-o") | ||
antlrToolArgs.append(s"${T.dest}") | ||
if (antlrGenerateVisitor) { | ||
antlrToolArgs.append("-visitor") | ||
} | ||
if (antlrGenerateListener) { | ||
antlrToolArgs.append("-listener") | ||
} | ||
if (antlrPackage.isDefined) { | ||
antlrToolArgs.append("-package") | ||
antlrToolArgs.append(antlrPackage.get) | ||
} | ||
|
||
val antlrTool = new org.antlr.v4.Tool(antlrToolArgs.toArray) | ||
antlrTool.addListener(new ToolListener()) | ||
antlrTool.processGrammarsOnCommandLine() | ||
|
||
os.walk(T.dest).filter(path => os.isFile(path) && path.ext == "java").map(PathRef(_)) | ||
} | ||
|
||
override def generatedSources = T { | ||
super.generatedSources() ++ antlrGenerate() | ||
} | ||
} | ||
|
||
class ToolListener extends ANTLRToolListener { | ||
override def info(msg: String): Unit = throw new RuntimeException(msg) | ||
override def error(msg: ANTLRMessage): Unit = throw new RuntimeException(msg.toString) | ||
override def warning(msg: ANTLRMessage): Unit = throw new RuntimeException(msg.toString) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import mill._, mill.define._, scalalib._ | ||
|
||
import $file.antlr // https://index.scala-lang.org/ml86/mill-antlr | ||
|
||
import os.Path | ||
import $ivy.`com.lihaoyi::mill-contrib-scalapblib:$MILL_VERSION` | ||
import contrib.scalapblib._ | ||
|
||
|
||
|
||
object basil extends RootModule with ScalaModule with antlr.AntlrModule with ScalaPBModule{ | ||
def scalaVersion = "3.3.1" | ||
|
||
val javaTests = ivy"com.novocode:junit-interface:0.11" | ||
val scalaTests = ivy"org.scalatest::scalatest:3.2.10" | ||
val scalactic = ivy"org.scalactic::scalactic:3.2.10" | ||
val antlrRuntime = ivy"org.antlr:antlr4-runtime:4.9" | ||
val sourceCode = ivy"com.lihaoyi::sourcecode:0.3.0" | ||
val mainArgs = ivy"com.lihaoyi::mainargs:0.5.1" | ||
val sprayJson = ivy"io.spray::spray-json:1.3.6" | ||
val scalapb = ivy"com.thesamet.scalapb::scalapb-runtime:0.11.15" | ||
|
||
def scalaPBVersion = "0.11.15" | ||
|
||
|
||
def mainClass = Some("Main") | ||
|
||
override def scalaPBSources = T.sources {Seq(PathRef(this.millSourcePath / "main" / "protobuf"))} | ||
def millSourcePath = super.millSourcePath / "src" | ||
def ivyDeps = Agg(scalactic, antlrRuntime, sourceCode, mainArgs, sprayJson, scalapb) | ||
def sources = T.sources {Seq(PathRef(this.millSourcePath / "main" / "scala" ))} | ||
|
||
|
||
override def antlrPackage: Option[String] = Some("Parsers") | ||
override def antlrGenerateVisitor = true | ||
override def antlrGrammarSources = T.sources { | ||
Seq(PathRef(millSourcePath / "main" / "antlr4")) | ||
} | ||
|
||
object test extends ScalaTests with TestModule.ScalaTest { | ||
def ivyDeps = Agg(scalaTests, javaTests) | ||
def sources = T.sources {Seq(PathRef(this.millSourcePath / "scala" ))} | ||
} | ||
|
||
|
||
/** | ||
* Updates the expected | ||
*/ | ||
def updateExpected() = T.command { | ||
val correctPath = test.millSourcePath / "correct" | ||
val incorrectPath = test.millSourcePath / "incorrect" | ||
|
||
def expectedUpdate(path: Path, shouldVerify: Boolean): Unit = { | ||
val examples = os.list(path).filter(os.isDir) | ||
for (e <- examples) { | ||
val variations = os.list(e).filter(os.isDir) | ||
for (v <- variations) { | ||
val name = e.last | ||
val outPath = v / (name + ".bpl") | ||
val expectedPath = v / (name + ".expected") | ||
val resultPath = v / (name + "_result.txt") | ||
if (os.exists(resultPath)) { | ||
val result = os.read(resultPath) | ||
val verified = result.strip().equals("Boogie program verifier finished with 0 errors") | ||
if (verified == shouldVerify) { | ||
if (os.exists(outPath) && !(os.exists(expectedPath) && filesContentEqual(outPath, expectedPath))) { | ||
println(s"updated $expectedPath") | ||
os.copy.over(outPath, expectedPath) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
def filesContentEqual(path1: Path, path2: Path): Boolean = { | ||
os.read(path1) == os.read(path2) | ||
} | ||
|
||
expectedUpdate(correctPath, true) | ||
expectedUpdate(incorrectPath, false) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
FROM docker.io/nixos/nix:latest AS nix-dev-base | ||
RUN nix-channel --update | ||
RUN printf '%s\n' "extra-experimental-features = nix-command flakes" "extra-trusted-users = $USER" | tee -a /etc/nix/nix.conf | ||
RUN nix profile install --impure 'github:katrinafyi/pac-nix#aslp' | ||
RUN nix profile install --impure 'github:katrinafyi/pac-nix#bap-aslp' | ||
RUN nix profile install --impure 'nixpkgs#boogie' | ||
RUN nix profile install --impure 'nixpkgs#openjdk' | ||
RUN nix profile install --impure 'nixpkgs#coursier' && cs setup --yes | ||
RUN cs install mill | ||
ENV PATH=$PATH:/root/.local/share/coursier/bin | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.