Created
November 26, 2012 19:26
-
-
Save SethTisue/4150095 to your computer and use it in GitHub Desktop.
using JFlex from sbt
This file contains hidden or 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
sourceGenerators in Compile <+= JFlexRunner.task |
This file contains hidden or 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
import java.io.File | |
import sbt._ | |
import Keys._ | |
object JFlexRunner { | |
val task = | |
(cacheDirectory, javaSource in Compile, streams) map { | |
(cacheDir, src, s) => | |
val cache = | |
FileFunction.cached(cacheDir / "lexers", inStyle = FilesInfo.hash, outStyle = FilesInfo.hash) { | |
in: Set[File] => | |
Set(flex(s.log.info(_), src, "agent", "ImportLexer"), | |
flex(s.log.info(_), src, "lex", "TokenLexer")) | |
} | |
cache(Set(file("..") / "project" / "warning.txt", | |
file("..") / "project" / "ImportLexer.flex", | |
file("..") / "project" / "TokenLexer.flex")).toSeq | |
} | |
// this used to be broken into two tasks, but jflex doesnt seem to be threadsafe | |
// so we have to run them serially, which means we have to generate them both each time. -JC 6/8/10 | |
def flex(log: String => Unit, dir: File, ppackage: String, kind: String): File = { | |
val project = file(".") / "project" | |
val nlogoPackage = dir / "org" / "nlogo" | |
val result = nlogoPackage / ppackage / (kind + ".java") | |
log("generating " + result) | |
JFlex.Main.main(Array("--quiet", (project / (kind + ".flex")).asFile.toString)) | |
IO.write(result, | |
IO.read(project / "warning.txt") + | |
IO.read(project / (kind + ".java"))) | |
(project / (kind + ".java")).asFile.delete() | |
result | |
} | |
} |
This file contains hidden or 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
libraryDependencies += "de.jflex" % "jflex" % "1.4.3" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment