Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Remove deprecated functionality #447

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 29 additions & 31 deletions fuzz/fuzz_targets/fuzz_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand Down Expand Up @@ -65,24 +65,23 @@ fn term(i: &mut &str) -> PResult<i64> {
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
Expand All @@ -95,19 +94,18 @@ fn expr(i: &mut &str) -> PResult<i64> {
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
Expand Down
7 changes: 4 additions & 3 deletions src/_topic/why.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -98,4 +98,5 @@

#![allow(unused_imports)]
use crate::binary::length_take;
use crate::combinator::trace;
use crate::stream::Accumulate;
22 changes: 5 additions & 17 deletions src/ascii/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
I: Compare<&'static str>,
<I as Stream>::Token: AsChar + Clone,
{
till_line_ending(input)
}

fn till_line_ending_<I, E: ParserError<I>, const PARTIAL: bool>(
input: &mut I,
) -> PResult<<I as Stream>::Slice, E>
Expand Down Expand Up @@ -1351,6 +1338,7 @@ where
I: StreamIsPartial,
I: Stream,
I: Compare<&'static str>,
I: Compare<Caseless<&'static str>>,
<I as Stream>::Slice: ParseSlice<O>,
<I as Stream>::Token: AsChar + Clone,
<I as Stream>::IterOffsets: Clone,
Expand All @@ -1365,27 +1353,27 @@ where
}

#[allow(clippy::trait_duplication_in_bounds)] // HACK: clippy 1.64.0 bug
#[allow(deprecated)]
fn recognize_float_or_exceptions<I, E: ParserError<I>>(
input: &mut I,
) -> PResult<<I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
I: Compare<&'static str>,
I: Compare<Caseless<&'static str>>,
<I as Stream>::Token: AsChar + Clone,
<I as Stream>::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)
}
Expand Down
45 changes: 2 additions & 43 deletions src/binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<I, N, E, F>(f: F) -> impl Parser<I, <I as Stream>::Slice, E>
where
I: StreamIsPartial,
I: Stream,
N: ToUsize,
F: Parser<I, N, E>,
E: ParserError<I>,
{
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.
Expand Down Expand Up @@ -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<I, O, N, E, F, G>(f: F, g: G) -> impl Parser<I, O, E>
where
I: StreamIsPartial,
I: Stream + UpdateSlice + Clone,
N: ToUsize,
F: Parser<I, N, E>,
G: Parser<I, O, E>,
E: ParserError<I>,
{
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`]
Expand All @@ -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;
Expand All @@ -2550,7 +2523,7 @@ where
/// }
///
/// fn parser(s: Stream<'_>) -> IResult<Stream<'_>, Vec<&[u8]>> {
/// length_count(u8.map(|i| {
/// length_repeat(u8.map(|i| {
/// println!("got number: {}", i);
/// i
/// }), "abc").parse_peek(s)
Expand All @@ -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<I, O, C, N, E, F, G>(f: F, g: G) -> impl Parser<I, C, E>
where
I: Stream,
N: ToUsize,
C: Accumulate<O>,
F: Parser<I, N, E>,
G: Parser<I, O, E>,
E: ParserError<I>,
{
length_repeat(f, g)
}
6 changes: 0 additions & 6 deletions src/combinator/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,6 @@ pub fn empty<I: Stream, E: ParserError<I>>(_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<I: Stream, O: Clone, E: ParserError<I>>(val: O) -> impl Parser<I, O, E> {
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
Expand Down
10 changes: 5 additions & 5 deletions src/combinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand Down Expand Up @@ -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
//!
Expand Down Expand Up @@ -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
//!
Expand Down
Loading
Loading