summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dhall_parser/Cargo.toml3
-rw-r--r--dhall_parser/build.rs18
-rw-r--r--dhall_parser/src/lib.rs7
3 files changed, 21 insertions, 7 deletions
diff --git a/dhall_parser/Cargo.toml b/dhall_parser/Cargo.toml
index a73d445..758c273 100644
--- a/dhall_parser/Cargo.toml
+++ b/dhall_parser/Cargo.toml
@@ -11,7 +11,8 @@ doctest = false
[build-dependencies]
abnf_to_pest = { path = "../abnf_to_pest" }
+pest_generator = "2.1"
+quote = "0.6.11"
[dependencies]
pest = { git = "https://github.com/pest-parser/pest" }
-pest_derive = "2.1"
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(())
}
diff --git a/dhall_parser/src/lib.rs b/dhall_parser/src/lib.rs
index 452b4cd..94b49b5 100644
--- a/dhall_parser/src/lib.rs
+++ b/dhall_parser/src/lib.rs
@@ -1,6 +1 @@
-#[allow(unused_imports)]
-use pest_derive::*;
-
-#[derive(Parser)]
-#[grammar = "dhall.pest"]
-pub struct DhallParser;
+include!(concat!(env!("OUT_DIR"), "/grammar.rs"));