Skip to main content

antlr_rust_codegen/
lib.rs

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