Skip to main content

antlr_rust_codegen/
lib.rs

1//! ANTLR v4 grammar compiler and Rust source generator.
2
3mod artifact;
4mod builder;
5mod cli;
6mod cli_report;
7mod config;
8mod driver;
9pub(crate) mod embedded;
10mod error;
11#[path = "pipeline.rs"]
12mod generator;
13#[allow(dead_code)]
14pub(crate) mod grammar;
15mod lexer;
16mod optimization;
17mod parser;
18mod rust_output;
19mod semantics;
20mod structural;
21mod test_rig;
22mod testrig_cli;
23
24pub use artifact::Generation;
25pub use builder::{ActionMode, Builder, UnknownSemanticPolicy};
26pub use error::{Diagnostic, Error, ErrorKind, Severity};
27
28/// Version of this generator package.
29pub const VERSION: &str = env!("CARGO_PKG_VERSION");
30
31/// Generated-source/runtime API revision emitted by this generator.
32pub const CODEGEN_API: u32 = antlr4_runtime::__ANTLR4_RUST_CODEGEN_API;
33
34#[cfg(test)]
35pub(crate) use generator::ParserCodegenData;
36#[cfg(test)]
37pub(crate) use parser::render_parser;
38#[cfg(test)]
39pub(crate) use rust_output::rust_string;
40#[cfg(test)]
41pub(crate) use semantics::collect_structural_grammar_options;
42#[cfg(test)]
43pub(crate) use structural::{structural_embedded_model, structural_predicates};
44
45/// Runs the `antlr4-rust-gen` command using the process arguments and streams.
46///
47/// The public [`Builder`] API is the preferred integration point for build
48/// scripts. This function exists for the package's binary adapter.
49#[doc(hidden)]
50pub fn run_cli() -> miette::Result<()> {
51    cli_report::install_handler_from_env();
52    cli::run_cli()
53}
54
55/// Runs the `antlr4-rust-testrig` command using the process arguments.
56#[doc(hidden)]
57pub fn run_testrig_cli() -> miette::Result<std::process::ExitCode> {
58    cli_report::install_handler_from_env();
59    testrig_cli::run_cli()
60}