From 4f4649fe1c0cdd16435c4e2b19df8fd5c9f8c638 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 9 Mar 2019 23:39:01 +0100 Subject: rustfmt --- abnf_to_pest/src/lib.rs | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'abnf_to_pest') diff --git a/abnf_to_pest/src/lib.rs b/abnf_to_pest/src/lib.rs index 7853773..b2fcbbd 100644 --- a/abnf_to_pest/src/lib.rs +++ b/abnf_to_pest/src/lib.rs @@ -1,10 +1,11 @@ #![allow(clippy::implicit_hasher, clippy::or_fun_call)] +use abnf::abnf::Rule; +pub use abnf::abnf::{ + Alternation, Concatenation, Element, Range, Repeat, Repetition, +}; use itertools::Itertools; -use std::collections::HashMap; use pretty::{BoxDoc, Doc}; -pub use abnf::abnf::{Alternation, Concatenation, Repetition, Repeat, Range, Element}; -use abnf::abnf::Rule; - +use std::collections::HashMap; trait Pretty { fn pretty(&self) -> Doc<'static, BoxDoc<'static, ()>>; @@ -82,9 +83,7 @@ impl Pretty for Range { Range(x, y) => { format!("'{}'..'{}'", format_char(x), format_char(y)) } - OneOf(v) => { - format!("\"{}\"", v.iter().map(format_char).join("")) - } + OneOf(v) => format!("\"{}\"", v.iter().map(format_char).join("")), }) } } @@ -139,23 +138,34 @@ impl Pretty for (String, PestyRule) { } } - /// Parse an abnf file. Returns a map of rules. -pub fn parse_abnf(data: &[u8]) -> Result, std::io::Error> { +pub fn parse_abnf( + data: &[u8], +) -> Result, std::io::Error> { let make_err = |e| std::io::Error::new(std::io::ErrorKind::Other, format!("{}", e)); - let rules: Vec = abnf::abnf::rulelist_comp(&data).map_err(make_err)?.1; - Ok(rules.into_iter().map(|rule| { - let name = escape_rulename(&rule.name); - (name.clone(), PestyRule { - silent: false, - elements: rule.elements.clone(), + let rules: Vec = + abnf::abnf::rulelist_comp(&data).map_err(make_err)?.1; + Ok(rules + .into_iter() + .map(|rule| { + let name = escape_rulename(&rule.name); + ( + name.clone(), + PestyRule { + silent: false, + elements: rule.elements.clone(), + }, + ) }) - }).collect()) + .collect()) } -pub fn render_rules_to_pest(rules: I) -> Doc<'static, BoxDoc<'static, ()>, ()> -where I: IntoIterator, +pub fn render_rules_to_pest( + rules: I, +) -> Doc<'static, BoxDoc<'static, ()>, ()> +where + I: IntoIterator, { let pretty_rules = rules.into_iter().map(|x| x.pretty()); let doc: Doc<_> = Doc::intersperse(pretty_rules, Doc::newline()); -- cgit v1.2.3