1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! Build script for the crate.
//!
//! This script automates lexer and parser code generation at build time,
//! using the **parlex-gen** tools (**Alex** and **ASLR**) to convert
//! grammar specification files into Rust source artifacts.
//!
//! # Overview
//! During the Cargo build process, this script is executed before
//! compilation to ensure that up-to-date lexer and parser data are
//! generated from their respective specification files. It monitors
//! both input specs for changes and triggers regeneration automatically.
//!
//! # Generation Steps
//! 1. Invokes [`parlex_gen::alex::generate`] to build lexer data from
//! `src/calc.alex` into the Cargo `OUT_DIR` as `lexer_data.rs`.
//! 2. Invokes [`parlex_gen::aslr::generate`] to build parser data from
//! `src/calc.g` into the same directory as `parser_data.rs`.
//!
//! # Cargo Integration
//! The script emits `cargo:rerun-if-changed` directives so Cargo will
//! automatically re-run the build script if either specification file
//! is modified. It also prints human-readable warnings to the build log
//! showing input and output paths for clarity.
//!
//! # Notes
//! - This script assumes both the `parlex_gen` crate and its `alex` and
//! `aslr` modules are available at build time.
//! - Errors in generation will cause the build to fail immediately.
use PathBuf;
/// Build-time entry point for lexer and parser generation.
///
/// Called automatically by Cargo before compilation. This function:
/// - Determines the manifest and output directories.
/// - Invokes **Alex** and **ASLR** generators to produce lexer and parser code.
/// - Emits Cargo directives to trigger regeneration on input file changes.
///
/// # Panics
/// Panics if environment variables `CARGO_MANIFEST_DIR` or `OUT_DIR`
/// are missing, or if generation fails.