summaryrefslogtreecommitdiff
path: root/dhall_parser
diff options
context:
space:
mode:
authorNadrieril2019-03-08 00:49:42 +0100
committerNadrieril2019-03-08 00:49:42 +0100
commit465c3d2b97cfebcf47cbcef1dc847e592d31f434 (patch)
tree30c6f2894afc1367d3a2e97687c476b7cba99a32 /dhall_parser
parent16ce1082465a11bf76df5f59530cde02bddc4f21 (diff)
Generate pest file manually in the hopes to reduce spurious recompilations
Diffstat (limited to 'dhall_parser')
-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"));