Skip to content

Commit

Permalink
use need_more anywhere needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Nov 25, 2017
1 parent 2c45a08 commit 2d86abf
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 53 deletions.
12 changes: 8 additions & 4 deletions src/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,9 @@ mod tests {
macro_rules! tag_bytes (
($i:expr, $bytes: expr) => (
{
use $crate::need_more;
use std::cmp::min;

let len = $i.len();
let blen = $bytes.len();
let m = min(len, blen);
Expand All @@ -728,9 +730,9 @@ mod tests {
let e: ErrorKind<u32> = ErrorKind::Tag;
Err(Err::Error(error_position!(e, $i)))
} else if m < blen {
let e:Err<&[u8], u32> = Err::Incomplete(Needed::Size(blen));
Err(e)
//Err(Err::Incomplete(Needed::Size(blen)))
//let e:Err<&[u8], u32> = need_more($i, Needed::Size(blen));
//Err(e)
need_more($i, Needed::Size(blen))
} else {
Ok((&$i[blen..], reduced))
};
Expand All @@ -742,9 +744,11 @@ mod tests {
macro_rules! take(
($i:expr, $count:expr) => (
{
use $crate::need_more;

let cnt = $count as usize;
let res:IResult<&[u8],&[u8],u32> = if $i.len() < cnt {
Err(Err::Incomplete(Needed::Size(cnt)))
need_more($i, Needed::Size(cnt))
} else {
Ok((&$i[cnt..],&$i[0..cnt]))
};
Expand Down
40 changes: 20 additions & 20 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ macro_rules! tag (
{
use ::std::result::Result::*;
use $crate::{Err,Needed,IResult,ErrorKind};
use $crate::{Compare,CompareResult,InputLength,Slice};
use $crate::{Compare,CompareResult,InputLength,Slice,need_more};

let res: IResult<_,_> = match ($i).compare($tag) {
CompareResult::Ok => {
let blen = $tag.input_len();
Ok(($i.slice(blen..), $i.slice(..blen)))
},
CompareResult::Incomplete => {
Err(Err::Incomplete(Needed::Size($tag.input_len())))
need_more($i, Needed::Size($tag.input_len()))
},
CompareResult::Error => {
let e:ErrorKind<u32> = ErrorKind::Tag;
Expand Down Expand Up @@ -196,7 +196,7 @@ macro_rules! escaped (
(__impl $i: expr, $normal:ident!( $($args:tt)* ), $control_char: expr, $escapable:ident!( $($args2:tt)* )) => (
{
use ::std::result::Result::*;
use $crate::{Err,Needed,IResult,ErrorKind};
use $crate::{Err,Needed,IResult,ErrorKind,need_more};

use $crate::InputLength;
use $crate::Slice;
Expand All @@ -216,7 +216,7 @@ macro_rules! escaped (
Err(Err::Error(e)) => {
if $i[index] == $control_char as u8 {
if index + 1 >= $i.input_len() {
return Err(Err::Incomplete(Needed::Unknown))
return need_more($i, Needed::Unknown)
} else {
match $escapable!($i.slice(index+1..), $($args2)*) {
Ok((i,_)) => {
Expand Down Expand Up @@ -451,15 +451,15 @@ macro_rules! take_while1 (
{
use ::std::result::Result::*;
use ::std::option::Option::*;
use $crate::{Err,ErrorKind,Needed};
use $crate::{Err,ErrorKind,Needed,need_more};

let input = $input;

use $crate::InputLength;
use $crate::InputIter;
use $crate::Slice;
if input.input_len() == 0 {
Err(Err::Incomplete(Needed::Unknown))
need_more(input, Needed::Unknown)
} else {
match input.position(|c| !$submac!(c, $($args)*)) {
Some(0) => {
Expand Down Expand Up @@ -518,15 +518,15 @@ macro_rules! take_till1 (
{
use ::std::result::Result::*;
use ::std::option::Option::*;
use $crate::{Err,Needed,ErrorKind};
use $crate::{Err,Needed,ErrorKind,need_more};

let input = $input;

use $crate::InputLength;
use $crate::InputIter;
use $crate::Slice;
if input.input_len() == 0 {
Err(Err::Incomplete(Needed::Unknown))
need_more(input, Needed::Unknown)
} else {
match input.position(|c| $submac!(c, $($args)*)) {
Some(0) => {
Expand Down Expand Up @@ -603,14 +603,14 @@ macro_rules! take_until_and_consume (
{
use ::std::result::Result::*;
use ::std::option::Option::*;
use $crate::{Err,Needed,IResult,ErrorKind};
use $crate::{Err,Needed,IResult,ErrorKind,need_more};

use $crate::InputLength;
use $crate::FindSubstring;
use $crate::Slice;

let res: IResult<_,_> = if $substr.input_len() > $i.input_len() {
Err(Err::Incomplete(Needed::Size($substr.input_len())))
need_more($i, Needed::Size($substr.input_len()))
} else {
match ($i).find_substring($substr) {
None => {
Expand All @@ -635,12 +635,12 @@ macro_rules! take_until_and_consume1 (
{
use ::std::result::Result::*;
use ::std::option::Option::*;
use $crate::{Err,Needed,IResult,ErrorKind};
use $crate::{Err,Needed,IResult,ErrorKind,need_more};

use $crate::InputLength;

let res: IResult<_,_> = if 1 + $substr.input_len() > $i.input_len() {
Err(Err::Incomplete(Needed::Size($substr.input_len())))
need_more(Needed::Size($substr.input_len()))
} else {
match ($i).find_substring($substr) {
None => {
Expand All @@ -665,14 +665,14 @@ macro_rules! take_until (
{
use ::std::result::Result::*;
use ::std::option::Option::*;
use $crate::{Err,Needed,IResult,ErrorKind};
use $crate::{Err,Needed,IResult,ErrorKind,need_more};

use $crate::InputLength;
use $crate::FindSubstring;
use $crate::Slice;

let res: IResult<_,_> = if $substr.input_len() > $i.input_len() {
Err(Err::Incomplete(Needed::Size($substr.input_len())))
need_more($i, Needed::Size($substr.input_len()))
} else {
match ($i).find_substring($substr) {
None => {
Expand All @@ -697,13 +697,13 @@ macro_rules! take_until1 (
{
use ::std::result::Result::*;
use ::std::option::Option::*;
use $crate::{Err,Needed,IResult};
use $crate::{Err,Needed,IResult,need_more};
use $crate::InputLength;
use $crate::FindSubstring;
use $crate::Slice;

let res: IResult<_,_> = if 1+$substr.input_len() > $i.input_len() {
Err(Err::Incomplete(Needed::Size($substr.input_len())))
need_more(Needed::Size($substr.input_len()))
} else {
match ($i).find_substring($substr) {
None => {
Expand All @@ -727,15 +727,15 @@ macro_rules! take_until_either_and_consume (
{
use ::std::result::Result::*;
use ::std::option::Option::*;
use $crate::{Err,Needed,IResult};
use $crate::{Err,Needed,IResult,need_more};

use $crate::InputLength;
use $crate::InputIter;
use $crate::FindToken;
use $crate::Slice;

if $input.input_len() == 0 {
Err(Err::Incomplete(Needed::Unknown))
need_more($input, Needed::Unknown)
} else {
let res: IResult<_,_> = match $input.position(|c| {
c.find_token($arr)
Expand All @@ -762,15 +762,15 @@ macro_rules! take_until_either (
{
use ::std::result::Result::*;
use ::std::option::Option::*;
use $crate::{Err,Needed,IResult};
use $crate::{Err,Needed,IResult,need_more};

use $crate::InputLength;
use $crate::InputIter;
use $crate::FindToken;
use $crate::Slice;

if $input.input_len() == 0 {
Err(Err::Incomplete(Needed::Unknown))
need_more($input, Needed::Unknown)
} else {
let res: IResult<_,_> = match $input.position(|c| {
c.find_token($arr)
Expand Down
4 changes: 2 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,10 +1173,10 @@ macro_rules! eof (
($i:expr,) => (
{
use ::std::result::Result::*;
use $crate::Err;
use $crate::{AtEof,Err};

use $crate::InputLength;
if ($i).input_len() == 0 {
if ($i).at_eof() && ($i).input_len() == 0 {
Ok(($i, $i))
} else {
//FIXME what do we do with need_more?
Expand Down
8 changes: 4 additions & 4 deletions src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ mod tests {
($i:expr, $tag: expr) => (
{
use ::std::result::Result::*;
use $crate::{Err,Needed,IResult};
use $crate::{Err,Needed,IResult, need_more};

let res: IResult<_,_> = if $tag.len() > $i.len() {
Err(Err::Incomplete(Needed::Size($tag.len())))
need_more($i, Needed::Size($tag.len()))
//} else if &$i[0..$tag.len()] == $tag {
} else if ($i).starts_with($tag) {
Ok((&$i[$tag.len()..], &$i[0..$tag.len()]))
Expand All @@ -306,11 +306,11 @@ mod tests {
($i:expr, $count:expr) => (
{
use ::std::result::Result::*;
use $crate::{Err,Needed,IResult};
use $crate::{Err,Needed,IResult,need_more};

let cnt = $count as usize;
let res: IResult<_,_> = if $i.chars().count() < cnt {
Err(Err::Incomplete(Needed::Size(cnt)))
need_more($i, Needed::Size(cnt))
} else {
let mut offset = $i.len();
let mut count = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,16 +526,16 @@ macro_rules! many_m_n(
match failure {
::std::option::Option::Some(i) => Err(Err::Failure(i)),
::std::option::Option::None => match incomplete {
::std::option::Option::Some(i) => Err(Err::Incomplete(i)),
::std::option::Option::None => Err(Err::Incomplete(Needed::Unknown))
::std::option::Option::Some(i) => $crate::need_more($i, i),
::std::option::Option::None => $crate::need_more($i, Needed::Unknown)
}
}
}
} else {
match failure {
::std::option::Option::Some(i) => Err(Err::Failure(i)),
::std::option::Option::None => match incomplete {
::std::option::Option::Some(i) => Err(Err::Incomplete(i)),
::std::option::Option::Some(i) => $crate::need_more($i, i),
::std::option::Option::None => Ok((input, res))
}
}
Expand Down Expand Up @@ -928,7 +928,7 @@ macro_rules! fold_many1(
match failure {
::std::option::Option::Some(e) => Err(Err::Failure(e)),
::std::option::Option::None => match incomplete {
::std::option::Option::Some(i) => Err(Err::Incomplete(i)),
::std::option::Option::Some(i) => $crate::need_more($i, i),
::std::option::Option::None => Ok((input, acc))
}
}
Expand Down
Loading

0 comments on commit 2d86abf

Please sign in to comment.