diff options
author | Nadrieril | 2019-12-22 19:43:32 +0000 |
---|---|---|
committer | Nadrieril | 2019-12-22 19:43:32 +0000 |
commit | 4322d1b0b7041eb160b1baadf9f6e63f0d4e9d9c (patch) | |
tree | 9ac1cc469e2cf7e21802b07214a6b44b981d000b | |
parent | faccb680fbede2191e23161e7060be843bcc229e (diff) |
Update abnf dependency in the hopes of fixing a bug
Diffstat (limited to '')
-rw-r--r-- | Cargo.lock | 87 | ||||
-rw-r--r-- | abnf_to_pest/Cargo.toml | 4 | ||||
-rw-r--r-- | abnf_to_pest/src/lib.rs | 110 | ||||
-rw-r--r-- | dhall/Cargo.toml | 2 | ||||
-rw-r--r-- | dhall/build.rs | 10 |
5 files changed, 129 insertions, 84 deletions
@@ -2,17 +2,17 @@ # It is not intended for manual editing. [[package]] name = "abnf" -version = "0.1.3" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "nom 5.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "abnf_to_pest" -version = "0.1.2" +version = "0.2.0" dependencies = [ - "abnf 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "abnf 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "pretty 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -27,6 +27,14 @@ dependencies = [ ] [[package]] +name = "arrayvec" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nodrop 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "autocfg" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -61,6 +69,11 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "ctor" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -73,7 +86,7 @@ dependencies = [ name = "dhall" version = "0.1.1" dependencies = [ - "abnf_to_pest 0.1.2", + "abnf_to_pest 0.2.0", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -167,6 +180,18 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "lexical-core" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "static_assertions 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "maplit" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -177,10 +202,16 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "nodrop" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "nom" -version = "4.2.3" +version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "lexical-core 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -310,6 +341,19 @@ dependencies = [ ] [[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ryu" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "same-file" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -318,6 +362,19 @@ dependencies = [ ] [[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "serde" version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -371,6 +428,11 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "static_assertions" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "syn" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -448,13 +510,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum abnf 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d972ae01fad2d4693b272854546bd763966c95575a4f1d6333dc95b85ff182db" +"checksum abnf 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e065019cf2f9438a593954cc8e774925656b86701b72720b82ec3141e682ac14" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9" "checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" "checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" +"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum ctor 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "cd8ce37ad4184ab2ce004c33bf6379185d3b1c95801cab51026bd271bf68eedc" "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" @@ -466,9 +530,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2" "checksum itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +"checksum lexical-core 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2304bccb228c4b020f3a4835d247df0a02a7c4686098d4167762cfbbe4c5cb14" "checksum maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" "checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" -"checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" +"checksum nodrop 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" +"checksum nom 5.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c618b63422da4401283884e6668d39f819a106ef51f5f59b81add00075da35ca" "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" "checksum output_vt100 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9" "checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" @@ -483,12 +549,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5" "checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" +"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +"checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" "checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421" +"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" "checksum serde_cbor 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45cd6d95391b16cd57e88b68be41d504183b7faae22030c0cc3b3f73dd57b2fd" "checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" "checksum sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "23962131a91661d643c98940b20fcaffe62d776a823247be80a48fcb8b6fce68" "checksum smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44e59e0c9fa00817912ae6e4e6e3c4fe04455e75699d06eedc7d85917ed8e8f4" +"checksum static_assertions 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7f3eb36b47e512f8f1c9e3d10c2c1965bc992bd9cdb024fa581e2194501c83d3" "checksum syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "dff0acdb207ae2fe6d5976617f887eb1e35a2ba52c13c7234c790960cdad9238" "checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" "checksum typed-arena 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9b2228007eba4120145f785df0f6c92ea538f5a3635a612ecf4e334c8c1446d" diff --git a/abnf_to_pest/Cargo.toml b/abnf_to_pest/Cargo.toml index 93ec829..780010e 100644 --- a/abnf_to_pest/Cargo.toml +++ b/abnf_to_pest/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "abnf_to_pest" -version = "0.1.2" # remember to update html_root_url +version = "0.2.0" # remember to update html_root_url authors = ["Nadrieril <nadrieril@users.noreply.github.com>"] license = "MIT OR Apache-2.0" edition = "2018" @@ -12,7 +12,7 @@ repository = "https://github.com/Nadrieril/dhall-rust" doctest = false [dependencies] -abnf = "0.1.2" +abnf = "0.6.0" indexmap = "1.0.2" itertools = "0.8.0" pretty = "0.5.2" diff --git a/abnf_to_pest/src/lib.rs b/abnf_to_pest/src/lib.rs index d460bf9..8615fc2 100644 --- a/abnf_to_pest/src/lib.rs +++ b/abnf_to_pest/src/lib.rs @@ -1,4 +1,4 @@ -#![doc(html_root_url = "https://docs.rs/abnf_to_pest/0.1.1")] +#![doc(html_root_url = "https://docs.rs/abnf_to_pest/0.2.0")] //! A tiny crate that helps convert ABNF grammars to [pest][pest]. //! @@ -21,10 +21,7 @@ //! //! [pest]: https://pest.rs -use abnf::abnf::Rule; -pub use abnf::abnf::{ - Alternation, Concatenation, Element, Range, Repeat, Repetition, -}; +use abnf::types::{Node, NumVal, Repeat, Rule}; use indexmap::map::IndexMap; use itertools::Itertools; use pretty::{BoxDoc, Doc}; @@ -33,40 +30,41 @@ trait Pretty { fn pretty(&self) -> Doc<'static, BoxDoc<'static, ()>>; } -impl Pretty for Alternation { +impl Pretty for Node { fn pretty(&self) -> Doc<'static, BoxDoc<'static, ()>> { - Doc::intersperse( - self.concatenations - .iter() - .map(|x| x.pretty().nest(2).group()), - Doc::space().append(Doc::text("| ")), - ) - } -} - -impl Pretty for Concatenation { - fn pretty(&self) -> Doc<'static, BoxDoc<'static, ()>> { - Doc::intersperse( - self.repetitions.iter().map(Repetition::pretty), - Doc::space().append(Doc::text("~ ")), - ) - } -} - -impl Pretty for Repetition { - fn pretty(&self) -> Doc<'static, BoxDoc<'static, ()>> { - self.element.pretty().append( - self.repeat - .as_ref() - .map(Repeat::pretty) - .unwrap_or_else(Doc::nil), - ) + use Node::*; + match self { + Alternation(nodes) => Doc::intersperse( + nodes.iter().map(|x| x.pretty().nest(2).group()), + Doc::space().append(Doc::text("| ")), + ), + Concatenation(nodes) => Doc::intersperse( + nodes.iter().map(|x| x.pretty()), + Doc::space().append(Doc::text("~ ")), + ), + Repetition(rep) => { + rep.get_node().pretty().append(rep.get_repeat().pretty()) + } + Rulename(s) => Doc::text(escape_rulename(s)), + Group(n) => Doc::text("(") + .append(n.pretty().nest(4).group()) + .append(Doc::text(")")), + Optional(n) => Doc::text("(") + .append(n.pretty().nest(4).group()) + .append(Doc::text(")?")), + CharVal(s) => Doc::text(format!( + "^\"{}\"", + s.replace("\"", "\\\"").replace("\\", "\\\\") + )), + NumVal(r) => r.pretty(), + ProseVal(_) => unimplemented!(), + } } } impl Pretty for Repeat { fn pretty(&self) -> Doc<'static, BoxDoc<'static, ()>> { - Doc::text(match (self.min.unwrap_or(0), self.max) { + Doc::text(match (self.get_min().unwrap_or(0), self.get_max()) { (0, None) => "*".into(), (1, None) => "+".into(), (0, Some(1)) => "?".into(), @@ -77,35 +75,14 @@ impl Pretty for Repeat { } } -impl Pretty for Element { - fn pretty(&self) -> Doc<'static, BoxDoc<'static, ()>> { - use abnf::abnf::Element::*; - match self { - Rulename(s) => Doc::text(escape_rulename(s)), - Group(g) => Doc::text("(") - .append((g.alternation).pretty().nest(4).group()) - .append(Doc::text(")")), - Option(o) => Doc::text("(") - .append((o.alternation).pretty().nest(4).group()) - .append(Doc::text(")?")), - CharVal(s) => Doc::text(format!( - "^\"{}\"", - s.replace("\"", "\\\"").replace("\\", "\\\\") - )), - NumVal(r) => r.pretty(), - ProseVal(_) => unimplemented!(), - } - } -} - -impl Pretty for Range { +impl Pretty for NumVal { fn pretty(&self) -> Doc<'static, BoxDoc<'static, ()>> { - use abnf::abnf::Range::*; + use NumVal::*; Doc::text(match self { Range(x, y) => { format!("'{}'..'{}'", format_char(*x), format_char(*y)) } - OneOf(v) => { + Terminal(v) => { format!("\"{}\"", v.iter().map(|x| format_char(*x)).join("")) } }) @@ -154,17 +131,18 @@ fn format_char(x: u32) -> String { #[derive(Debug, Clone)] pub struct PestyRule { pub silent: bool, - pub elements: Alternation, + pub node: Node, } impl Pretty for (String, PestyRule) { fn pretty(&self) -> Doc<'static, BoxDoc<'static, ()>> { + let (name, rule) = self; Doc::nil() - .append(Doc::text(self.0.clone())) + .append(Doc::text(name.clone())) .append(Doc::text(" = ")) - .append(Doc::text(if self.1.silent { "_" } else { "" })) + .append(Doc::text(if rule.silent { "_" } else { "" })) .append(Doc::text("{")) - .append(Doc::space().append(self.1.elements.pretty()).nest(2)) + .append(Doc::space().append(rule.node.pretty()).nest(2)) .append(Doc::space()) .append(Doc::text("}")) .group() @@ -173,21 +151,19 @@ impl Pretty for (String, PestyRule) { /// Parse an abnf file. Returns a map of rules. pub fn parse_abnf( - data: &[u8], + data: &str, ) -> Result<IndexMap<String, PestyRule>, std::io::Error> { let make_err = |e| std::io::Error::new(std::io::ErrorKind::Other, format!("{}", e)); - let rules: Vec<Rule> = - abnf::abnf::rulelist_comp(&data).map_err(make_err)?.1; + let rules: Vec<Rule> = abnf::rulelist(data).map_err(make_err)?; Ok(rules .into_iter() .map(|rule| { - let name = escape_rulename(&rule.name); ( - name.clone(), + escape_rulename(rule.get_name()), PestyRule { silent: false, - elements: rule.elements.clone(), + node: rule.get_node().clone(), }, ) }) diff --git a/dhall/Cargo.toml b/dhall/Cargo.toml index 34cf444..8674f44 100644 --- a/dhall/Cargo.toml +++ b/dhall/Cargo.toml @@ -26,7 +26,7 @@ pretty_assertions = "0.6.1" [build-dependencies] walkdir = "2" -abnf_to_pest = { version = "0.1.2", path = "../abnf_to_pest" } +abnf_to_pest = { version = "0.2.0", path = "../abnf_to_pest" } pest_generator = "2.1" quote = "1.0" diff --git a/dhall/build.rs b/dhall/build.rs index ec06ece..2a65f24 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -1,7 +1,7 @@ use std::env; use std::ffi::OsString; -use std::fs::File; -use std::io::{BufRead, BufReader, Read, Write}; +use std::fs::{read_to_string, File}; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use walkdir::WalkDir; @@ -383,10 +383,8 @@ fn convert_abnf_to_pest() -> std::io::Result<()> { println!("cargo:rerun-if-changed={}", abnf_path); println!("cargo:rerun-if-changed={}", visibility_path); - let mut file = File::open(abnf_path)?; - let mut data = Vec::new(); - file.read_to_end(&mut data)?; - data.push('\n' as u8); + let mut data = read_to_string(abnf_path)?; + data.push('\n'); let mut rules = abnf_to_pest::parse_abnf(&data)?; for line in BufReader::new(File::open(visibility_path)?).lines() { |