summaryrefslogtreecommitdiffstats
path: root/vendor/winnow/src/token
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/winnow/src/token')
-rw-r--r--vendor/winnow/src/token/mod.rs447
-rw-r--r--vendor/winnow/src/token/tests.rs123
2 files changed, 312 insertions, 258 deletions
diff --git a/vendor/winnow/src/token/mod.rs b/vendor/winnow/src/token/mod.rs
index 6f99dfa8d..fba019c97 100644
--- a/vendor/winnow/src/token/mod.rs
+++ b/vendor/winnow/src/token/mod.rs
@@ -6,16 +6,13 @@ mod tests;
use crate::error::ErrMode;
use crate::error::ErrorKind;
use crate::error::Needed;
-use crate::error::ParseError;
+use crate::error::ParserError;
use crate::lib::std::result::Result::Ok;
use crate::stream::Range;
-use crate::stream::{
- split_at_offset1_complete, split_at_offset1_partial, split_at_offset_complete,
- split_at_offset_partial, Compare, CompareResult, ContainsToken, FindSlice, SliceLen, Stream,
-};
+use crate::stream::{Compare, CompareResult, ContainsToken, FindSlice, SliceLen, Stream};
use crate::stream::{StreamIsPartial, ToUsize};
use crate::trace::trace;
-use crate::IResult;
+use crate::PResult;
use crate::Parser;
/// Matches one token
@@ -27,31 +24,31 @@ use crate::Parser;
/// # Example
///
/// ```rust
-/// # use winnow::{token::any, error::ErrMode, error::{Error, ErrorKind}};
+/// # use winnow::{token::any, error::ErrMode, error::{InputError, ErrorKind}};
/// # use winnow::prelude::*;
/// fn parser(input: &str) -> IResult<&str, char> {
-/// any.parse_next(input)
+/// any.parse_peek(input)
/// }
///
/// assert_eq!(parser("abc"), Ok(("bc",'a')));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Token))));
+/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Token))));
/// ```
///
/// ```rust
-/// # use winnow::{token::any, error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{token::any, error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
-/// assert_eq!(any::<_, Error<_>>.parse_next(Partial::new("abc")), Ok((Partial::new("bc"),'a')));
-/// assert_eq!(any::<_, Error<_>>.parse_next(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(any::<_, InputError<_>>.parse_peek(Partial::new("abc")), Ok((Partial::new("bc"),'a')));
+/// assert_eq!(any::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
#[doc(alias = "token")]
-pub fn any<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Token, E>
+pub fn any<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Token, E>
where
I: StreamIsPartial,
I: Stream,
{
- trace("any", move |input: I| {
+ trace("any", move |input: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() {
any_::<_, _, true>(input)
} else {
@@ -61,7 +58,9 @@ where
.parse_next(input)
}
-fn any_<I, E: ParseError<I>, const PARTIAL: bool>(input: I) -> IResult<I, <I as Stream>::Token, E>
+fn any_<I, E: ParserError<I>, const PARTIAL: bool>(
+ input: &mut I,
+) -> PResult<<I as Stream>::Token, E>
where
I: StreamIsPartial,
I: Stream,
@@ -80,7 +79,7 @@ where
/// The input data will be compared to the tag combinator's argument and will return the part of
/// the input that matches the argument
///
-/// It will return `Err(ErrMode::Backtrack(Error::new(_, ErrorKind::Tag)))` if the input doesn't match the pattern
+/// It will return `Err(ErrMode::Backtrack(InputError::new(_, ErrorKind::Tag)))` if the input doesn't match the pattern
///
/// **Note:** [`Parser`][crate::Parser] is implemented for strings and byte strings as a convenience (complete
/// only)
@@ -88,44 +87,44 @@ where
/// # Example
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// use winnow::token::tag;
///
/// fn parser(s: &str) -> IResult<&str, &str> {
-/// "Hello".parse_next(s)
+/// "Hello".parse_peek(s)
/// }
///
/// assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello")));
-/// assert_eq!(parser("Something"), Err(ErrMode::Backtrack(Error::new("Something", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
+/// assert_eq!(parser("Something"), Err(ErrMode::Backtrack(InputError::new("Something", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// ```
///
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::Partial;
/// use winnow::token::tag;
///
/// fn parser(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// "Hello".parse_next(s)
+/// "Hello".parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new("Hello, World!")), Ok((Partial::new(", World!"), "Hello")));
-/// assert_eq!(parser(Partial::new("Something")), Err(ErrMode::Backtrack(Error::new(Partial::new("Something"), ErrorKind::Tag))));
-/// assert_eq!(parser(Partial::new("S")), Err(ErrMode::Backtrack(Error::new(Partial::new("S"), ErrorKind::Tag))));
+/// assert_eq!(parser(Partial::new("Something")), Err(ErrMode::Backtrack(InputError::new(Partial::new("Something"), ErrorKind::Tag))));
+/// assert_eq!(parser(Partial::new("S")), Err(ErrMode::Backtrack(InputError::new(Partial::new("S"), ErrorKind::Tag))));
/// assert_eq!(parser(Partial::new("H")), Err(ErrMode::Incomplete(Needed::new(4))));
/// ```
#[inline(always)]
#[doc(alias = "literal")]
#[doc(alias = "bytes")]
#[doc(alias = "just")]
-pub fn tag<T, I, Error: ParseError<I>>(tag: T) -> impl Parser<I, <I as Stream>::Slice, Error>
+pub fn tag<T, I, Error: ParserError<I>>(tag: T) -> impl Parser<I, <I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream + Compare<T>,
T: SliceLen + Clone,
{
- trace("tag", move |i: I| {
+ trace("tag", move |i: &mut I| {
let t = tag.clone();
if <I as StreamIsPartial>::is_partial_supported() {
tag_::<_, _, _, true>(i, t)
@@ -135,10 +134,10 @@ where
})
}
-fn tag_<T, I, Error: ParseError<I>, const PARTIAL: bool>(
- i: I,
+fn tag_<T, I, Error: ParserError<I>, const PARTIAL: bool>(
+ i: &mut I,
t: T,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream + Compare<T>,
@@ -162,47 +161,47 @@ where
/// The input data will be compared to the tag combinator's argument and will return the part of
/// the input that matches the argument with no regard to case.
///
-/// It will return `Err(ErrMode::Backtrack(Error::new(_, ErrorKind::Tag)))` if the input doesn't match the pattern.
+/// It will return `Err(ErrMode::Backtrack(InputError::new(_, ErrorKind::Tag)))` if the input doesn't match the pattern.
///
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::tag_no_case;
///
/// fn parser(s: &str) -> IResult<&str, &str> {
-/// tag_no_case("hello").parse_next(s)
+/// tag_no_case("hello").parse_peek(s)
/// }
///
/// assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello")));
/// assert_eq!(parser("hello, World!"), Ok((", World!", "hello")));
/// assert_eq!(parser("HeLlO, World!"), Ok((", World!", "HeLlO")));
-/// assert_eq!(parser("Something"), Err(ErrMode::Backtrack(Error::new("Something", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
+/// assert_eq!(parser("Something"), Err(ErrMode::Backtrack(InputError::new("Something", ErrorKind::Tag))));
+/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::tag_no_case;
///
/// fn parser(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// tag_no_case("hello").parse_next(s)
+/// tag_no_case("hello").parse_peek(s)
/// }
///
/// assert_eq!(parser(Partial::new("Hello, World!")), Ok((Partial::new(", World!"), "Hello")));
/// assert_eq!(parser(Partial::new("hello, World!")), Ok((Partial::new(", World!"), "hello")));
/// assert_eq!(parser(Partial::new("HeLlO, World!")), Ok((Partial::new(", World!"), "HeLlO")));
-/// assert_eq!(parser(Partial::new("Something")), Err(ErrMode::Backtrack(Error::new(Partial::new("Something"), ErrorKind::Tag))));
+/// assert_eq!(parser(Partial::new("Something")), Err(ErrMode::Backtrack(InputError::new(Partial::new("Something"), ErrorKind::Tag))));
/// assert_eq!(parser(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(5))));
/// ```
#[inline(always)]
#[doc(alias = "literal")]
#[doc(alias = "bytes")]
#[doc(alias = "just")]
-pub fn tag_no_case<T, I, Error: ParseError<I>>(
+pub fn tag_no_case<T, I, Error: ParserError<I>>(
tag: T,
) -> impl Parser<I, <I as Stream>::Slice, Error>
where
@@ -210,7 +209,7 @@ where
I: Stream + Compare<T>,
T: SliceLen + Clone,
{
- trace("tag_no_case", move |i: I| {
+ trace("tag_no_case", move |i: &mut I| {
let t = tag.clone();
if <I as StreamIsPartial>::is_partial_supported() {
tag_no_case_::<_, _, _, true>(i, t)
@@ -220,10 +219,10 @@ where
})
}
-fn tag_no_case_<T, I, Error: ParseError<I>, const PARTIAL: bool>(
- i: I,
+fn tag_no_case_<T, I, Error: ParserError<I>, const PARTIAL: bool>(
+ i: &mut I,
t: T,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream + Compare<T>,
@@ -231,7 +230,7 @@ where
{
let tag_len = t.slice_len();
- match (i).compare_no_case(t) {
+ match i.compare_no_case(t) {
CompareResult::Ok => Ok(i.next_slice(tag_len)),
CompareResult::Incomplete if PARTIAL && i.is_partial() => {
Err(ErrMode::Incomplete(Needed::new(tag_len - i.eof_offset())))
@@ -258,50 +257,50 @@ where
///
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError};
/// # use winnow::token::one_of;
-/// assert_eq!(one_of::<_, _, Error<_>>("abc").parse_next("b"), Ok(("", 'b')));
-/// assert_eq!(one_of::<_, _, Error<_>>("a").parse_next("bc"), Err(ErrMode::Backtrack(Error::new("bc", ErrorKind::Verify))));
-/// assert_eq!(one_of::<_, _, Error<_>>("a").parse_next(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Token))));
+/// assert_eq!(one_of::<_, _, InputError<_>>(['a', 'b', 'c']).parse_peek("b"), Ok(("", 'b')));
+/// assert_eq!(one_of::<_, _, InputError<_>>('a').parse_peek("bc"), Err(ErrMode::Backtrack(InputError::new("bc", ErrorKind::Verify))));
+/// assert_eq!(one_of::<_, _, InputError<_>>('a').parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Token))));
///
/// fn parser_fn(i: &str) -> IResult<&str, char> {
-/// one_of(|c| c == 'a' || c == 'b').parse_next(i)
+/// one_of(|c| c == 'a' || c == 'b').parse_peek(i)
/// }
/// assert_eq!(parser_fn("abc"), Ok(("bc", 'a')));
-/// assert_eq!(parser_fn("cd"), Err(ErrMode::Backtrack(Error::new("cd", ErrorKind::Verify))));
-/// assert_eq!(parser_fn(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Token))));
+/// assert_eq!(parser_fn("cd"), Err(ErrMode::Backtrack(InputError::new("cd", ErrorKind::Verify))));
+/// assert_eq!(parser_fn(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Token))));
/// ```
///
/// ```
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::token::one_of;
-/// assert_eq!(one_of::<_, _, Error<_>>("abc").parse_next(Partial::new("b")), Ok((Partial::new(""), 'b')));
-/// assert_eq!(one_of::<_, _, Error<_>>("a").parse_next(Partial::new("bc")), Err(ErrMode::Backtrack(Error::new(Partial::new("bc"), ErrorKind::Verify))));
-/// assert_eq!(one_of::<_, _, Error<_>>("a").parse_next(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(one_of::<_, _, InputError<_>>(['a', 'b', 'c']).parse_peek(Partial::new("b")), Ok((Partial::new(""), 'b')));
+/// assert_eq!(one_of::<_, _, InputError<_>>('a').parse_peek(Partial::new("bc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("bc"), ErrorKind::Verify))));
+/// assert_eq!(one_of::<_, _, InputError<_>>('a').parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
///
/// fn parser_fn(i: Partial<&str>) -> IResult<Partial<&str>, char> {
-/// one_of(|c| c == 'a' || c == 'b').parse_next(i)
+/// one_of(|c| c == 'a' || c == 'b').parse_peek(i)
/// }
/// assert_eq!(parser_fn(Partial::new("abc")), Ok((Partial::new("bc"), 'a')));
-/// assert_eq!(parser_fn(Partial::new("cd")), Err(ErrMode::Backtrack(Error::new(Partial::new("cd"), ErrorKind::Verify))));
+/// assert_eq!(parser_fn(Partial::new("cd")), Err(ErrMode::Backtrack(InputError::new(Partial::new("cd"), ErrorKind::Verify))));
/// assert_eq!(parser_fn(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
#[doc(alias = "char")]
#[doc(alias = "token")]
#[doc(alias = "satisfy")]
-pub fn one_of<I, T, Error: ParseError<I>>(list: T) -> impl Parser<I, <I as Stream>::Token, Error>
+pub fn one_of<I, T, Error: ParserError<I>>(list: T) -> impl Parser<I, <I as Stream>::Token, Error>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: Copy,
+ <I as Stream>::Token: Clone,
T: ContainsToken<<I as Stream>::Token>,
{
trace(
"one_of",
- any.verify(move |t: &<I as Stream>::Token| list.contains_token(*t)),
+ any.verify(move |t: &<I as Stream>::Token| list.contains_token(t.clone())),
)
}
@@ -314,40 +313,40 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError};
/// # use winnow::prelude::*;
/// # use winnow::token::none_of;
-/// assert_eq!(none_of::<_, _, Error<_>>("abc").parse_next("z"), Ok(("", 'z')));
-/// assert_eq!(none_of::<_, _, Error<_>>("ab").parse_next("a"), Err(ErrMode::Backtrack(Error::new("a", ErrorKind::Verify))));
-/// assert_eq!(none_of::<_, _, Error<_>>("a").parse_next(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Token))));
+/// assert_eq!(none_of::<_, _, InputError<_>>(['a', 'b', 'c']).parse_peek("z"), Ok(("", 'z')));
+/// assert_eq!(none_of::<_, _, InputError<_>>(['a', 'b']).parse_peek("a"), Err(ErrMode::Backtrack(InputError::new("a", ErrorKind::Verify))));
+/// assert_eq!(none_of::<_, _, InputError<_>>('a').parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Token))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// # use winnow::token::none_of;
-/// assert_eq!(none_of::<_, _, Error<_>>("abc").parse_next(Partial::new("z")), Ok((Partial::new(""), 'z')));
-/// assert_eq!(none_of::<_, _, Error<_>>("ab").parse_next(Partial::new("a")), Err(ErrMode::Backtrack(Error::new(Partial::new("a"), ErrorKind::Verify))));
-/// assert_eq!(none_of::<_, _, Error<_>>("a").parse_next(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(none_of::<_, _, InputError<_>>(['a', 'b', 'c']).parse_peek(Partial::new("z")), Ok((Partial::new(""), 'z')));
+/// assert_eq!(none_of::<_, _, InputError<_>>(['a', 'b']).parse_peek(Partial::new("a")), Err(ErrMode::Backtrack(InputError::new(Partial::new("a"), ErrorKind::Verify))));
+/// assert_eq!(none_of::<_, _, InputError<_>>('a').parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn none_of<I, T, Error: ParseError<I>>(list: T) -> impl Parser<I, <I as Stream>::Token, Error>
+pub fn none_of<I, T, Error: ParserError<I>>(list: T) -> impl Parser<I, <I as Stream>::Token, Error>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: Copy,
+ <I as Stream>::Token: Clone,
T: ContainsToken<<I as Stream>::Token>,
{
trace(
"none_of",
- any.verify(move |t: &<I as Stream>::Token| !list.contains_token(*t)),
+ any.verify(move |t: &<I as Stream>::Token| !list.contains_token(t.clone())),
)
}
/// Recognize the longest (m <= len <= n) input slice that matches the [pattern][ContainsToken]
///
-/// It will return an `ErrMode::Backtrack(Error::new(_, ErrorKind::Slice))` if the pattern wasn't met or is out
+/// It will return an `ErrMode::Backtrack(InputError::new(_, ErrorKind::Slice))` if the pattern wasn't met or is out
/// of range (m <= len <= n).
///
/// *Partial version* will return a `ErrMode::Incomplete(Needed::new(1))` if the pattern reaches the end of the input or is too short.
@@ -358,13 +357,13 @@ where
///
/// Zero or more tokens:
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take_while;
/// use winnow::stream::AsChar;
///
/// fn alpha(s: &[u8]) -> IResult<&[u8], &[u8]> {
-/// take_while(0.., AsChar::is_alpha).parse_next(s)
+/// take_while(0.., AsChar::is_alpha).parse_peek(s)
/// }
///
/// assert_eq!(alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
@@ -374,14 +373,14 @@ where
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::take_while;
/// use winnow::stream::AsChar;
///
/// fn alpha(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
-/// take_while(0.., AsChar::is_alpha).parse_next(s)
+/// take_while(0.., AsChar::is_alpha).parse_peek(s)
/// }
///
/// assert_eq!(alpha(Partial::new(b"latin123")), Ok((Partial::new(&b"123"[..]), &b"latin"[..])));
@@ -392,47 +391,47 @@ where
///
/// One or more tokens:
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take_while;
/// use winnow::stream::AsChar;
///
/// fn alpha(s: &[u8]) -> IResult<&[u8], &[u8]> {
-/// take_while(1.., AsChar::is_alpha).parse_next(s)
+/// take_while(1.., AsChar::is_alpha).parse_peek(s)
/// }
///
/// assert_eq!(alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
/// assert_eq!(alpha(b"latin"), Ok((&b""[..], &b"latin"[..])));
-/// assert_eq!(alpha(b"12345"), Err(ErrMode::Backtrack(Error::new(&b"12345"[..], ErrorKind::Slice))));
+/// assert_eq!(alpha(b"12345"), Err(ErrMode::Backtrack(InputError::new(&b"12345"[..], ErrorKind::Slice))));
///
/// fn hex(s: &str) -> IResult<&str, &str> {
-/// take_while(1.., "1234567890ABCDEF").parse_next(s)
+/// take_while(1.., ('0'..='9', 'A'..='F')).parse_peek(s)
/// }
///
/// assert_eq!(hex("123 and voila"), Ok((" and voila", "123")));
/// assert_eq!(hex("DEADBEEF and others"), Ok((" and others", "DEADBEEF")));
/// assert_eq!(hex("BADBABEsomething"), Ok(("something", "BADBABE")));
/// assert_eq!(hex("D15EA5E"), Ok(("", "D15EA5E")));
-/// assert_eq!(hex(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(hex(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::take_while;
/// use winnow::stream::AsChar;
///
/// fn alpha(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
-/// take_while(1.., AsChar::is_alpha).parse_next(s)
+/// take_while(1.., AsChar::is_alpha).parse_peek(s)
/// }
///
/// assert_eq!(alpha(Partial::new(b"latin123")), Ok((Partial::new(&b"123"[..]), &b"latin"[..])));
/// assert_eq!(alpha(Partial::new(b"latin")), Err(ErrMode::Incomplete(Needed::new(1))));
-/// assert_eq!(alpha(Partial::new(b"12345")), Err(ErrMode::Backtrack(Error::new(Partial::new(&b"12345"[..]), ErrorKind::Slice))));
+/// assert_eq!(alpha(Partial::new(b"12345")), Err(ErrMode::Backtrack(InputError::new(Partial::new(&b"12345"[..]), ErrorKind::Slice))));
///
/// fn hex(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// take_while(1.., "1234567890ABCDEF").parse_next(s)
+/// take_while(1.., ('0'..='9', 'A'..='F')).parse_peek(s)
/// }
///
/// assert_eq!(hex(Partial::new("123 and voila")), Ok((Partial::new(" and voila"), "123")));
@@ -444,44 +443,44 @@ where
///
/// Arbitrary amount of tokens:
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take_while;
/// use winnow::stream::AsChar;
///
/// fn short_alpha(s: &[u8]) -> IResult<&[u8], &[u8]> {
-/// take_while(3..=6, AsChar::is_alpha).parse_next(s)
+/// take_while(3..=6, AsChar::is_alpha).parse_peek(s)
/// }
///
/// assert_eq!(short_alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
/// assert_eq!(short_alpha(b"lengthy"), Ok((&b"y"[..], &b"length"[..])));
/// assert_eq!(short_alpha(b"latin"), Ok((&b""[..], &b"latin"[..])));
-/// assert_eq!(short_alpha(b"ed"), Err(ErrMode::Backtrack(Error::new(&b"ed"[..], ErrorKind::Slice))));
-/// assert_eq!(short_alpha(b"12345"), Err(ErrMode::Backtrack(Error::new(&b"12345"[..], ErrorKind::Slice))));
+/// assert_eq!(short_alpha(b"ed"), Err(ErrMode::Backtrack(InputError::new(&b"ed"[..], ErrorKind::Slice))));
+/// assert_eq!(short_alpha(b"12345"), Err(ErrMode::Backtrack(InputError::new(&b"12345"[..], ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::take_while;
/// use winnow::stream::AsChar;
///
/// fn short_alpha(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
-/// take_while(3..=6, AsChar::is_alpha).parse_next(s)
+/// take_while(3..=6, AsChar::is_alpha).parse_peek(s)
/// }
///
/// assert_eq!(short_alpha(Partial::new(b"latin123")), Ok((Partial::new(&b"123"[..]), &b"latin"[..])));
/// assert_eq!(short_alpha(Partial::new(b"lengthy")), Ok((Partial::new(&b"y"[..]), &b"length"[..])));
/// assert_eq!(short_alpha(Partial::new(b"latin")), Err(ErrMode::Incomplete(Needed::new(1))));
/// assert_eq!(short_alpha(Partial::new(b"ed")), Err(ErrMode::Incomplete(Needed::new(1))));
-/// assert_eq!(short_alpha(Partial::new(b"12345")), Err(ErrMode::Backtrack(Error::new(Partial::new(&b"12345"[..]), ErrorKind::Slice))));
+/// assert_eq!(short_alpha(Partial::new(b"12345")), Err(ErrMode::Backtrack(InputError::new(Partial::new(&b"12345"[..]), ErrorKind::Slice))));
/// ```
#[inline(always)]
#[doc(alias = "is_a")]
#[doc(alias = "take_while0")]
#[doc(alias = "take_while1")]
-pub fn take_while<T, I, Error: ParseError<I>>(
+pub fn take_while<T, I, Error: ParserError<I>>(
range: impl Into<Range>,
list: T,
) -> impl Parser<I, <I as Stream>::Slice, Error>
@@ -494,7 +493,7 @@ where
start_inclusive,
end_inclusive,
} = range.into();
- trace("take_while", move |i: I| {
+ trace("take_while", move |i: &mut I| {
match (start_inclusive, end_inclusive) {
(0, None) => {
if <I as StreamIsPartial>::is_partial_supported() {
@@ -522,73 +521,127 @@ where
})
}
-/// Deprecated, see [`take_while`]
-#[deprecated(since = "0.4.6", note = "Replaced with `take_while`")]
-#[inline(always)]
-pub fn take_while0<T, I, Error: ParseError<I>>(
- list: T,
-) -> impl Parser<I, <I as Stream>::Slice, Error>
+fn take_while0_<T, I, Error: ParserError<I>, const PARTIAL: bool>(
+ input: &mut I,
+ list: &T,
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream,
T: ContainsToken<<I as Stream>::Token>,
{
- take_while(0.., list)
+ if PARTIAL && input.is_partial() {
+ take_till0_partial(input, |c| !list.contains_token(c))
+ } else {
+ take_till0_complete(input, |c| !list.contains_token(c))
+ }
}
-/// Deprecated, see [`take_while`]
-#[deprecated(since = "0.4.6", note = "Replaced with `take_while`")]
-#[inline(always)]
-pub fn take_while1<T, I, Error: ParseError<I>>(
- list: T,
-) -> impl Parser<I, <I as Stream>::Slice, Error>
+fn take_while1_<T, I, Error: ParserError<I>, const PARTIAL: bool>(
+ input: &mut I,
+ list: &T,
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream,
T: ContainsToken<<I as Stream>::Token>,
{
- take_while(1.., list)
+ let e: ErrorKind = ErrorKind::Slice;
+ if PARTIAL && input.is_partial() {
+ take_till1_partial(input, |c| !list.contains_token(c), e)
+ } else {
+ take_till1_complete(input, |c| !list.contains_token(c), e)
+ }
}
-fn take_while0_<T, I, Error: ParseError<I>, const PARTIAL: bool>(
- input: I,
- list: &T,
-) -> IResult<I, <I as Stream>::Slice, Error>
+/// Looks for the first element of the input type for which the condition returns true,
+/// and returns the input up to this position.
+///
+/// *Partial version*: If no element is found matching the condition, this will return `Incomplete`
+fn take_till0_partial<P, I: Stream, E: ParserError<I>>(
+ input: &mut I,
+ predicate: P,
+) -> PResult<<I as Stream>::Slice, E>
where
- I: StreamIsPartial,
- I: Stream,
- T: ContainsToken<<I as Stream>::Token>,
+ P: Fn(I::Token) -> bool,
{
- if PARTIAL && input.is_partial() {
- split_at_offset_partial(&input, |c| !list.contains_token(c))
+ let offset = input
+ .offset_for(predicate)
+ .ok_or_else(|| ErrMode::Incomplete(Needed::new(1)))?;
+ Ok(input.next_slice(offset))
+}
+
+/// Looks for the first element of the input type for which the condition returns true
+/// and returns the input up to this position.
+///
+/// Fails if the produced slice is empty.
+///
+/// *Partial version*: If no element is found matching the condition, this will return `Incomplete`
+fn take_till1_partial<P, I: Stream, E: ParserError<I>>(
+ input: &mut I,
+ predicate: P,
+ e: ErrorKind,
+) -> PResult<<I as Stream>::Slice, E>
+where
+ P: Fn(I::Token) -> bool,
+{
+ let offset = input
+ .offset_for(predicate)
+ .ok_or_else(|| ErrMode::Incomplete(Needed::new(1)))?;
+ if offset == 0 {
+ Err(ErrMode::from_error_kind(input, e))
} else {
- split_at_offset_complete(&input, |c| !list.contains_token(c))
+ Ok(input.next_slice(offset))
}
}
-fn take_while1_<T, I, Error: ParseError<I>, const PARTIAL: bool>(
- input: I,
- list: &T,
-) -> IResult<I, <I as Stream>::Slice, Error>
+/// Looks for the first element of the input type for which the condition returns true,
+/// and returns the input up to this position.
+///
+/// *Complete version*: If no element is found matching the condition, this will return the whole input
+fn take_till0_complete<P, I: Stream, E: ParserError<I>>(
+ input: &mut I,
+ predicate: P,
+) -> PResult<<I as Stream>::Slice, E>
where
- I: StreamIsPartial,
- I: Stream,
- T: ContainsToken<<I as Stream>::Token>,
+ P: Fn(I::Token) -> bool,
{
- let e: ErrorKind = ErrorKind::Slice;
- if PARTIAL && input.is_partial() {
- split_at_offset1_partial(&input, |c| !list.contains_token(c), e)
+ let offset = input
+ .offset_for(predicate)
+ .unwrap_or_else(|| input.eof_offset());
+ Ok(input.next_slice(offset))
+}
+
+/// Looks for the first element of the input type for which the condition returns true
+/// and returns the input up to this position.
+///
+/// Fails if the produced slice is empty.
+///
+/// *Complete version*: If no element is found matching the condition, this will return the whole input
+fn take_till1_complete<P, I: Stream, E: ParserError<I>>(
+ input: &mut I,
+ predicate: P,
+ e: ErrorKind,
+) -> PResult<<I as Stream>::Slice, E>
+where
+ P: Fn(I::Token) -> bool,
+{
+ let offset = input
+ .offset_for(predicate)
+ .unwrap_or_else(|| input.eof_offset());
+ if offset == 0 {
+ Err(ErrMode::from_error_kind(input, e))
} else {
- split_at_offset1_complete(&input, |c| !list.contains_token(c), e)
+ Ok(input.next_slice(offset))
}
}
-fn take_while_m_n_<T, I, Error: ParseError<I>, const PARTIAL: bool>(
- input: I,
+fn take_while_m_n_<T, I, Error: ParserError<I>, const PARTIAL: bool>(
+ input: &mut I,
m: usize,
n: usize,
list: &T,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream,
@@ -615,7 +668,7 @@ where
}
if PARTIAL && input.is_partial() {
if final_count == n {
- Ok(input.next_slice(input.eof_offset()))
+ Ok(input.finish())
} else {
let needed = if m > input.eof_offset() {
m - input.eof_offset()
@@ -626,7 +679,7 @@ where
}
} else {
if m <= final_count {
- Ok(input.next_slice(input.eof_offset()))
+ Ok(input.finish())
} else {
Err(ErrMode::from_error_kind(input, ErrorKind::Slice))
}
@@ -641,12 +694,12 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take_till0;
///
/// fn till_colon(s: &str) -> IResult<&str, &str> {
-/// take_till0(|c| c == ':').parse_next(s)
+/// take_till0(|c| c == ':').parse_peek(s)
/// }
///
/// assert_eq!(till_colon("latin:123"), Ok((":123", "latin")));
@@ -656,13 +709,13 @@ where
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::take_till0;
///
/// fn till_colon(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// take_till0(|c| c == ':').parse_next(s)
+/// take_till0(|c| c == ':').parse_peek(s)
/// }
///
/// assert_eq!(till_colon(Partial::new("latin:123")), Ok((Partial::new(":123"), "latin")));
@@ -671,7 +724,7 @@ where
/// assert_eq!(till_colon(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn take_till0<T, I, Error: ParseError<I>>(
+pub fn take_till0<T, I, Error: ParserError<I>>(
list: T,
) -> impl Parser<I, <I as Stream>::Slice, Error>
where
@@ -679,18 +732,18 @@ where
I: Stream,
T: ContainsToken<<I as Stream>::Token>,
{
- trace("take_till0", move |i: I| {
+ trace("take_till0", move |i: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() && i.is_partial() {
- split_at_offset_partial(&i, |c| list.contains_token(c))
+ take_till0_partial(i, |c| list.contains_token(c))
} else {
- split_at_offset_complete(&i, |c| list.contains_token(c))
+ take_till0_complete(i, |c| list.contains_token(c))
}
})
}
/// Recognize the longest (at least 1) input slice till a [pattern][ContainsToken] is met.
///
-/// It will return `Err(ErrMode::Backtrack(Error::new(_, ErrorKind::Slice)))` if the input is empty or the
+/// It will return `Err(ErrMode::Backtrack(InputError::new(_, ErrorKind::Slice)))` if the input is empty or the
/// predicate matches the first input.
///
/// *Partial version* will return a `ErrMode::Incomplete(Needed::new(1))` if the match reaches the
@@ -699,46 +752,46 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take_till1;
///
/// fn till_colon(s: &str) -> IResult<&str, &str> {
-/// take_till1(|c| c == ':').parse_next(s)
+/// take_till1(|c| c == ':').parse_peek(s)
/// }
///
/// assert_eq!(till_colon("latin:123"), Ok((":123", "latin")));
-/// assert_eq!(till_colon(":empty matched"), Err(ErrMode::Backtrack(Error::new(":empty matched", ErrorKind::Slice))));
+/// assert_eq!(till_colon(":empty matched"), Err(ErrMode::Backtrack(InputError::new(":empty matched", ErrorKind::Slice))));
/// assert_eq!(till_colon("12345"), Ok(("", "12345")));
-/// assert_eq!(till_colon(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(till_colon(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
///
/// fn not_space(s: &str) -> IResult<&str, &str> {
-/// take_till1(" \t\r\n").parse_next(s)
+/// take_till1([' ', '\t', '\r', '\n']).parse_peek(s)
/// }
///
/// assert_eq!(not_space("Hello, World!"), Ok((" World!", "Hello,")));
/// assert_eq!(not_space("Sometimes\t"), Ok(("\t", "Sometimes")));
/// assert_eq!(not_space("Nospace"), Ok(("", "Nospace")));
-/// assert_eq!(not_space(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(not_space(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::take_till1;
///
/// fn till_colon(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// take_till1(|c| c == ':').parse_next(s)
+/// take_till1(|c| c == ':').parse_peek(s)
/// }
///
/// assert_eq!(till_colon(Partial::new("latin:123")), Ok((Partial::new(":123"), "latin")));
-/// assert_eq!(till_colon(Partial::new(":empty matched")), Err(ErrMode::Backtrack(Error::new(Partial::new(":empty matched"), ErrorKind::Slice))));
+/// assert_eq!(till_colon(Partial::new(":empty matched")), Err(ErrMode::Backtrack(InputError::new(Partial::new(":empty matched"), ErrorKind::Slice))));
/// assert_eq!(till_colon(Partial::new("12345")), Err(ErrMode::Incomplete(Needed::new(1))));
/// assert_eq!(till_colon(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
///
/// fn not_space(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// take_till1(" \t\r\n").parse_next(s)
+/// take_till1([' ', '\t', '\r', '\n']).parse_peek(s)
/// }
///
/// assert_eq!(not_space(Partial::new("Hello, World!")), Ok((Partial::new(" World!"), "Hello,")));
@@ -748,7 +801,7 @@ where
/// ```
#[inline(always)]
#[doc(alias = "is_not")]
-pub fn take_till1<T, I, Error: ParseError<I>>(
+pub fn take_till1<T, I, Error: ParserError<I>>(
list: T,
) -> impl Parser<I, <I as Stream>::Slice, Error>
where
@@ -756,19 +809,19 @@ where
I: Stream,
T: ContainsToken<<I as Stream>::Token>,
{
- trace("take_till1", move |i: I| {
+ trace("take_till1", move |i: &mut I| {
let e: ErrorKind = ErrorKind::Slice;
if <I as StreamIsPartial>::is_partial_supported() && i.is_partial() {
- split_at_offset1_partial(&i, |c| list.contains_token(c), e)
+ take_till1_partial(i, |c| list.contains_token(c), e)
} else {
- split_at_offset1_complete(&i, |c| list.contains_token(c), e)
+ take_till1_complete(i, |c| list.contains_token(c), e)
}
})
}
/// Recognize an input slice containing the first N input elements (I[..N]).
///
-/// *Complete version*: It will return `Err(ErrMode::Backtrack(Error::new(_, ErrorKind::Slice)))` if the input is shorter than the argument.
+/// *Complete version*: It will return `Err(ErrMode::Backtrack(InputError::new(_, ErrorKind::Slice)))` if the input is shorter than the argument.
///
/// *Partial version*: if the input has less than N elements, `take` will
/// return a `ErrMode::Incomplete(Needed::new(M))` where M is the number of
@@ -780,18 +833,18 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take;
///
/// fn take6(s: &str) -> IResult<&str, &str> {
-/// take(6usize).parse_next(s)
+/// take(6usize).parse_peek(s)
/// }
///
/// assert_eq!(take6("1234567"), Ok(("7", "123456")));
/// assert_eq!(take6("things"), Ok(("", "things")));
-/// assert_eq!(take6("short"), Err(ErrMode::Backtrack(Error::new("short", ErrorKind::Slice))));
-/// assert_eq!(take6(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(take6("short"), Err(ErrMode::Backtrack(InputError::new("short", ErrorKind::Slice))));
+/// assert_eq!(take6(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// The units that are taken will depend on the input type. For example, for a
@@ -800,21 +853,21 @@ where
///
/// ```rust
/// # use winnow::prelude::*;
-/// use winnow::error::Error;
+/// use winnow::error::InputError;
/// use winnow::token::take;
///
-/// assert_eq!(take::<_, _, Error<_>>(1usize).parse_next("💙"), Ok(("", "💙")));
-/// assert_eq!(take::<_, _, Error<_>>(1usize).parse_next("💙".as_bytes()), Ok((b"\x9F\x92\x99".as_ref(), b"\xF0".as_ref())));
+/// assert_eq!(take::<_, _, InputError<_>>(1usize).parse_peek("💙"), Ok(("", "💙")));
+/// assert_eq!(take::<_, _, InputError<_>>(1usize).parse_peek("💙".as_bytes()), Ok((b"\x9F\x92\x99".as_ref(), b"\xF0".as_ref())));
/// ```
///
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// use winnow::token::take;
///
/// fn take6(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// take(6usize).parse_next(s)
+/// take(6usize).parse_peek(s)
/// }
///
/// assert_eq!(take6(Partial::new("1234567")), Ok((Partial::new("7"), "123456")));
@@ -823,14 +876,14 @@ where
/// assert_eq!(take6(Partial::new("short")), Err(ErrMode::Incomplete(Needed::Unknown)));
/// ```
#[inline(always)]
-pub fn take<C, I, Error: ParseError<I>>(count: C) -> impl Parser<I, <I as Stream>::Slice, Error>
+pub fn take<C, I, Error: ParserError<I>>(count: C) -> impl Parser<I, <I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream,
C: ToUsize,
{
let c = count.to_usize();
- trace("take", move |i: I| {
+ trace("take", move |i: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() {
take_::<_, _, true>(i, c)
} else {
@@ -839,10 +892,10 @@ where
})
}
-fn take_<I, Error: ParseError<I>, const PARTIAL: bool>(
- i: I,
+fn take_<I, Error: ParserError<I>, const PARTIAL: bool>(
+ i: &mut I,
c: usize,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream,
@@ -858,7 +911,7 @@ where
///
/// It doesn't consume the pattern.
///
-/// *Complete version*: It will return `Err(ErrMode::Backtrack(Error::new(_, ErrorKind::Slice)))`
+/// *Complete version*: It will return `Err(ErrMode::Backtrack(InputError::new(_, ErrorKind::Slice)))`
/// if the pattern wasn't met.
///
/// *Partial version*: will return a `ErrMode::Incomplete(Needed::new(N))` if the input doesn't
@@ -867,28 +920,28 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take_until0;
///
/// fn until_eof(s: &str) -> IResult<&str, &str> {
-/// take_until0("eof").parse_next(s)
+/// take_until0("eof").parse_peek(s)
/// }
///
/// assert_eq!(until_eof("hello, worldeof"), Ok(("eof", "hello, world")));
-/// assert_eq!(until_eof("hello, world"), Err(ErrMode::Backtrack(Error::new("hello, world", ErrorKind::Slice))));
-/// assert_eq!(until_eof(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(until_eof("hello, world"), Err(ErrMode::Backtrack(InputError::new("hello, world", ErrorKind::Slice))));
+/// assert_eq!(until_eof(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// assert_eq!(until_eof("1eof2eof"), Ok(("eof2eof", "1")));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::take_until0;
///
/// fn until_eof(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// take_until0("eof").parse_next(s)
+/// take_until0("eof").parse_peek(s)
/// }
///
/// assert_eq!(until_eof(Partial::new("hello, worldeof")), Ok((Partial::new("eof"), "hello, world")));
@@ -897,7 +950,7 @@ where
/// assert_eq!(until_eof(Partial::new("1eof2eof")), Ok((Partial::new("eof2eof"), "1")));
/// ```
#[inline(always)]
-pub fn take_until0<T, I, Error: ParseError<I>>(
+pub fn take_until0<T, I, Error: ParserError<I>>(
tag: T,
) -> impl Parser<I, <I as Stream>::Slice, Error>
where
@@ -905,7 +958,7 @@ where
I: Stream + FindSlice<T>,
T: SliceLen + Clone,
{
- trace("take_until0", move |i: I| {
+ trace("take_until0", move |i: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() {
take_until0_::<_, _, _, true>(i, tag.clone())
} else {
@@ -914,10 +967,10 @@ where
})
}
-fn take_until0_<T, I, Error: ParseError<I>, const PARTIAL: bool>(
- i: I,
+fn take_until0_<T, I, Error: ParserError<I>, const PARTIAL: bool>(
+ i: &mut I,
t: T,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream + FindSlice<T>,
@@ -934,7 +987,7 @@ where
///
/// It doesn't consume the pattern.
///
-/// *Complete version*: It will return `Err(ErrMode::Backtrack(Error::new(_, ErrorKind::Slice)))`
+/// *Complete version*: It will return `Err(ErrMode::Backtrack(InputError::new(_, ErrorKind::Slice)))`
/// if the pattern wasn't met.
///
/// *Partial version*: will return a `ErrMode::Incomplete(Needed::new(N))` if the input doesn't
@@ -943,39 +996,39 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// use winnow::token::take_until1;
///
/// fn until_eof(s: &str) -> IResult<&str, &str> {
-/// take_until1("eof").parse_next(s)
+/// take_until1("eof").parse_peek(s)
/// }
///
/// assert_eq!(until_eof("hello, worldeof"), Ok(("eof", "hello, world")));
-/// assert_eq!(until_eof("hello, world"), Err(ErrMode::Backtrack(Error::new("hello, world", ErrorKind::Slice))));
-/// assert_eq!(until_eof(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(until_eof("hello, world"), Err(ErrMode::Backtrack(InputError::new("hello, world", ErrorKind::Slice))));
+/// assert_eq!(until_eof(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// assert_eq!(until_eof("1eof2eof"), Ok(("eof2eof", "1")));
-/// assert_eq!(until_eof("eof"), Err(ErrMode::Backtrack(Error::new("eof", ErrorKind::Slice))));
+/// assert_eq!(until_eof("eof"), Err(ErrMode::Backtrack(InputError::new("eof", ErrorKind::Slice))));
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, error::Needed};
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::prelude::*;
/// # use winnow::Partial;
/// use winnow::token::take_until1;
///
/// fn until_eof(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// take_until1("eof").parse_next(s)
+/// take_until1("eof").parse_peek(s)
/// }
///
/// assert_eq!(until_eof(Partial::new("hello, worldeof")), Ok((Partial::new("eof"), "hello, world")));
/// assert_eq!(until_eof(Partial::new("hello, world")), Err(ErrMode::Incomplete(Needed::Unknown)));
/// assert_eq!(until_eof(Partial::new("hello, worldeo")), Err(ErrMode::Incomplete(Needed::Unknown)));
/// assert_eq!(until_eof(Partial::new("1eof2eof")), Ok((Partial::new("eof2eof"), "1")));
-/// assert_eq!(until_eof(Partial::new("eof")), Err(ErrMode::Backtrack(Error::new(Partial::new("eof"), ErrorKind::Slice))));
+/// assert_eq!(until_eof(Partial::new("eof")), Err(ErrMode::Backtrack(InputError::new(Partial::new("eof"), ErrorKind::Slice))));
/// ```
#[inline(always)]
-pub fn take_until1<T, I, Error: ParseError<I>>(
+pub fn take_until1<T, I, Error: ParserError<I>>(
tag: T,
) -> impl Parser<I, <I as Stream>::Slice, Error>
where
@@ -983,7 +1036,7 @@ where
I: Stream + FindSlice<T>,
T: SliceLen + Clone,
{
- trace("take_until1", move |i: I| {
+ trace("take_until1", move |i: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() {
take_until1_::<_, _, _, true>(i, tag.clone())
} else {
@@ -992,10 +1045,10 @@ where
})
}
-fn take_until1_<T, I, Error: ParseError<I>, const PARTIAL: bool>(
- i: I,
+fn take_until1_<T, I, Error: ParserError<I>, const PARTIAL: bool>(
+ i: &mut I,
t: T,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
I: Stream + FindSlice<T>,
diff --git a/vendor/winnow/src/token/tests.rs b/vendor/winnow/src/token/tests.rs
index e1c7999c2..d9f364607 100644
--- a/vendor/winnow/src/token/tests.rs
+++ b/vendor/winnow/src/token/tests.rs
@@ -6,11 +6,12 @@ use proptest::prelude::*;
use crate::binary::length_data;
use crate::combinator::delimited;
use crate::error::ErrMode;
-use crate::error::Error;
use crate::error::ErrorKind;
+use crate::error::InputError;
use crate::error::Needed;
use crate::stream::AsChar;
use crate::token::tag;
+use crate::unpeek;
use crate::IResult;
use crate::Parser;
use crate::Partial;
@@ -18,13 +19,13 @@ use crate::Partial;
#[test]
fn complete_take_while_m_n_utf8_all_matching() {
let result: IResult<&str, &str> =
- take_while(1..=4, |c: char| c.is_alphabetic()).parse_next("øn");
+ take_while(1..=4, |c: char| c.is_alphabetic()).parse_peek("øn");
assert_eq!(result, Ok(("", "øn")));
}
#[test]
fn complete_take_while_m_n_utf8_all_matching_substring() {
- let result: IResult<&str, &str> = take_while(1, |c: char| c.is_alphabetic()).parse_next("øn");
+ let result: IResult<&str, &str> = take_while(1, |c: char| c.is_alphabetic()).parse_peek("øn");
assert_eq!(result, Ok(("n", "ø")));
}
@@ -37,7 +38,7 @@ fn model_complete_take_while_m_n(
) -> IResult<&str, &str> {
if n < m {
Err(crate::error::ErrMode::from_error_kind(
- input,
+ &input,
crate::error::ErrorKind::Slice,
))
} else if m <= valid {
@@ -45,7 +46,7 @@ fn model_complete_take_while_m_n(
Ok((&input[offset..], &input[0..offset]))
} else {
Err(crate::error::ErrMode::from_error_kind(
- input,
+ &input,
crate::error::ErrorKind::Slice,
))
}
@@ -59,7 +60,7 @@ proptest! {
let input = format!("{:a<valid$}{:b<invalid$}", "", "", valid=valid, invalid=invalid);
let expected = model_complete_take_while_m_n(m, n, valid, &input);
if m <= n {
- let actual = take_while(m..=n, |c: char| c == 'a').parse_next(input.as_str());
+ let actual = take_while(m..=n, |c: char| c == 'a').parse_peek(input.as_str());
assert_eq!(expected, actual);
}
}
@@ -69,7 +70,7 @@ proptest! {
fn partial_any_str() {
use super::any;
assert_eq!(
- any::<_, Error<Partial<&str>>>(Partial::new("Ó˜")),
+ any::<_, InputError<Partial<&str>>>.parse_peek(Partial::new("Ó˜")),
Ok((Partial::new(""), 'Ó˜'))
);
}
@@ -77,7 +78,7 @@ fn partial_any_str() {
#[test]
fn partial_one_of_test() {
fn f(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u8> {
- one_of("ab").parse_next(i)
+ one_of(['a', 'b']).parse_peek(i)
}
let a = &b"abcd"[..];
@@ -87,13 +88,13 @@ fn partial_one_of_test() {
assert_eq!(
f(Partial::new(b)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(b),
+ &Partial::new(b),
ErrorKind::Verify
)))
);
fn utf8(i: Partial<&str>) -> IResult<Partial<&str>, char> {
- one_of("+\u{FF0B}").parse_next(i)
+ one_of(['+', '\u{FF0B}']).parse_peek(i)
}
assert!(utf8(Partial::new("+")).is_ok());
@@ -103,14 +104,14 @@ fn partial_one_of_test() {
#[test]
fn char_byteslice() {
fn f(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u8> {
- 'c'.parse_next(i)
+ 'c'.parse_peek(i)
}
let a = &b"abcd"[..];
assert_eq!(
f(Partial::new(a)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(a),
+ &Partial::new(a),
ErrorKind::Verify
)))
);
@@ -122,14 +123,14 @@ fn char_byteslice() {
#[test]
fn char_str() {
fn f(i: Partial<&str>) -> IResult<Partial<&str>, char> {
- 'c'.parse_next(i)
+ 'c'.parse_peek(i)
}
let a = "abcd";
assert_eq!(
f(Partial::new(a)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(a),
+ &Partial::new(a),
ErrorKind::Verify
)))
);
@@ -141,14 +142,14 @@ fn char_str() {
#[test]
fn partial_none_of_test() {
fn f(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u8> {
- none_of("ab").parse_next(i)
+ none_of(['a', 'b']).parse_peek(i)
}
let a = &b"abcd"[..];
assert_eq!(
f(Partial::new(a)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(a),
+ &Partial::new(a),
ErrorKind::Verify
)))
);
@@ -160,7 +161,7 @@ fn partial_none_of_test() {
#[test]
fn partial_is_a() {
fn a_or_b(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_while(1.., "ab").parse_next(i)
+ take_while(1.., ['a', 'b']).parse_peek(i)
}
let a = Partial::new(&b"abcd"[..]);
@@ -172,7 +173,7 @@ fn partial_is_a() {
let c = Partial::new(&b"cdef"[..]);
assert_eq!(
a_or_b(c),
- Err(ErrMode::Backtrack(error_position!(c, ErrorKind::Slice)))
+ Err(ErrMode::Backtrack(error_position!(&c, ErrorKind::Slice)))
);
let d = Partial::new(&b"bacdef"[..]);
@@ -182,7 +183,7 @@ fn partial_is_a() {
#[test]
fn partial_is_not() {
fn a_or_b(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_till1("ab").parse_next(i)
+ take_till1(['a', 'b']).parse_peek(i)
}
let a = Partial::new(&b"cdab"[..]);
@@ -194,7 +195,7 @@ fn partial_is_not() {
let c = Partial::new(&b"abab"[..]);
assert_eq!(
a_or_b(c),
- Err(ErrMode::Backtrack(error_position!(c, ErrorKind::Slice)))
+ Err(ErrMode::Backtrack(error_position!(&c, ErrorKind::Slice)))
);
let d = Partial::new(&b"cdefba"[..]);
@@ -207,7 +208,7 @@ fn partial_is_not() {
#[test]
fn partial_take_until_incomplete() {
fn y(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_until0("end").parse_next(i)
+ take_until0("end").parse_peek(i)
}
assert_eq!(
y(Partial::new(&b"nd"[..])),
@@ -226,7 +227,7 @@ fn partial_take_until_incomplete() {
#[test]
fn partial_take_until_incomplete_s() {
fn ys(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_until0("end").parse_next(i)
+ take_until0("end").parse_peek(i)
}
assert_eq!(
ys(Partial::new("123en")),
@@ -244,7 +245,7 @@ fn partial_recognize() {
fn x(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
delimited("<!--", take(5_usize), "-->")
.recognize()
- .parse_next(i)
+ .parse_peek(i)
}
let r = x(Partial::new(&b"<!-- abc --> aaa"[..]));
assert_eq!(r, Ok((Partial::new(&b" aaa"[..]), &b"<!-- abc -->"[..])));
@@ -252,43 +253,43 @@ fn partial_recognize() {
let semicolon = &b";"[..];
fn ya(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- alpha.recognize().parse_next(i)
+ alpha.recognize().parse_peek(i)
}
let ra = ya(Partial::new(&b"abc;"[..]));
assert_eq!(ra, Ok((Partial::new(semicolon), &b"abc"[..])));
fn yd(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- digit.recognize().parse_next(i)
+ digit.recognize().parse_peek(i)
}
let rd = yd(Partial::new(&b"123;"[..]));
assert_eq!(rd, Ok((Partial::new(semicolon), &b"123"[..])));
fn yhd(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- hex_digit.recognize().parse_next(i)
+ hex_digit.recognize().parse_peek(i)
}
let rhd = yhd(Partial::new(&b"123abcDEF;"[..]));
assert_eq!(rhd, Ok((Partial::new(semicolon), &b"123abcDEF"[..])));
fn yod(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- oct_digit.recognize().parse_next(i)
+ oct_digit.recognize().parse_peek(i)
}
let rod = yod(Partial::new(&b"1234567;"[..]));
assert_eq!(rod, Ok((Partial::new(semicolon), &b"1234567"[..])));
fn yan(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- alphanumeric.recognize().parse_next(i)
+ alphanumeric.recognize().parse_peek(i)
}
let ran = yan(Partial::new(&b"123abc;"[..]));
assert_eq!(ran, Ok((Partial::new(semicolon), &b"123abc"[..])));
fn ys(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- space.recognize().parse_next(i)
+ space.recognize().parse_peek(i)
}
let rs = ys(Partial::new(&b" \t;"[..]));
assert_eq!(rs, Ok((Partial::new(semicolon), &b" \t"[..])));
fn yms(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- multispace.recognize().parse_next(i)
+ multispace.recognize().parse_peek(i)
}
let rms = yms(Partial::new(&b" \t\r\n;"[..]));
assert_eq!(rms, Ok((Partial::new(semicolon), &b" \t\r\n"[..])));
@@ -297,7 +298,7 @@ fn partial_recognize() {
#[test]
fn partial_take_while0() {
fn f(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_while(0.., AsChar::is_alpha).parse_next(i)
+ take_while(0.., AsChar::is_alpha).parse_peek(i)
}
let a = &b""[..];
let b = &b"abcd"[..];
@@ -313,7 +314,7 @@ fn partial_take_while0() {
#[test]
fn partial_take_while1() {
fn f(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_while(1.., AsChar::is_alpha).parse_next(i)
+ take_while(1.., AsChar::is_alpha).parse_peek(i)
}
let a = &b""[..];
let b = &b"abcd"[..];
@@ -326,7 +327,7 @@ fn partial_take_while1() {
assert_eq!(
f(Partial::new(d)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(d),
+ &Partial::new(d),
ErrorKind::Slice
)))
);
@@ -335,7 +336,7 @@ fn partial_take_while1() {
#[test]
fn partial_take_while_m_n() {
fn x(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_while(2..=4, AsChar::is_alpha).parse_next(i)
+ take_while(2..=4, AsChar::is_alpha).parse_peek(i)
}
let a = &b""[..];
let b = &b"a"[..];
@@ -355,7 +356,7 @@ fn partial_take_while_m_n() {
assert_eq!(
x(Partial::new(f)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(f),
+ &Partial::new(f),
ErrorKind::Slice
)))
);
@@ -364,7 +365,7 @@ fn partial_take_while_m_n() {
#[test]
fn partial_take_till0() {
fn f(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_till0(AsChar::is_alpha).parse_next(i)
+ take_till0(AsChar::is_alpha).parse_peek(i)
}
let a = &b""[..];
let b = &b"abcd"[..];
@@ -386,7 +387,7 @@ fn partial_take_till0() {
#[test]
fn partial_take_till1() {
fn f(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_till1(AsChar::is_alpha).parse_next(i)
+ take_till1(AsChar::is_alpha).parse_peek(i)
}
let a = &b""[..];
let b = &b"abcd"[..];
@@ -397,7 +398,7 @@ fn partial_take_till1() {
assert_eq!(
f(Partial::new(b)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(b),
+ &Partial::new(b),
ErrorKind::Slice
)))
);
@@ -411,7 +412,7 @@ fn partial_take_till1() {
#[test]
fn partial_take_while_utf8() {
fn f(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_while(0.., |c| c != '點').parse_next(i)
+ take_while(0.., |c| c != '點').parse_peek(i)
}
assert_eq!(
@@ -429,7 +430,7 @@ fn partial_take_while_utf8() {
);
fn g(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_while(0.., |c| c == '點').parse_next(i)
+ take_while(0.., |c| c == '點').parse_peek(i)
}
assert_eq!(
@@ -446,7 +447,7 @@ fn partial_take_while_utf8() {
#[test]
fn partial_take_till0_utf8() {
fn f(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_till0(|c| c == '點').parse_next(i)
+ take_till0(|c| c == '點').parse_peek(i)
}
assert_eq!(
@@ -464,7 +465,7 @@ fn partial_take_till0_utf8() {
);
fn g(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_till0(|c| c != '點').parse_next(i)
+ take_till0(|c| c != '點').parse_peek(i)
}
assert_eq!(
@@ -481,7 +482,7 @@ fn partial_take_till0_utf8() {
#[test]
fn partial_take_utf8() {
fn f(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take(3_usize).parse_next(i)
+ take(3_usize).parse_peek(i)
}
assert_eq!(
@@ -501,7 +502,7 @@ fn partial_take_utf8() {
assert_eq!(f(Partial::new("a點b")), Ok((Partial::new(""), "a點b")));
fn g(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_while(0.., |c| c == '點').parse_next(i)
+ take_while(0.., |c| c == '點').parse_peek(i)
}
assert_eq!(
@@ -518,7 +519,7 @@ fn partial_take_utf8() {
#[test]
fn partial_take_while_m_n_utf8_fixed() {
fn parser(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_while(1, |c| c == 'A' || c == '😃').parse_next(i)
+ take_while(1, |c| c == 'A' || c == '😃').parse_peek(i)
}
assert_eq!(parser(Partial::new("A!")), Ok((Partial::new("!"), "A")));
assert_eq!(parser(Partial::new("😃!")), Ok((Partial::new("!"), "😃")));
@@ -527,7 +528,7 @@ fn partial_take_while_m_n_utf8_fixed() {
#[test]
fn partial_take_while_m_n_utf8_range() {
fn parser(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_while(1..=2, |c| c == 'A' || c == '😃').parse_next(i)
+ take_while(1..=2, |c| c == 'A' || c == '😃').parse_peek(i)
}
assert_eq!(parser(Partial::new("A!")), Ok((Partial::new("!"), "A")));
assert_eq!(parser(Partial::new("😃!")), Ok((Partial::new("!"), "😃")));
@@ -536,7 +537,7 @@ fn partial_take_while_m_n_utf8_range() {
#[test]
fn partial_take_while_m_n_utf8_full_match_fixed() {
fn parser(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_while(1, |c: char| c.is_alphabetic()).parse_next(i)
+ take_while(1, |c: char| c.is_alphabetic()).parse_peek(i)
}
assert_eq!(parser(Partial::new("øn")), Ok((Partial::new("n"), "ø")));
}
@@ -544,7 +545,7 @@ fn partial_take_while_m_n_utf8_full_match_fixed() {
#[test]
fn partial_take_while_m_n_utf8_full_match_range() {
fn parser(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- take_while(1..=2, |c: char| c.is_alphabetic()).parse_next(i)
+ take_while(1..=2, |c: char| c.is_alphabetic()).parse_peek(i)
}
assert_eq!(parser(Partial::new("øn")), Ok((Partial::new(""), "øn")));
}
@@ -553,10 +554,10 @@ fn partial_take_while_m_n_utf8_full_match_range() {
#[cfg(feature = "std")]
fn partial_recognize_take_while0() {
fn x(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- take_while(0.., AsChar::is_alphanum).parse_next(i)
+ take_while(0.., AsChar::is_alphanum).parse_peek(i)
}
fn y(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- x.recognize().parse_next(i)
+ unpeek(x).recognize().parse_peek(i)
}
assert_eq!(
x(Partial::new(&b"ab."[..])),
@@ -573,7 +574,7 @@ fn partial_length_bytes() {
use crate::binary::le_u8;
fn x(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- length_data(le_u8).parse_next(i)
+ length_data(le_u8).parse_peek(i)
}
assert_eq!(
x(Partial::new(b"\x02..>>")),
@@ -593,8 +594,8 @@ fn partial_length_bytes() {
);
fn y(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- let (i, _) = "magic".parse_next(i)?;
- length_data(le_u8).parse_next(i)
+ let (i, _) = "magic".parse_peek(i)?;
+ length_data(le_u8).parse_peek(i)
}
assert_eq!(
y(Partial::new(b"magic\x02..>>")),
@@ -618,7 +619,7 @@ fn partial_length_bytes() {
#[test]
fn partial_case_insensitive() {
fn test(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- tag_no_case("ABcd").parse_next(i)
+ tag_no_case("ABcd").parse_peek(i)
}
assert_eq!(
test(Partial::new(&b"aBCdefgh"[..])),
@@ -639,20 +640,20 @@ fn partial_case_insensitive() {
assert_eq!(
test(Partial::new(&b"Hello"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"Hello"[..]),
+ &Partial::new(&b"Hello"[..]),
ErrorKind::Tag
)))
);
assert_eq!(
test(Partial::new(&b"Hel"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"Hel"[..]),
+ &Partial::new(&b"Hel"[..]),
ErrorKind::Tag
)))
);
fn test2(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
- tag_no_case("ABcd").parse_next(i)
+ tag_no_case("ABcd").parse_peek(i)
}
assert_eq!(
test2(Partial::new("aBCdefgh")),
@@ -673,14 +674,14 @@ fn partial_case_insensitive() {
assert_eq!(
test2(Partial::new("Hello")),
Err(ErrMode::Backtrack(error_position!(
- Partial::new("Hello"),
+ &Partial::new("Hello"),
ErrorKind::Tag
)))
);
assert_eq!(
test2(Partial::new("Hel")),
Err(ErrMode::Backtrack(error_position!(
- Partial::new("Hel"),
+ &Partial::new("Hel"),
ErrorKind::Tag
)))
);
@@ -689,10 +690,10 @@ fn partial_case_insensitive() {
#[test]
fn partial_tag_fixed_size_array() {
fn test(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- tag([0x42]).parse_next(i)
+ tag([0x42]).parse_peek(i)
}
fn test2(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
- tag(&[0x42]).parse_next(i)
+ tag(&[0x42]).parse_peek(i)
}
let input = Partial::new(&[0x42, 0x00][..]);
assert_eq!(test(input), Ok((Partial::new(&b"\x00"[..]), &b"\x42"[..])));