summaryrefslogtreecommitdiff
path: root/dhall_parser/build.rs
diff options
context:
space:
mode:
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(())
}