diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f56fc098..f81797b2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,10 +2,8 @@ Before doing anything else, run `cargo build -p lalrpop`! -From now on use `cargo compile/test -p lalrpop --features=test` instead of -`cargo build -p lalrpop`. - -Just before your final commit, run `sh update_lrgrammar.sh` +When making changes the alter the generated code, use `sh update_lrgrammar.sh` +to pass the `verify_lalrpop_generates_itself` test. ### Contributor's "How to" @@ -37,20 +35,8 @@ generate your own `lrgrammar.rs` parser. That's how you do it: $ cargo build -p lalrpop # --release ``` -Now you need to tell cargo that you're using `lalrpop/src/parser/lrgrammar.lalrpop` to generate -a new `lrgrammar.rs` inside `{CARGO_OUT_DIR}` and use it for the compilation: - -```sh -$ cargo build/test -p lalrpop --features=test -# or -$ cargo build/test -p lalrpop --all-features -``` - -When this flag is passed, cargo uses not `lalrpop/src/parser/lrgrammar.rs` but the newly generated -`lrgrammar.rs` instead (generating it if needed). From now on you use this command. - -Once you're done with your work, all the tests are passed, and you are ready to finally commit -you changes run +Once you're done with your work, make sure that you are running against an +updated version of the grammar. ```sh $ sh update_lrgrammar.sh diff --git a/lalrpop/build.rs b/lalrpop/build.rs deleted file mode 100644 index f6698f18..00000000 --- a/lalrpop/build.rs +++ /dev/null @@ -1,62 +0,0 @@ -use std::env; -use std::error::Error; -use std::fs; -use std::path::{Path, PathBuf}; -use std::process::{exit, Command}; - -fn main() { - if let Err(err) = main_() { - eprintln!("{}", err); - exit(1); - } -} - -fn find_lalrpop_binary(prefix: &str) -> Option { - let lalrpop_path = Path::new(prefix) - .join("target") - .join(env::var("PROFILE").unwrap()) - .join("lalrpop") - .with_extension(env::consts::EXE_EXTENSION); - if lalrpop_path.exists() { - Some(lalrpop_path) - } else { - None - } -} - -fn main_() -> Result<(), Box> { - let grammar_file = "src/parser/lrgrammar.lalrpop"; - println!(r#"cargo:rerun-if-changed={}"#, grammar_file); - - let out_dir = PathBuf::from(env::var("OUT_DIR").expect("cargo did not set OUT_DIR")); - - fs::create_dir_all(out_dir.join("src/parser"))?; - - if env::var("CARGO_FEATURE_TEST").is_ok() { - let lalrpop_path = find_lalrpop_binary("..").or_else(|| find_lalrpop_binary(".")) - .unwrap_or_else(|| { - panic!( - "Can't find a lalrpop binary to use for the snapshot. Make sure it is built and exists at target/{}/lalrpop!", - env::var("PROFILE").unwrap() - ) - }); - - let copied_grammar = out_dir.join("src/parser/lrgrammar.lalrpop"); - fs::copy(grammar_file, &copied_grammar) - .map_err(|err| format!("Unable to grammar to OUT_DIR: {}", err))?; - let status = Command::new(lalrpop_path) - .args([ - "--force", - "--features", - "test", - copied_grammar - .to_str() - .expect("grammar path is not valid UTF-8"), - ]) - .status()?; - if !status.success() { - return Err("Compiling the .lalrpop file failed".into()); - } - } - Ok(()) -} diff --git a/lalrpop/src/parser/mod.rs b/lalrpop/src/parser/mod.rs index 2a424660..0e9731e9 100644 --- a/lalrpop/src/parser/mod.rs +++ b/lalrpop/src/parser/mod.rs @@ -4,20 +4,11 @@ use crate::grammar::parse_tree::*; use crate::grammar::pattern::*; use crate::tok; -#[cfg(not(feature = "test"))] #[rustfmt::skip] #[allow(dead_code)] #[allow(clippy::all)] mod lrgrammar; -#[cfg(feature = "test")] -lalrpop_mod!( - #[rustfmt::skip] - #[allow(dead_code)] - #[allow(clippy::all)] - lrgrammar, - "/src/parser/lrgrammar.rs" -); #[cfg(test)] mod test;