bld extension for generating ANTLR4 grammars https://github.com/ethauvin/bld-antlr4.git
Find a file
Geert Bevin e1b3c111e9 Updated for bld 1.9.1.
Updated version to 1.2.8.
2024-05-01 16:43:12 -04:00
.github/workflows GitHub setup 2023-04-04 09:25:28 -04:00
.idea Updated for bld 1.9.1. 2024-05-01 16:43:12 -04:00
.vscode Updated for bld 1.9.1. 2024-05-01 16:43:12 -04:00
lib/bld Updated for bld 1.9.1. 2024-05-01 16:43:12 -04:00
src Updated for bld 1.9.1. 2024-05-01 16:43:12 -04:00
.gitignore Initial commit 2023-04-01 01:07:12 -04:00
bld Initial commit 2023-04-01 01:07:12 -04:00
bld.bat Initial commit 2023-04-01 01:07:12 -04:00
LICENSE Initial commit 2023-04-01 01:03:21 -04:00
README.md Updated for bld 1.9.0. 2024-02-25 22:42:00 -05:00

Bld extension to generate ANTLR4 parsers

License Java bld Release GitHub CI

A bld extension for generating Java sources from ANTLR4 parsers.

The complete documentation 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();
private final CompileOperation compileOperation = new CompileOperation();

@BuildCommand(summary = "Generates the grammar Java sources")
public void generateGrammar()
throws Exception {
    antlr4Operation.executeOnce(() -> antlr4Operation
        .sourceDirectories(List.of(new File(srcMainDirectory(), "antlr")))
        .outputDirectory(new File(buildDirectory(), "generated"))
        // these options are specific to ANTLR4, please refer to the extension
        // documentation to learn more about these and others
        .visitor()
        .longMessages());
}

public void compile()
throws Exception {
    // always generate the latest grammar before compiling the sources
    generateGrammar();

    // include the generated grammar with the main sources
    compileOperation.executeOnce(() -> compileOperation
        .fromProject(this)
        .mainSourceDirectories(List.of(antlr4Operation.outputDirectory())));
}