From 8c14a3321f516d9e789671ce64584dafb656473f Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 21 Dec 2019 22:16:59 +0000 Subject: Prepare for publishing on crates.io --- dhall/src/lib.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'dhall/src') diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index 12660b4..54111dd 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -1,3 +1,4 @@ +#![doc(html_root_url = "https://docs.rs/dhall/0.1.0")] #![feature(trace_macros)] #![feature(slice_patterns)] #![feature(never_type)] -- cgit v1.3.1 From be9510bc21724077fd27dcdb3825557475a6bb44 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 21 Dec 2019 23:00:52 +0000 Subject: Generate parser manually to make the crate publishable --- Cargo.lock | 2 ++ dhall/.gitignore | 1 - dhall/Cargo.toml | 2 ++ dhall/build.rs | 28 ++++++++++++++++++++++++++-- dhall/src/syntax/text/parser.rs | 12 +++++++++--- 5 files changed, 39 insertions(+), 6 deletions(-) delete mode 100644 dhall/.gitignore (limited to 'dhall/src') diff --git a/Cargo.lock b/Cargo.lock index ffdf17b..29aba92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -80,7 +80,9 @@ dependencies = [ "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "pest 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "pest_consume 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pest_generator 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_cbor 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/dhall/.gitignore b/dhall/.gitignore deleted file mode 100644 index 8a0bac6..0000000 --- a/dhall/.gitignore +++ /dev/null @@ -1 +0,0 @@ -src/dhall.pest diff --git a/dhall/Cargo.toml b/dhall/Cargo.toml index 44c8932..a9c237c 100644 --- a/dhall/Cargo.toml +++ b/dhall/Cargo.toml @@ -27,5 +27,7 @@ pretty_assertions = "0.6.1" [build-dependencies] walkdir = "2" abnf_to_pest = { version = "0.1.2", path = "../abnf_to_pest" } +pest_generator = "2.1" +quote = "1.0" diff --git a/dhall/build.rs b/dhall/build.rs index 50f423e..3021f03 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -408,9 +408,10 @@ fn generate_tests() -> std::io::Result<()> { } fn convert_abnf_to_pest() -> std::io::Result<()> { + let out_dir = env::var("OUT_DIR").unwrap(); let abnf_path = "src/dhall.abnf"; let visibility_path = "src/dhall.pest.visibility"; - let pest_path = "src/dhall.pest"; + let grammar_path = Path::new(&out_dir).join("dhall.pest"); println!("cargo:rerun-if-changed={}", abnf_path); println!("cargo:rerun-if-changed={}", visibility_path); @@ -427,7 +428,7 @@ fn convert_abnf_to_pest() -> std::io::Result<()> { } } - let mut file = File::create(pest_path)?; + let mut file = File::create(grammar_path)?; writeln!(&mut file, "// AUTO-GENERATED FILE. See build.rs.")?; // TODO: this is a cheat; properly support RFC3986 URLs instead @@ -493,8 +494,31 @@ fn convert_abnf_to_pest() -> std::io::Result<()> { Ok(()) } +// Generate pest parser manually becaue otherwise we'd need to modify something outside of +// OUT_DIR and that's forbidden by docs.rs. +fn generate_pest_parser() -> std::io::Result<()> { + let out_dir = env::var("OUT_DIR").unwrap(); + let grammar_path = Path::new(&out_dir).join("dhall.pest"); + let grammar_path = grammar_path.to_str(); + let output_path = Path::new(&out_dir).join("dhall_parser.rs"); + + let pest = quote::quote!( + #[grammar = #grammar_path] + struct DhallParser; + ); + let derived = pest_generator::derive_parser(pest, false); + let file_contents = quote::quote!( + struct DhallParser; + #derived + ); + + let mut file = File::create(output_path)?; + writeln!(file, "{}", file_contents) +} + fn main() -> std::io::Result<()> { convert_abnf_to_pest()?; + generate_pest_parser()?; generate_tests()?; Ok(()) } diff --git a/dhall/src/syntax/text/parser.rs b/dhall/src/syntax/text/parser.rs index 90cb4b1..832472b 100644 --- a/dhall/src/syntax/text/parser.rs +++ b/dhall/src/syntax/text/parser.rs @@ -156,9 +156,15 @@ lazy_static::lazy_static! { }; } -#[derive(Parser)] -#[grammar = "dhall.pest"] -struct DhallParser; +// Generate pest parser manually becaue otherwise we'd need to modify something outside of OUT_DIR +// and that's forbidden by docs.rs. +// This is equivalent to: +// ``` +// #[derive(Parser) +// #[grammar = "..."] +// struct DhallParser; +// ``` +include!(concat!(env!("OUT_DIR"), "/dhall_parser.rs")); #[pest_consume::parser(parser = DhallParser, rule = Rule)] impl DhallParser { -- cgit v1.3.1 From 6e6094731a3b6a8ff2adc23f8ecae43b25d02731 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 21 Dec 2019 23:01:41 +0000 Subject: Bump dhall version --- dhall/Cargo.toml | 2 +- dhall/src/lib.rs | 2 +- serde_dhall/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'dhall/src') diff --git a/dhall/Cargo.toml b/dhall/Cargo.toml index a9c237c..34cf444 100644 --- a/dhall/Cargo.toml +++ b/dhall/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dhall" -version = "0.1.0" # remember to update html_root_url +version = "0.1.1" # remember to update html_root_url authors = ["NanoTech ", "Nadrieril "] license = "BSD-2-Clause" description = "Implementation of the Dhall configuration language" diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index 54111dd..dfa06e7 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -1,4 +1,4 @@ -#![doc(html_root_url = "https://docs.rs/dhall/0.1.0")] +#![doc(html_root_url = "https://docs.rs/dhall/0.1.1")] #![feature(trace_macros)] #![feature(slice_patterns)] #![feature(never_type)] diff --git a/serde_dhall/Cargo.toml b/serde_dhall/Cargo.toml index 8c75f68..0dd0cd5 100644 --- a/serde_dhall/Cargo.toml +++ b/serde_dhall/Cargo.toml @@ -11,5 +11,5 @@ edition = "2018" [dependencies] serde = { version = "1.0", features = ["derive"] } -dhall = { version = "0.1.0", path = "../dhall" } +dhall = { version = "0.1.1", path = "../dhall" } dhall_proc_macros = { version = "0.1.0", path = "../dhall_proc_macros" } -- cgit v1.3.1