summaryrefslogtreecommitdiffstats
path: root/vendor/winnow/src/ascii
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/winnow/src/ascii')
-rw-r--r--vendor/winnow/src/ascii/mod.rs1074
-rw-r--r--vendor/winnow/src/ascii/tests.rs660
2 files changed, 842 insertions, 892 deletions
diff --git a/vendor/winnow/src/ascii/mod.rs b/vendor/winnow/src/ascii/mod.rs
index 4ada7c00b..8b3119fbf 100644
--- a/vendor/winnow/src/ascii/mod.rs
+++ b/vendor/winnow/src/ascii/mod.rs
@@ -8,21 +8,20 @@ mod tests;
use crate::lib::std::ops::{Add, Shl};
use crate::combinator::alt;
-use crate::token::one_of;
-
use crate::combinator::cut_err;
use crate::combinator::opt;
-use crate::error::ParseError;
+use crate::error::ParserError;
use crate::error::{ErrMode, ErrorKind, Needed};
-use crate::stream::ContainsToken;
-use crate::stream::{AsBStr, AsChar, Offset, ParseSlice, Stream, StreamIsPartial};
+use crate::stream::{AsBStr, AsChar, ParseSlice, Stream, StreamIsPartial};
use crate::stream::{Compare, CompareResult};
+use crate::token::one_of;
+use crate::token::take_till0;
use crate::token::take_while;
use crate::trace::trace;
-use crate::IResult;
+use crate::PResult;
use crate::Parser;
-/// Recognizes the string "\r\n".
+/// Recognizes the string `"\r\n"`.
///
/// *Complete version*: Will return an error if there's not enough input data.
///
@@ -31,36 +30,38 @@ use crate::Parser;
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}};
/// # use winnow::ascii::crlf;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// crlf(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// crlf.parse_next(input)
/// }
///
-/// assert_eq!(parser("\r\nc"), Ok(("c", "\r\n")));
-/// assert_eq!(parser("ab\r\nc"), Err(ErrMode::Backtrack(Error::new("ab\r\nc", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek("\r\nc"), Ok(("c", "\r\n")));
+/// assert_eq!(parser.parse_peek("ab\r\nc"), Err(ErrMode::Backtrack(InputError::new("ab\r\nc", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::crlf;
-/// assert_eq!(crlf::<_, Error<_>>(Partial::new("\r\nc")), Ok((Partial::new("c"), "\r\n")));
-/// assert_eq!(crlf::<_, Error<_>>(Partial::new("ab\r\nc")), Err(ErrMode::Backtrack(Error::new(Partial::new("ab\r\nc"), ErrorKind::Tag))));
-/// assert_eq!(crlf::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(2))));
+/// assert_eq!(crlf::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Ok((Partial::new("c"), "\r\n")));
+/// assert_eq!(crlf::<_, InputError<_>>.parse_peek(Partial::new("ab\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("ab\r\nc"), ErrorKind::Tag))));
+/// assert_eq!(crlf::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(2))));
/// ```
#[inline(always)]
-pub fn crlf<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn crlf<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
I: Compare<&'static str>,
{
- trace("crlf", move |input: I| "\r\n".parse_next(input)).parse_next(input)
+ trace("crlf", "\r\n").parse_next(input)
}
-/// Recognizes a string of any char except '\r\n' or '\n'.
+/// Recognizes a string of any char except `"\r\n"` or `"\n"`.
///
/// *Complete version*: Will return an error if there's not enough input data.
///
@@ -69,39 +70,41 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::not_line_ending;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// not_line_ending(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// not_line_ending.parse_next(input)
/// }
///
-/// assert_eq!(parser("ab\r\nc"), Ok(("\r\nc", "ab")));
-/// assert_eq!(parser("ab\nc"), Ok(("\nc", "ab")));
-/// assert_eq!(parser("abc"), Ok(("", "abc")));
-/// assert_eq!(parser(""), Ok(("", "")));
-/// assert_eq!(parser("a\rb\nc"), Err(ErrMode::Backtrack(Error { input: "a\rb\nc", kind: ErrorKind::Tag })));
-/// assert_eq!(parser("a\rbc"), Err(ErrMode::Backtrack(Error { input: "a\rbc", kind: ErrorKind::Tag })));
+/// assert_eq!(parser.parse_peek("ab\r\nc"), Ok(("\r\nc", "ab")));
+/// assert_eq!(parser.parse_peek("ab\nc"), Ok(("\nc", "ab")));
+/// assert_eq!(parser.parse_peek("abc"), Ok(("", "abc")));
+/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
+/// assert_eq!(parser.parse_peek("a\rb\nc"), Err(ErrMode::Backtrack(InputError::new("\rb\nc", ErrorKind::Tag ))));
+/// assert_eq!(parser.parse_peek("a\rbc"), Err(ErrMode::Backtrack(InputError::new("\rbc", ErrorKind::Tag ))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::not_line_ending;
-/// assert_eq!(not_line_ending::<_, Error<_>>(Partial::new("ab\r\nc")), Ok((Partial::new("\r\nc"), "ab")));
-/// assert_eq!(not_line_ending::<_, Error<_>>(Partial::new("abc")), Err(ErrMode::Incomplete(Needed::Unknown)));
-/// assert_eq!(not_line_ending::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::Unknown)));
-/// assert_eq!(not_line_ending::<_, Error<_>>(Partial::new("a\rb\nc")), Err(ErrMode::Backtrack(Error::new(Partial::new("a\rb\nc"), ErrorKind::Tag ))));
-/// assert_eq!(not_line_ending::<_, Error<_>>(Partial::new("a\rbc")), Err(ErrMode::Backtrack(Error::new(Partial::new("a\rbc"), ErrorKind::Tag ))));
+/// assert_eq!(not_line_ending::<_, InputError<_>>.parse_peek(Partial::new("ab\r\nc")), Ok((Partial::new("\r\nc"), "ab")));
+/// assert_eq!(not_line_ending::<_, InputError<_>>.parse_peek(Partial::new("abc")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(not_line_ending::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(not_line_ending::<_, InputError<_>>.parse_peek(Partial::new("a\rb\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\rb\nc"), ErrorKind::Tag ))));
+/// assert_eq!(not_line_ending::<_, InputError<_>>.parse_peek(Partial::new("a\rbc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\rbc"), ErrorKind::Tag ))));
/// ```
#[inline(always)]
-pub fn not_line_ending<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn not_line_ending<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
- I: Stream + AsBStr,
+ I: Stream,
I: Compare<&'static str>,
- <I as Stream>::Token: AsChar,
+ <I as Stream>::Token: AsChar + Clone,
{
- trace("not_line_ending", move |input: I| {
+ trace("not_line_ending", move |input: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() {
not_line_ending_::<_, _, true>(input)
} else {
@@ -111,45 +114,34 @@ where
.parse_next(input)
}
-fn not_line_ending_<I, E: ParseError<I>, const PARTIAL: bool>(
- input: I,
-) -> IResult<I, <I as Stream>::Slice, E>
+fn not_line_ending_<I, E: ParserError<I>, const PARTIAL: bool>(
+ input: &mut I,
+) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
- I: Stream + AsBStr,
+ I: Stream,
I: Compare<&'static str>,
- <I as Stream>::Token: AsChar,
+ <I as Stream>::Token: AsChar + Clone,
{
- match input.offset_for(|item| {
- let c = item.as_char();
- c == '\r' || c == '\n'
- }) {
- None if PARTIAL && input.is_partial() => Err(ErrMode::Incomplete(Needed::Unknown)),
- None => Ok(input.next_slice(input.eof_offset())),
- Some(offset) => {
- let (new_input, res) = input.next_slice(offset);
- let bytes = new_input.as_bstr();
- let nth = bytes[0];
- if nth == b'\r' {
- let comp = new_input.compare("\r\n");
- match comp {
- //FIXME: calculate the right index
- CompareResult::Ok => {}
- CompareResult::Incomplete if PARTIAL && input.is_partial() => {
- return Err(ErrMode::Incomplete(Needed::Unknown));
- }
- CompareResult::Incomplete | CompareResult::Error => {
- let e: ErrorKind = ErrorKind::Tag;
- return Err(ErrMode::from_error_kind(input, e));
- }
- }
+ let res = take_till0(('\r', '\n')).parse_next(input)?;
+ if input.compare("\r") == CompareResult::Ok {
+ let comp = input.compare("\r\n");
+ match comp {
+ //FIXME: calculate the right index
+ CompareResult::Ok => {}
+ CompareResult::Incomplete if PARTIAL && input.is_partial() => {
+ return Err(ErrMode::Incomplete(Needed::Unknown));
+ }
+ CompareResult::Incomplete | CompareResult::Error => {
+ let e: ErrorKind = ErrorKind::Tag;
+ return Err(ErrMode::from_error_kind(input, e));
}
- Ok((new_input, res))
}
}
+ Ok(res)
}
-/// Recognizes an end of line (both '\n' and '\r\n').
+/// Recognizes an end of line (both `"\n"` and `"\r\n"`).
///
/// *Complete version*: Will return an error if there's not enough input data.
///
@@ -158,39 +150,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::line_ending;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// line_ending(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// line_ending.parse_next(input)
/// }
///
-/// assert_eq!(parser("\r\nc"), Ok(("c", "\r\n")));
-/// assert_eq!(parser("ab\r\nc"), Err(ErrMode::Backtrack(Error::new("ab\r\nc", ErrorKind::Tag))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek("\r\nc"), Ok(("c", "\r\n")));
+/// assert_eq!(parser.parse_peek("ab\r\nc"), Err(ErrMode::Backtrack(InputError::new("ab\r\nc", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::line_ending;
-/// assert_eq!(line_ending::<_, Error<_>>(Partial::new("\r\nc")), Ok((Partial::new("c"), "\r\n")));
-/// assert_eq!(line_ending::<_, Error<_>>(Partial::new("ab\r\nc")), Err(ErrMode::Backtrack(Error::new(Partial::new("ab\r\nc"), ErrorKind::Tag))));
-/// assert_eq!(line_ending::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(line_ending::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Ok((Partial::new("c"), "\r\n")));
+/// assert_eq!(line_ending::<_, InputError<_>>.parse_peek(Partial::new("ab\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("ab\r\nc"), ErrorKind::Tag))));
+/// assert_eq!(line_ending::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn line_ending<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn line_ending<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
I: Compare<&'static str>,
{
- trace("line_ending", move |input: I| {
- alt(("\n", "\r\n")).parse_next(input)
- })
- .parse_next(input)
+ trace("line_ending", alt(("\n", "\r\n"))).parse_next(input)
}
-/// Matches a newline character '\n'.
+/// Matches a newline character `'\n'`.
///
/// *Complete version*: Will return an error if there's not enough input data.
///
@@ -199,40 +190,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::newline;
-/// fn parser(input: &str) -> IResult<&str, char> {
-/// newline(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<char, InputError<&'s str>> {
+/// newline.parse_next(input)
/// }
///
-/// assert_eq!(parser("\nc"), Ok(("c", '\n')));
-/// assert_eq!(parser("\r\nc"), Err(ErrMode::Backtrack(Error::new("\r\nc", ErrorKind::Verify))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Token))));
+/// assert_eq!(parser.parse_peek("\nc"), Ok(("c", '\n')));
+/// assert_eq!(parser.parse_peek("\r\nc"), Err(ErrMode::Backtrack(InputError::new("\r\nc", ErrorKind::Verify))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Token))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::newline;
-/// assert_eq!(newline::<_, Error<_>>(Partial::new("\nc")), Ok((Partial::new("c"), '\n')));
-/// assert_eq!(newline::<_, Error<_>>(Partial::new("\r\nc")), Err(ErrMode::Backtrack(Error::new(Partial::new("\r\nc"), ErrorKind::Verify))));
-/// assert_eq!(newline::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(newline::<_, InputError<_>>.parse_peek(Partial::new("\nc")), Ok((Partial::new("c"), '\n')));
+/// assert_eq!(newline::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\r\nc"), ErrorKind::Verify))));
+/// assert_eq!(newline::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn newline<I, Error: ParseError<I>>(input: I) -> IResult<I, char, Error>
+pub fn newline<I, Error: ParserError<I>>(input: &mut I) -> PResult<char, Error>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
{
- trace("newline", move |input: I| {
- '\n'.map(|c: <I as Stream>::Token| c.as_char())
- .parse_next(input)
- })
- .parse_next(input)
+ trace("newline", '\n'.map(AsChar::as_char)).parse_next(input)
}
-/// Matches a tab character '\t'.
+/// Matches a tab character `'\t'`.
///
/// *Complete version*: Will return an error if there's not enough input data.
///
@@ -241,40 +230,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::tab;
-/// fn parser(input: &str) -> IResult<&str, char> {
-/// tab(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<char, InputError<&'s str>> {
+/// tab.parse_next(input)
/// }
///
-/// assert_eq!(parser("\tc"), Ok(("c", '\t')));
-/// assert_eq!(parser("\r\nc"), Err(ErrMode::Backtrack(Error::new("\r\nc", ErrorKind::Verify))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Token))));
+/// assert_eq!(parser.parse_peek("\tc"), Ok(("c", '\t')));
+/// assert_eq!(parser.parse_peek("\r\nc"), Err(ErrMode::Backtrack(InputError::new("\r\nc", ErrorKind::Verify))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Token))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::tab;
-/// assert_eq!(tab::<_, Error<_>>(Partial::new("\tc")), Ok((Partial::new("c"), '\t')));
-/// assert_eq!(tab::<_, Error<_>>(Partial::new("\r\nc")), Err(ErrMode::Backtrack(Error::new(Partial::new("\r\nc"), ErrorKind::Verify))));
-/// assert_eq!(tab::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(tab::<_, InputError<_>>.parse_peek(Partial::new("\tc")), Ok((Partial::new("c"), '\t')));
+/// assert_eq!(tab::<_, InputError<_>>.parse_peek(Partial::new("\r\nc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("\r\nc"), ErrorKind::Verify))));
+/// assert_eq!(tab::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn tab<I, Error: ParseError<I>>(input: I) -> IResult<I, char, Error>
+pub fn tab<I, Error: ParserError<I>>(input: &mut I) -> PResult<char, Error>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
{
- trace("tab", move |input: I| {
- '\t'.map(|c: <I as Stream>::Token| c.as_char())
- .parse_next(input)
- })
- .parse_next(input)
+ trace("tab", '\t'.map(AsChar::as_char)).parse_next(input)
}
-/// Recognizes zero or more lowercase and uppercase ASCII alphabetic characters: a-z, A-Z
+/// Recognizes zero or more lowercase and uppercase ASCII alphabetic characters: `'a'..='z'`, `'A'..='Z'`
///
/// *Complete version*: Will return the whole input if no terminating token is found (a non
/// alphabetic character).
@@ -285,39 +272,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::ascii::alpha0;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// alpha0(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// alpha0.parse_next(input)
/// }
///
-/// assert_eq!(parser("ab1c"), Ok(("1c", "ab")));
-/// assert_eq!(parser("1c"), Ok(("1c", "")));
-/// assert_eq!(parser(""), Ok(("", "")));
+/// assert_eq!(parser.parse_peek("ab1c"), Ok(("1c", "ab")));
+/// assert_eq!(parser.parse_peek("1c"), Ok(("1c", "")));
+/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::alpha0;
-/// assert_eq!(alpha0::<_, Error<_>>(Partial::new("ab1c")), Ok((Partial::new("1c"), "ab")));
-/// assert_eq!(alpha0::<_, Error<_>>(Partial::new("1c")), Ok((Partial::new("1c"), "")));
-/// assert_eq!(alpha0::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(alpha0::<_, InputError<_>>.parse_peek(Partial::new("ab1c")), Ok((Partial::new("1c"), "ab")));
+/// assert_eq!(alpha0::<_, InputError<_>>.parse_peek(Partial::new("1c")), Ok((Partial::new("1c"), "")));
+/// assert_eq!(alpha0::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn alpha0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn alpha0<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("alpha0", move |input: I| {
- take_while(0.., |c: <I as Stream>::Token| c.is_alpha()).parse_next(input)
- })
- .parse_next(input)
+ trace("alpha0", take_while(0.., AsChar::is_alpha)).parse_next(input)
}
-/// Recognizes one or more lowercase and uppercase ASCII alphabetic characters: a-z, A-Z
+/// Recognizes one or more lowercase and uppercase ASCII alphabetic characters: `'a'..='z'`, `'A'..='Z'`
///
/// *Complete version*: Will return an error if there's not enough input data,
/// or the whole input if no terminating token is found (a non alphabetic character).
@@ -328,39 +314,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::alpha1;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// alpha1(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// alpha1.parse_next(input)
/// }
///
-/// assert_eq!(parser("aB1c"), Ok(("1c", "aB")));
-/// assert_eq!(parser("1c"), Err(ErrMode::Backtrack(Error::new("1c", ErrorKind::Slice))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek("aB1c"), Ok(("1c", "aB")));
+/// assert_eq!(parser.parse_peek("1c"), Err(ErrMode::Backtrack(InputError::new("1c", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::alpha1;
-/// assert_eq!(alpha1::<_, Error<_>>(Partial::new("aB1c")), Ok((Partial::new("1c"), "aB")));
-/// assert_eq!(alpha1::<_, Error<_>>(Partial::new("1c")), Err(ErrMode::Backtrack(Error::new(Partial::new("1c"), ErrorKind::Slice))));
-/// assert_eq!(alpha1::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(alpha1::<_, InputError<_>>.parse_peek(Partial::new("aB1c")), Ok((Partial::new("1c"), "aB")));
+/// assert_eq!(alpha1::<_, InputError<_>>.parse_peek(Partial::new("1c")), Err(ErrMode::Backtrack(InputError::new(Partial::new("1c"), ErrorKind::Slice))));
+/// assert_eq!(alpha1::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn alpha1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn alpha1<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("alpha1", move |input: I| {
- take_while(1.., |c: <I as Stream>::Token| c.is_alpha()).parse_next(input)
- })
- .parse_next(input)
+ trace("alpha1", take_while(1.., AsChar::is_alpha)).parse_next(input)
}
-/// Recognizes zero or more ASCII numerical characters: 0-9
+/// Recognizes zero or more ASCII numerical characters: `'0'..='9'`
///
/// *Complete version*: Will return an error if there's not enough input data,
/// or the whole input if no terminating token is found (a non digit character).
@@ -371,40 +356,39 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::ascii::digit0;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// digit0(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// digit0.parse_next(input)
/// }
///
-/// assert_eq!(parser("21c"), Ok(("c", "21")));
-/// assert_eq!(parser("21"), Ok(("", "21")));
-/// assert_eq!(parser("a21c"), Ok(("a21c", "")));
-/// assert_eq!(parser(""), Ok(("", "")));
+/// assert_eq!(parser.parse_peek("21c"), Ok(("c", "21")));
+/// assert_eq!(parser.parse_peek("21"), Ok(("", "21")));
+/// assert_eq!(parser.parse_peek("a21c"), Ok(("a21c", "")));
+/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::digit0;
-/// assert_eq!(digit0::<_, Error<_>>(Partial::new("21c")), Ok((Partial::new("c"), "21")));
-/// assert_eq!(digit0::<_, Error<_>>(Partial::new("a21c")), Ok((Partial::new("a21c"), "")));
-/// assert_eq!(digit0::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(digit0::<_, InputError<_>>.parse_peek(Partial::new("21c")), Ok((Partial::new("c"), "21")));
+/// assert_eq!(digit0::<_, InputError<_>>.parse_peek(Partial::new("a21c")), Ok((Partial::new("a21c"), "")));
+/// assert_eq!(digit0::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn digit0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn digit0<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("digit0", move |input: I| {
- take_while(0.., |c: <I as Stream>::Token| c.is_dec_digit()).parse_next(input)
- })
- .parse_next(input)
+ trace("digit0", take_while(0.., AsChar::is_dec_digit)).parse_next(input)
}
-/// Recognizes one or more ASCII numerical characters: 0-9
+/// Recognizes one or more ASCII numerical characters: `'0'..='9'`
///
/// *Complete version*: Will return an error if there's not enough input data,
/// or the whole input if no terminating token is found (a non digit character).
@@ -415,24 +399,26 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::digit1;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// digit1(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// digit1.parse_next(input)
/// }
///
-/// assert_eq!(parser("21c"), Ok(("c", "21")));
-/// assert_eq!(parser("c1"), Err(ErrMode::Backtrack(Error::new("c1", ErrorKind::Slice))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek("21c"), Ok(("c", "21")));
+/// assert_eq!(parser.parse_peek("c1"), Err(ErrMode::Backtrack(InputError::new("c1", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::digit1;
-/// assert_eq!(digit1::<_, Error<_>>(Partial::new("21c")), Ok((Partial::new("c"), "21")));
-/// assert_eq!(digit1::<_, Error<_>>(Partial::new("c1")), Err(ErrMode::Backtrack(Error::new(Partial::new("c1"), ErrorKind::Slice))));
-/// assert_eq!(digit1::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(digit1::<_, InputError<_>>.parse_peek(Partial::new("21c")), Ok((Partial::new("c"), "21")));
+/// assert_eq!(digit1::<_, InputError<_>>.parse_peek(Partial::new("c1")), Err(ErrMode::Backtrack(InputError::new(Partial::new("c1"), ErrorKind::Slice))));
+/// assert_eq!(digit1::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
///
/// ## Parsing an integer
@@ -440,30 +426,29 @@ where
/// You can use `digit1` in combination with [`Parser::try_map`][crate::Parser::try_map] to parse an integer:
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed, Parser};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed, Parser};
/// # use winnow::ascii::digit1;
-/// fn parser(input: &str) -> IResult<&str, u32> {
+/// fn parser<'s>(input: &mut &'s str) -> PResult<u32, InputError<&'s str>> {
/// digit1.try_map(str::parse).parse_next(input)
/// }
///
-/// assert_eq!(parser("416"), Ok(("", 416)));
-/// assert_eq!(parser("12b"), Ok(("b", 12)));
-/// assert!(parser("b").is_err());
+/// assert_eq!(parser.parse_peek("416"), Ok(("", 416)));
+/// assert_eq!(parser.parse_peek("12b"), Ok(("b", 12)));
+/// assert!(parser.parse_peek("b").is_err());
/// ```
#[inline(always)]
-pub fn digit1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn digit1<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("digit1", move |input: I| {
- take_while(1.., |c: <I as Stream>::Token| c.is_dec_digit()).parse_next(input)
- })
- .parse_next(input)
+ trace("digit1", take_while(1.., AsChar::is_dec_digit)).parse_next(input)
}
-/// Recognizes zero or more ASCII hexadecimal numerical characters: 0-9, A-F, a-f
+/// Recognizes zero or more ASCII hexadecimal numerical characters: `'0'..='9'`, `'A'..='F'`,
+/// `'a'..='f'`
///
/// *Complete version*: Will return the whole input if no terminating token is found (a non hexadecimal digit character).
///
@@ -473,39 +458,39 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::ascii::hex_digit0;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// hex_digit0(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// hex_digit0.parse_next(input)
/// }
///
-/// assert_eq!(parser("21cZ"), Ok(("Z", "21c")));
-/// assert_eq!(parser("Z21c"), Ok(("Z21c", "")));
-/// assert_eq!(parser(""), Ok(("", "")));
+/// assert_eq!(parser.parse_peek("21cZ"), Ok(("Z", "21c")));
+/// assert_eq!(parser.parse_peek("Z21c"), Ok(("Z21c", "")));
+/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::hex_digit0;
-/// assert_eq!(hex_digit0::<_, Error<_>>(Partial::new("21cZ")), Ok((Partial::new("Z"), "21c")));
-/// assert_eq!(hex_digit0::<_, Error<_>>(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
-/// assert_eq!(hex_digit0::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(hex_digit0::<_, InputError<_>>.parse_peek(Partial::new("21cZ")), Ok((Partial::new("Z"), "21c")));
+/// assert_eq!(hex_digit0::<_, InputError<_>>.parse_peek(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
+/// assert_eq!(hex_digit0::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn hex_digit0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn hex_digit0<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("hex_digit0", move |input: I| {
- take_while(0.., |c: <I as Stream>::Token| c.is_hex_digit()).parse_next(input)
- })
- .parse_next(input)
+ trace("hex_digit0", take_while(0.., AsChar::is_hex_digit)).parse_next(input)
}
-/// Recognizes one or more ASCII hexadecimal numerical characters: 0-9, A-F, a-f
+/// Recognizes one or more ASCII hexadecimal numerical characters: `'0'..='9'`, `'A'..='F'`,
+/// `'a'..='f'`
///
/// *Complete version*: Will return an error if there's not enough input data,
/// or the whole input if no terminating token is found (a non hexadecimal digit character).
@@ -516,39 +501,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::hex_digit1;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// hex_digit1(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// hex_digit1.parse_next(input)
/// }
///
-/// assert_eq!(parser("21cZ"), Ok(("Z", "21c")));
-/// assert_eq!(parser("H2"), Err(ErrMode::Backtrack(Error::new("H2", ErrorKind::Slice))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek("21cZ"), Ok(("Z", "21c")));
+/// assert_eq!(parser.parse_peek("H2"), Err(ErrMode::Backtrack(InputError::new("H2", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::hex_digit1;
-/// assert_eq!(hex_digit1::<_, Error<_>>(Partial::new("21cZ")), Ok((Partial::new("Z"), "21c")));
-/// assert_eq!(hex_digit1::<_, Error<_>>(Partial::new("H2")), Err(ErrMode::Backtrack(Error::new(Partial::new("H2"), ErrorKind::Slice))));
-/// assert_eq!(hex_digit1::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(Partial::new("21cZ")), Ok((Partial::new("Z"), "21c")));
+/// assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(Partial::new("H2")), Err(ErrMode::Backtrack(InputError::new(Partial::new("H2"), ErrorKind::Slice))));
+/// assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn hex_digit1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn hex_digit1<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("hex_digit1", move |input: I| {
- take_while(1.., |c: <I as Stream>::Token| c.is_hex_digit()).parse_next(input)
- })
- .parse_next(input)
+ trace("hex_digit1", take_while(1.., AsChar::is_hex_digit)).parse_next(input)
}
-/// Recognizes zero or more octal characters: 0-7
+/// Recognizes zero or more octal characters: `'0'..='7'`
///
/// *Complete version*: Will return the whole input if no terminating token is found (a non octal
/// digit character).
@@ -559,39 +543,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::ascii::oct_digit0;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// oct_digit0(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// oct_digit0.parse_next(input)
/// }
///
-/// assert_eq!(parser("21cZ"), Ok(("cZ", "21")));
-/// assert_eq!(parser("Z21c"), Ok(("Z21c", "")));
-/// assert_eq!(parser(""), Ok(("", "")));
+/// assert_eq!(parser.parse_peek("21cZ"), Ok(("cZ", "21")));
+/// assert_eq!(parser.parse_peek("Z21c"), Ok(("Z21c", "")));
+/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::oct_digit0;
-/// assert_eq!(oct_digit0::<_, Error<_>>(Partial::new("21cZ")), Ok((Partial::new("cZ"), "21")));
-/// assert_eq!(oct_digit0::<_, Error<_>>(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
-/// assert_eq!(oct_digit0::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(oct_digit0::<_, InputError<_>>.parse_peek(Partial::new("21cZ")), Ok((Partial::new("cZ"), "21")));
+/// assert_eq!(oct_digit0::<_, InputError<_>>.parse_peek(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
+/// assert_eq!(oct_digit0::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn oct_digit0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn oct_digit0<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("oct_digit0", move |input: I| {
- take_while(0.., |c: <I as Stream>::Token| c.is_oct_digit()).parse_next(input)
- })
- .parse_next(input)
+ trace("oct_digit0", take_while(0.., AsChar::is_oct_digit)).parse_next(input)
}
-/// Recognizes one or more octal characters: 0-7
+/// Recognizes one or more octal characters: `'0'..='7'`
///
/// *Complete version*: Will return an error if there's not enough input data,
/// or the whole input if no terminating token is found (a non octal digit character).
@@ -602,39 +585,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::oct_digit1;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// oct_digit1(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// oct_digit1.parse_next(input)
/// }
///
-/// assert_eq!(parser("21cZ"), Ok(("cZ", "21")));
-/// assert_eq!(parser("H2"), Err(ErrMode::Backtrack(Error::new("H2", ErrorKind::Slice))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek("21cZ"), Ok(("cZ", "21")));
+/// assert_eq!(parser.parse_peek("H2"), Err(ErrMode::Backtrack(InputError::new("H2", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::oct_digit1;
-/// assert_eq!(oct_digit1::<_, Error<_>>(Partial::new("21cZ")), Ok((Partial::new("cZ"), "21")));
-/// assert_eq!(oct_digit1::<_, Error<_>>(Partial::new("H2")), Err(ErrMode::Backtrack(Error::new(Partial::new("H2"), ErrorKind::Slice))));
-/// assert_eq!(oct_digit1::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(oct_digit1::<_, InputError<_>>.parse_peek(Partial::new("21cZ")), Ok((Partial::new("cZ"), "21")));
+/// assert_eq!(oct_digit1::<_, InputError<_>>.parse_peek(Partial::new("H2")), Err(ErrMode::Backtrack(InputError::new(Partial::new("H2"), ErrorKind::Slice))));
+/// assert_eq!(oct_digit1::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn oct_digit1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn oct_digit1<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("oct_digit0", move |input: I| {
- take_while(1.., |c: <I as Stream>::Token| c.is_oct_digit()).parse_next(input)
- })
- .parse_next(input)
+ trace("oct_digit0", take_while(1.., AsChar::is_oct_digit)).parse_next(input)
}
-/// Recognizes zero or more ASCII numerical and alphabetic characters: 0-9, a-z, A-Z
+/// Recognizes zero or more ASCII numerical and alphabetic characters: `'a'..='z'`, `'A'..='Z'`, `'0'..='9'`
///
/// *Complete version*: Will return the whole input if no terminating token is found (a non
/// alphanumerical character).
@@ -645,39 +627,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::ascii::alphanumeric0;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// alphanumeric0(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// alphanumeric0.parse_next(input)
/// }
///
-/// assert_eq!(parser("21cZ%1"), Ok(("%1", "21cZ")));
-/// assert_eq!(parser("&Z21c"), Ok(("&Z21c", "")));
-/// assert_eq!(parser(""), Ok(("", "")));
+/// assert_eq!(parser.parse_peek("21cZ%1"), Ok(("%1", "21cZ")));
+/// assert_eq!(parser.parse_peek("&Z21c"), Ok(("&Z21c", "")));
+/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::alphanumeric0;
-/// assert_eq!(alphanumeric0::<_, Error<_>>(Partial::new("21cZ%1")), Ok((Partial::new("%1"), "21cZ")));
-/// assert_eq!(alphanumeric0::<_, Error<_>>(Partial::new("&Z21c")), Ok((Partial::new("&Z21c"), "")));
-/// assert_eq!(alphanumeric0::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(alphanumeric0::<_, InputError<_>>.parse_peek(Partial::new("21cZ%1")), Ok((Partial::new("%1"), "21cZ")));
+/// assert_eq!(alphanumeric0::<_, InputError<_>>.parse_peek(Partial::new("&Z21c")), Ok((Partial::new("&Z21c"), "")));
+/// assert_eq!(alphanumeric0::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn alphanumeric0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn alphanumeric0<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("alphanumeric0", move |input: I| {
- take_while(0.., |c: <I as Stream>::Token| c.is_alphanum()).parse_next(input)
- })
- .parse_next(input)
+ trace("alphanumeric0", take_while(0.., AsChar::is_alphanum)).parse_next(input)
}
-/// Recognizes one or more ASCII numerical and alphabetic characters: 0-9, a-z, A-Z
+/// Recognizes one or more ASCII numerical and alphabetic characters: `'a'..='z'`, `'A'..='Z'`, `'0'..='9'`
///
/// *Complete version*: Will return an error if there's not enough input data,
/// or the whole input if no terminating token is found (a non alphanumerical character).
@@ -688,36 +669,35 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::alphanumeric1;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// alphanumeric1(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// alphanumeric1.parse_next(input)
/// }
///
-/// assert_eq!(parser("21cZ%1"), Ok(("%1", "21cZ")));
-/// assert_eq!(parser("&H2"), Err(ErrMode::Backtrack(Error::new("&H2", ErrorKind::Slice))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek("21cZ%1"), Ok(("%1", "21cZ")));
+/// assert_eq!(parser.parse_peek("&H2"), Err(ErrMode::Backtrack(InputError::new("&H2", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::alphanumeric1;
-/// assert_eq!(alphanumeric1::<_, Error<_>>(Partial::new("21cZ%1")), Ok((Partial::new("%1"), "21cZ")));
-/// assert_eq!(alphanumeric1::<_, Error<_>>(Partial::new("&H2")), Err(ErrMode::Backtrack(Error::new(Partial::new("&H2"), ErrorKind::Slice))));
-/// assert_eq!(alphanumeric1::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new("21cZ%1")), Ok((Partial::new("%1"), "21cZ")));
+/// assert_eq!(alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new("&H2")), Err(ErrMode::Backtrack(InputError::new(Partial::new("&H2"), ErrorKind::Slice))));
+/// assert_eq!(alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn alphanumeric1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn alphanumeric1<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
<I as Stream>::Token: AsChar,
{
- trace("alphanumeric1", move |input: I| {
- take_while(1.., |c: <I as Stream>::Token| c.is_alphanum()).parse_next(input)
- })
- .parse_next(input)
+ trace("alphanumeric1", take_while(1.., AsChar::is_alphanum)).parse_next(input)
}
/// Recognizes zero or more spaces and tabs.
@@ -731,34 +711,28 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::space0;
-/// assert_eq!(space0::<_, Error<_>>(Partial::new(" \t21c")), Ok((Partial::new("21c"), " \t")));
-/// assert_eq!(space0::<_, Error<_>>(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
-/// assert_eq!(space0::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(space0::<_, InputError<_>>.parse_peek(Partial::new(" \t21c")), Ok((Partial::new("21c"), " \t")));
+/// assert_eq!(space0::<_, InputError<_>>.parse_peek(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
+/// assert_eq!(space0::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn space0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn space0<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
{
- trace("space0", move |input: I| {
- take_while(0.., |c: <I as Stream>::Token| {
- let ch = c.as_char();
- matches!(ch, ' ' | '\t')
- })
- .parse_next(input)
- })
- .parse_next(input)
+ trace("space0", take_while(0.., AsChar::is_space)).parse_next(input)
}
-/// Recognizes one or more spaces and tabs.
+/// Recognizes zero or more spaces and tabs.
///
-/// *Complete version*: Will return an error if there's not enough input data,
-/// or the whole input if no terminating token is found (a non space character).
+/// *Complete version*: Will return the whole input if no terminating token is found (a non space
+/// character).
///
/// *Partial version*: Will return `Err(winnow::error::ErrMode::Incomplete(_))` if there's not enough input data,
/// or if no terminating token is found (a non space character).
@@ -766,40 +740,35 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::ascii::space1;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// space1(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// space1.parse_next(input)
/// }
///
-/// assert_eq!(parser(" \t21c"), Ok(("21c", " \t")));
-/// assert_eq!(parser("H2"), Err(ErrMode::Backtrack(Error::new("H2", ErrorKind::Slice))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(" \t21c"), Ok(("21c", " \t")));
+/// assert_eq!(parser.parse_peek("H2"), Err(ErrMode::Backtrack(InputError::new("H2", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::space1;
-/// assert_eq!(space1::<_, Error<_>>(Partial::new(" \t21c")), Ok((Partial::new("21c"), " \t")));
-/// assert_eq!(space1::<_, Error<_>>(Partial::new("H2")), Err(ErrMode::Backtrack(Error::new(Partial::new("H2"), ErrorKind::Slice))));
-/// assert_eq!(space1::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(space1::<_, InputError<_>>.parse_peek(Partial::new(" \t21c")), Ok((Partial::new("21c"), " \t")));
+/// assert_eq!(space1::<_, InputError<_>>.parse_peek(Partial::new("H2")), Err(ErrMode::Backtrack(InputError::new(Partial::new("H2"), ErrorKind::Slice))));
+/// assert_eq!(space1::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn space1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn space1<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
{
- trace("space1", move |input: I| {
- take_while(1.., |c: <I as Stream>::Token| {
- let ch = c.as_char();
- matches!(ch, ' ' | '\t')
- })
- .parse_next(input)
- })
- .parse_next(input)
+ trace("space1", take_while(1.., AsChar::is_space)).parse_next(input)
}
/// Recognizes zero or more spaces, tabs, carriage returns and line feeds.
@@ -813,40 +782,35 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::ascii::multispace0;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// multispace0(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// multispace0.parse_next(input)
/// }
///
-/// assert_eq!(parser(" \t\n\r21c"), Ok(("21c", " \t\n\r")));
-/// assert_eq!(parser("Z21c"), Ok(("Z21c", "")));
-/// assert_eq!(parser(""), Ok(("", "")));
+/// assert_eq!(parser.parse_peek(" \t\n\r21c"), Ok(("21c", " \t\n\r")));
+/// assert_eq!(parser.parse_peek("Z21c"), Ok(("Z21c", "")));
+/// assert_eq!(parser.parse_peek(""), Ok(("", "")));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::multispace0;
-/// assert_eq!(multispace0::<_, Error<_>>(Partial::new(" \t\n\r21c")), Ok((Partial::new("21c"), " \t\n\r")));
-/// assert_eq!(multispace0::<_, Error<_>>(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
-/// assert_eq!(multispace0::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(multispace0::<_, InputError<_>>.parse_peek(Partial::new(" \t\n\r21c")), Ok((Partial::new("21c"), " \t\n\r")));
+/// assert_eq!(multispace0::<_, InputError<_>>.parse_peek(Partial::new("Z21c")), Ok((Partial::new("Z21c"), "")));
+/// assert_eq!(multispace0::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn multispace0<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn multispace0<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
{
- trace("multispace0", move |input: I| {
- take_while(0.., |c: <I as Stream>::Token| {
- let ch = c.as_char();
- matches!(ch, ' ' | '\t' | '\r' | '\n')
- })
- .parse_next(input)
- })
- .parse_next(input)
+ trace("multispace0", take_while(0.., (' ', '\t', '\r', '\n'))).parse_next(input)
}
/// Recognizes one or more spaces, tabs, carriage returns and line feeds.
@@ -860,43 +824,38 @@ where
/// # Example
///
/// ```
-/// # use winnow::{error::ErrMode, error::{Error, ErrorKind}, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed};
/// # use winnow::ascii::multispace1;
-/// fn parser(input: &str) -> IResult<&str, &str> {
-/// multispace1(input)
+/// fn parser<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
+/// multispace1.parse_next(input)
/// }
///
-/// assert_eq!(parser(" \t\n\r21c"), Ok(("21c", " \t\n\r")));
-/// assert_eq!(parser("H2"), Err(ErrMode::Backtrack(Error::new("H2", ErrorKind::Slice))));
-/// assert_eq!(parser(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(" \t\n\r21c"), Ok(("21c", " \t\n\r")));
+/// assert_eq!(parser.parse_peek("H2"), Err(ErrMode::Backtrack(InputError::new("H2", ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Slice))));
/// ```
///
/// ```
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, IResult, error::Needed};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use winnow::Partial;
/// # use winnow::ascii::multispace1;
-/// assert_eq!(multispace1::<_, Error<_>>(Partial::new(" \t\n\r21c")), Ok((Partial::new("21c"), " \t\n\r")));
-/// assert_eq!(multispace1::<_, Error<_>>(Partial::new("H2")), Err(ErrMode::Backtrack(Error::new(Partial::new("H2"), ErrorKind::Slice))));
-/// assert_eq!(multispace1::<_, Error<_>>(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(multispace1::<_, InputError<_>>.parse_peek(Partial::new(" \t\n\r21c")), Ok((Partial::new("21c"), " \t\n\r")));
+/// assert_eq!(multispace1::<_, InputError<_>>.parse_peek(Partial::new("H2")), Err(ErrMode::Backtrack(InputError::new(Partial::new("H2"), ErrorKind::Slice))));
+/// assert_eq!(multispace1::<_, InputError<_>>.parse_peek(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(1))));
/// ```
#[inline(always)]
-pub fn multispace1<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+pub fn multispace1<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
{
- trace("multispace1", move |input: I| {
- take_while(1.., |c: <I as Stream>::Token| {
- let ch = c.as_char();
- matches!(ch, ' ' | '\t' | '\r' | '\n')
- })
- .parse_next(input)
- })
- .parse_next(input)
+ trace("multispace1", take_while(1.., (' ', '\t', '\r', '\n'))).parse_next(input)
}
-/// Decode a decimal unsigned integer
+/// Decode a decimal unsigned integer (e.g. [`u32`])
///
/// *Complete version*: can parse until the end of input.
///
@@ -906,14 +865,14 @@ where
#[doc(alias = "u32")]
#[doc(alias = "u64")]
#[doc(alias = "u128")]
-pub fn dec_uint<I, O, E: ParseError<I>>(input: I) -> IResult<I, O, E>
+pub fn dec_uint<I, O, E: ParserError<I>>(input: &mut I) -> PResult<O, E>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
O: Uint,
{
- trace("dec_uint", move |input: I| {
+ trace("dec_uint", move |input: &mut I| {
if input.eof_offset() == 0 {
if <I as StreamIsPartial>::is_partial_supported() && input.is_partial() {
return Err(ErrMode::Incomplete(Needed::new(1)));
@@ -936,7 +895,8 @@ where
if offset == 0 {
return Err(ErrMode::from_error_kind(input, ErrorKind::Slice));
} else {
- return Ok((input.next_slice(offset).0, value));
+ let _ = input.next_slice(offset);
+ return Ok(value);
}
}
}
@@ -945,7 +905,8 @@ where
if <I as StreamIsPartial>::is_partial_supported() && input.is_partial() {
Err(ErrMode::Incomplete(Needed::new(1)))
} else {
- Ok((input.next_slice(input.eof_offset()).0, value))
+ let _ = input.finish();
+ Ok(value)
}
})
.parse_next(input)
@@ -1049,7 +1010,7 @@ impl Uint for i128 {
}
}
-/// Decode a decimal signed integer
+/// Decode a decimal signed integer (e.g. [`i32`])
///
/// *Complete version*: can parse until the end of input.
///
@@ -1059,19 +1020,19 @@ impl Uint for i128 {
#[doc(alias = "i32")]
#[doc(alias = "i64")]
#[doc(alias = "i128")]
-pub fn dec_int<I, O, E: ParseError<I>>(input: I) -> IResult<I, O, E>
+pub fn dec_int<I, O, E: ParserError<I>>(input: &mut I) -> PResult<O, E>
where
I: StreamIsPartial,
I: Stream,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
O: Int,
{
- trace("dec_int", move |input: I| {
+ trace("dec_int", move |input: &mut I| {
fn sign(token: impl AsChar) -> bool {
let token = token.as_char();
token == '+' || token == '-'
}
- let (input, sign) = opt(crate::token::one_of(sign).map(AsChar::as_char))
+ let sign = opt(crate::token::one_of(sign).map(AsChar::as_char))
.map(|c| c != Some('-'))
.parse_next(input)?;
@@ -1101,7 +1062,8 @@ where
if offset == 0 {
return Err(ErrMode::from_error_kind(input, ErrorKind::Slice));
} else {
- return Ok((input.next_slice(offset).0, value));
+ let _ = input.next_slice(offset);
+ return Ok(value);
}
}
}
@@ -1110,7 +1072,8 @@ where
if <I as StreamIsPartial>::is_partial_supported() && input.is_partial() {
Err(ErrMode::Incomplete(Needed::new(1)))
} else {
- Ok((input.next_slice(input.eof_offset()).0, value))
+ let _ = input.finish();
+ Ok(value)
}
})
.parse_next(input)
@@ -1152,7 +1115,7 @@ impl Int for i128 {
}
}
-/// Decode a variable-width hexadecimal integer.
+/// Decode a variable-width hexadecimal integer (e.g. [`u32`])
///
/// *Complete version*: Will parse until the end of input if it has fewer characters than the type
/// supports.
@@ -1164,34 +1127,34 @@ impl Int for i128 {
///
/// ```rust
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError};
/// use winnow::ascii::hex_uint;
///
-/// fn parser(s: &[u8]) -> IResult<&[u8], u32> {
+/// fn parser<'s>(s: &mut &'s [u8]) -> PResult<u32, InputError<&'s [u8]>> {
/// hex_uint(s)
/// }
///
-/// assert_eq!(parser(&b"01AE"[..]), Ok((&b""[..], 0x01AE)));
-/// assert_eq!(parser(&b"abc"[..]), Ok((&b""[..], 0x0ABC)));
-/// assert_eq!(parser(&b"ggg"[..]), Err(ErrMode::Backtrack(Error::new(&b"ggg"[..], ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(&b"01AE"[..]), Ok((&b""[..], 0x01AE)));
+/// assert_eq!(parser.parse_peek(&b"abc"[..]), Ok((&b""[..], 0x0ABC)));
+/// assert_eq!(parser.parse_peek(&b"ggg"[..]), Err(ErrMode::Backtrack(InputError::new(&b"ggg"[..], ErrorKind::Slice))));
/// ```
///
/// ```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::ascii::hex_uint;
///
-/// fn parser(s: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> {
+/// fn parser<'s>(s: &mut Partial<&'s [u8]>) -> PResult<u32, InputError<Partial<&'s [u8]>>> {
/// hex_uint(s)
/// }
///
-/// assert_eq!(parser(Partial::new(&b"01AE;"[..])), Ok((Partial::new(&b";"[..]), 0x01AE)));
-/// assert_eq!(parser(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
-/// assert_eq!(parser(Partial::new(&b"ggg"[..])), Err(ErrMode::Backtrack(Error::new(Partial::new(&b"ggg"[..]), ErrorKind::Slice))));
+/// assert_eq!(parser.parse_peek(Partial::new(&b"01AE;"[..])), Ok((Partial::new(&b";"[..]), 0x01AE)));
+/// assert_eq!(parser.parse_peek(Partial::new(&b"abc"[..])), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(parser.parse_peek(Partial::new(&b"ggg"[..])), Err(ErrMode::Backtrack(InputError::new(Partial::new(&b"ggg"[..]), ErrorKind::Slice))));
/// ```
#[inline]
-pub fn hex_uint<I, O, E: ParseError<I>>(input: I) -> IResult<I, O, E>
+pub fn hex_uint<I, O, E: ParserError<I>>(input: &mut I) -> PResult<O, E>
where
I: StreamIsPartial,
I: Stream,
@@ -1199,7 +1162,7 @@ where
<I as Stream>::Token: AsChar,
<I as Stream>::Slice: AsBStr,
{
- trace("hex_uint", move |input: I| {
+ trace("hex_uint", move |input: &mut I| {
let invalid_offset = input
.offset_for(|c| {
let c = c.as_char();
@@ -1233,7 +1196,7 @@ where
// Must be at least one digit
return Err(ErrMode::from_error_kind(input, ErrorKind::Slice));
}
- let (remaining, parsed) = input.next_slice(offset);
+ let parsed = input.next_slice(offset);
let mut res = O::default();
for c in parsed.as_bstr() {
@@ -1243,7 +1206,7 @@ where
res = (res << O::from(4)) + nibble;
}
- Ok((remaining, res))
+ Ok(res)
})
.parse_next(input)
}
@@ -1291,7 +1254,7 @@ impl HexUint for u128 {
}
}
-/// Recognizes floating point number in text format and returns a f32 or f64.
+/// Recognizes floating point number in text format and returns a [`f32`] or [`f64`].
///
/// *Complete version*: Can parse until the end of input.
///
@@ -1301,99 +1264,97 @@ impl HexUint for u128 {
///
/// ```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::error::Needed::Size;
/// use winnow::ascii::float;
///
-/// fn parser(s: &str) -> IResult<&str, f64> {
+/// fn parser<'s>(s: &mut &'s str) -> PResult<f64, InputError<&'s str>> {
/// float(s)
/// }
///
-/// assert_eq!(parser("11e-1"), Ok(("", 1.1)));
-/// assert_eq!(parser("123E-02"), Ok(("", 1.23)));
-/// assert_eq!(parser("123K-01"), Ok(("K-01", 123.0)));
-/// assert_eq!(parser("abc"), Err(ErrMode::Backtrack(Error::new("abc", ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek("11e-1"), Ok(("", 1.1)));
+/// assert_eq!(parser.parse_peek("123E-02"), Ok(("", 1.23)));
+/// assert_eq!(parser.parse_peek("123K-01"), Ok(("K-01", 123.0)));
+/// assert_eq!(parser.parse_peek("abc"), Err(ErrMode::Backtrack(InputError::new("abc", ErrorKind::Tag))));
/// ```
///
/// ```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::error::Needed::Size;
/// # use winnow::Partial;
/// use winnow::ascii::float;
///
-/// fn parser(s: Partial<&str>) -> IResult<Partial<&str>, f64> {
+/// fn parser<'s>(s: &mut Partial<&'s str>) -> PResult<f64, InputError<Partial<&'s str>>> {
/// float(s)
/// }
///
-/// assert_eq!(parser(Partial::new("11e-1 ")), Ok((Partial::new(" "), 1.1)));
-/// assert_eq!(parser(Partial::new("11e-1")), Err(ErrMode::Incomplete(Needed::new(1))));
-/// assert_eq!(parser(Partial::new("123E-02")), Err(ErrMode::Incomplete(Needed::new(1))));
-/// assert_eq!(parser(Partial::new("123K-01")), Ok((Partial::new("K-01"), 123.0)));
-/// assert_eq!(parser(Partial::new("abc")), Err(ErrMode::Backtrack(Error::new(Partial::new("abc"), ErrorKind::Tag))));
+/// assert_eq!(parser.parse_peek(Partial::new("11e-1 ")), Ok((Partial::new(" "), 1.1)));
+/// assert_eq!(parser.parse_peek(Partial::new("11e-1")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(parser.parse_peek(Partial::new("123E-02")), Err(ErrMode::Incomplete(Needed::new(1))));
+/// assert_eq!(parser.parse_peek(Partial::new("123K-01")), Ok((Partial::new("K-01"), 123.0)));
+/// assert_eq!(parser.parse_peek(Partial::new("abc")), Err(ErrMode::Backtrack(InputError::new(Partial::new("abc"), ErrorKind::Tag))));
/// ```
#[inline(always)]
#[doc(alias = "f32")]
#[doc(alias = "double")]
-pub fn float<I, O, E: ParseError<I>>(input: I) -> IResult<I, O, E>
+#[allow(clippy::trait_duplication_in_bounds)] // HACK: clippy 1.64.0 bug
+pub fn float<I, O, E: ParserError<I>>(input: &mut I) -> PResult<O, E>
where
I: StreamIsPartial,
I: Stream,
- I: Offset + Compare<&'static str>,
+ I: Compare<&'static str>,
<I as Stream>::Slice: ParseSlice<O>,
- <I as Stream>::Token: AsChar + Copy,
+ <I as Stream>::Token: AsChar + Clone,
<I as Stream>::IterOffsets: Clone,
I: AsBStr,
- &'static str: ContainsToken<<I as Stream>::Token>,
{
- trace("float", move |input: I| {
- let (i, s) = recognize_float_or_exceptions(input)?;
- match s.parse_slice() {
- Some(f) => Ok((i, f)),
- None => Err(ErrMode::from_error_kind(i, ErrorKind::Verify)),
- }
+ trace("float", move |input: &mut I| {
+ let s = recognize_float_or_exceptions(input)?;
+ s.parse_slice()
+ .ok_or_else(|| ErrMode::from_error_kind(input, ErrorKind::Verify))
})
.parse_next(input)
}
-fn recognize_float_or_exceptions<I, E: ParseError<I>>(
- input: I,
-) -> IResult<I, <I as Stream>::Slice, E>
+#[allow(clippy::trait_duplication_in_bounds)] // HACK: clippy 1.64.0 bug
+fn recognize_float_or_exceptions<I, E: ParserError<I>>(
+ input: &mut I,
+) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
- I: Offset + Compare<&'static str>,
- <I as Stream>::Token: AsChar + Copy,
+ I: Compare<&'static str>,
+ <I as Stream>::Token: AsChar + Clone,
<I as Stream>::IterOffsets: Clone,
I: AsBStr,
- &'static str: ContainsToken<<I as Stream>::Token>,
{
alt((
recognize_float,
crate::token::tag_no_case("nan"),
- crate::token::tag_no_case("inf"),
crate::token::tag_no_case("infinity"),
+ crate::token::tag_no_case("inf"),
))
.parse_next(input)
}
-fn recognize_float<I, E: ParseError<I>>(input: I) -> IResult<I, <I as Stream>::Slice, E>
+#[allow(clippy::trait_duplication_in_bounds)] // HACK: clippy 1.64.0 bug
+fn recognize_float<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
- I: Offset + Compare<&'static str>,
- <I as Stream>::Token: AsChar + Copy,
+ I: Compare<&'static str>,
+ <I as Stream>::Token: AsChar + Clone,
<I as Stream>::IterOffsets: Clone,
I: AsBStr,
- &'static str: ContainsToken<<I as Stream>::Token>,
{
(
- opt(one_of("+-")),
+ opt(one_of(['+', '-'])),
alt((
(digit1, opt(('.', opt(digit1)))).map(|_| ()),
('.', digit1).map(|_| ()),
)),
- opt((one_of("eE"), opt(one_of("+-")), cut_err(digit1))),
+ opt((one_of(['e', 'E']), opt(one_of(['+', '-'])), cut_err(digit1))),
)
.recognize()
.parse_next(input)
@@ -1408,14 +1369,15 @@ where
/// # Example
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed, IResult};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed, IResult};
/// # use winnow::ascii::digit1;
/// # use winnow::prelude::*;
/// use winnow::ascii::escaped;
/// use winnow::token::one_of;
///
/// fn esc(s: &str) -> IResult<&str, &str> {
-/// escaped(digit1, '\\', one_of(r#""n\"#)).parse_next(s)
+/// escaped(digit1, '\\', one_of(['"', 'n', '\\'])).parse_peek(s)
/// }
///
/// assert_eq!(esc("123;"), Ok((";", "123")));
@@ -1423,7 +1385,8 @@ where
/// ```
///
/// ```rust
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed, IResult};
+/// # use winnow::prelude::*;
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed, IResult};
/// # use winnow::ascii::digit1;
/// # use winnow::prelude::*;
/// # use winnow::Partial;
@@ -1431,7 +1394,7 @@ where
/// use winnow::token::one_of;
///
/// fn esc(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
-/// escaped(digit1, '\\', one_of("\"n\\")).parse_next(s)
+/// escaped(digit1, '\\', one_of(['"', 'n', '\\'])).parse_peek(s)
/// }
///
/// assert_eq!(esc(Partial::new("123;")), Ok((Partial::new(";"), "123")));
@@ -1445,13 +1408,13 @@ pub fn escaped<'a, I: 'a, Error, F, G, O1, O2>(
) -> impl Parser<I, <I as Stream>::Slice, Error>
where
I: StreamIsPartial,
- I: Stream + Offset,
- <I as Stream>::Token: crate::stream::AsChar,
+ I: Stream,
+ <I as Stream>::Token: AsChar + Clone,
F: Parser<I, O1, Error>,
G: Parser<I, O2, Error>,
- Error: ParseError<I>,
+ Error: ParserError<I>,
{
- trace("escaped", move |input: I| {
+ trace("escaped", move |input: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() && input.is_partial() {
streaming_escaped_internal(input, &mut normal, control_char, &mut escapable)
} else {
@@ -1461,56 +1424,41 @@ where
}
fn streaming_escaped_internal<I, Error, F, G, O1, O2>(
- input: I,
+ input: &mut I,
normal: &mut F,
control_char: char,
escapable: &mut G,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
- I: Stream + Offset,
- <I as Stream>::Token: crate::stream::AsChar,
+ I: Stream,
+ <I as Stream>::Token: AsChar + Clone,
F: Parser<I, O1, Error>,
G: Parser<I, O2, Error>,
- Error: ParseError<I>,
+ Error: ParserError<I>,
{
- let mut i = input.clone();
+ let start = input.checkpoint();
- while i.eof_offset() > 0 {
- let current_len = i.eof_offset();
+ while input.eof_offset() > 0 {
+ let current_len = input.eof_offset();
- match normal.parse_next(i.clone()) {
- Ok((i2, _)) => {
- if i2.eof_offset() == 0 {
- return Err(ErrMode::Incomplete(Needed::Unknown));
- } else if i2.eof_offset() == current_len {
- let offset = input.offset_to(&i2);
+ match opt(normal.by_ref()).parse_next(input)? {
+ Some(_) => {
+ if input.eof_offset() == current_len {
+ let offset = input.offset_from(&start);
+ input.reset(start);
return Ok(input.next_slice(offset));
- } else {
- i = i2;
}
}
- Err(ErrMode::Backtrack(_)) => {
- if i.next_token().expect("eof_offset > 0").1.as_char() == control_char {
- let next = control_char.len_utf8();
- match escapable.parse_next(i.next_slice(next).0) {
- Ok((i2, _)) => {
- if i2.eof_offset() == 0 {
- return Err(ErrMode::Incomplete(Needed::Unknown));
- } else {
- i = i2;
- }
- }
- Err(e) => return Err(e),
- }
+ None => {
+ if opt(control_char).parse_next(input)?.is_some() {
+ let _ = escapable.parse_next(input)?;
} else {
- let offset = input.offset_to(&i);
+ let offset = input.offset_from(&start);
+ input.reset(start);
return Ok(input.next_slice(offset));
}
}
- Err(e) => {
- return Err(e);
- }
}
}
@@ -1518,62 +1466,46 @@ where
}
fn complete_escaped_internal<'a, I: 'a, Error, F, G, O1, O2>(
- input: I,
+ input: &mut I,
normal: &mut F,
control_char: char,
escapable: &mut G,
-) -> IResult<I, <I as Stream>::Slice, Error>
+) -> PResult<<I as Stream>::Slice, Error>
where
I: StreamIsPartial,
- I: Stream + Offset,
- <I as Stream>::Token: crate::stream::AsChar,
+ I: Stream,
+ <I as Stream>::Token: crate::stream::AsChar + Clone,
F: Parser<I, O1, Error>,
G: Parser<I, O2, Error>,
- Error: ParseError<I>,
+ Error: ParserError<I>,
{
- let mut i = input.clone();
-
- while i.eof_offset() > 0 {
- let current_len = i.eof_offset();
-
- match normal.parse_next(i.clone()) {
- Ok((i2, _)) => {
- // return if we consumed everything or if the normal parser
- // does not consume anything
- if i2.eof_offset() == 0 {
- return Ok(input.next_slice(input.eof_offset()));
- } else if i2.eof_offset() == current_len {
- let offset = input.offset_to(&i2);
+ let start = input.checkpoint();
+
+ while input.eof_offset() > 0 {
+ let current_len = input.eof_offset();
+
+ match opt(normal.by_ref()).parse_next(input)? {
+ Some(_) => {
+ if input.eof_offset() == current_len {
+ let offset = input.offset_from(&start);
+ input.reset(start);
return Ok(input.next_slice(offset));
- } else {
- i = i2;
}
}
- Err(ErrMode::Backtrack(_)) => {
- if i.next_token().expect("eof_offset > 0").1.as_char() == control_char {
- let next = control_char.len_utf8();
- match escapable.parse_next(i.next_slice(next).0) {
- Ok((i2, _)) => {
- if i2.eof_offset() == 0 {
- return Ok(input.next_slice(input.eof_offset()));
- } else {
- i = i2;
- }
- }
- Err(e) => return Err(e),
- }
+ None => {
+ if opt(control_char).parse_next(input)?.is_some() {
+ let _ = escapable.parse_next(input)?;
} else {
- let offset = input.offset_to(&i);
+ let offset = input.offset_from(&start);
+ input.reset(start);
return Ok(input.next_slice(offset));
}
}
- Err(e) => {
- return Err(e);
- }
}
}
- Ok(input.next_slice(input.eof_offset()))
+ input.reset(start);
+ Ok(input.finish())
}
/// Matches a byte string with escaped characters.
@@ -1588,14 +1520,14 @@ where
///
/// ```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 std::str::from_utf8;
/// use winnow::token::tag;
/// use winnow::ascii::escaped_transform;
/// use winnow::ascii::alpha1;
/// use winnow::combinator::alt;
///
-/// fn parser(input: &str) -> IResult<&str, String> {
+/// fn parser<'s>(input: &mut &'s str) -> PResult<String, InputError<&'s str>> {
/// escaped_transform(
/// alpha1,
/// '\\',
@@ -1607,13 +1539,13 @@ where
/// ).parse_next(input)
/// }
///
-/// assert_eq!(parser("ab\\\"cd"), Ok(("", String::from("ab\"cd"))));
-/// assert_eq!(parser("ab\\ncd"), Ok(("", String::from("ab\ncd"))));
+/// assert_eq!(parser.parse_peek("ab\\\"cd"), Ok(("", String::from("ab\"cd"))));
+/// assert_eq!(parser.parse_peek("ab\\ncd"), Ok(("", String::from("ab\ncd"))));
/// ```
///
/// ```
/// # use winnow::prelude::*;
-/// # use winnow::{error::ErrMode, error::ErrorKind, error::Error, error::Needed};
+/// # use winnow::{error::ErrMode, error::ErrorKind, error::InputError, error::Needed};
/// # use std::str::from_utf8;
/// # use winnow::Partial;
/// use winnow::token::tag;
@@ -1621,7 +1553,7 @@ where
/// use winnow::ascii::alpha1;
/// use winnow::combinator::alt;
///
-/// fn parser(input: Partial<&str>) -> IResult<Partial<&str>, String> {
+/// fn parser<'s>(input: &mut Partial<&'s str>) -> PResult<String, InputError<Partial<&'s str>>> {
/// escaped_transform(
/// alpha1,
/// '\\',
@@ -1633,9 +1565,8 @@ where
/// ).parse_next(input)
/// }
///
-/// assert_eq!(parser(Partial::new("ab\\\"cd\"")), Ok((Partial::new("\""), String::from("ab\"cd"))));
+/// assert_eq!(parser.parse_peek(Partial::new("ab\\\"cd\"")), Ok((Partial::new("\""), String::from("ab\"cd"))));
/// ```
-#[cfg(feature = "alloc")]
#[inline(always)]
pub fn escaped_transform<I, Error, F, G, Output>(
mut normal: F,
@@ -1644,14 +1575,14 @@ pub fn escaped_transform<I, Error, F, G, Output>(
) -> impl Parser<I, Output, Error>
where
I: StreamIsPartial,
- I: Stream + Offset,
- <I as Stream>::Token: crate::stream::AsChar,
+ I: Stream,
+ <I as Stream>::Token: crate::stream::AsChar + Clone,
Output: crate::stream::Accumulate<<I as Stream>::Slice>,
F: Parser<I, <I as Stream>::Slice, Error>,
G: Parser<I, <I as Stream>::Slice, Error>,
- Error: ParseError<I>,
+ Error: ParserError<I>,
{
- trace("escaped_transform", move |input: I| {
+ trace("escaped_transform", move |input: &mut I| {
if <I as StreamIsPartial>::is_partial_supported() && input.is_partial() {
streaming_escaped_transform_internal(input, &mut normal, control_char, &mut transform)
} else {
@@ -1660,122 +1591,83 @@ where
})
}
-#[cfg(feature = "alloc")]
fn streaming_escaped_transform_internal<I, Error, F, G, Output>(
- input: I,
+ input: &mut I,
normal: &mut F,
control_char: char,
transform: &mut G,
-) -> IResult<I, Output, Error>
+) -> PResult<Output, Error>
where
I: StreamIsPartial,
- I: Stream + Offset,
- <I as Stream>::Token: crate::stream::AsChar,
+ I: Stream,
+ <I as Stream>::Token: crate::stream::AsChar + Clone,
Output: crate::stream::Accumulate<<I as Stream>::Slice>,
F: Parser<I, <I as Stream>::Slice, Error>,
G: Parser<I, <I as Stream>::Slice, Error>,
- Error: ParseError<I>,
+ Error: ParserError<I>,
{
- let mut offset = 0;
let mut res = Output::initial(Some(input.eof_offset()));
- let i = input.clone();
-
- while offset < i.eof_offset() {
- let current_len = i.eof_offset();
- let remainder = i.next_slice(offset).0;
- match normal.parse_next(remainder.clone()) {
- Ok((i2, o)) => {
+ while input.eof_offset() > 0 {
+ let current_len = input.eof_offset();
+ match opt(normal.by_ref()).parse_next(input)? {
+ Some(o) => {
res.accumulate(o);
- if i2.eof_offset() == 0 {
- return Err(ErrMode::Incomplete(Needed::Unknown));
- } else if i2.eof_offset() == current_len {
- return Ok((remainder, res));
- } else {
- offset = input.offset_to(&i2);
+ if input.eof_offset() == current_len {
+ return Ok(res);
}
}
- Err(ErrMode::Backtrack(_)) => {
- if remainder.next_token().expect("eof_offset > 0").1.as_char() == control_char {
- let next = offset + control_char.len_utf8();
- match transform.parse_next(i.next_slice(next).0) {
- Ok((i2, o)) => {
- res.accumulate(o);
- if i2.eof_offset() == 0 {
- return Err(ErrMode::Incomplete(Needed::Unknown));
- } else {
- offset = input.offset_to(&i2);
- }
- }
- Err(e) => return Err(e),
- }
+ None => {
+ if opt(control_char).parse_next(input)?.is_some() {
+ let o = transform.parse_next(input)?;
+ res.accumulate(o);
} else {
- return Ok((remainder, res));
+ return Ok(res);
}
}
- Err(e) => return Err(e),
}
}
Err(ErrMode::Incomplete(Needed::Unknown))
}
-#[cfg(feature = "alloc")]
fn complete_escaped_transform_internal<I, Error, F, G, Output>(
- input: I,
+ input: &mut I,
normal: &mut F,
control_char: char,
transform: &mut G,
-) -> IResult<I, Output, Error>
+) -> PResult<Output, Error>
where
I: StreamIsPartial,
- I: Stream + Offset,
- <I as Stream>::Token: crate::stream::AsChar,
+ I: Stream,
+ <I as Stream>::Token: crate::stream::AsChar + Clone,
Output: crate::stream::Accumulate<<I as Stream>::Slice>,
F: Parser<I, <I as Stream>::Slice, Error>,
G: Parser<I, <I as Stream>::Slice, Error>,
- Error: ParseError<I>,
+ Error: ParserError<I>,
{
- let mut offset = 0;
let mut res = Output::initial(Some(input.eof_offset()));
- let i = input.clone();
+ while input.eof_offset() > 0 {
+ let current_len = input.eof_offset();
- while offset < i.eof_offset() {
- let current_len = i.eof_offset();
- let (remainder, _) = i.next_slice(offset);
- match normal.parse_next(remainder.clone()) {
- Ok((i2, o)) => {
+ match opt(normal.by_ref()).parse_next(input)? {
+ Some(o) => {
res.accumulate(o);
- if i2.eof_offset() == 0 {
- return Ok((i.next_slice(i.eof_offset()).0, res));
- } else if i2.eof_offset() == current_len {
- return Ok((remainder, res));
- } else {
- offset = input.offset_to(&i2);
+ if input.eof_offset() == current_len {
+ return Ok(res);
}
}
- Err(ErrMode::Backtrack(_)) => {
- if remainder.next_token().expect("eof_offset > 0").1.as_char() == control_char {
- let next = offset + control_char.len_utf8();
- match transform.parse_next(i.next_slice(next).0) {
- Ok((i2, o)) => {
- res.accumulate(o);
- if i2.eof_offset() == 0 {
- return Ok((i.next_slice(i.eof_offset()).0, res));
- } else {
- offset = input.offset_to(&i2);
- }
- }
- Err(e) => return Err(e),
- }
+ None => {
+ if opt(control_char).parse_next(input)?.is_some() {
+ let o = transform.parse_next(input)?;
+ res.accumulate(o);
} else {
- return Ok((remainder, res));
+ return Ok(res);
}
}
- Err(e) => return Err(e),
}
}
- Ok((input.next_slice(offset).0, res))
+ Ok(res)
}
mod sealed {
diff --git a/vendor/winnow/src/ascii/tests.rs b/vendor/winnow/src/ascii/tests.rs
index b715d0920..aacbd86f2 100644
--- a/vendor/winnow/src/ascii/tests.rs
+++ b/vendor/winnow/src/ascii/tests.rs
@@ -1,12 +1,13 @@
use super::*;
+use crate::prelude::*;
mod complete {
use super::*;
use crate::combinator::alt;
use crate::combinator::opt;
use crate::error::ErrMode;
- use crate::error::Error;
use crate::error::ErrorKind;
+ use crate::error::InputError;
use crate::stream::ParseSlice;
use crate::token::none_of;
use crate::token::one_of;
@@ -16,7 +17,7 @@ mod complete {
macro_rules! assert_parse(
($left: expr, $right: expr) => {
- let res: $crate::IResult<_, _, Error<_>> = $left;
+ let res: $crate::IResult<_, _, InputError<_>> = $left;
assert_eq!(res, $right);
};
);
@@ -30,60 +31,75 @@ mod complete {
let d: &[u8] = "azé12".as_bytes();
let e: &[u8] = b" ";
let f: &[u8] = b" ;";
- //assert_eq!(alpha1::<_, Error>(a), Err(ErrMode::Incomplete(Needed::Size(1))));
- assert_parse!(alpha1(a), Ok((empty, a)));
+ //assert_eq!(alpha1::<_, InputError>(a), Err(ErrMode::Incomplete(Needed::Size(1))));
+ assert_parse!(alpha1.parse_peek(a), Ok((empty, a)));
assert_eq!(
- alpha1(b),
- Err(ErrMode::Backtrack(Error::new(b, ErrorKind::Slice)))
+ alpha1.parse_peek(b),
+ Err(ErrMode::Backtrack(InputError::new(b, ErrorKind::Slice)))
);
- assert_eq!(alpha1::<_, Error<_>>(c), Ok((&c[1..], &b"a"[..])));
- assert_eq!(alpha1::<_, Error<_>>(d), Ok(("é12".as_bytes(), &b"az"[..])));
assert_eq!(
- digit1(a),
- Err(ErrMode::Backtrack(Error::new(a, ErrorKind::Slice)))
+ alpha1::<_, InputError<_>>.parse_peek(c),
+ Ok((&c[1..], &b"a"[..]))
);
- assert_eq!(digit1::<_, Error<_>>(b), Ok((empty, b)));
assert_eq!(
- digit1(c),
- Err(ErrMode::Backtrack(Error::new(c, ErrorKind::Slice)))
+ alpha1::<_, InputError<_>>.parse_peek(d),
+ Ok(("é12".as_bytes(), &b"az"[..]))
+ );
+ assert_eq!(
+ digit1.parse_peek(a),
+ Err(ErrMode::Backtrack(InputError::new(a, ErrorKind::Slice)))
+ );
+ assert_eq!(digit1::<_, InputError<_>>.parse_peek(b), Ok((empty, b)));
+ assert_eq!(
+ digit1.parse_peek(c),
+ Err(ErrMode::Backtrack(InputError::new(c, ErrorKind::Slice)))
);
assert_eq!(
- digit1(d),
- Err(ErrMode::Backtrack(Error::new(d, ErrorKind::Slice)))
+ digit1.parse_peek(d),
+ Err(ErrMode::Backtrack(InputError::new(d, ErrorKind::Slice)))
);
- assert_eq!(hex_digit1::<_, Error<_>>(a), Ok((empty, a)));
- assert_eq!(hex_digit1::<_, Error<_>>(b), Ok((empty, b)));
- assert_eq!(hex_digit1::<_, Error<_>>(c), Ok((empty, c)));
+ assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(a), Ok((empty, a)));
+ assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(b), Ok((empty, b)));
+ assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(c), Ok((empty, c)));
assert_eq!(
- hex_digit1::<_, Error<_>>(d),
+ hex_digit1::<_, InputError<_>>.parse_peek(d),
Ok(("zé12".as_bytes(), &b"a"[..]))
);
assert_eq!(
- hex_digit1(e),
- Err(ErrMode::Backtrack(Error::new(e, ErrorKind::Slice)))
+ hex_digit1.parse_peek(e),
+ Err(ErrMode::Backtrack(InputError::new(e, ErrorKind::Slice)))
);
assert_eq!(
- oct_digit1(a),
- Err(ErrMode::Backtrack(Error::new(a, ErrorKind::Slice)))
+ oct_digit1.parse_peek(a),
+ Err(ErrMode::Backtrack(InputError::new(a, ErrorKind::Slice)))
);
- assert_eq!(oct_digit1::<_, Error<_>>(b), Ok((empty, b)));
+ assert_eq!(oct_digit1::<_, InputError<_>>.parse_peek(b), Ok((empty, b)));
assert_eq!(
- oct_digit1(c),
- Err(ErrMode::Backtrack(Error::new(c, ErrorKind::Slice)))
+ oct_digit1.parse_peek(c),
+ Err(ErrMode::Backtrack(InputError::new(c, ErrorKind::Slice)))
);
assert_eq!(
- oct_digit1(d),
- Err(ErrMode::Backtrack(Error::new(d, ErrorKind::Slice)))
+ oct_digit1.parse_peek(d),
+ Err(ErrMode::Backtrack(InputError::new(d, ErrorKind::Slice)))
+ );
+ assert_eq!(
+ alphanumeric1::<_, InputError<_>>.parse_peek(a),
+ Ok((empty, a))
);
- assert_eq!(alphanumeric1::<_, Error<_>>(a), Ok((empty, a)));
//assert_eq!(fix_error!(b,(), alphanumeric), Ok((empty, b)));
- assert_eq!(alphanumeric1::<_, Error<_>>(c), Ok((empty, c)));
assert_eq!(
- alphanumeric1::<_, Error<_>>(d),
+ alphanumeric1::<_, InputError<_>>.parse_peek(c),
+ Ok((empty, c))
+ );
+ assert_eq!(
+ alphanumeric1::<_, InputError<_>>.parse_peek(d),
Ok(("é12".as_bytes(), &b"az"[..]))
);
- assert_eq!(space1::<_, Error<_>>(e), Ok((empty, e)));
- assert_eq!(space1::<_, Error<_>>(f), Ok((&b";"[..], &b" "[..])));
+ assert_eq!(space1::<_, InputError<_>>.parse_peek(e), Ok((empty, e)));
+ assert_eq!(
+ space1::<_, InputError<_>>.parse_peek(f),
+ Ok((&b";"[..], &b" "[..]))
+ );
}
#[cfg(feature = "alloc")]
@@ -95,52 +111,64 @@ mod complete {
let c = "a123";
let d = "azé12";
let e = " ";
- assert_eq!(alpha1::<_, Error<_>>(a), Ok((empty, a)));
+ assert_eq!(alpha1::<_, InputError<_>>.parse_peek(a), Ok((empty, a)));
+ assert_eq!(
+ alpha1.parse_peek(b),
+ Err(ErrMode::Backtrack(InputError::new(b, ErrorKind::Slice)))
+ );
+ assert_eq!(alpha1::<_, InputError<_>>.parse_peek(c), Ok((&c[1..], "a")));
+ assert_eq!(alpha1::<_, InputError<_>>.parse_peek(d), Ok(("é12", "az")));
+ assert_eq!(
+ digit1.parse_peek(a),
+ Err(ErrMode::Backtrack(InputError::new(a, ErrorKind::Slice)))
+ );
+ assert_eq!(digit1::<_, InputError<_>>.parse_peek(b), Ok((empty, b)));
assert_eq!(
- alpha1(b),
- Err(ErrMode::Backtrack(Error::new(b, ErrorKind::Slice)))
+ digit1.parse_peek(c),
+ Err(ErrMode::Backtrack(InputError::new(c, ErrorKind::Slice)))
);
- assert_eq!(alpha1::<_, Error<_>>(c), Ok((&c[1..], "a")));
- assert_eq!(alpha1::<_, Error<_>>(d), Ok(("é12", "az")));
assert_eq!(
- digit1(a),
- Err(ErrMode::Backtrack(Error::new(a, ErrorKind::Slice)))
+ digit1.parse_peek(d),
+ Err(ErrMode::Backtrack(InputError::new(d, ErrorKind::Slice)))
);
- assert_eq!(digit1::<_, Error<_>>(b), Ok((empty, b)));
+ assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(a), Ok((empty, a)));
+ assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(b), Ok((empty, b)));
+ assert_eq!(hex_digit1::<_, InputError<_>>.parse_peek(c), Ok((empty, c)));
assert_eq!(
- digit1(c),
- Err(ErrMode::Backtrack(Error::new(c, ErrorKind::Slice)))
+ hex_digit1::<_, InputError<_>>.parse_peek(d),
+ Ok(("zé12", "a"))
);
assert_eq!(
- digit1(d),
- Err(ErrMode::Backtrack(Error::new(d, ErrorKind::Slice)))
+ hex_digit1.parse_peek(e),
+ Err(ErrMode::Backtrack(InputError::new(e, ErrorKind::Slice)))
);
- assert_eq!(hex_digit1::<_, Error<_>>(a), Ok((empty, a)));
- assert_eq!(hex_digit1::<_, Error<_>>(b), Ok((empty, b)));
- assert_eq!(hex_digit1::<_, Error<_>>(c), Ok((empty, c)));
- assert_eq!(hex_digit1::<_, Error<_>>(d), Ok(("zé12", "a")));
assert_eq!(
- hex_digit1(e),
- Err(ErrMode::Backtrack(Error::new(e, ErrorKind::Slice)))
+ oct_digit1.parse_peek(a),
+ Err(ErrMode::Backtrack(InputError::new(a, ErrorKind::Slice)))
);
+ assert_eq!(oct_digit1::<_, InputError<_>>.parse_peek(b), Ok((empty, b)));
assert_eq!(
- oct_digit1(a),
- Err(ErrMode::Backtrack(Error::new(a, ErrorKind::Slice)))
+ oct_digit1.parse_peek(c),
+ Err(ErrMode::Backtrack(InputError::new(c, ErrorKind::Slice)))
);
- assert_eq!(oct_digit1::<_, Error<_>>(b), Ok((empty, b)));
assert_eq!(
- oct_digit1(c),
- Err(ErrMode::Backtrack(Error::new(c, ErrorKind::Slice)))
+ oct_digit1.parse_peek(d),
+ Err(ErrMode::Backtrack(InputError::new(d, ErrorKind::Slice)))
);
assert_eq!(
- oct_digit1(d),
- Err(ErrMode::Backtrack(Error::new(d, ErrorKind::Slice)))
+ alphanumeric1::<_, InputError<_>>.parse_peek(a),
+ Ok((empty, a))
);
- assert_eq!(alphanumeric1::<_, Error<_>>(a), Ok((empty, a)));
//assert_eq!(fix_error!(b,(), alphanumeric), Ok((empty, b)));
- assert_eq!(alphanumeric1::<_, Error<_>>(c), Ok((empty, c)));
- assert_eq!(alphanumeric1::<_, Error<_>>(d), Ok(("é12", "az")));
- assert_eq!(space1::<_, Error<_>>(e), Ok((empty, e)));
+ assert_eq!(
+ alphanumeric1::<_, InputError<_>>.parse_peek(c),
+ Ok((empty, c))
+ );
+ assert_eq!(
+ alphanumeric1::<_, InputError<_>>.parse_peek(d),
+ Ok(("é12", "az"))
+ );
+ assert_eq!(space1::<_, InputError<_>>.parse_peek(e), Ok((empty, e)));
}
use crate::stream::Offset;
@@ -153,45 +181,45 @@ mod complete {
let e = &b" \t\r\n;"[..];
let f = &b"123abcDEF;"[..];
- match alpha1::<_, Error<_>>(a) {
+ match alpha1::<_, InputError<_>>.parse_peek(a) {
Ok((i, _)) => {
- assert_eq!(a.offset_to(i) + i.len(), a.len());
+ assert_eq!(i.offset_from(&a) + i.len(), a.len());
}
_ => panic!("wrong return type in offset test for alpha"),
}
- match digit1::<_, Error<_>>(b) {
+ match digit1::<_, InputError<_>>.parse_peek(b) {
Ok((i, _)) => {
- assert_eq!(b.offset_to(i) + i.len(), b.len());
+ assert_eq!(i.offset_from(&b) + i.len(), b.len());
}
_ => panic!("wrong return type in offset test for digit"),
}
- match alphanumeric1::<_, Error<_>>(c) {
+ match alphanumeric1::<_, InputError<_>>.parse_peek(c) {
Ok((i, _)) => {
- assert_eq!(c.offset_to(i) + i.len(), c.len());
+ assert_eq!(i.offset_from(&c) + i.len(), c.len());
}
_ => panic!("wrong return type in offset test for alphanumeric"),
}
- match space1::<_, Error<_>>(d) {
+ match space1::<_, InputError<_>>.parse_peek(d) {
Ok((i, _)) => {
- assert_eq!(d.offset_to(i) + i.len(), d.len());
+ assert_eq!(i.offset_from(&d) + i.len(), d.len());
}
_ => panic!("wrong return type in offset test for space"),
}
- match multispace1::<_, Error<_>>(e) {
+ match multispace1::<_, InputError<_>>.parse_peek(e) {
Ok((i, _)) => {
- assert_eq!(e.offset_to(i) + i.len(), e.len());
+ assert_eq!(i.offset_from(&e) + i.len(), e.len());
}
_ => panic!("wrong return type in offset test for multispace"),
}
- match hex_digit1::<_, Error<_>>(f) {
+ match hex_digit1::<_, InputError<_>>.parse_peek(f) {
Ok((i, _)) => {
- assert_eq!(f.offset_to(i) + i.len(), f.len());
+ assert_eq!(i.offset_from(&f) + i.len(), f.len());
}
_ => panic!("wrong return type in offset test for hex_digit"),
}
- match oct_digit1::<_, Error<_>>(f) {
+ match oct_digit1::<_, InputError<_>>.parse_peek(f) {
Ok((i, _)) => {
- assert_eq!(f.offset_to(i) + i.len(), f.len());
+ assert_eq!(i.offset_from(&f) + i.len(), f.len());
}
_ => panic!("wrong return type in offset test for oct_digit"),
}
@@ -201,53 +229,62 @@ mod complete {
fn is_not_line_ending_bytes() {
let a: &[u8] = b"ab12cd\nefgh";
assert_eq!(
- not_line_ending::<_, Error<_>>(a),
+ not_line_ending::<_, InputError<_>>.parse_peek(a),
Ok((&b"\nefgh"[..], &b"ab12cd"[..]))
);
let b: &[u8] = b"ab12cd\nefgh\nijkl";
assert_eq!(
- not_line_ending::<_, Error<_>>(b),
+ not_line_ending::<_, InputError<_>>.parse_peek(b),
Ok((&b"\nefgh\nijkl"[..], &b"ab12cd"[..]))
);
let c: &[u8] = b"ab12cd\r\nefgh\nijkl";
assert_eq!(
- not_line_ending::<_, Error<_>>(c),
+ not_line_ending::<_, InputError<_>>.parse_peek(c),
Ok((&b"\r\nefgh\nijkl"[..], &b"ab12cd"[..]))
);
let d: &[u8] = b"ab12cd";
- assert_eq!(not_line_ending::<_, Error<_>>(d), Ok((&[][..], d)));
+ assert_eq!(
+ not_line_ending::<_, InputError<_>>.parse_peek(d),
+ Ok((&[][..], d))
+ );
}
#[test]
fn is_not_line_ending_str() {
let f = "βèƒôřè\rÂßÇáƒƭèř";
assert_eq!(
- not_line_ending(f),
- Err(ErrMode::Backtrack(Error::new(f, ErrorKind::Tag)))
+ not_line_ending.parse_peek(f),
+ Err(ErrMode::Backtrack(InputError::new(
+ &f[12..],
+ ErrorKind::Tag
+ )))
);
let g2: &str = "ab12cd";
- assert_eq!(not_line_ending::<_, Error<_>>(g2), Ok(("", g2)));
+ assert_eq!(
+ not_line_ending::<_, InputError<_>>.parse_peek(g2),
+ Ok(("", g2))
+ );
}
#[test]
fn hex_digit_test() {
let i = &b"0123456789abcdefABCDEF;"[..];
- assert_parse!(hex_digit1(i), Ok((&b";"[..], &i[..i.len() - 1])));
+ assert_parse!(hex_digit1.parse_peek(i), Ok((&b";"[..], &i[..i.len() - 1])));
let i = &b"g"[..];
assert_parse!(
- hex_digit1(i),
- Err(ErrMode::Backtrack(error_position!(i, ErrorKind::Slice)))
+ hex_digit1.parse_peek(i),
+ Err(ErrMode::Backtrack(error_position!(&i, ErrorKind::Slice)))
);
let i = &b"G"[..];
assert_parse!(
- hex_digit1(i),
- Err(ErrMode::Backtrack(error_position!(i, ErrorKind::Slice)))
+ hex_digit1.parse_peek(i),
+ Err(ErrMode::Backtrack(error_position!(&i, ErrorKind::Slice)))
);
assert!(AsChar::is_hex_digit(b'0'));
@@ -267,12 +304,12 @@ mod complete {
#[test]
fn oct_digit_test() {
let i = &b"01234567;"[..];
- assert_parse!(oct_digit1(i), Ok((&b";"[..], &i[..i.len() - 1])));
+ assert_parse!(oct_digit1.parse_peek(i), Ok((&b";"[..], &i[..i.len() - 1])));
let i = &b"8"[..];
assert_parse!(
- oct_digit1(i),
- Err(ErrMode::Backtrack(error_position!(i, ErrorKind::Slice)))
+ oct_digit1.parse_peek(i),
+ Err(ErrMode::Backtrack(error_position!(&i, ErrorKind::Slice)))
);
assert!(AsChar::is_oct_digit(b'0'));
@@ -290,7 +327,7 @@ mod complete {
#[test]
fn full_line_windows() {
fn take_full_line(i: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
- (not_line_ending, line_ending).parse_next(i)
+ (not_line_ending, line_ending).parse_peek(i)
}
let input = b"abc\r\n";
let output = take_full_line(input);
@@ -300,7 +337,7 @@ mod complete {
#[test]
fn full_line_unix() {
fn take_full_line(i: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
- (not_line_ending, line_ending).parse_next(i)
+ (not_line_ending, line_ending).parse_peek(i)
}
let input = b"abc\n";
let output = take_full_line(input);
@@ -310,87 +347,96 @@ mod complete {
#[test]
fn check_windows_lineending() {
let input = b"\r\n";
- let output = line_ending(&input[..]);
+ let output = line_ending.parse_peek(&input[..]);
assert_parse!(output, Ok((&b""[..], &b"\r\n"[..])));
}
#[test]
fn check_unix_lineending() {
let input = b"\n";
- let output = line_ending(&input[..]);
+ let output = line_ending.parse_peek(&input[..]);
assert_parse!(output, Ok((&b""[..], &b"\n"[..])));
}
#[test]
fn cr_lf() {
- assert_parse!(crlf(&b"\r\na"[..]), Ok((&b"a"[..], &b"\r\n"[..])));
assert_parse!(
- crlf(&b"\r"[..]),
+ crlf.parse_peek(&b"\r\na"[..]),
+ Ok((&b"a"[..], &b"\r\n"[..]))
+ );
+ assert_parse!(
+ crlf.parse_peek(&b"\r"[..]),
Err(ErrMode::Backtrack(error_position!(
- &b"\r"[..],
+ &&b"\r"[..],
ErrorKind::Tag
)))
);
assert_parse!(
- crlf(&b"\ra"[..]),
+ crlf.parse_peek(&b"\ra"[..]),
Err(ErrMode::Backtrack(error_position!(
- &b"\ra"[..],
+ &&b"\ra"[..],
ErrorKind::Tag
)))
);
- assert_parse!(crlf("\r\na"), Ok(("a", "\r\n")));
+ assert_parse!(crlf.parse_peek("\r\na"), Ok(("a", "\r\n")));
assert_parse!(
- crlf("\r"),
- Err(ErrMode::Backtrack(error_position!("\r", ErrorKind::Tag)))
+ crlf.parse_peek("\r"),
+ Err(ErrMode::Backtrack(error_position!(&"\r", ErrorKind::Tag)))
);
assert_parse!(
- crlf("\ra"),
- Err(ErrMode::Backtrack(error_position!("\ra", ErrorKind::Tag)))
+ crlf.parse_peek("\ra"),
+ Err(ErrMode::Backtrack(error_position!(&"\ra", ErrorKind::Tag)))
);
}
#[test]
fn end_of_line() {
- assert_parse!(line_ending(&b"\na"[..]), Ok((&b"a"[..], &b"\n"[..])));
- assert_parse!(line_ending(&b"\r\na"[..]), Ok((&b"a"[..], &b"\r\n"[..])));
assert_parse!(
- line_ending(&b"\r"[..]),
+ line_ending.parse_peek(&b"\na"[..]),
+ Ok((&b"a"[..], &b"\n"[..]))
+ );
+ assert_parse!(
+ line_ending.parse_peek(&b"\r\na"[..]),
+ Ok((&b"a"[..], &b"\r\n"[..]))
+ );
+ assert_parse!(
+ line_ending.parse_peek(&b"\r"[..]),
Err(ErrMode::Backtrack(error_position!(
- &b"\r"[..],
+ &&b"\r"[..],
ErrorKind::Tag
)))
);
assert_parse!(
- line_ending(&b"\ra"[..]),
+ line_ending.parse_peek(&b"\ra"[..]),
Err(ErrMode::Backtrack(error_position!(
- &b"\ra"[..],
+ &&b"\ra"[..],
ErrorKind::Tag
)))
);
- assert_parse!(line_ending("\na"), Ok(("a", "\n")));
- assert_parse!(line_ending("\r\na"), Ok(("a", "\r\n")));
+ assert_parse!(line_ending.parse_peek("\na"), Ok(("a", "\n")));
+ assert_parse!(line_ending.parse_peek("\r\na"), Ok(("a", "\r\n")));
assert_parse!(
- line_ending("\r"),
- Err(ErrMode::Backtrack(error_position!("\r", ErrorKind::Tag)))
+ line_ending.parse_peek("\r"),
+ Err(ErrMode::Backtrack(error_position!(&"\r", ErrorKind::Tag)))
);
assert_parse!(
- line_ending("\ra"),
- Err(ErrMode::Backtrack(error_position!("\ra", ErrorKind::Tag)))
+ line_ending.parse_peek("\ra"),
+ Err(ErrMode::Backtrack(error_position!(&"\ra", ErrorKind::Tag)))
);
}
fn digit_to_i16(input: &str) -> IResult<&str, i16> {
let i = input;
- let (i, opt_sign) = opt(alt(('+', '-'))).parse_next(i)?;
+ let (i, opt_sign) = opt(alt(('+', '-'))).parse_peek(i)?;
let sign = match opt_sign {
Some('+') | None => true,
Some('-') => false,
_ => unreachable!(),
};
- let (i, s) = digit1::<_, crate::error::Error<_>>(i)?;
+ let (i, s) = digit1::<_, InputError<_>>.parse_peek(i)?;
match s.parse_slice() {
Some(n) => {
if sign {
@@ -399,15 +445,15 @@ mod complete {
Ok((i, -n))
}
}
- None => Err(ErrMode::from_error_kind(i, ErrorKind::Verify)),
+ None => Err(ErrMode::from_error_kind(&i, ErrorKind::Verify)),
}
}
fn digit_to_u32(i: &str) -> IResult<&str, u32> {
- let (i, s) = digit1(i)?;
+ let (i, s) = digit1.parse_peek(i)?;
match s.parse_slice() {
Some(n) => Ok((i, n)),
- None => Err(ErrMode::from_error_kind(i, ErrorKind::Verify)),
+ None => Err(ErrMode::from_error_kind(&i, ErrorKind::Verify)),
}
}
@@ -416,7 +462,7 @@ mod complete {
#[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253
fn ints(s in "\\PC*") {
let res1 = digit_to_i16(&s);
- let res2 = dec_int(s.as_str());
+ let res2 = dec_int.parse_peek(s.as_str());
assert_eq!(res1, res2);
}
@@ -424,7 +470,7 @@ mod complete {
#[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253
fn uints(s in "\\PC*") {
let res1 = digit_to_u32(&s);
- let res2 = dec_uint(s.as_str());
+ let res2 = dec_uint.parse_peek(s.as_str());
assert_eq!(res1, res2);
}
}
@@ -432,13 +478,13 @@ mod complete {
#[test]
fn hex_uint_tests() {
fn hex_u32(input: &[u8]) -> IResult<&[u8], u32> {
- hex_uint(input)
+ hex_uint.parse_peek(input)
}
assert_parse!(
hex_u32(&b";"[..]),
Err(ErrMode::Backtrack(error_position!(
- &b";"[..],
+ &&b";"[..],
ErrorKind::Slice
)))
);
@@ -449,14 +495,14 @@ mod complete {
assert_parse!(
hex_u32(&b"00c5a31be2;"[..]), // overflow
Err(ErrMode::Backtrack(error_position!(
- &b"00c5a31be2;"[..],
+ &&b"00c5a31be2;"[..],
ErrorKind::Verify
)))
);
assert_parse!(
hex_u32(&b"c5a31be201;"[..]), // overflow
Err(ErrMode::Backtrack(error_position!(
- &b"c5a31be201;"[..],
+ &&b"c5a31be201;"[..],
ErrorKind::Verify
)))
);
@@ -464,14 +510,14 @@ mod complete {
assert_parse!(
hex_u32(&b"ffffffffffffffff;"[..]), // overflow
Err(ErrMode::Backtrack(error_position!(
- &b"ffffffffffffffff;"[..],
+ &&b"ffffffffffffffff;"[..],
ErrorKind::Verify
)))
);
assert_parse!(
hex_u32(&b"ffffffffffffffff"[..]), // overflow
Err(ErrMode::Backtrack(error_position!(
- &b"ffffffffffffffff"[..],
+ &&b"ffffffffffffffff"[..],
ErrorKind::Verify
)))
);
@@ -510,35 +556,40 @@ mod complete {
let larger = test.to_string();
- assert_parse!(float(larger.as_bytes()), Ok((&b""[..], expected32)));
- assert_parse!(float(&larger[..]), Ok(("", expected32)));
-
- assert_parse!(float(larger.as_bytes()), Ok((&b""[..], expected64)));
- assert_parse!(float(&larger[..]), Ok(("", expected64)));
+ assert_parse!(
+ float.parse_peek(larger.as_bytes()),
+ Ok((&b""[..], expected32))
+ );
+ assert_parse!(float.parse_peek(&larger[..]), Ok(("", expected32)));
+
+ assert_parse!(
+ float.parse_peek(larger.as_bytes()),
+ Ok((&b""[..], expected64))
+ );
+ assert_parse!(float.parse_peek(&larger[..]), Ok(("", expected64)));
}
let remaining_exponent = "-1.234E-";
assert_parse!(
- float::<_, f64, _>(remaining_exponent),
- Err(ErrMode::Cut(Error {
- input: "",
- kind: ErrorKind::Slice
- }))
+ float::<_, f64, _>.parse_peek(remaining_exponent),
+ Err(ErrMode::Cut(InputError::new("", ErrorKind::Slice)))
);
- let (_i, nan) = float::<_, f32, ()>("NaN").unwrap();
+ let (i, nan) = float::<_, f32, ()>.parse_peek("NaN").unwrap();
assert!(nan.is_nan());
+ assert_eq!(i, "");
- let (_i, inf) = float::<_, f32, ()>("inf").unwrap();
+ let (i, inf) = float::<_, f32, ()>.parse_peek("inf").unwrap();
assert!(inf.is_infinite());
- let (_i, inf) = float::<_, f32, ()>("infinite").unwrap();
+ assert_eq!(i, "");
+ let (i, inf) = float::<_, f32, ()>.parse_peek("infinity").unwrap();
assert!(inf.is_infinite());
+ assert_eq!(i, "");
}
#[cfg(feature = "std")]
fn parse_f64(i: &str) -> IResult<&str, f64, ()> {
- #[allow(deprecated)] // will just become `pub(crate)` later
- match super::recognize_float_or_exceptions(i) {
+ match super::recognize_float_or_exceptions.parse_peek(i) {
Err(e) => Err(e),
Ok((i, s)) => {
if s.is_empty() {
@@ -559,7 +610,7 @@ mod complete {
fn floats(s in "\\PC*") {
println!("testing {}", s);
let res1 = parse_f64(&s);
- let res2 = float::<_, f64, ()>(s.as_str());
+ let res2 = float::<_, f64, ()>.parse_peek(s.as_str());
assert_eq!(res1, res2);
}
}
@@ -571,7 +622,7 @@ mod complete {
fn escaped_string(input: &str) -> IResult<&str, &str> {
use crate::ascii::alpha0;
use crate::token::one_of;
- escaped(alpha0, '\\', one_of("n")).parse_next(input)
+ escaped(alpha0, '\\', one_of(['n'])).parse_peek(input)
}
escaped_string("7").unwrap();
@@ -588,10 +639,14 @@ mod complete {
delimited(
'"',
- escaped(opt(none_of(r#"\""#)), '\\', one_of(r#"\"rnt"#)),
+ escaped(
+ opt(none_of(['\\', '"'])),
+ '\\',
+ one_of(['\\', '"', 'r', 'n', 't']),
+ ),
'"',
)
- .parse_next(input)
+ .parse_peek(input)
}
assert_eq!(unquote(r#""""#), Ok(("", "")));
@@ -605,7 +660,7 @@ mod complete {
use crate::token::one_of;
fn esc(i: &[u8]) -> IResult<&[u8], &[u8]> {
- escaped(alpha, '\\', one_of("\"n\\")).parse_next(i)
+ escaped(alpha, '\\', one_of(['\"', 'n', '\\'])).parse_peek(i)
}
assert_eq!(esc(&b"abcd;"[..]), Ok((&b";"[..], &b"abcd"[..])));
assert_eq!(esc(&b"ab\\\"cd;"[..]), Ok((&b";"[..], &b"ab\\\"cd"[..])));
@@ -615,21 +670,21 @@ mod complete {
assert_eq!(
esc(&b"AB\\"[..]),
Err(ErrMode::Backtrack(error_position!(
- &b""[..],
+ &&b""[..],
ErrorKind::Token
)))
);
assert_eq!(
esc(&b"AB\\A"[..]),
Err(ErrMode::Backtrack(error_node_position!(
- &b"AB\\A"[..],
+ &&b"AB\\A"[..],
ErrorKind::Token,
- error_position!(&b"A"[..], ErrorKind::Verify)
+ error_position!(&&b"A"[..], ErrorKind::Verify)
)))
);
fn esc2(i: &[u8]) -> IResult<&[u8], &[u8]> {
- escaped(digit, '\\', one_of("\"n\\")).parse_next(i)
+ escaped(digit, '\\', one_of(['\"', 'n', '\\'])).parse_peek(i)
}
assert_eq!(esc2(&b"12\\nnn34"[..]), Ok((&b"nn34"[..], &b"12\\n"[..])));
}
@@ -641,7 +696,7 @@ mod complete {
use crate::token::one_of;
fn esc(i: &str) -> IResult<&str, &str> {
- escaped(alpha, '\\', one_of("\"n\\")).parse_next(i)
+ escaped(alpha, '\\', one_of(['\"', 'n', '\\'])).parse_peek(i)
}
assert_eq!(esc("abcd;"), Ok((";", "abcd")));
assert_eq!(esc("ab\\\"cd;"), Ok((";", "ab\\\"cd")));
@@ -650,24 +705,24 @@ mod complete {
assert_eq!(esc("ab\\\"12"), Ok(("12", "ab\\\"")));
assert_eq!(
esc("AB\\"),
- Err(ErrMode::Backtrack(error_position!("", ErrorKind::Token)))
+ Err(ErrMode::Backtrack(error_position!(&"", ErrorKind::Token)))
);
assert_eq!(
esc("AB\\A"),
Err(ErrMode::Backtrack(error_node_position!(
- "AB\\A",
+ &"AB\\A",
ErrorKind::Token,
- error_position!("A", ErrorKind::Verify)
+ error_position!(&"A", ErrorKind::Verify)
)))
);
fn esc2(i: &str) -> IResult<&str, &str> {
- escaped(digit, '\\', one_of("\"n\\")).parse_next(i)
+ escaped(digit, '\\', one_of(['\"', 'n', '\\'])).parse_peek(i)
}
assert_eq!(esc2("12\\nnn34"), Ok(("nn34", "12\\n")));
fn esc3(i: &str) -> IResult<&str, &str> {
- escaped(alpha, '\u{241b}', one_of("\"n")).parse_next(i)
+ escaped(alpha, '\u{241b}', one_of(['\"', 'n'])).parse_peek(i)
}
assert_eq!(esc3("ab␛ncd;"), Ok((";", "ab␛ncd")));
}
@@ -676,7 +731,7 @@ mod complete {
fn test_escaped_error() {
fn esc(s: &str) -> IResult<&str, &str> {
use crate::ascii::digit1;
- escaped(digit1, '\\', one_of("\"n\\")).parse_next(s)
+ escaped(digit1, '\\', one_of(['\"', 'n', '\\'])).parse_peek(s)
}
assert_eq!(esc("abcd"), Ok(("abcd", "")));
@@ -703,7 +758,7 @@ mod complete {
)),
)
.map(to_s)
- .parse_next(i)
+ .parse_peek(i)
}
assert_eq!(esc(&b"abcd;"[..]), Ok((&b";"[..], String::from("abcd"))));
@@ -723,16 +778,16 @@ mod complete {
assert_eq!(
esc(&b"AB\\"[..]),
Err(ErrMode::Backtrack(error_position!(
- &b""[..],
+ &&b""[..],
ErrorKind::Tag
)))
);
assert_eq!(
esc(&b"AB\\A"[..]),
Err(ErrMode::Backtrack(error_node_position!(
- &b"AB\\A"[..],
+ &&b"AB\\A"[..],
ErrorKind::Eof,
- error_position!(&b"A"[..], ErrorKind::Tag)
+ error_position!(&&b"A"[..], ErrorKind::Tag)
)))
);
@@ -746,7 +801,7 @@ mod complete {
)),
)
.map(to_s)
- .parse_next(i)
+ .parse_peek(i)
}
assert_eq!(
esc2(&b"ab&egrave;DEF;"[..]),
@@ -769,7 +824,7 @@ mod complete {
'\\',
alt(("\\".value("\\"), "\"".value("\""), "n".value("\n"))),
)
- .parse_next(i)
+ .parse_peek(i)
}
assert_eq!(esc("abcd;"), Ok((";", String::from("abcd"))));
@@ -779,14 +834,14 @@ mod complete {
assert_eq!(esc("ab\\\"12"), Ok(("12", String::from("ab\""))));
assert_eq!(
esc("AB\\"),
- Err(ErrMode::Backtrack(error_position!("", ErrorKind::Tag)))
+ Err(ErrMode::Backtrack(error_position!(&"", ErrorKind::Tag)))
);
assert_eq!(
esc("AB\\A"),
Err(ErrMode::Backtrack(error_node_position!(
- "AB\\A",
+ &"AB\\A",
ErrorKind::Eof,
- error_position!("A", ErrorKind::Tag)
+ error_position!(&"A", ErrorKind::Tag)
)))
);
@@ -796,7 +851,7 @@ mod complete {
'&',
alt(("egrave;".value("è"), "agrave;".value("à"))),
)
- .parse_next(i)
+ .parse_peek(i)
}
assert_eq!(esc2("ab&egrave;DEF;"), Ok((";", String::from("abèDEF"))));
assert_eq!(
@@ -805,7 +860,7 @@ mod complete {
);
fn esc3(i: &str) -> IResult<&str, String> {
- escaped_transform(alpha, '␛', alt(("0".value("\0"), "n".value("\n")))).parse_next(i)
+ escaped_transform(alpha, '␛', alt(("0".value("\0"), "n".value("\n")))).parse_peek(i)
}
assert_eq!(esc3("a␛0bc␛n"), Ok(("", String::from("a\0bc\n"))));
}
@@ -815,7 +870,7 @@ mod complete {
fn test_escaped_transform_error() {
fn esc_trans(s: &str) -> IResult<&str, String> {
use crate::ascii::digit1;
- escaped_transform(digit1, '\\', "n").parse_next(s)
+ escaped_transform(digit1, '\\', "n").parse_peek(s)
}
assert_eq!(esc_trans("abcd"), Ok(("abcd", String::new())));
@@ -825,8 +880,8 @@ mod complete {
mod partial {
use super::*;
use crate::combinator::opt;
- use crate::error::Error;
use crate::error::ErrorKind;
+ use crate::error::InputError;
use crate::error::{ErrMode, Needed};
use crate::stream::ParseSlice;
use crate::IResult;
@@ -835,7 +890,7 @@ mod partial {
macro_rules! assert_parse(
($left: expr, $right: expr) => {
- let res: $crate::IResult<_, _, Error<_>> = $left;
+ let res: $crate::IResult<_, _, InputError<_>> = $left;
assert_eq!(res, $right);
};
);
@@ -850,116 +905,116 @@ mod partial {
let f: &[u8] = b" ;";
//assert_eq!(alpha1::<_, Error<_>>(a), Err(ErrMode::Incomplete(Needed::new(1))));
assert_parse!(
- alpha1(Partial::new(a)),
+ alpha1.parse_peek(Partial::new(a)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- alpha1(Partial::new(b)),
- Err(ErrMode::Backtrack(Error::new(
+ alpha1.parse_peek(Partial::new(b)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(b),
ErrorKind::Slice
)))
);
assert_eq!(
- alpha1::<_, Error<_>>(Partial::new(c)),
+ alpha1::<_, InputError<_>>.parse_peek(Partial::new(c)),
Ok((Partial::new(&c[1..]), &b"a"[..]))
);
assert_eq!(
- alpha1::<_, Error<_>>(Partial::new(d)),
+ alpha1::<_, InputError<_>>.parse_peek(Partial::new(d)),
Ok((Partial::new("é12".as_bytes()), &b"az"[..]))
);
assert_eq!(
- digit1(Partial::new(a)),
- Err(ErrMode::Backtrack(Error::new(
+ digit1.parse_peek(Partial::new(a)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(a),
ErrorKind::Slice
)))
);
assert_eq!(
- digit1::<_, Error<_>>(Partial::new(b)),
+ digit1::<_, InputError<_>>.parse_peek(Partial::new(b)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- digit1(Partial::new(c)),
- Err(ErrMode::Backtrack(Error::new(
+ digit1.parse_peek(Partial::new(c)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(c),
ErrorKind::Slice
)))
);
assert_eq!(
- digit1(Partial::new(d)),
- Err(ErrMode::Backtrack(Error::new(
+ digit1.parse_peek(Partial::new(d)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(d),
ErrorKind::Slice
)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(a)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(a)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(b)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(b)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(c)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(c)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(d)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(d)),
Ok((Partial::new("zé12".as_bytes()), &b"a"[..]))
);
assert_eq!(
- hex_digit1(Partial::new(e)),
- Err(ErrMode::Backtrack(Error::new(
+ hex_digit1.parse_peek(Partial::new(e)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(e),
ErrorKind::Slice
)))
);
assert_eq!(
- oct_digit1(Partial::new(a)),
- Err(ErrMode::Backtrack(Error::new(
+ oct_digit1.parse_peek(Partial::new(a)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(a),
ErrorKind::Slice
)))
);
assert_eq!(
- oct_digit1::<_, Error<_>>(Partial::new(b)),
+ oct_digit1::<_, InputError<_>>.parse_peek(Partial::new(b)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- oct_digit1(Partial::new(c)),
- Err(ErrMode::Backtrack(Error::new(
+ oct_digit1.parse_peek(Partial::new(c)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(c),
ErrorKind::Slice
)))
);
assert_eq!(
- oct_digit1(Partial::new(d)),
- Err(ErrMode::Backtrack(Error::new(
+ oct_digit1.parse_peek(Partial::new(d)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(d),
ErrorKind::Slice
)))
);
assert_eq!(
- alphanumeric1::<_, Error<_>>(Partial::new(a)),
+ alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new(a)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
//assert_eq!(fix_error!(b,(), alphanumeric1), Ok((empty, b)));
assert_eq!(
- alphanumeric1::<_, Error<_>>(Partial::new(c)),
+ alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new(c)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- alphanumeric1::<_, Error<_>>(Partial::new(d)),
+ alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new(d)),
Ok((Partial::new("é12".as_bytes()), &b"az"[..]))
);
assert_eq!(
- space1::<_, Error<_>>(Partial::new(e)),
+ space1::<_, InputError<_>>.parse_peek(Partial::new(e)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- space1::<_, Error<_>>(Partial::new(f)),
+ space1::<_, InputError<_>>.parse_peek(Partial::new(f)),
Ok((Partial::new(&b";"[..]), &b" "[..]))
);
}
@@ -973,112 +1028,112 @@ mod partial {
let d = "azé12";
let e = " ";
assert_eq!(
- alpha1::<_, Error<_>>(Partial::new(a)),
+ alpha1::<_, InputError<_>>.parse_peek(Partial::new(a)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- alpha1(Partial::new(b)),
- Err(ErrMode::Backtrack(Error::new(
+ alpha1.parse_peek(Partial::new(b)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(b),
ErrorKind::Slice
)))
);
assert_eq!(
- alpha1::<_, Error<_>>(Partial::new(c)),
+ alpha1::<_, InputError<_>>.parse_peek(Partial::new(c)),
Ok((Partial::new(&c[1..]), "a"))
);
assert_eq!(
- alpha1::<_, Error<_>>(Partial::new(d)),
+ alpha1::<_, InputError<_>>.parse_peek(Partial::new(d)),
Ok((Partial::new("é12"), "az"))
);
assert_eq!(
- digit1(Partial::new(a)),
- Err(ErrMode::Backtrack(Error::new(
+ digit1.parse_peek(Partial::new(a)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(a),
ErrorKind::Slice
)))
);
assert_eq!(
- digit1::<_, Error<_>>(Partial::new(b)),
+ digit1::<_, InputError<_>>.parse_peek(Partial::new(b)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- digit1(Partial::new(c)),
- Err(ErrMode::Backtrack(Error::new(
+ digit1.parse_peek(Partial::new(c)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(c),
ErrorKind::Slice
)))
);
assert_eq!(
- digit1(Partial::new(d)),
- Err(ErrMode::Backtrack(Error::new(
+ digit1.parse_peek(Partial::new(d)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(d),
ErrorKind::Slice
)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(a)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(a)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(b)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(b)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(c)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(c)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- hex_digit1::<_, Error<_>>(Partial::new(d)),
+ hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(d)),
Ok((Partial::new("zé12"), "a"))
);
assert_eq!(
- hex_digit1(Partial::new(e)),
- Err(ErrMode::Backtrack(Error::new(
+ hex_digit1.parse_peek(Partial::new(e)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(e),
ErrorKind::Slice
)))
);
assert_eq!(
- oct_digit1(Partial::new(a)),
- Err(ErrMode::Backtrack(Error::new(
+ oct_digit1.parse_peek(Partial::new(a)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(a),
ErrorKind::Slice
)))
);
assert_eq!(
- oct_digit1::<_, Error<_>>(Partial::new(b)),
+ oct_digit1::<_, InputError<_>>.parse_peek(Partial::new(b)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- oct_digit1(Partial::new(c)),
- Err(ErrMode::Backtrack(Error::new(
+ oct_digit1.parse_peek(Partial::new(c)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(c),
ErrorKind::Slice
)))
);
assert_eq!(
- oct_digit1(Partial::new(d)),
- Err(ErrMode::Backtrack(Error::new(
+ oct_digit1.parse_peek(Partial::new(d)),
+ Err(ErrMode::Backtrack(InputError::new(
Partial::new(d),
ErrorKind::Slice
)))
);
assert_eq!(
- alphanumeric1::<_, Error<_>>(Partial::new(a)),
+ alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new(a)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
//assert_eq!(fix_error!(b,(), alphanumeric1), Ok((empty, b)));
assert_eq!(
- alphanumeric1::<_, Error<_>>(Partial::new(c)),
+ alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new(c)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_eq!(
- alphanumeric1::<_, Error<_>>(Partial::new(d)),
+ alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new(d)),
Ok((Partial::new("é12"), "az"))
);
assert_eq!(
- space1::<_, Error<_>>(Partial::new(e)),
+ space1::<_, InputError<_>>.parse_peek(Partial::new(e)),
Err(ErrMode::Incomplete(Needed::new(1)))
);
}
@@ -1093,52 +1148,52 @@ mod partial {
let e = &b" \t\r\n;"[..];
let f = &b"123abcDEF;"[..];
- match alpha1::<_, Error<_>>(Partial::new(a)) {
+ match alpha1::<_, InputError<_>>.parse_peek(Partial::new(a)) {
Ok((i, _)) => {
let i = i.into_inner();
- assert_eq!(a.offset_to(i) + i.len(), a.len());
+ assert_eq!(i.offset_from(&a) + i.len(), a.len());
}
_ => panic!("wrong return type in offset test for alpha"),
}
- match digit1::<_, Error<_>>(Partial::new(b)) {
+ match digit1::<_, InputError<_>>.parse_peek(Partial::new(b)) {
Ok((i, _)) => {
let i = i.into_inner();
- assert_eq!(b.offset_to(i) + i.len(), b.len());
+ assert_eq!(i.offset_from(&b) + i.len(), b.len());
}
_ => panic!("wrong return type in offset test for digit"),
}
- match alphanumeric1::<_, Error<_>>(Partial::new(c)) {
+ match alphanumeric1::<_, InputError<_>>.parse_peek(Partial::new(c)) {
Ok((i, _)) => {
let i = i.into_inner();
- assert_eq!(c.offset_to(i) + i.len(), c.len());
+ assert_eq!(i.offset_from(&c) + i.len(), c.len());
}
_ => panic!("wrong return type in offset test for alphanumeric"),
}
- match space1::<_, Error<_>>(Partial::new(d)) {
+ match space1::<_, InputError<_>>.parse_peek(Partial::new(d)) {
Ok((i, _)) => {
let i = i.into_inner();
- assert_eq!(d.offset_to(i) + i.len(), d.len());
+ assert_eq!(i.offset_from(&d) + i.len(), d.len());
}
_ => panic!("wrong return type in offset test for space"),
}
- match multispace1::<_, Error<_>>(Partial::new(e)) {
+ match multispace1::<_, InputError<_>>.parse_peek(Partial::new(e)) {
Ok((i, _)) => {
let i = i.into_inner();
- assert_eq!(e.offset_to(i) + i.len(), e.len());
+ assert_eq!(i.offset_from(&e) + i.len(), e.len());
}
_ => panic!("wrong return type in offset test for multispace"),
}
- match hex_digit1::<_, Error<_>>(Partial::new(f)) {
+ match hex_digit1::<_, InputError<_>>.parse_peek(Partial::new(f)) {
Ok((i, _)) => {
let i = i.into_inner();
- assert_eq!(f.offset_to(i) + i.len(), f.len());
+ assert_eq!(i.offset_from(&f) + i.len(), f.len());
}
_ => panic!("wrong return type in offset test for hex_digit"),
}
- match oct_digit1::<_, Error<_>>(Partial::new(f)) {
+ match oct_digit1::<_, InputError<_>>.parse_peek(Partial::new(f)) {
Ok((i, _)) => {
let i = i.into_inner();
- assert_eq!(f.offset_to(i) + i.len(), f.len());
+ assert_eq!(i.offset_from(&f) + i.len(), f.len());
}
_ => panic!("wrong return type in offset test for oct_digit"),
}
@@ -1148,26 +1203,26 @@ mod partial {
fn is_not_line_ending_bytes() {
let a: &[u8] = b"ab12cd\nefgh";
assert_eq!(
- not_line_ending::<_, Error<_>>(Partial::new(a)),
+ not_line_ending::<_, InputError<_>>.parse_peek(Partial::new(a)),
Ok((Partial::new(&b"\nefgh"[..]), &b"ab12cd"[..]))
);
let b: &[u8] = b"ab12cd\nefgh\nijkl";
assert_eq!(
- not_line_ending::<_, Error<_>>(Partial::new(b)),
+ not_line_ending::<_, InputError<_>>.parse_peek(Partial::new(b)),
Ok((Partial::new(&b"\nefgh\nijkl"[..]), &b"ab12cd"[..]))
);
let c: &[u8] = b"ab12cd\r\nefgh\nijkl";
assert_eq!(
- not_line_ending::<_, Error<_>>(Partial::new(c)),
+ not_line_ending::<_, InputError<_>>.parse_peek(Partial::new(c)),
Ok((Partial::new(&b"\r\nefgh\nijkl"[..]), &b"ab12cd"[..]))
);
let d: &[u8] = b"ab12cd";
assert_eq!(
- not_line_ending::<_, Error<_>>(Partial::new(d)),
- Err(ErrMode::Incomplete(Needed::Unknown))
+ not_line_ending::<_, InputError<_>>.parse_peek(Partial::new(d)),
+ Err(ErrMode::Incomplete(Needed::new(1)))
);
}
@@ -1175,17 +1230,17 @@ mod partial {
fn is_not_line_ending_str() {
let f = "βèƒôřè\rÂßÇáƒƭèř";
assert_eq!(
- not_line_ending(Partial::new(f)),
- Err(ErrMode::Backtrack(Error::new(
- Partial::new(f),
+ not_line_ending.parse_peek(Partial::new(f)),
+ Err(ErrMode::Backtrack(InputError::new(
+ Partial::new(&f[12..]),
ErrorKind::Tag
)))
);
let g2: &str = "ab12cd";
assert_eq!(
- not_line_ending::<_, Error<_>>(Partial::new(g2)),
- Err(ErrMode::Incomplete(Needed::Unknown))
+ not_line_ending::<_, InputError<_>>.parse_peek(Partial::new(g2)),
+ Err(ErrMode::Incomplete(Needed::new(1)))
);
}
@@ -1193,24 +1248,24 @@ mod partial {
fn hex_digit_test() {
let i = &b"0123456789abcdefABCDEF;"[..];
assert_parse!(
- hex_digit1(Partial::new(i)),
+ hex_digit1.parse_peek(Partial::new(i)),
Ok((Partial::new(&b";"[..]), &i[..i.len() - 1]))
);
let i = &b"g"[..];
assert_parse!(
- hex_digit1(Partial::new(i)),
+ hex_digit1.parse_peek(Partial::new(i)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(i),
+ &Partial::new(i),
ErrorKind::Slice
)))
);
let i = &b"G"[..];
assert_parse!(
- hex_digit1(Partial::new(i)),
+ hex_digit1.parse_peek(Partial::new(i)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(i),
+ &Partial::new(i),
ErrorKind::Slice
)))
);
@@ -1233,15 +1288,15 @@ mod partial {
fn oct_digit_test() {
let i = &b"01234567;"[..];
assert_parse!(
- oct_digit1(Partial::new(i)),
+ oct_digit1.parse_peek(Partial::new(i)),
Ok((Partial::new(&b";"[..]), &i[..i.len() - 1]))
);
let i = &b"8"[..];
assert_parse!(
- oct_digit1(Partial::new(i)),
+ oct_digit1.parse_peek(Partial::new(i)),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(i),
+ &Partial::new(i),
ErrorKind::Slice
)))
);
@@ -1262,7 +1317,7 @@ mod partial {
fn full_line_windows() {
#[allow(clippy::type_complexity)]
fn take_full_line(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, (&[u8], &[u8])> {
- (not_line_ending, line_ending).parse_next(i)
+ (not_line_ending, line_ending).parse_peek(i)
}
let input = b"abc\r\n";
let output = take_full_line(Partial::new(input));
@@ -1276,7 +1331,7 @@ mod partial {
fn full_line_unix() {
#[allow(clippy::type_complexity)]
fn take_full_line(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, (&[u8], &[u8])> {
- (not_line_ending, line_ending).parse_next(i)
+ (not_line_ending, line_ending).parse_peek(i)
}
let input = b"abc\n";
let output = take_full_line(Partial::new(input));
@@ -1289,44 +1344,47 @@ mod partial {
#[test]
fn check_windows_lineending() {
let input = b"\r\n";
- let output = line_ending(Partial::new(&input[..]));
+ let output = line_ending.parse_peek(Partial::new(&input[..]));
assert_parse!(output, Ok((Partial::new(&b""[..]), &b"\r\n"[..])));
}
#[test]
fn check_unix_lineending() {
let input = b"\n";
- let output = line_ending(Partial::new(&input[..]));
+ let output = line_ending.parse_peek(Partial::new(&input[..]));
assert_parse!(output, Ok((Partial::new(&b""[..]), &b"\n"[..])));
}
#[test]
fn cr_lf() {
assert_parse!(
- crlf(Partial::new(&b"\r\na"[..])),
+ crlf.parse_peek(Partial::new(&b"\r\na"[..])),
Ok((Partial::new(&b"a"[..]), &b"\r\n"[..]))
);
assert_parse!(
- crlf(Partial::new(&b"\r"[..])),
+ crlf.parse_peek(Partial::new(&b"\r"[..])),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_parse!(
- crlf(Partial::new(&b"\ra"[..])),
+ crlf.parse_peek(Partial::new(&b"\ra"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"\ra"[..]),
+ &Partial::new(&b"\ra"[..]),
ErrorKind::Tag
)))
);
- assert_parse!(crlf(Partial::new("\r\na")), Ok((Partial::new("a"), "\r\n")));
assert_parse!(
- crlf(Partial::new("\r")),
+ crlf.parse_peek(Partial::new("\r\na")),
+ Ok((Partial::new("a"), "\r\n"))
+ );
+ assert_parse!(
+ crlf.parse_peek(Partial::new("\r")),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_parse!(
- crlf(Partial::new("\ra")),
+ crlf.parse_peek(Partial::new("\ra")),
Err(ErrMode::Backtrack(error_position!(
- Partial::new("\ra"),
+ &Partial::new("\ra"),
ErrorKind::Tag
)))
);
@@ -1335,41 +1393,41 @@ mod partial {
#[test]
fn end_of_line() {
assert_parse!(
- line_ending(Partial::new(&b"\na"[..])),
+ line_ending.parse_peek(Partial::new(&b"\na"[..])),
Ok((Partial::new(&b"a"[..]), &b"\n"[..]))
);
assert_parse!(
- line_ending(Partial::new(&b"\r\na"[..])),
+ line_ending.parse_peek(Partial::new(&b"\r\na"[..])),
Ok((Partial::new(&b"a"[..]), &b"\r\n"[..]))
);
assert_parse!(
- line_ending(Partial::new(&b"\r"[..])),
+ line_ending.parse_peek(Partial::new(&b"\r"[..])),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_parse!(
- line_ending(Partial::new(&b"\ra"[..])),
+ line_ending.parse_peek(Partial::new(&b"\ra"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"\ra"[..]),
+ &Partial::new(&b"\ra"[..]),
ErrorKind::Tag
)))
);
assert_parse!(
- line_ending(Partial::new("\na")),
+ line_ending.parse_peek(Partial::new("\na")),
Ok((Partial::new("a"), "\n"))
);
assert_parse!(
- line_ending(Partial::new("\r\na")),
+ line_ending.parse_peek(Partial::new("\r\na")),
Ok((Partial::new("a"), "\r\n"))
);
assert_parse!(
- line_ending(Partial::new("\r")),
+ line_ending.parse_peek(Partial::new("\r")),
Err(ErrMode::Incomplete(Needed::new(1)))
);
assert_parse!(
- line_ending(Partial::new("\ra")),
+ line_ending.parse_peek(Partial::new("\ra")),
Err(ErrMode::Backtrack(error_position!(
- Partial::new("\ra"),
+ &Partial::new("\ra"),
ErrorKind::Tag
)))
);
@@ -1377,14 +1435,14 @@ mod partial {
fn digit_to_i16(input: Partial<&str>) -> IResult<Partial<&str>, i16> {
let i = input;
- let (i, opt_sign) = opt(one_of("+-")).parse_next(i)?;
+ let (i, opt_sign) = opt(one_of(['+', '-'])).parse_peek(i)?;
let sign = match opt_sign {
Some('+') | None => true,
Some('-') => false,
_ => unreachable!(),
};
- let (i, s) = digit1::<_, crate::error::Error<_>>(i)?;
+ let (i, s) = digit1::<_, InputError<_>>.parse_peek(i)?;
match s.parse_slice() {
Some(n) => {
if sign {
@@ -1393,15 +1451,15 @@ mod partial {
Ok((i, -n))
}
}
- None => Err(ErrMode::from_error_kind(i, ErrorKind::Verify)),
+ None => Err(ErrMode::from_error_kind(&i, ErrorKind::Verify)),
}
}
fn digit_to_u32(i: Partial<&str>) -> IResult<Partial<&str>, u32> {
- let (i, s) = digit1(i)?;
+ let (i, s) = digit1.parse_peek(i)?;
match s.parse_slice() {
Some(n) => Ok((i, n)),
- None => Err(ErrMode::from_error_kind(i, ErrorKind::Verify)),
+ None => Err(ErrMode::from_error_kind(&i, ErrorKind::Verify)),
}
}
@@ -1410,7 +1468,7 @@ mod partial {
#[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253
fn ints(s in "\\PC*") {
let res1 = digit_to_i16(Partial::new(&s));
- let res2 = dec_int(Partial::new(s.as_str()));
+ let res2 = dec_int.parse_peek(Partial::new(s.as_str()));
assert_eq!(res1, res2);
}
@@ -1418,7 +1476,7 @@ mod partial {
#[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253
fn uints(s in "\\PC*") {
let res1 = digit_to_u32(Partial::new(&s));
- let res2 = dec_uint(Partial::new(s.as_str()));
+ let res2 = dec_uint.parse_peek(Partial::new(s.as_str()));
assert_eq!(res1, res2);
}
}
@@ -1426,13 +1484,13 @@ mod partial {
#[test]
fn hex_uint_tests() {
fn hex_u32(input: Partial<&[u8]>) -> IResult<Partial<&[u8]>, u32> {
- hex_uint(input)
+ hex_uint.parse_peek(input)
}
assert_parse!(
hex_u32(Partial::new(&b";"[..])),
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b";"[..]),
+ &Partial::new(&b";"[..]),
ErrorKind::Slice
)))
);
@@ -1455,14 +1513,14 @@ mod partial {
assert_parse!(
hex_u32(Partial::new(&b"00c5a31be2;"[..])), // overflow
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"00c5a31be2;"[..]),
+ &Partial::new(&b"00c5a31be2;"[..]),
ErrorKind::Verify
)))
);
assert_parse!(
hex_u32(Partial::new(&b"c5a31be201;"[..])), // overflow
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"c5a31be201;"[..]),
+ &Partial::new(&b"c5a31be201;"[..]),
ErrorKind::Verify
)))
);
@@ -1473,14 +1531,14 @@ mod partial {
assert_parse!(
hex_u32(Partial::new(&b"ffffffffffffffff;"[..])), // overflow
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"ffffffffffffffff;"[..]),
+ &Partial::new(&b"ffffffffffffffff;"[..]),
ErrorKind::Verify
)))
);
assert_parse!(
hex_u32(Partial::new(&b"ffffffffffffffff"[..])), // overflow
Err(ErrMode::Backtrack(error_position!(
- Partial::new(&b"ffffffffffffffff"[..]),
+ &Partial::new(&b"ffffffffffffffff"[..]),
ErrorKind::Verify
)))
);