summaryrefslogtreecommitdiff
path: root/dhall_parser/build.rs
diff options
context:
space:
mode:
authorNadrieril2019-03-08 00:49:42 +0100
committerNadrieril2019-03-08 00:49:42 +0100
commit465c3d2b97cfebcf47cbcef1dc847e592d31f434 (patch)
tree30c6f2894afc1367d3a2e97687c476b7cba99a32 /dhall_parser/build.rs
parent16ce1082465a11bf76df5f59530cde02bddc4f21 (diff)
Generate pest file manually in the hopes to reduce spurious recompilations
Diffstat (limited to 'dhall_parser/build.rs')
-rw-r--r--dhall_parser/build.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/dhall_parser/build.rs b/dhall_parser/build.rs
index a206517..bc342c1 100644
--- a/dhall_parser/build.rs
+++ b/dhall_parser/build.rs
@@ -1,6 +1,8 @@
use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader, Read, Write};
+use std::env;
+use std::path::Path;
use abnf_to_pest::{abnf_to_pest, PestRuleSettings};
@@ -68,5 +70,21 @@ fn main() -> std::io::Result<()> {
"final_expression = {{ SOI ~ complete_expression ~ EOI }}"
)?;
+
+ // Generate pest parser manually to avoid spurious recompilations
+ let derived = {
+ let pest_path = "dhall.pest";
+ let pest = quote::quote! {
+ #[grammar = #pest_path]
+ pub struct DhallParser;
+ };
+ pest_generator::derive_parser(pest, false)
+ };
+
+ let out_dir = env::var("OUT_DIR").unwrap();
+ let grammar_path = Path::new(&out_dir).join("grammar.rs");
+ let mut file = File::create(grammar_path)?;
+ writeln!(file, "pub struct DhallParser;\n{}", derived,)?;
+
Ok(())
}