diff --git a/src/char_class.rs b/src/char_class.rs index 49a0128..7fb7733 100644 --- a/src/char_class.rs +++ b/src/char_class.rs @@ -19,9 +19,9 @@ pub fn alphanum(term: u8) -> bool { /// Recognises a hexadecimal digit, `0-9a-fA-F`. #[inline] pub fn hex_digit(term: u8) -> bool { - (term >= 0x30 && term <= 0x39) || - (term >= 0x41 && term <= 0x46) || - (term >= 0x61 && term <= 0x66) + (term >= 0x30 && term <= 0x39) + || (term >= 0x41 && term <= 0x46) + || (term >= 0x61 && term <= 0x66) } /// Recognises an octal digit, `0-7`. diff --git a/src/lib.rs b/src/lib.rs index 68ed539..fb82d9f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ -mod result; pub mod range; +mod result; pub mod set; /// Constains predefined parsers and combinators. @@ -8,7 +8,7 @@ pub mod parser; /// Utility functions to recognize char class of byte value. pub mod char_class; -pub use crate::result::{Result, Error}; +pub use crate::result::{Error, Result}; /// Parser type, `Parser` is alias of `parser::Parser<'static, I, O>`. pub type Parser = parser::Parser<'static, I, O>; diff --git a/src/parser.rs b/src/parser.rs index 6aece11..8870b0d 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -79,7 +79,7 @@ impl<'a, I, O> Parser<'a, I, O> { results .borrow_mut() .entry(key) - .or_insert_with(||(self.method)(input, start)) + .or_insert_with(|| (self.method)(input, start)) .clone() }) } @@ -508,9 +508,7 @@ impl<'a, I: Copy + 'a, O: 'a, U: 'a> Mul> for Parser<'a, I, O> } /// Chain two passers where the second parser depends on the first's result. -impl<'a, I: Copy, O: 'a, U: 'a, F: Fn(O) -> Parser<'a, I, U> + 'a> Shr - for Parser<'a, I, O> -{ +impl<'a, I: Copy, O: 'a, U: 'a, F: Fn(O) -> Parser<'a, I, U> + 'a> Shr for Parser<'a, I, O> { type Output = Parser<'a, I, U>; fn shr(self, other: F) -> Self::Output { diff --git a/src/range.rs b/src/range.rs index 826d177..6d0fa36 100644 --- a/src/range.rs +++ b/src/range.rs @@ -1,5 +1,4 @@ - -use std::ops::{Range, RangeFrom, RangeTo, RangeFull}; +use std::ops::{Range, RangeFrom, RangeFull, RangeTo}; pub enum Bound<'a, T: 'a> { Excluded(&'a T), @@ -14,26 +13,46 @@ pub trait RangeArgument { } impl RangeArgument for Range { - fn start(&self) -> Bound { Included(&self.start) } - fn end(&self) -> Bound { Excluded(&self.end) } + fn start(&self) -> Bound { + Included(&self.start) + } + fn end(&self) -> Bound { + Excluded(&self.end) + } } impl RangeArgument for RangeFrom { - fn start(&self) -> Bound { Included(&self.start) } - fn end(&self) -> Bound { Unbounded } + fn start(&self) -> Bound { + Included(&self.start) + } + fn end(&self) -> Bound { + Unbounded + } } impl RangeArgument for RangeTo { - fn start(&self) -> Bound { Unbounded } - fn end(&self) -> Bound { Excluded(&self.end) } + fn start(&self) -> Bound { + Unbounded + } + fn end(&self) -> Bound { + Excluded(&self.end) + } } impl RangeArgument for RangeFull { - fn start(&self) -> Bound { Unbounded } - fn end(&self) -> Bound { Unbounded } + fn start(&self) -> Bound { + Unbounded + } + fn end(&self) -> Bound { + Unbounded + } } impl RangeArgument for usize { - fn start(&self) -> Bound { Included(self) } - fn end(&self) -> Bound { Included(self) } + fn start(&self) -> Bound { + Included(self) + } + fn end(&self) -> Bound { + Included(self) + } } diff --git a/src/result.rs b/src/result.rs index 78ff16b..2c6607b 100644 --- a/src/result.rs +++ b/src/result.rs @@ -1,14 +1,28 @@ -use std::fmt::{self, Display}; use std::error; +use std::fmt::{self, Display}; /// Parser error. #[derive(Debug, PartialEq, Clone)] pub enum Error { Incomplete, - Mismatch { message: String, position: usize }, - Conversion { message: String, position: usize }, - Expect { message: String, position: usize, inner: Box }, - Custom { message: String, position: usize, inner: Option> }, + Mismatch { + message: String, + position: usize, + }, + Conversion { + message: String, + position: usize, + }, + Expect { + message: String, + position: usize, + inner: Box, + }, + Custom { + message: String, + position: usize, + inner: Option>, + }, } impl error::Error for Error { @@ -20,18 +34,30 @@ impl error::Error for Error { impl Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Error::Incomplete => - write!(f, "Incomplete"), - Error::Mismatch { ref message, ref position } => - write!(f, "Mismatch at {}: {}", position, message), - Error::Conversion { ref message, ref position } => - write!(f, "Conversion failed at {}: {}", position, message), - Error::Expect { ref message, ref position, ref inner } => - write!(f, "{} at {}: {}", message, position, inner), - Error::Custom { ref message, ref position, inner: Some(ref inner) } => - write!(f, "{} at {}, (inner: {})", message, position, inner), - Error::Custom { ref message, ref position, inner: None } => - write!(f, "{} at {}", message, position), + Error::Incomplete => write!(f, "Incomplete"), + Error::Mismatch { + ref message, + ref position, + } => write!(f, "Mismatch at {}: {}", position, message), + Error::Conversion { + ref message, + ref position, + } => write!(f, "Conversion failed at {}: {}", position, message), + Error::Expect { + ref message, + ref position, + ref inner, + } => write!(f, "{} at {}: {}", message, position, inner), + Error::Custom { + ref message, + ref position, + inner: Some(ref inner), + } => write!(f, "{} at {}, (inner: {})", message, position, inner), + Error::Custom { + ref message, + ref position, + inner: None, + } => write!(f, "{} at {}", message, position), } } } diff --git a/src/set.rs b/src/set.rs index a0ad4b1..abe9833 100644 --- a/src/set.rs +++ b/src/set.rs @@ -1,5 +1,5 @@ use std::cmp::{PartialEq, PartialOrd}; -use std::ops::{Range, RangeFrom, RangeTo, RangeFull}; +use std::ops::{Range, RangeFrom, RangeFull, RangeTo}; use std::str; /// Set relationship. @@ -57,8 +57,7 @@ impl Set for RangeFull { } } -macro_rules! impl_set_for_array -{ +macro_rules! impl_set_for_array { ($n:expr) => { impl Set for [u8; $n] { fn contains(&self, elem: &u8) -> bool { diff --git a/tests/list.rs b/tests/list.rs index efcc6e6..ec4d9a8 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -1,7 +1,7 @@ extern crate pom; -use pom::Parser; use pom::parser::*; +use pom::Parser; fn spaces() -> Parser { one_of(b" ").repeat(1..).discard() @@ -21,5 +21,8 @@ fn test_list() { assert_eq!(works().parse(one), Ok(vec![b'a', b'b', b'c'])); let two = b"a and b and c and "; - assert_eq!(dangle().parse(two), Ok((vec![b'a', b'b', b'c'], &b" and"[..]))); + assert_eq!( + dangle().parse(two), + Ok((vec![b'a', b'b', b'c'], &b" and"[..])) + ); }