MAINT: cargo fmt

This commit is contained in:
Jeremy Wall 2018-09-12 19:55:14 -05:00
parent e1698065c6
commit e833730fbb
5 changed files with 108 additions and 114 deletions

View File

@ -1,6 +1,6 @@
//! Contains combinators that can assemble other matchers or combinators into more complex grammars.
use super::{InputIter, Error, Result};
use super::{Error, InputIter, Result};
/// Turns a `Result` to it's inverse.
///
@ -14,7 +14,10 @@ where
I: InputIter,
{
match result {
Result::Complete(i, _) => Result::Fail(Error::new("Matched on input when we shouldn't have.".to_string(), &i)),
Result::Complete(i, _) => Result::Fail(Error::new(
"Matched on input when we shouldn't have.".to_string(),
&i,
)),
Result::Abort(e) => Result::Abort(e),
Result::Incomplete(offset) => Result::Incomplete(offset),
Result::Fail(_) => Result::Complete(i, ()),
@ -109,7 +112,7 @@ macro_rules! run {
/// The `must!` macro provided syntactice sugar for using this combinator.
pub fn must<I, O>(result: Result<I, O>) -> Result<I, O>
where
I: InputIter
I: InputIter,
{
match result {
Result::Complete(i, o) => Result::Complete(i, o),
@ -117,7 +120,6 @@ where
Result::Fail(e) => Result::Abort(e),
Result::Abort(e) => Result::Abort(e),
}
}
/// Turns `Result::Fail` into `Result::Abort`.
@ -181,7 +183,7 @@ macro_rules! wrap_err {
/// The `trap!` macro provides syntactic sugar for using this combinator.
pub fn trap<I, O>(result: Result<I, O>) -> Result<I, O>
where
I: InputIter
I: InputIter,
{
match result {
Result::Complete(i, o) => Result::Complete(i, o),
@ -474,17 +476,11 @@ where
I: InputIter,
{
match result {
Result::Complete(i, o) => {
Result::Complete(i, Some(o))
}
Result::Complete(i, o) => Result::Complete(i, Some(o)),
// Incomplete could still work possibly parse.
Result::Incomplete(i) => {
Result::Incomplete(i)
}
Result::Incomplete(i) => Result::Incomplete(i),
// Fail just means it didn't match.
Result::Fail(_) => {
Result::Complete(iter, None)
},
Result::Fail(_) => Result::Complete(iter, None),
// Aborts are hard failures that the parser can't recover from.
Result::Abort(e) => Result::Abort(e),
}
@ -699,18 +695,14 @@ macro_rules! discard {
/// Matches and returns any ascii charactar whitespace byte.
pub fn ascii_ws<'a, I: InputIter<Item = &'a u8>>(mut i: I) -> Result<I, u8> {
match i.next() {
Some(b) => {
match b {
Some(b) => match b {
b'\r' => Result::Complete(i, *b),
b'\n' => Result::Complete(i, *b),
b'\t' => Result::Complete(i, *b),
b' ' => Result::Complete(i, *b),
_ => Result::Fail(Error::new("Not whitespace", &i)),
}
},
None => {
Result::Fail(Error::new("Unexpected End Of Input", &i))
}
None => Result::Fail(Error::new("Unexpected End Of Input", &i)),
}
}

View File

@ -1,5 +1,6 @@
use super::{ascii_ws, eoi, Result};
use iter::StrIter;
use super::{Result, eoi, ascii_ws};
make_fn!(proto<StrIter, &str>,
do_each!(

View File

@ -91,7 +91,8 @@ impl Error {
pub fn new<S, M>(msg: M, offset: &S) -> Self
where
S: Offsetable,
M: Into<String> {
M: Into<String>,
{
Error {
msg: msg.into(),
offset: offset.get_offset(),
@ -103,8 +104,8 @@ impl Error {
pub fn caused_by<S, M>(msg: M, offset: &S, cause: Self) -> Self
where
S: Offsetable,
M: Into<String> {
M: Into<String>,
{
Error {
msg: msg.into(),
offset: offset.get_offset(),
@ -189,14 +190,14 @@ impl<I: InputIter, O> Result<I, O> {
}
}
pub use iter::SliceIter;
pub use combinators::*;
pub use iter::SliceIter;
#[macro_use]
pub mod combinators;
pub mod iter;
#[cfg(test)]
mod test;
#[cfg(test)]
mod integration_tests;
#[cfg(test)]
mod test;

View File

@ -1,8 +1,8 @@
use std::fmt::{Debug, Display};
use super::{InputIter, Offsetable, Result};
use iter::{StrIter, SliceIter};
use combinators::*;
use iter::{SliceIter, StrIter};
#[test]
fn test_slice_iter() {