Skip to content

v2.1.0

Compare
Choose a tag to compare
@ehwan ehwan released this 18 Aug 06:15
· 58 commits to main since this release

Add feature for build.rs support

  • This buildscripting tool will provide much more detailed, pretty-printed error messages than the procedural macros, at compile time.
  • Generated code will contain the same structs and functions as the procedural macros.
  • In your actual source code, you can include! the generated file.
    You can enable the feature build to use in the build script.
[build-dependencies]
rusty_lr = { version = "...", features = ["build"] }
// build.rs
use rusty_lr::build;

fn main() {
    println!("cargo::rerun-if-changed=src/parser.rs");

    let output = format!("{}/parser.rs", std::env::var("OUT_DIR").unwrap());
    build::Builder::new()
        .file("src/parser.rs") // path to the input file
    //  .lalr()                // to generate LALR(1) parser
        .build(&output);       // path to the output file
}

The program searches for %% in the input file, not the lr1!, lalr1! macro. The contents before %% will be copied into the output file as it is. And the context-free grammar must be followed by %%.

If there is any errors when building a grammar, it will print error messages to stderr and then panic. This will make the messages to be shown during compilation.

image