bld extension for generating ANTLR4 grammars https://github.com/ethauvin/bld-antlr4.git
Find a file
Erik C. Thauvin f37a626997
Some checks failed
bld-ci / build-project (20) (push) Has been cancelled
javadocs-pages / deploy (push) Has been cancelled
bld-ci / build-project (17) (push) Has been cancelled
bld-ci / build-project (19) (push) Has been cancelled
Revert antlr4 update to preserve backward compatibility
2024-08-28 18:47:25 -07:00
.github/workflows GitHub setup 2023-04-04 09:25:28 -04:00
.idea Upgraded to bld 2.0.1 2024-07-28 21:08:23 -04:00
.vscode Upgraded to bld 2.0.1 2024-07-28 21:08:23 -04:00
lib/bld Upgraded to bld 2.0.1 2024-07-28 21:08:23 -04:00
src Revert antlr4 update to preserve backward compatibility 2024-08-28 18:47:25 -07: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
local.properties Updated version to 1.3.0. 2024-07-28 20:00:23 -04:00
README.md Upgraded to bld 2.0.1 2024-07-28 21:08:23 -04: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())));
}