mirror of
https://github.com/zaphar/abortable_parser.git
synced 2025-07-21 20:29:49 -04:00
MAINT: cargo fmt.
This commit is contained in:
parent
d24df3b852
commit
170e74209d
@ -1,8 +1,8 @@
|
||||
//! Contains implementations of `InputIter`.
|
||||
use std::iter::Iterator;
|
||||
use std::fmt::Debug;
|
||||
use std::iter::Iterator;
|
||||
|
||||
use super::{Offsetable, InputIter};
|
||||
use super::{InputIter, Offsetable};
|
||||
|
||||
/// Implements `InputIter` for any slice of T.
|
||||
#[derive(Debug)]
|
||||
@ -29,7 +29,7 @@ impl<'a, T: Debug + 'a> Iterator for SliceIter<'a, T> {
|
||||
Some(item) => {
|
||||
self.offset += 1;
|
||||
Some(item)
|
||||
},
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
18
src/lib.rs
18
src/lib.rs
@ -1,6 +1,6 @@
|
||||
//! A parser combinator library with a focus on fully abortable parsing and error handling.
|
||||
use std::iter::Iterator;
|
||||
use std::fmt::Display;
|
||||
use std::iter::Iterator;
|
||||
|
||||
pub trait Offsetable {
|
||||
fn get_offset(&self) -> usize;
|
||||
@ -25,7 +25,7 @@ pub struct Error<E: Display> {
|
||||
impl<E: Display> Error<E> {
|
||||
// Constructs a new Error with an offset and no cause.
|
||||
pub fn new<S: Offsetable>(err: E, offset: &S) -> Self {
|
||||
Error{
|
||||
Error {
|
||||
err: err,
|
||||
offset: offset.get_offset(),
|
||||
cause: None,
|
||||
@ -34,7 +34,7 @@ impl<E: Display> Error<E> {
|
||||
|
||||
// Constructs a new Error with an offset and a cause.
|
||||
pub fn caused_by<S: Offsetable>(err: E, offset: &S, cause: Self) -> Self {
|
||||
Error{
|
||||
Error {
|
||||
err: err,
|
||||
offset: offset.get_offset(),
|
||||
cause: Some(Box::new(cause)),
|
||||
@ -62,9 +62,7 @@ impl<E: Display> Display for Error<E> {
|
||||
try!(write!(f, "{}", self.err));
|
||||
match self.cause {
|
||||
Some(ref c) => write!(f, "\n\tCaused By:{}", c),
|
||||
None => {
|
||||
Ok(())
|
||||
},
|
||||
None => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -87,7 +85,7 @@ impl<I: InputIter, O, E: Display> Result<I, O, E> {
|
||||
/// Returns true if the Result is Complete.
|
||||
pub fn is_complete(&self) -> bool {
|
||||
if let &Result::Complete(_, _) = self {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -95,7 +93,7 @@ impl<I: InputIter, O, E: Display> Result<I, O, E> {
|
||||
/// Returns true if the Result is Incomoplete.
|
||||
pub fn is_incomplete(&self) -> bool {
|
||||
if let &Result::Incomplete(_) = self {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -103,7 +101,7 @@ impl<I: InputIter, O, E: Display> Result<I, O, E> {
|
||||
/// Returns true if the Result is Fail.
|
||||
pub fn is_fail(&self) -> bool {
|
||||
if let &Result::Fail(_) = self {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -111,7 +109,7 @@ impl<I: InputIter, O, E: Display> Result<I, O, E> {
|
||||
/// Returns true if the Result is Abort.
|
||||
pub fn is_abort(&self) -> bool {
|
||||
if let &Result::Abort(_) = self {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
23
src/test.rs
23
src/test.rs
@ -1,5 +1,5 @@
|
||||
use super::iter::SliceIter;
|
||||
use super::{Result, Offsetable};
|
||||
use super::{Offsetable, Result};
|
||||
|
||||
#[test]
|
||||
fn test_slice_iter() {
|
||||
@ -31,7 +31,7 @@ fn test_slice_iter() {
|
||||
assert_eq!('o' as u8, out[2]);
|
||||
}
|
||||
|
||||
fn will_fail(i: SliceIter<u8>) -> Result<SliceIter<u8>, String, String> {
|
||||
fn will_fail(i: SliceIter<u8>) -> Result<SliceIter<u8>, String, String> {
|
||||
Result::Fail(super::Error::new("AAAAHHH!!!".to_string(), &i))
|
||||
}
|
||||
|
||||
@ -172,10 +172,7 @@ fn test_do_each() {
|
||||
fn test_either_idents() {
|
||||
let input_str = "foo";
|
||||
let iter = SliceIter::new(input_str.as_bytes());
|
||||
let result = either!(iter,
|
||||
will_fail,
|
||||
will_fail,
|
||||
parse_three);
|
||||
let result = either!(iter, will_fail, will_fail, parse_three);
|
||||
assert!(result.is_complete());
|
||||
if let Result::Complete(_, o) = result {
|
||||
assert_eq!("foo".to_string(), o);
|
||||
@ -188,10 +185,7 @@ fn test_either_idents() {
|
||||
fn test_either_macros() {
|
||||
let input_str = "foo";
|
||||
let iter = SliceIter::new(input_str.as_bytes());
|
||||
let result = either!(iter,
|
||||
run!(will_fail),
|
||||
run!(will_fail),
|
||||
run!(parse_three));
|
||||
let result = either!(iter, run!(will_fail), run!(will_fail), run!(parse_three));
|
||||
assert!(result.is_complete());
|
||||
if let Result::Complete(_, o) = result {
|
||||
assert_eq!("foo".to_string(), o);
|
||||
@ -204,9 +198,7 @@ fn test_either_macros() {
|
||||
fn test_either_fail() {
|
||||
let input_str = "foo";
|
||||
let iter = SliceIter::new(input_str.as_bytes());
|
||||
let result = either!(iter,
|
||||
run!(will_fail),
|
||||
run!(will_fail));
|
||||
let result = either!(iter, run!(will_fail), run!(will_fail));
|
||||
assert!(result.is_fail());
|
||||
}
|
||||
|
||||
@ -214,10 +206,7 @@ fn test_either_fail() {
|
||||
fn test_either_abort() {
|
||||
let input_str = "foo";
|
||||
let iter = SliceIter::new(input_str.as_bytes());
|
||||
let result = either!(iter,
|
||||
must!(will_fail),
|
||||
parse_three,
|
||||
run!(will_fail));
|
||||
let result = either!(iter, must!(will_fail), parse_three, run!(will_fail));
|
||||
assert!(result.is_abort());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user