diff --git a/fuzz/fuzz_targets/fuzz_arithmetic.rs b/fuzz/fuzz_targets/fuzz_arithmetic.rs index 1b1f1784..c48d2008 100644 --- a/fuzz/fuzz_targets/fuzz_arithmetic.rs +++ b/fuzz/fuzz_targets/fuzz_arithmetic.rs @@ -7,7 +7,7 @@ use winnow::prelude::*; use winnow::{ ascii::{digit1 as digit, space0 as space}, combinator::alt, - combinator::fold_repeat, + combinator::repeat, combinator::{delimited, terminated}, }; @@ -65,24 +65,23 @@ fn term(i: &mut &str) -> PResult { e })?; - let res = fold_repeat( - 0.., - alt((('*', factor), ('/', factor.verify(|i| *i != 0)))), - || init, - |acc, (op, val): (char, i64)| { - if op == '*' { - acc.saturating_mul(val) - } else { - match acc.checked_div(val) { - Some(v) => v, - // we get a division with overflow because we can get acc = i64::MIN and val = -1 - // the division by zero is already checked earlier by verify - None => i64::MAX, + let res = repeat(0.., alt((('*', factor), ('/', factor.verify(|i| *i != 0))))) + .fold( + || init, + |acc, (op, val): (char, i64)| { + if op == '*' { + acc.saturating_mul(val) + } else { + match acc.checked_div(val) { + Some(v) => v, + // we get a division with overflow because we can get acc = i64::MIN and val = -1 + // the division by zero is already checked earlier by verify + None => i64::MAX, + } } - } - }, - ) - .parse_next(i); + }, + ) + .parse_next(i); decr(); res @@ -95,19 +94,18 @@ fn expr(i: &mut &str) -> PResult { e })?; - let res = fold_repeat( - 0.., - (alt(('+', '-')), term), - || init, - |acc, (op, val): (char, i64)| { - if op == '+' { - acc.saturating_add(val) - } else { - acc.saturating_sub(val) - } - }, - ) - .parse_next(i); + let res = repeat(0.., (alt(('+', '-')), term)) + .fold( + || init, + |acc, (op, val): (char, i64)| { + if op == '+' { + acc.saturating_add(val) + } else { + acc.saturating_sub(val) + } + }, + ) + .parse_next(i); decr(); res diff --git a/src/_topic/why.rs b/src/_topic/why.rs index fc1716a0..d632267e 100644 --- a/src/_topic/why.rs +++ b/src/_topic/why.rs @@ -36,18 +36,18 @@ //! //! `winnow` includes support for: //! - Zero-copy parsing -//! - [Parse traces][crate::trace] for easier debugging +//! - [Parse traces] for easier debugging //! - [Streaming parsing][crate::Partial] for network communication or large file //! - [Stateful][crate::Stateful] parsers //! //! For binary formats, `winnow` includes: -//! - [A hexadecimal view][crate::Bytes] in [traces][crate::trace] +//! - [A hexadecimal view][crate::Bytes] in [trace] //! - [TLV](https://en.wikipedia.org/wiki/Type-length-value) (e.g. [`length_take`]) //! - Some common parsers to help get started, like numbers //! //! For text formats, `winnow` includes: //! - [Tracking of spans][crate::Located] -//! - [A textual view when parsing as bytes][crate::BStr] in [traces][crate::trace] +//! - [A textual view when parsing as bytes][crate::BStr] in [trace] //! - Ability to evaluate directly, parse to an AST, or lex and parse the format //! //! This works well for: @@ -98,4 +98,5 @@ #![allow(unused_imports)] use crate::binary::length_take; +use crate::combinator::trace; use crate::stream::Accumulate; diff --git a/src/ascii/mod.rs b/src/ascii/mod.rs index 8e6a480d..01cf7304 100644 --- a/src/ascii/mod.rs +++ b/src/ascii/mod.rs @@ -143,19 +143,6 @@ where .parse_next(input) } -/// Deprecated, replaced with [`till_line_ending`] -#[deprecated(since = "0.5.35", note = "Replaced with `till_line_ending`")] -#[inline(always)] -pub fn not_line_ending>(input: &mut I) -> PResult<::Slice, E> -where - I: StreamIsPartial, - I: Stream, - I: Compare<&'static str>, - ::Token: AsChar + Clone, -{ - till_line_ending(input) -} - fn till_line_ending_, const PARTIAL: bool>( input: &mut I, ) -> PResult<::Slice, E> @@ -1351,6 +1338,7 @@ where I: StreamIsPartial, I: Stream, I: Compare<&'static str>, + I: Compare>, ::Slice: ParseSlice, ::Token: AsChar + Clone, ::IterOffsets: Clone, @@ -1365,7 +1353,6 @@ where } #[allow(clippy::trait_duplication_in_bounds)] // HACK: clippy 1.64.0 bug -#[allow(deprecated)] fn recognize_float_or_exceptions>( input: &mut I, ) -> PResult<::Slice, E> @@ -1373,19 +1360,20 @@ where I: StreamIsPartial, I: Stream, I: Compare<&'static str>, + I: Compare>, ::Token: AsChar + Clone, ::IterOffsets: Clone, I: AsBStr, { alt(( recognize_float, - crate::token::tag_no_case("nan"), + crate::token::tag(Caseless("nan")), ( opt(one_of(['+', '-'])), - crate::token::tag_no_case("infinity"), + crate::token::tag(Caseless("infinity")), ) .recognize(), - (opt(one_of(['+', '-'])), crate::token::tag_no_case("inf")).recognize(), + (opt(one_of(['+', '-'])), crate::token::tag(Caseless("inf"))).recognize(), )) .parse_next(input) } diff --git a/src/binary/mod.rs b/src/binary/mod.rs index 01053a52..04712a4b 100644 --- a/src/binary/mod.rs +++ b/src/binary/mod.rs @@ -2438,19 +2438,6 @@ where }) } -/// Deprecated since 0.5.27, replaced with [`length_take`] -#[deprecated(since = "0.5.27", note = "Replaced with `length_take`")] -pub fn length_data(f: F) -> impl Parser::Slice, E> -where - I: StreamIsPartial, - I: Stream, - N: ToUsize, - F: Parser, - E: ParserError, -{ - length_take(f) -} - /// Parse a length-prefixed slice ([TLV](https://en.wikipedia.org/wiki/Type-length-value)) /// /// *Complete version*: Returns an error if there is not enough input data. @@ -2509,20 +2496,6 @@ where }) } -/// Deprecated since 0.5.27, replaced with [`length_and_then`] -#[deprecated(since = "0.5.27", note = "Replaced with `length_and_then`")] -pub fn length_value(f: F, g: G) -> impl Parser -where - I: StreamIsPartial, - I: Stream + UpdateSlice + Clone, - N: ToUsize, - F: Parser, - G: Parser, - E: ParserError, -{ - length_and_then(f, g) -} - /// [`Accumulate`] a length-prefixed sequence of values ([TLV](https://en.wikipedia.org/wiki/Type-length-value)) /// /// If the length represents token counts, see instead [`length_take`] @@ -2540,7 +2513,7 @@ where /// # use winnow::prelude::*; /// use winnow::Bytes; /// use winnow::binary::u8; -/// use winnow::binary::length_count; +/// use winnow::binary::length_repeat; /// use winnow::token::tag; /// /// type Stream<'i> = &'i Bytes; @@ -2550,7 +2523,7 @@ where /// } /// /// fn parser(s: Stream<'_>) -> IResult, Vec<&[u8]>> { -/// length_count(u8.map(|i| { +/// length_repeat(u8.map(|i| { /// println!("got number: {}", i); /// i /// }), "abc").parse_peek(s) @@ -2575,17 +2548,3 @@ where repeat(n, g.by_ref()).parse_next(i) }) } - -/// Deprecated since 0.5.27, replaced with [`length_repeat`] -#[deprecated(since = "0.5.27", note = "Replaced with `length_repeat`")] -pub fn length_count(f: F, g: G) -> impl Parser -where - I: Stream, - N: ToUsize, - C: Accumulate, - F: Parser, - G: Parser, - E: ParserError, -{ - length_repeat(f, g) -} diff --git a/src/combinator/core.rs b/src/combinator/core.rs index efd77580..2e60687b 100644 --- a/src/combinator/core.rs +++ b/src/combinator/core.rs @@ -471,12 +471,6 @@ pub fn empty>(_input: &mut I) -> PResult<(), E> { Ok(()) } -/// Deprecated, replaced with [`empty`] + [`Parser::value`] -#[deprecated(since = "0.5.35", note = "Replaced with empty.value(...)`")] -pub fn success>(val: O) -> impl Parser { - trace("success", move |_input: &mut I| Ok(val.clone())) -} - /// A parser which always fails. /// /// For example, it can be used as the last alternative in `alt` to diff --git a/src/combinator/mod.rs b/src/combinator/mod.rs index da5fa792..9ad5f61e 100644 --- a/src/combinator/mod.rs +++ b/src/combinator/mod.rs @@ -42,7 +42,7 @@ //! | [`repeat`] | `repeat(1..=3, "ab")` | `"ababc"` | `"c"` | `Ok(vec!["ab", "ab"])` |Applies the parser between m and n times (n included) and returns the list of results in a Vec| //! | [`repeat_till`] | `repeat_till(0.., tag( "ab" ), tag( "ef" ))` | `"ababefg"` | `"g"` | `Ok((vec!["ab", "ab"], "ef"))` |Applies the first parser until the second applies. Returns a tuple containing the list of results from the first in a Vec and the result of the second| //! | [`separated`] | `separated(1..=3, "ab", ",")` | `"ab,ab,ab."` | `"."` | `Ok(vec!["ab", "ab", "ab"])` |Applies the parser and separator between m and n times (n included) and returns the list of results in a Vec| -//! | [`fold_repeat`] | `fold_repeat(1..=2, be_u8, \|\| 0, \|acc, item\| acc + item)` | `[1, 2, 3]` | `[3]` | `Ok(3)` |Applies the parser between m and n times (n included) and folds the list of return value| +//! | [`Repeat::fold`] | `repeat(1..=2, be_u8).fold(\|\| 0, \|acc, item\| acc + item)` | `[1, 2, 3]` | `[3]` | `Ok(3)` |Applies the parser between m and n times (n included) and folds the list of return value| //! //! ## Partial related //! @@ -81,7 +81,7 @@ //! //! ## Remaining combinators //! -//! - [`success`]: Returns a value without consuming any input, always succeeds +//! - [`empty`]: Returns a value without consuming any input, always succeeds //! - [`fail`]: Inversion of `success`. Always fails. //! - [`Parser::by_ref`]: Allow moving `&mut impl Parser` into other parsers //! @@ -125,9 +125,9 @@ //! //! ## Binary format parsing //! -//! - [`length_count`][crate::binary::length_count] Gets a number from the first parser, then applies the second parser that many times -//! - [`length_data`][crate::binary::length_data]: Gets a number from the first parser, then takes a subslice of the input of that size, and returns that subslice -//! - [`length_value`][crate::binary::length_value]: Gets a number from the first parser, takes a subslice of the input of that size, then applies the second parser on that subslice. If the second parser returns `Incomplete`, `length_value` will return an error +//! - [`length_repeat`][crate::binary::length_repeat] Gets a number from the first parser, then applies the second parser that many times +//! - [`length_take`][crate::binary::length_take]: Gets a number from the first parser, then takes a subslice of the input of that size, and returns that subslice +//! - [`length_and_then`][crate::binary::length_and_then]: Gets a number from the first parser, takes a subslice of the input of that size, then applies the second parser on that subslice. If the second parser returns `Incomplete`, `length_value` will return an error //! //! ### Integers //! diff --git a/src/combinator/multi.rs b/src/combinator/multi.rs index f76d6351..613619ec 100644 --- a/src/combinator/multi.rs +++ b/src/combinator/multi.rs @@ -491,20 +491,6 @@ where }) } -/// Deprecated, replaced with [`repeat_till`] -#[deprecated(since = "0.5.35", note = "Replaced with `repeat_till`")] -#[inline(always)] -pub fn repeat_till0(f: F, g: G) -> impl Parser -where - I: Stream, - C: Accumulate, - F: Parser, - G: Parser, - E: ParserError, -{ - repeat_till(0.., f, g) -} - fn repeat_till0_(f: &mut F, g: &mut G, i: &mut I) -> PResult<(C, P), E> where I: Stream, @@ -732,51 +718,6 @@ where }) } -/// [`Accumulate`] the output of a parser, interleaved with `sep` -/// -/// This stops when either parser returns [`ErrMode::Backtrack`]. To instead chain an error up, see -/// [`cut_err`][crate::combinator::cut_err]. -/// -/// # Arguments -/// * `parser` Parses the elements of the list. -/// * `sep` Parses the separator between list elements. -/// -/// # Example -/// -/// ```rust -/// # #[cfg(feature = "std")] { -/// # use winnow::{error::ErrMode, error::ErrorKind, error::Needed}; -/// # use winnow::prelude::*; -/// use winnow::combinator::separated0; -/// use winnow::token::tag; -/// -/// fn parser(s: &str) -> IResult<&str, Vec<&str>> { -/// separated0("abc", "|").parse_peek(s) -/// } -/// -/// assert_eq!(parser("abc|abc|abc"), Ok(("", vec!["abc", "abc", "abc"]))); -/// assert_eq!(parser("abc123abc"), Ok(("123abc", vec!["abc"]))); -/// assert_eq!(parser("abc|def"), Ok(("|def", vec!["abc"]))); -/// assert_eq!(parser(""), Ok(("", vec![]))); -/// assert_eq!(parser("def|abc"), Ok(("def|abc", vec![]))); -/// # } -/// ``` -#[doc(alias = "sep_by")] -#[doc(alias = "separated_list0")] -#[deprecated(since = "0.5.19", note = "Replaced with `combinator::separated`")] -pub fn separated0(mut parser: P, mut sep: S) -> impl Parser -where - I: Stream, - C: Accumulate, - P: Parser, - S: Parser, - E: ParserError, -{ - trace("separated0", move |i: &mut I| { - separated0_(&mut parser, &mut sep, i) - }) -} - fn separated0_( parser: &mut P, separator: &mut S, @@ -836,53 +777,6 @@ where } } -/// [`Accumulate`] the output of a parser, interleaved with `sep` -/// -/// Fails if the element parser does not produce at least one element.$ -/// -/// This stops when either parser returns [`ErrMode::Backtrack`]. To instead chain an error up, see -/// [`cut_err`][crate::combinator::cut_err]. -/// -/// # Arguments -/// * `sep` Parses the separator between list elements. -/// * `f` Parses the elements of the list. -/// -/// # Example -/// -/// ```rust -/// # #[cfg(feature = "std")] { -/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed}; -/// # use winnow::prelude::*; -/// use winnow::combinator::separated1; -/// use winnow::token::tag; -/// -/// fn parser(s: &str) -> IResult<&str, Vec<&str>> { -/// separated1("abc", "|").parse_peek(s) -/// } -/// -/// assert_eq!(parser("abc|abc|abc"), Ok(("", vec!["abc", "abc", "abc"]))); -/// assert_eq!(parser("abc123abc"), Ok(("123abc", vec!["abc"]))); -/// assert_eq!(parser("abc|def"), Ok(("|def", vec!["abc"]))); -/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag)))); -/// assert_eq!(parser("def|abc"), Err(ErrMode::Backtrack(InputError::new("def|abc", ErrorKind::Tag)))); -/// # } -/// ``` -#[doc(alias = "sep_by1")] -#[doc(alias = "separated_list1")] -#[deprecated(since = "0.5.19", note = "Replaced with `combinator::separated`")] -pub fn separated1(mut parser: P, mut sep: S) -> impl Parser -where - I: Stream, - C: Accumulate, - P: Parser, - S: Parser, - E: ParserError, -{ - trace("separated1", move |i: &mut I| { - separated1_(&mut parser, &mut sep, i) - }) -} - fn separated1_( parser: &mut P, separator: &mut S, @@ -1248,25 +1142,6 @@ where }) } -/// Deprecated, replaced with [`Repeat::fold`] -#[deprecated(since = "0.5.36", note = "Replaced with `repeat(...).fold(...)`")] -#[inline(always)] -pub fn fold_repeat( - range: impl Into, - f: F, - init: H, - g: G, -) -> impl Parser -where - I: Stream, - F: Parser, - G: FnMut(R, O) -> R, - H: FnMut() -> R, - E: ParserError, -{ - repeat(range, f).fold(init, g) -} - fn fold_repeat0_( f: &mut F, init: &mut H, diff --git a/src/error.rs b/src/error.rs index 3f280132..fc9dc859 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1036,113 +1036,6 @@ impl fmt::Display for TreeError } } -/// Deprecated, replaced with [`ContextError`] -#[cfg(feature = "std")] -#[allow(deprecated)] -#[deprecated(since = "0.5.8", note = "Replaced with `ContextError`")] -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct VerboseError { - /// Accumulated error information - pub errors: crate::lib::std::vec::Vec<(I, VerboseErrorKind)>, -} - -#[cfg(feature = "std")] -#[allow(deprecated)] -impl<'i, I: ToOwned, C> VerboseError<&'i I, C> -where - ::Owned: Clone, -{ - /// Obtaining ownership - pub fn into_owned(self) -> VerboseError<::Owned, C> { - self.map_input(ToOwned::to_owned) - } -} - -#[cfg(feature = "std")] -#[allow(deprecated)] -impl VerboseError { - /// Translate the input type - pub fn map_input(self, op: O) -> VerboseError - where - O: Fn(I) -> I2, - { - VerboseError { - errors: self.errors.into_iter().map(|(i, k)| (op(i), k)).collect(), - } - } -} - -/// Deprecated, replaced with [`ContextError`] -#[cfg(feature = "std")] -#[deprecated(since = "0.5.8", note = "Replaced with `ContextError`")] -#[derive(Clone, Debug, Eq, PartialEq)] -pub enum VerboseErrorKind { - /// Static string added by the `context` function - Context(C), - /// Error kind given by various parsers - Winnow(ErrorKind), -} - -#[cfg(feature = "std")] -#[allow(deprecated)] -impl ParserError for VerboseError { - fn from_error_kind(input: &I, kind: ErrorKind) -> Self { - VerboseError { - errors: vec![(input.clone(), VerboseErrorKind::Winnow(kind))], - } - } - - fn append(mut self, input: &I, kind: ErrorKind) -> Self { - self.errors - .push((input.clone(), VerboseErrorKind::Winnow(kind))); - self - } -} - -#[cfg(feature = "std")] -#[allow(deprecated)] -impl AddContext for VerboseError { - fn add_context(mut self, input: &I, ctx: C) -> Self { - self.errors - .push((input.clone(), VerboseErrorKind::Context(ctx))); - self - } -} - -#[cfg(feature = "std")] -#[allow(deprecated)] -impl FromExternalError for VerboseError { - /// Create a new error from an input position and an external error - fn from_external_error(input: &I, kind: ErrorKind, _e: E) -> Self { - Self::from_error_kind(input, kind) - } -} - -#[cfg(feature = "std")] -#[allow(deprecated)] -impl fmt::Display for VerboseError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - writeln!(f, "Parse error:")?; - for (input, error) in &self.errors { - match error { - VerboseErrorKind::Winnow(e) => writeln!(f, "{} at: {}", e.description(), input)?, - VerboseErrorKind::Context(s) => writeln!(f, "in section '{}', at: {}", s, input)?, - } - } - - Ok(()) - } -} - -#[cfg(feature = "std")] -#[allow(deprecated)] -impl< - I: Clone + fmt::Debug + fmt::Display + Sync + Send + 'static, - C: fmt::Display + fmt::Debug, - > std::error::Error for VerboseError -{ -} - /// Provide some minor debug context for errors #[rustfmt::skip] #[derive(Debug,PartialEq,Eq,Hash,Clone,Copy)] diff --git a/src/lib.rs b/src/lib.rs index 6dcbda5a..9b648a0f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -207,7 +207,6 @@ pub mod ascii; pub mod binary; pub mod combinator; pub mod token; -pub mod trace; #[cfg(feature = "unstable-doc")] pub mod _topic; diff --git a/src/parser.rs b/src/parser.rs index 1afa7e5e..434fcc57 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -97,19 +97,19 @@ pub trait Parser { /// # Example /// /// Because parsers are `FnMut`, they can be called multiple times. This prevents moving `f` - /// into [`length_data`][crate::binary::length_data] and `g` into + /// into [`length_take`][crate::binary::length_take] and `g` into /// [`Parser::complete_err`]: /// ```rust,compile_fail /// # use winnow::prelude::*; /// # use winnow::Parser; /// # use winnow::error::ParserError; - /// # use winnow::binary::length_data; + /// # use winnow::binary::length_take; /// pub fn length_value<'i, O, E: ParserError<&'i [u8]>>( /// mut f: impl Parser<&'i [u8], usize, E>, /// mut g: impl Parser<&'i [u8], O, E> /// ) -> impl Parser<&'i [u8], O, E> { /// move |i: &mut &'i [u8]| { - /// let mut data = length_data(f).parse_next(i)?; + /// let mut data = length_take(f).parse_next(i)?; /// let o = g.complete_err().parse_next(&mut data)?; /// Ok(o) /// } @@ -121,13 +121,13 @@ pub trait Parser { /// # use winnow::prelude::*; /// # use winnow::Parser; /// # use winnow::error::ParserError; - /// # use winnow::binary::length_data; + /// # use winnow::binary::length_take; /// pub fn length_value<'i, O, E: ParserError<&'i [u8]>>( /// mut f: impl Parser<&'i [u8], usize, E>, /// mut g: impl Parser<&'i [u8], O, E> /// ) -> impl Parser<&'i [u8], O, E> { /// move |i: &mut &'i [u8]| { - /// let mut data = length_data(f.by_ref()).parse_next(i)?; + /// let mut data = length_take(f.by_ref()).parse_next(i)?; /// let o = g.by_ref().complete_err().parse_next(&mut data)?; /// Ok(o) /// } @@ -492,12 +492,12 @@ pub trait Parser { /// use winnow::token::take; /// use winnow::binary::u8; /// - /// fn length_data<'s>(input: &mut &'s [u8]) -> PResult<&'s [u8], InputError<&'s [u8]>> { + /// fn length_take<'s>(input: &mut &'s [u8]) -> PResult<&'s [u8], InputError<&'s [u8]>> { /// u8.flat_map(take).parse_next(input) /// } /// - /// assert_eq!(length_data.parse_peek(&[2, 0, 1, 2][..]), Ok((&[2][..], &[0, 1][..]))); - /// assert_eq!(length_data.parse_peek(&[4, 0, 1, 2][..]), Err(ErrMode::Backtrack(InputError::new(&[0, 1, 2][..], ErrorKind::Slice)))); + /// assert_eq!(length_take.parse_peek(&[2, 0, 1, 2][..]), Ok((&[2][..], &[0, 1][..]))); + /// assert_eq!(length_take.parse_peek(&[4, 0, 1, 2][..]), Err(ErrMode::Backtrack(InputError::new(&[0, 1, 2][..], ErrorKind::Slice)))); /// ``` /// /// which is the same as @@ -506,14 +506,14 @@ pub trait Parser { /// use winnow::token::take; /// use winnow::binary::u8; /// - /// fn length_data<'s>(input: &mut &'s [u8]) -> PResult<&'s [u8], InputError<&'s [u8]>> { + /// fn length_take<'s>(input: &mut &'s [u8]) -> PResult<&'s [u8], InputError<&'s [u8]>> { /// let length = u8.parse_next(input)?; /// let data = take(length).parse_next(input)?; /// Ok(data) /// } /// - /// assert_eq!(length_data.parse_peek(&[2, 0, 1, 2][..]), Ok((&[2][..], &[0, 1][..]))); - /// assert_eq!(length_data.parse_peek(&[4, 0, 1, 2][..]), Err(ErrMode::Backtrack(InputError::new(&[0, 1, 2][..], ErrorKind::Slice)))); + /// assert_eq!(length_take.parse_peek(&[2, 0, 1, 2][..]), Ok((&[2][..], &[0, 1][..]))); + /// assert_eq!(length_take.parse_peek(&[4, 0, 1, 2][..]), Err(ErrMode::Backtrack(InputError::new(&[0, 1, 2][..], ErrorKind::Slice)))); /// ``` #[inline(always)] fn flat_map(self, map: G) -> FlatMap diff --git a/src/stream/mod.rs b/src/stream/mod.rs index 6f625849..a587487b 100644 --- a/src/stream/mod.rs +++ b/src/stream/mod.rs @@ -2059,15 +2059,6 @@ pub enum CompareResult { pub trait Compare { /// Compares self to another value for equality fn compare(&self, t: T) -> CompareResult; - /// Compares self to another value for equality - /// independently of the case. - /// - /// Warning: for `&str`, the comparison is done - /// by lowercasing both strings and comparing - /// the result. This is a temporary solution until - /// a better one appears - #[deprecated(since = "0.5.20", note = "Replaced with `compare(ascii::Caseless(_))`")] - fn compare_no_case(&self, t: T) -> CompareResult; } impl<'a, 'b> Compare<&'b [u8]> for &'a [u8] { @@ -2081,12 +2072,6 @@ impl<'a, 'b> Compare<&'b [u8]> for &'a [u8] { CompareResult::Ok } } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: &'b [u8]) -> CompareResult { - self.compare(AsciiCaseless(t)) - } } impl<'a, 'b> Compare> for &'a [u8] { @@ -2104,12 +2089,6 @@ impl<'a, 'b> Compare> for &'a [u8] { CompareResult::Ok } } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: AsciiCaseless<&'b [u8]>) -> CompareResult { - self.compare(t) - } } impl<'a, const LEN: usize> Compare<[u8; LEN]> for &'a [u8] { @@ -2117,12 +2096,6 @@ impl<'a, const LEN: usize> Compare<[u8; LEN]> for &'a [u8] { fn compare(&self, t: [u8; LEN]) -> CompareResult { self.compare(&t[..]) } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: [u8; LEN]) -> CompareResult { - self.compare_no_case(&t[..]) - } } impl<'a, const LEN: usize> Compare> for &'a [u8] { @@ -2130,12 +2103,6 @@ impl<'a, const LEN: usize> Compare> for &'a [u8] { fn compare(&self, t: AsciiCaseless<[u8; LEN]>) -> CompareResult { self.compare(AsciiCaseless(&t.0[..])) } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: AsciiCaseless<[u8; LEN]>) -> CompareResult { - self.compare_no_case(AsciiCaseless(&t.0[..])) - } } impl<'a, 'b, const LEN: usize> Compare<&'b [u8; LEN]> for &'a [u8] { @@ -2143,12 +2110,6 @@ impl<'a, 'b, const LEN: usize> Compare<&'b [u8; LEN]> for &'a [u8] { fn compare(&self, t: &'b [u8; LEN]) -> CompareResult { self.compare(&t[..]) } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: &'b [u8; LEN]) -> CompareResult { - self.compare_no_case(&t[..]) - } } impl<'a, 'b, const LEN: usize> Compare> for &'a [u8] { @@ -2156,12 +2117,6 @@ impl<'a, 'b, const LEN: usize> Compare> for &'a [u8 fn compare(&self, t: AsciiCaseless<&'b [u8; LEN]>) -> CompareResult { self.compare(AsciiCaseless(&t.0[..])) } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: AsciiCaseless<&'b [u8; LEN]>) -> CompareResult { - self.compare_no_case(AsciiCaseless(&t.0[..])) - } } impl<'a, 'b> Compare<&'b str> for &'a [u8] { @@ -2169,11 +2124,6 @@ impl<'a, 'b> Compare<&'b str> for &'a [u8] { fn compare(&self, t: &'b str) -> CompareResult { self.compare(t.as_bytes()) } - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: &'b str) -> CompareResult { - self.compare_no_case(t.as_bytes()) - } } impl<'a, 'b> Compare> for &'a [u8] { @@ -2181,11 +2131,6 @@ impl<'a, 'b> Compare> for &'a [u8] { fn compare(&self, t: AsciiCaseless<&'b str>) -> CompareResult { self.compare(AsciiCaseless(t.0.as_bytes())) } - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: AsciiCaseless<&'b str>) -> CompareResult { - self.compare_no_case(AsciiCaseless(t.0.as_bytes())) - } } impl<'a> Compare for &'a [u8] { @@ -2193,12 +2138,6 @@ impl<'a> Compare for &'a [u8] { fn compare(&self, t: char) -> CompareResult { self.compare(t.encode_utf8(&mut [0; 4]).as_bytes()) } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: char) -> CompareResult { - self.compare_no_case(t.encode_utf8(&mut [0; 4]).as_bytes()) - } } impl<'a> Compare> for &'a [u8] { @@ -2206,12 +2145,6 @@ impl<'a> Compare> for &'a [u8] { fn compare(&self, t: AsciiCaseless) -> CompareResult { self.compare(AsciiCaseless(t.0.encode_utf8(&mut [0; 4]).as_bytes())) } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: AsciiCaseless) -> CompareResult { - self.compare_no_case(AsciiCaseless(t.0.encode_utf8(&mut [0; 4]).as_bytes())) - } } impl<'a, 'b> Compare<&'b str> for &'a str { @@ -2219,12 +2152,6 @@ impl<'a, 'b> Compare<&'b str> for &'a str { fn compare(&self, t: &'b str) -> CompareResult { self.as_bytes().compare(t.as_bytes()) } - - #[inline] - #[allow(deprecated)] - fn compare_no_case(&self, t: &'b str) -> CompareResult { - self.compare(AsciiCaseless(t)) - } } impl<'a, 'b> Compare> for &'a str { @@ -2232,12 +2159,6 @@ impl<'a, 'b> Compare> for &'a str { fn compare(&self, t: AsciiCaseless<&'b str>) -> CompareResult { self.as_bytes().compare(t.as_bytes()) } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: AsciiCaseless<&'b str>) -> CompareResult { - self.compare(t) - } } impl<'a> Compare for &'a str { @@ -2245,12 +2166,6 @@ impl<'a> Compare for &'a str { fn compare(&self, t: char) -> CompareResult { self.compare(t.encode_utf8(&mut [0; 4]).as_bytes()) } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: char) -> CompareResult { - self.compare_no_case(t.encode_utf8(&mut [0; 4]).as_bytes()) - } } impl<'a> Compare> for &'a str { @@ -2258,12 +2173,6 @@ impl<'a> Compare> for &'a str { fn compare(&self, t: AsciiCaseless) -> CompareResult { self.compare(AsciiCaseless(t.0.encode_utf8(&mut [0; 4]).as_bytes())) } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: AsciiCaseless) -> CompareResult { - self.compare_no_case(AsciiCaseless(t.0.encode_utf8(&mut [0; 4]).as_bytes())) - } } impl<'a, 'b> Compare<&'b [u8]> for &'a str { @@ -2271,11 +2180,6 @@ impl<'a, 'b> Compare<&'b [u8]> for &'a str { fn compare(&self, t: &'b [u8]) -> CompareResult { AsBStr::as_bstr(self).compare(t) } - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: &'b [u8]) -> CompareResult { - AsBStr::as_bstr(self).compare_no_case(t) - } } impl<'a, 'b> Compare> for &'a str { @@ -2283,11 +2187,6 @@ impl<'a, 'b> Compare> for &'a str { fn compare(&self, t: AsciiCaseless<&'b [u8]>) -> CompareResult { AsBStr::as_bstr(self).compare(t) } - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: AsciiCaseless<&'b [u8]>) -> CompareResult { - AsBStr::as_bstr(self).compare_no_case(t) - } } impl<'a, T> Compare for &'a Bytes @@ -2299,13 +2198,6 @@ where let bytes = (*self).as_bytes(); bytes.compare(t) } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: T) -> CompareResult { - let bytes = (*self).as_bytes(); - bytes.compare_no_case(t) - } } impl<'a, T> Compare for &'a BStr @@ -2317,13 +2209,6 @@ where let bytes = (*self).as_bytes(); bytes.compare(t) } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: T) -> CompareResult { - let bytes = (*self).as_bytes(); - bytes.compare_no_case(t) - } } impl Compare for Located @@ -2334,12 +2219,6 @@ where fn compare(&self, other: U) -> CompareResult { self.input.compare(other) } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, other: U) -> CompareResult { - self.input.compare_no_case(other) - } } #[cfg(feature = "unstable-recover")] @@ -2352,12 +2231,6 @@ where fn compare(&self, other: U) -> CompareResult { self.input.compare(other) } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, other: U) -> CompareResult { - self.input.compare_no_case(other) - } } impl Compare for Stateful @@ -2368,12 +2241,6 @@ where fn compare(&self, other: U) -> CompareResult { self.input.compare(other) } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, other: U) -> CompareResult { - self.input.compare_no_case(other) - } } impl Compare for Partial @@ -2384,12 +2251,6 @@ where fn compare(&self, t: T) -> CompareResult { self.input.compare(t) } - - #[inline(always)] - #[allow(deprecated)] - fn compare_no_case(&self, t: T) -> CompareResult { - self.input.compare_no_case(t) - } } /// Look for a slice in self diff --git a/src/token/mod.rs b/src/token/mod.rs index 86415157..6a77ad38 100644 --- a/src/token/mod.rs +++ b/src/token/mod.rs @@ -173,94 +173,6 @@ where } } -/// Recognizes a case insensitive literal. -/// -/// The input data will be compared to the tag combinator's argument and will return the part of -/// the input that matches the argument with no regard to case. -/// -/// It will return `Err(ErrMode::Backtrack(InputError::new(_, ErrorKind::Tag)))` if the input doesn't match the pattern. -/// -/// # Example -/// -/// ```rust -/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed}; -/// # use winnow::prelude::*; -/// use winnow::token::tag_no_case; -/// -/// fn parser(s: &str) -> IResult<&str, &str> { -/// tag_no_case("hello").parse_peek(s) -/// } -/// -/// assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello"))); -/// assert_eq!(parser("hello, World!"), Ok((", World!", "hello"))); -/// assert_eq!(parser("HeLlO, World!"), Ok((", World!", "HeLlO"))); -/// assert_eq!(parser("Something"), Err(ErrMode::Backtrack(InputError::new("Something", ErrorKind::Tag)))); -/// assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag)))); -/// ``` -/// -/// ```rust -/// # use winnow::{error::ErrMode, error::{InputError, ErrorKind}, error::Needed}; -/// # use winnow::prelude::*; -/// # use winnow::Partial; -/// use winnow::token::tag_no_case; -/// -/// fn parser(s: Partial<&str>) -> IResult, &str> { -/// tag_no_case("hello").parse_peek(s) -/// } -/// -/// assert_eq!(parser(Partial::new("Hello, World!")), Ok((Partial::new(", World!"), "Hello"))); -/// assert_eq!(parser(Partial::new("hello, World!")), Ok((Partial::new(", World!"), "hello"))); -/// assert_eq!(parser(Partial::new("HeLlO, World!")), Ok((Partial::new(", World!"), "HeLlO"))); -/// assert_eq!(parser(Partial::new("Something")), Err(ErrMode::Backtrack(InputError::new(Partial::new("Something"), ErrorKind::Tag)))); -/// assert_eq!(parser(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(5)))); -/// ``` -#[inline(always)] -#[doc(alias = "literal")] -#[doc(alias = "bytes")] -#[doc(alias = "just")] -#[deprecated(since = "0.5.20", note = "Replaced with `tag(ascii::Caseless(_))`")] -pub fn tag_no_case>( - tag: T, -) -> impl Parser::Slice, Error> -where - I: StreamIsPartial, - I: Stream + Compare, - T: SliceLen + Clone, -{ - trace("tag_no_case", move |i: &mut I| { - let t = tag.clone(); - if ::is_partial_supported() { - tag_no_case_::<_, _, _, true>(i, t) - } else { - tag_no_case_::<_, _, _, false>(i, t) - } - }) -} - -#[allow(deprecated)] -fn tag_no_case_, const PARTIAL: bool>( - i: &mut I, - t: T, -) -> PResult<::Slice, Error> -where - I: StreamIsPartial, - I: Stream + Compare, - T: SliceLen, -{ - let tag_len = t.slice_len(); - - match i.compare_no_case(t) { - CompareResult::Ok => Ok(i.next_slice(tag_len)), - CompareResult::Incomplete if PARTIAL && i.is_partial() => { - Err(ErrMode::Incomplete(Needed::new(tag_len - i.eof_offset()))) - } - CompareResult::Incomplete | CompareResult::Error => { - let e: ErrorKind = ErrorKind::Tag; - Err(ErrMode::from_error_kind(i, e)) - } - } -} - /// Recognize a token that matches the [pattern][ContainsToken] /// /// **Note:** [`Parser`] is implemented as a convenience (complete diff --git a/src/trace.rs b/src/trace.rs deleted file mode 100644 index 9c055765..00000000 --- a/src/trace.rs +++ /dev/null @@ -1,11 +0,0 @@ -//! Deprecated, replaced with [`winnow::combinator`][crate::combinator] - -/// Deprecated, replaced with [`winnow::combinator::trace`][crate::combinator::trace] -#[deprecated(since = "0.5.35", note = "Replaced with `winnow::combinator::trace`")] -#[inline(always)] -pub fn trace( - name: impl crate::lib::std::fmt::Display, - parser: impl crate::Parser, -) -> impl crate::Parser { - crate::combinator::trace(name, parser) -}