Customizing the Build Process

When you setup LALRPOP, you create a build.rs file that looks something like this:

fn main() {
    lalrpop::process_root().unwrap();
}

This process_root() call simply applies the default configuration: so it will transform .lalrpop files into .rs files in-place (in your src directory), and it will only do so if the .lalrpop file has actually changed. But you can also use the Configuration struct to get more detailed control.

For example, to force the use of colors in the output (ignoring the TTY settings), you might make your build.rs file look like so:

fn main() {
    lalrpop::Configuration::new()
        .always_use_colors()
        .process_current_dir();
}

Rerun Directives

Cargo will rerun the build script on each compilation even if the lalrpop file has not changed. To disable this behavior, use the emit_rerun_directives function when setting up your lalrpop Configuration.

fn main() {
    lalrpop::Configuration::new()
        .emit_rerun_directives(true)
        .process_current_dir();
}

By default, this is set to false in case other parts of the build script or compilation code expects build.rs to be run unconditionally.

Using the Legacy LALR Parser

By default, LALRPOP uses the lane table algorithm which is LR(1) but creates much smaller tables. There is no longer any clear benefit to using the previous LALR implementation but it is still available.

To enable it, build with the LALRPOP_LANE_TABLE=disabled environment variable by setting std::env::set_var in your build.rs and add the #[LALR] attribute above the grammar; declaration in your lalrpop grammar file.