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: Clarify naming #239

Merged
merged 12 commits into from
Apr 27, 2023
8 changes: 4 additions & 4 deletions benches/contains_token.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use criterion::black_box;

use winnow::branch::alt;
use winnow::bytes::take_till1;
use winnow::bytes::take_while1;
use winnow::multi::many0;
use winnow::combinator::alt;
use winnow::combinator::many0;
use winnow::prelude::*;
use winnow::token::take_till1;
use winnow::token::take_while1;

fn contains_token(c: &mut criterion::Criterion) {
let data = [
Expand Down
4 changes: 2 additions & 2 deletions benches/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ extern crate criterion;

use criterion::Criterion;

use winnow::character::float;
use winnow::ascii::float;
use winnow::binary::be_u64;
use winnow::error::ErrMode;
use winnow::error::Error;
use winnow::error::ErrorKind;
use winnow::number::be_u64;
use winnow::prelude::*;
use winnow::stream::ParseSlice;

Expand Down
12 changes: 6 additions & 6 deletions examples/arithmetic/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::str::FromStr;

use winnow::prelude::*;
use winnow::{
branch::alt,
bytes::one_of,
character::{digit1 as digits, space0 as spaces},
multi::fold_many0,
sequence::delimited,
ascii::{digit1 as digits, space0 as spaces},
combinator::alt,
combinator::delimited,
combinator::fold_many0,
token::one_of,
IResult,
};

Expand Down Expand Up @@ -57,7 +57,7 @@ fn factor(i: &str) -> IResult<&str, i64> {
delimited(
spaces,
alt((
digits.map_res(FromStr::from_str),
digits.try_map(FromStr::from_str),
delimited('(', expr, ')'),
parens,
)),
Expand Down
10 changes: 5 additions & 5 deletions examples/arithmetic/parser_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::str::FromStr;

use winnow::prelude::*;
use winnow::{
branch::alt,
character::{digit1 as digit, multispace0 as multispace},
multi::many0,
sequence::{delimited, preceded},
ascii::{digit1 as digit, multispace0 as multispace},
combinator::alt,
combinator::many0,
combinator::{delimited, preceded},
IResult,
};

Expand Down Expand Up @@ -81,7 +81,7 @@ fn term(i: &str) -> IResult<&str, Expr> {
fn factor(i: &str) -> IResult<&str, Expr> {
alt((
delimited(multispace, digit, multispace)
.map_res(FromStr::from_str)
.try_map(FromStr::from_str)
.map(Expr::Value),
parens,
))
Expand Down
4 changes: 2 additions & 2 deletions examples/css/parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use winnow::bytes::take_while_m_n;
use winnow::prelude::*;
use winnow::token::take_while_m_n;

#[derive(Debug, Eq, PartialEq)]
pub struct Color {
Expand All @@ -26,6 +26,6 @@ pub fn hex_color(input: &str) -> IResult<&str, Color> {

fn hex_primary(input: &str) -> IResult<&str, u8> {
take_while_m_n(2, 2, |c: char| c.is_ascii_hexdigit())
.map_res(|input| u8::from_str_radix(input, 16))
.try_map(|input| u8::from_str_radix(input, 16))
.parse_next(input)
}
2 changes: 1 addition & 1 deletion examples/http/parser.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use winnow::{bytes::take_while1, character::line_ending, multi::many1, IResult, Parser};
use winnow::{ascii::line_ending, combinator::many1, token::take_while1, IResult, Parser};

pub type Stream<'i> = &'i [u8];

Expand Down
2 changes: 1 addition & 1 deletion examples/http/parser_streaming.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use winnow::{
bytes::take_while1, character::line_ending, multi::many1, stream::Partial, IResult, Parser,
ascii::line_ending, combinator::many1, stream::Partial, token::take_while1, IResult, Parser,
};

pub type Stream<'i> = Partial<&'i [u8]>;
Expand Down
2 changes: 1 addition & 1 deletion examples/ini/bench.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use winnow::multi::many0;
use winnow::combinator::many0;
use winnow::prelude::*;

mod parser;
Expand Down
14 changes: 7 additions & 7 deletions examples/ini/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::str;

use winnow::prelude::*;
use winnow::{
bytes::take_while0,
character::{alphanumeric1 as alphanumeric, multispace0 as multispace, space0 as space},
ascii::{alphanumeric1 as alphanumeric, multispace0 as multispace, space0 as space},
combinator::many0,
combinator::opt,
multi::many0,
sequence::{delimited, separated_pair, terminated},
combinator::{delimited, separated_pair, terminated},
token::take_while0,
};

pub type Stream<'i> = &'i [u8];
Expand All @@ -23,15 +23,15 @@ pub fn categories(i: Stream<'_>) -> IResult<Stream<'_>, HashMap<&str, HashMap<&s

fn category(i: Stream<'_>) -> IResult<Stream<'_>, &str> {
delimited('[', take_while0(|c| c != b']'), ']')
.map_res(str::from_utf8)
.try_map(str::from_utf8)
.parse_next(i)
}

pub fn key_value(i: Stream<'_>) -> IResult<Stream<'_>, (&str, &str)> {
let (i, key) = alphanumeric.map_res(str::from_utf8).parse_next(i)?;
let (i, key) = alphanumeric.try_map(str::from_utf8).parse_next(i)?;
let (i, _) = (opt(space), '=', opt(space)).parse_next(i)?;
let (i, val) = take_while0(|c| c != b'\n' && c != b';')
.map_res(str::from_utf8)
.try_map(str::from_utf8)
.parse_next(i)?;
let (i, _) = opt((';', take_while0(|c| c != b'\n'))).parse_next(i)?;
Ok((i, (key, val)))
Expand Down
8 changes: 4 additions & 4 deletions examples/ini/parser_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::collections::HashMap;

use winnow::prelude::*;
use winnow::{
bytes::{take_till0, take_while0, take_while1},
character::{alphanumeric1 as alphanumeric, space0 as space},
ascii::{alphanumeric1 as alphanumeric, space0 as space},
combinator::many0,
combinator::opt,
multi::many0,
sequence::{delimited, terminated},
combinator::{delimited, terminated},
token::{take_till0, take_while0, take_while1},
};

pub type Stream<'i> = &'i str;
Expand Down
4 changes: 2 additions & 2 deletions examples/iterator.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::collections::HashMap;
use std::iter::Iterator;

use winnow::character::alphanumeric1;
use winnow::ascii::alphanumeric1;
use winnow::combinator::iterator;
use winnow::combinator::{separated_pair, terminated};
use winnow::prelude::*;
use winnow::sequence::{separated_pair, terminated};

fn main() {
let mut data = "abcabcabcabc";
Expand Down
10 changes: 5 additions & 5 deletions examples/json/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::str;

use winnow::prelude::*;
use winnow::{
branch::alt,
bytes::{any, none_of, take, take_while0},
character::float,
ascii::float,
combinator::alt,
combinator::cut_err,
combinator::{delimited, preceded, separated_pair, terminated},
combinator::{fold_many0, separated0},
error::{ContextError, ParseError},
multi::{fold_many0, separated0},
sequence::{delimited, preceded, separated_pair, terminated},
token::{any, none_of, take, take_while0},
};

use crate::json::JsonValue;
Expand Down
10 changes: 5 additions & 5 deletions examples/json/parser_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ use std::str;

use winnow::prelude::*;
use winnow::{
branch::{alt, dispatch},
bytes::{any, none_of, take, take_while0},
character::float,
ascii::float,
combinator::cut_err,
combinator::fail,
combinator::peek,
combinator::success,
combinator::{alt, dispatch},
combinator::{delimited, preceded, separated_pair, terminated},
combinator::{fold_many0, separated0},
error::{ContextError, ParseError},
multi::{fold_many0, separated0},
sequence::{delimited, preceded, separated_pair, terminated},
token::{any, none_of, take, take_while0},
};

use crate::json::JsonValue;
Expand Down
10 changes: 5 additions & 5 deletions examples/json/parser_partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use std::str;

use winnow::prelude::*;
use winnow::{
branch::alt,
bytes::{any, none_of, take, take_while0},
character::float,
ascii::float,
combinator::alt,
combinator::{cut_err, rest},
combinator::{delimited, preceded, separated_pair, terminated},
combinator::{fold_many0, separated0},
error::{ContextError, ParseError},
multi::{fold_many0, separated0},
sequence::{delimited, preceded, separated_pair, terminated},
stream::Partial,
token::{any, none_of, take, take_while0},
};

use crate::json::JsonValue;
Expand Down
12 changes: 6 additions & 6 deletions examples/json_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use std::collections::HashMap;

use winnow::prelude::*;
use winnow::{
branch::alt,
bytes::one_of,
bytes::{tag, take_while0},
character::{alphanumeric1 as alphanumeric, escaped, float},
ascii::{alphanumeric1 as alphanumeric, escaped, float},
combinator::alt,
combinator::cut_err,
combinator::separated0,
combinator::{preceded, separated_pair, terminated},
error::ParseError,
multi::separated0,
sequence::{preceded, separated_pair, terminated},
token::one_of,
token::{tag, take_while0},
IResult,
};

Expand Down
12 changes: 6 additions & 6 deletions examples/ndjson/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use std::str;

use winnow::prelude::*;
use winnow::{
branch::alt,
bytes::{any, none_of, take, take_while0},
character::float,
character::line_ending,
ascii::float,
ascii::line_ending,
combinator::alt,
combinator::cut_err,
combinator::{delimited, preceded, separated_pair, terminated},
combinator::{fold_many0, separated0},
error::{ContextError, ParseError},
multi::{fold_many0, separated0},
sequence::{delimited, preceded, separated_pair, terminated},
stream::Partial,
token::{any, none_of, take, take_while0},
};

#[derive(Debug, PartialEq, Clone)]
Expand Down
12 changes: 6 additions & 6 deletions examples/s_expression/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
//! Lisp is a simple type of language made up of Atoms and Lists, forming easily parsable trees.

use winnow::{
branch::alt,
bytes::one_of,
character::{alpha1, digit1, multispace0, multispace1},
ascii::{alpha1, digit1, multispace0, multispace1},
combinator::alt,
combinator::many0,
combinator::{cut_err, opt},
combinator::{delimited, preceded, terminated},
error::VerboseError,
multi::many0,
sequence::{delimited, preceded, terminated},
token::one_of,
IResult, Parser,
};

Expand Down Expand Up @@ -97,7 +97,7 @@ fn parse_atom(i: &str) -> IResult<&str, Atom, VerboseError<&str>> {
/// of digits but ending the program if it doesn't fit into an i32.
fn parse_num(i: &str) -> IResult<&str, Atom, VerboseError<&str>> {
alt((
digit1.map_res(|digit_str: &str| digit_str.parse::<i32>().map(Atom::Num)),
digit1.try_map(|digit_str: &str| digit_str.parse::<i32>().map(Atom::Num)),
preceded("-", digit1).map(|digit_str: &str| Atom::Num(-digit_str.parse::<i32>().unwrap())),
))
.parse_next(i)
Expand Down
16 changes: 8 additions & 8 deletions examples/string/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
//! - an escape followed by whitespace consumes all whitespace between the
//! escape and the next non-whitespace character

use winnow::branch::alt;
use winnow::bytes::{take_till1, take_while_m_n};
use winnow::character::multispace1;
use winnow::ascii::multispace1;
use winnow::combinator::alt;
use winnow::combinator::fold_many0;
use winnow::combinator::{delimited, preceded};
use winnow::error::{FromExternalError, ParseError};
use winnow::multi::fold_many0;
use winnow::prelude::*;
use winnow::sequence::{delimited, preceded};
use winnow::token::{take_till1, take_while_m_n};

/// Parse a string. Use a loop of `parse_fragment` and push all of the fragments
/// into an output string.
Expand Down Expand Up @@ -143,12 +143,12 @@ where
delimited('{', parse_hex, '}'),
);

// `map_res` takes the result of a parser and applies a function that returns
// `try_map` takes the result of a parser and applies a function that returns
// a Result. In this case we take the hex bytes from parse_hex and attempt to
// convert them to a u32.
let parse_u32 = parse_delimited_hex.map_res(move |hex| u32::from_str_radix(hex, 16));
let parse_u32 = parse_delimited_hex.try_map(move |hex| u32::from_str_radix(hex, 16));

// verify_map is like map_res, but it takes an Option instead of a Result. If
// verify_map is like try_map, but it takes an Option instead of a Result. If
// the function returns None, verify_map returns an error. In this case, because
// not all u32 values are valid unicode code points, we have to fallibly
// convert to char with from_u32.
Expand Down
9 changes: 4 additions & 5 deletions fuzz/fuzz_targets/fuzz_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use std::str;

use winnow::prelude::*;
use winnow::{
branch::alt,
bytes::tag,
character::{digit1 as digit, space0 as space},
multi::fold_many0,
sequence::{delimited, terminated},
ascii::{digit1 as digit, space0 as space},
combinator::alt,
combinator::fold_many0,
combinator::{delimited, terminated},
};

use std::cell::RefCell;
Expand Down