diff options
| author | Nadrieril Feneanar | 2019-12-22 00:48:35 +0000 | 
|---|---|---|
| committer | GitHub | 2019-12-22 00:48:35 +0000 | 
| commit | 06e75c919d999c310f8ca1c151c6a5ad6918ca08 (patch) | |
| tree | 849a54821e08c78cbff4965e1a268e050466fa6c /dhall/build.rs | |
| parent | ce74f996808ae84b4967040f3441e1bbba31f506 (diff) | |
| parent | 139daf4da23c87366d920cea2775afe11cce7be7 (diff) | |
Merge pull request #122 from Nadrieril/publish
Publish to crates.io
Diffstat (limited to '')
| -rw-r--r-- | dhall/build.rs | 28 | 
1 files changed, 26 insertions, 2 deletions
| diff --git a/dhall/build.rs b/dhall/build.rs index 50f423e..3021f03 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -408,9 +408,10 @@ fn generate_tests() -> std::io::Result<()> {  }  fn convert_abnf_to_pest() -> std::io::Result<()> { +    let out_dir = env::var("OUT_DIR").unwrap();      let abnf_path = "src/dhall.abnf";      let visibility_path = "src/dhall.pest.visibility"; -    let pest_path = "src/dhall.pest"; +    let grammar_path = Path::new(&out_dir).join("dhall.pest");      println!("cargo:rerun-if-changed={}", abnf_path);      println!("cargo:rerun-if-changed={}", visibility_path); @@ -427,7 +428,7 @@ fn convert_abnf_to_pest() -> std::io::Result<()> {          }      } -    let mut file = File::create(pest_path)?; +    let mut file = File::create(grammar_path)?;      writeln!(&mut file, "// AUTO-GENERATED FILE. See build.rs.")?;      // TODO: this is a cheat; properly support RFC3986 URLs instead @@ -493,8 +494,31 @@ fn convert_abnf_to_pest() -> std::io::Result<()> {      Ok(())  } +// Generate pest parser manually becaue otherwise we'd need to modify something outside of +// OUT_DIR and that's forbidden by docs.rs. +fn generate_pest_parser() -> std::io::Result<()> { +    let out_dir = env::var("OUT_DIR").unwrap(); +    let grammar_path = Path::new(&out_dir).join("dhall.pest"); +    let grammar_path = grammar_path.to_str(); +    let output_path = Path::new(&out_dir).join("dhall_parser.rs"); + +    let pest = quote::quote!( +        #[grammar = #grammar_path] +        struct DhallParser; +    ); +    let derived = pest_generator::derive_parser(pest, false); +    let file_contents = quote::quote!( +        struct DhallParser; +        #derived +    ); + +    let mut file = File::create(output_path)?; +    writeln!(file, "{}", file_contents) +} +  fn main() -> std::io::Result<()> {      convert_abnf_to_pest()?; +    generate_pest_parser()?;      generate_tests()?;      Ok(())  } | 
