summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock13
-rw-r--r--dhall_parser/Cargo.toml3
-rw-r--r--dhall_parser/build.rs18
-rw-r--r--dhall_parser/src/lib.rs7
4 files changed, 23 insertions, 18 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4dbe2e4..6130c94 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -77,7 +77,8 @@ version = "0.1.0"
dependencies = [
"abnf_to_pest 0.1.0",
"pest 2.1.0 (git+https://github.com/pest-parser/pest)",
- "pest_derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pest_generator 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -164,15 +165,6 @@ dependencies = [
]
[[package]]
-name = "pest_derive"
-version = "2.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "pest 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "pest_generator 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "pest_generator"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -309,7 +301,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum nom 4.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4836e9d6036552017e107edc598c97b2dee245161ff1b1ad4af215004774b354"
"checksum pest 2.1.0 (git+https://github.com/pest-parser/pest)" = "<none>"
"checksum pest 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "54f0c72a98d8ab3c99560bfd16df8059cc10e1f9a8e83e6e3b97718dd766e9c3"
-"checksum pest_derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0"
"checksum pest_generator 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "63120576c4efd69615b5537d3d052257328a4ca82876771d6944424ccfd9f646"
"checksum pest_meta 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f5a3492a4ed208ffc247adcdcc7ba2a95be3104f58877d0d02f0df39bf3efb5e"
"checksum pretty 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f60c0d9f6fc88ecdd245d90c1920ff76a430ab34303fc778d33b1d0a4c3bf6d3"
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"));