summaryrefslogtreecommitdiff
path: root/dhall_generated_parser
diff options
context:
space:
mode:
authorNadrieril Feneanar2019-09-19 10:54:11 +0200
committerGitHub2019-09-19 10:54:11 +0200
commit4daead27eb65e3a38869924f0f3ed1f425de1b33 (patch)
tree06effc0f10795a208e929bdf9fdbbbfa6d94cc31 /dhall_generated_parser
parentbcaeab3b7b114d8782be9589ad673ab9ab8c59fd (diff)
parentbf417fadb206d6d2351a13cd7c6988977a46dd33 (diff)
Merge pull request #113 from Nadrieril/pest_consume
Extract parser macros into an independent crate
Diffstat (limited to 'dhall_generated_parser')
-rw-r--r--dhall_generated_parser/Cargo.toml3
-rw-r--r--dhall_generated_parser/build.rs17
-rw-r--r--dhall_generated_parser/src/lib.rs7
3 files changed, 7 insertions, 20 deletions
diff --git a/dhall_generated_parser/Cargo.toml b/dhall_generated_parser/Cargo.toml
index 0730f60..b1f0d02 100644
--- a/dhall_generated_parser/Cargo.toml
+++ b/dhall_generated_parser/Cargo.toml
@@ -12,8 +12,7 @@ doctest = false
[build-dependencies]
abnf_to_pest = { version = "0.1.1", path = "../abnf_to_pest" }
-pest_generator = "2.1"
-quote = "1.0.2"
[dependencies]
pest = "2.1"
+pest_derive = "2.1"
diff --git a/dhall_generated_parser/build.rs b/dhall_generated_parser/build.rs
index c562fad..68895dd 100644
--- a/dhall_generated_parser/build.rs
+++ b/dhall_generated_parser/build.rs
@@ -1,7 +1,5 @@
-use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader, Read, Write};
-use std::path::Path;
use abnf_to_pest::render_rules_to_pest;
@@ -90,20 +88,5 @@ fn main() -> std::io::Result<()> {
writeln!(&mut file)?;
writeln!(&mut file, "{}", render_rules_to_pest(rules).pretty(80))?;
- // 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_generated_parser/src/lib.rs b/dhall_generated_parser/src/lib.rs
index 280b75e..fbb9ccd 100644
--- a/dhall_generated_parser/src/lib.rs
+++ b/dhall_generated_parser/src/lib.rs
@@ -14,4 +14,9 @@
// additional overrides are done in ../build.rs.
// The lines that are commented out in ./dhall.pest.visibility are marked as
// silent (see pest docs for what that means) in the generated pest file.
-include!(concat!(env!("OUT_DIR"), "/grammar.rs"));
+
+use pest_derive::Parser;
+
+#[derive(Parser)]
+#[grammar = "dhall.pest"]
+pub struct DhallParser;