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