mirror of
https://github.com/ethauvin/bld-antlr4.git
synced 2025-04-25 00:37:12 -07:00
bld extension for generating ANTLR4 grammars
https://github.com/ethauvin/bld-antlr4.git
.github/workflows | ||
.idea | ||
.vscode | ||
lib/bld | ||
src | ||
.gitignore | ||
bld | ||
bld.bat | ||
LICENSE | ||
README.md |
Bld extension to generate ANTLR4 parsers
A bld
extension for generating Java sources from ANTLR4 parsers.
The complete document of Antrl4Operation
can be found in its javadocs.
This is an example usage where your ANTLR4 sources would be located at
src/main/antlr
and the parsers generated into build/generated
. The compile
command then uses an adapted CompileOperation
to include the generated
sources into the main source directories.
private final Antlr4Operation antlr4Operation_ = new Antlr4Operation();
@BuildCommand
public void generateGrammar()
throws Exception {
antlr4Operation_.executeOnce(o -> o
.sourceDirectories(List.of(new File(srcMainDirectory(), "antlr")))
.outputDirectory(new File(buildDirectory(), "generated"))
.visitor()
.longMessages());
}
// compileOperation_ is part of the main project
public void compile()
throws Exception {
generateGrammar();
compileOperation_.executeOnce(o -> o
.fromProject(this)
.mainSourceDirectories(List.of(antlr4Operation_.outputDirectory())));
}