Skip to main content

dbt_antlr_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 for the `dbt-antlr-runtime`
4//! runtime.
5//!
6//! The emission layer renders recognizers from the minijinja template
7//! `templates/dbt/Rust.stg.jinja` on top of the grammar analysis in `grammar`.
8//! There are two ways to run a generation:
9//!
10//! - [`Config`]: the build-script API. Add this crate as a build dependency
11//!   and call it from `build.rs`; the generated code compiles against the
12//!   `dbt-antlr-runtime` crate. No tool installation is needed.
13//! - The `dbt-antlr-codegen` binary: the Java-tool-like command line for
14//!   one-shot or checked-in generation.
15//!
16//! # Crate features
17//!
18//! - `generator` (default): the in-process grammar compiler and emission
19//!   layer. Disable it to use this crate as a thin client.
20//! - `download`: enables [`Config::pinned_release`], which downloads and runs
21//!   a pinned prebuilt release binary instead of compiling the generator.
22//! - `fancy` (default): pretty miette diagnostics for the command line.
23//! - `atn-export`: internal, for this workspace's own tests.
24#[cfg(feature = "atn-export")]
25pub mod atn_export;
26#[cfg(feature = "generator")]
27pub mod cli;
28#[cfg(feature = "generator")]
29mod compile_error;
30mod config;
31#[cfg(feature = "download")]
32mod download;
33#[cfg(feature = "generator")]
34pub mod emission;
35mod error;
36#[cfg(feature = "generator")]
37mod explain;
38#[cfg(feature = "generator")]
39#[allow(dead_code)]
40pub(crate) mod grammar;
41mod optimization;
42
43pub use config::{Config, Generation};
44pub use error::{Diagnostic, EmitError, Error, ErrorKind, Severity};
45pub use optimization::OptimizationOptions;
46
47/// Version of this generator package.
48pub const VERSION: &str = env!("CARGO_PKG_VERSION");
49
50/// Runs the `dbt-antlr-codegen` command using the process arguments and
51/// streams.
52#[cfg(feature = "generator")]
53#[doc(hidden)]
54pub fn run_cli() -> miette::Result<()> {
55    cli::run_cli()
56}