summaryrefslogtreecommitdiffstats
path: root/vendor/winnow/examples
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/winnow/examples
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/winnow/examples')
-rw-r--r--vendor/winnow/examples/arithmetic/parser.rs18
-rw-r--r--vendor/winnow/examples/arithmetic/parser_ast.rs56
-rw-r--r--vendor/winnow/examples/css/parser.rs6
-rw-r--r--vendor/winnow/examples/http/parser.rs22
-rw-r--r--vendor/winnow/examples/http/parser_streaming.rs22
-rw-r--r--vendor/winnow/examples/ini/bench.rs4
-rw-r--r--vendor/winnow/examples/ini/parser.rs33
-rw-r--r--vendor/winnow/examples/ini/parser_str.rs20
-rw-r--r--vendor/winnow/examples/iterator.rs4
-rw-r--r--vendor/winnow/examples/json/parser.rs16
-rw-r--r--vendor/winnow/examples/json/parser_dispatch.rs16
-rw-r--r--vendor/winnow/examples/json/parser_partial.rs16
-rw-r--r--vendor/winnow/examples/json_iterator.rs14
-rw-r--r--vendor/winnow/examples/ndjson/parser.rs18
-rw-r--r--vendor/winnow/examples/s_expression/parser.rs20
-rw-r--r--vendor/winnow/examples/string/parser.rs27
16 files changed, 162 insertions, 150 deletions
diff --git a/vendor/winnow/examples/arithmetic/parser.rs b/vendor/winnow/examples/arithmetic/parser.rs
index 346c501dc..ba6347a43 100644
--- a/vendor/winnow/examples/arithmetic/parser.rs
+++ b/vendor/winnow/examples/arithmetic/parser.rs
@@ -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_repeat,
+ token::one_of,
IResult,
};
@@ -15,7 +15,8 @@ use winnow::{
pub fn expr(i: &str) -> IResult<&str, i64> {
let (i, init) = term(i)?;
- fold_many0(
+ fold_repeat(
+ 0..,
(one_of("+-"), term),
move || init,
|acc, (op, val): (char, i64)| {
@@ -35,7 +36,8 @@ pub fn expr(i: &str) -> IResult<&str, i64> {
fn term(i: &str) -> IResult<&str, i64> {
let (i, init) = factor(i)?;
- fold_many0(
+ fold_repeat(
+ 0..,
(one_of("*/"), factor),
move || init,
|acc, (op, val): (char, i64)| {
@@ -57,7 +59,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,
)),
diff --git a/vendor/winnow/examples/arithmetic/parser_ast.rs b/vendor/winnow/examples/arithmetic/parser_ast.rs
index 6ae8c9bd3..fcf897e34 100644
--- a/vendor/winnow/examples/arithmetic/parser_ast.rs
+++ b/vendor/winnow/examples/arithmetic/parser_ast.rs
@@ -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::repeat,
+ combinator::{delimited, preceded},
IResult,
};
@@ -46,16 +46,19 @@ impl Display for Expr {
pub fn expr(i: &str) -> IResult<&str, Expr> {
let (i, initial) = term(i)?;
- let (i, remainder) = many0(alt((
- |i| {
- let (i, add) = preceded("+", term).parse_next(i)?;
- Ok((i, (Oper::Add, add)))
- },
- |i| {
- let (i, sub) = preceded("-", term).parse_next(i)?;
- Ok((i, (Oper::Sub, sub)))
- },
- )))
+ let (i, remainder) = repeat(
+ 0..,
+ alt((
+ |i| {
+ let (i, add) = preceded("+", term).parse_next(i)?;
+ Ok((i, (Oper::Add, add)))
+ },
+ |i| {
+ let (i, sub) = preceded("-", term).parse_next(i)?;
+ Ok((i, (Oper::Sub, sub)))
+ },
+ )),
+ )
.parse_next(i)?;
Ok((i, fold_exprs(initial, remainder)))
@@ -63,16 +66,19 @@ pub fn expr(i: &str) -> IResult<&str, Expr> {
fn term(i: &str) -> IResult<&str, Expr> {
let (i, initial) = factor(i)?;
- let (i, remainder) = many0(alt((
- |i| {
- let (i, mul) = preceded("*", factor).parse_next(i)?;
- Ok((i, (Oper::Mul, mul)))
- },
- |i| {
- let (i, div) = preceded("/", factor).parse_next(i)?;
- Ok((i, (Oper::Div, div)))
- },
- )))
+ let (i, remainder) = repeat(
+ 0..,
+ alt((
+ |i| {
+ let (i, mul) = preceded("*", factor).parse_next(i)?;
+ Ok((i, (Oper::Mul, mul)))
+ },
+ |i| {
+ let (i, div) = preceded("/", factor).parse_next(i)?;
+ Ok((i, (Oper::Div, div)))
+ },
+ )),
+ )
.parse_next(i)?;
Ok((i, fold_exprs(initial, remainder)))
@@ -81,7 +87,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,
))
diff --git a/vendor/winnow/examples/css/parser.rs b/vendor/winnow/examples/css/parser.rs
index e39b0f524..9b3238e2e 100644
--- a/vendor/winnow/examples/css/parser.rs
+++ b/vendor/winnow/examples/css/parser.rs
@@ -1,5 +1,5 @@
-use winnow::bytes::take_while_m_n;
use winnow::prelude::*;
+use winnow::token::take_while;
#[derive(Debug, Eq, PartialEq)]
pub struct Color {
@@ -25,7 +25,7 @@ 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))
+ take_while(2, |c: char| c.is_ascii_hexdigit())
+ .try_map(|input| u8::from_str_radix(input, 16))
.parse_next(input)
}
diff --git a/vendor/winnow/examples/http/parser.rs b/vendor/winnow/examples/http/parser.rs
index 83402fe26..f03b77eb7 100644
--- a/vendor/winnow/examples/http/parser.rs
+++ b/vendor/winnow/examples/http/parser.rs
@@ -1,4 +1,4 @@
-use winnow::{bytes::take_while1, character::line_ending, multi::many1, IResult, Parser};
+use winnow::{ascii::line_ending, combinator::repeat, token::take_while, IResult, Parser};
pub type Stream<'i> = &'i [u8];
@@ -44,17 +44,17 @@ pub fn parse(data: &[u8]) -> Option<Vec<(Request<'_>, Vec<Header<'_>>)>> {
fn request(input: Stream<'_>) -> IResult<Stream<'_>, (Request<'_>, Vec<Header<'_>>)> {
let (input, req) = request_line(input)?;
- let (input, h) = many1(message_header).parse_next(input)?;
+ let (input, h) = repeat(1.., message_header).parse_next(input)?;
let (input, _) = line_ending(input)?;
Ok((input, (req, h)))
}
fn request_line(input: Stream<'_>) -> IResult<Stream<'_>, Request<'_>> {
- let (input, method) = take_while1(is_token).parse_next(input)?;
- let (input, _) = take_while1(is_space).parse_next(input)?;
- let (input, uri) = take_while1(is_not_space).parse_next(input)?;
- let (input, _) = take_while1(is_space).parse_next(input)?;
+ let (input, method) = take_while(1.., is_token).parse_next(input)?;
+ let (input, _) = take_while(1.., is_space).parse_next(input)?;
+ let (input, uri) = take_while(1.., is_not_space).parse_next(input)?;
+ let (input, _) = take_while(1.., is_space).parse_next(input)?;
let (input, version) = http_version(input)?;
let (input, _) = line_ending(input)?;
@@ -70,23 +70,23 @@ fn request_line(input: Stream<'_>) -> IResult<Stream<'_>, Request<'_>> {
fn http_version(input: Stream<'_>) -> IResult<Stream<'_>, &[u8]> {
let (input, _) = "HTTP/".parse_next(input)?;
- let (input, version) = take_while1(is_version).parse_next(input)?;
+ let (input, version) = take_while(1.., is_version).parse_next(input)?;
Ok((input, version))
}
fn message_header_value(input: Stream<'_>) -> IResult<Stream<'_>, &[u8]> {
- let (input, _) = take_while1(is_horizontal_space).parse_next(input)?;
- let (input, data) = take_while1(not_line_ending).parse_next(input)?;
+ let (input, _) = take_while(1.., is_horizontal_space).parse_next(input)?;
+ let (input, data) = take_while(1.., not_line_ending).parse_next(input)?;
let (input, _) = line_ending(input)?;
Ok((input, data))
}
fn message_header(input: Stream<'_>) -> IResult<Stream<'_>, Header<'_>> {
- let (input, name) = take_while1(is_token).parse_next(input)?;
+ let (input, name) = take_while(1.., is_token).parse_next(input)?;
let (input, _) = ':'.parse_next(input)?;
- let (input, value) = many1(message_header_value).parse_next(input)?;
+ let (input, value) = repeat(1.., message_header_value).parse_next(input)?;
Ok((input, Header { name, value }))
}
diff --git a/vendor/winnow/examples/http/parser_streaming.rs b/vendor/winnow/examples/http/parser_streaming.rs
index f7774b7bc..d3b2c4aaa 100644
--- a/vendor/winnow/examples/http/parser_streaming.rs
+++ b/vendor/winnow/examples/http/parser_streaming.rs
@@ -1,5 +1,5 @@
use winnow::{
- bytes::take_while1, character::line_ending, multi::many1, stream::Partial, IResult, Parser,
+ ascii::line_ending, combinator::repeat, stream::Partial, token::take_while, IResult, Parser,
};
pub type Stream<'i> = Partial<&'i [u8]>;
@@ -46,17 +46,17 @@ pub fn parse(data: &[u8]) -> Option<Vec<(Request<'_>, Vec<Header<'_>>)>> {
fn request(input: Stream<'_>) -> IResult<Stream<'_>, (Request<'_>, Vec<Header<'_>>)> {
let (input, req) = request_line(input)?;
- let (input, h) = many1(message_header).parse_next(input)?;
+ let (input, h) = repeat(1.., message_header).parse_next(input)?;
let (input, _) = line_ending(input)?;
Ok((input, (req, h)))
}
fn request_line(input: Stream<'_>) -> IResult<Stream<'_>, Request<'_>> {
- let (input, method) = take_while1(is_token).parse_next(input)?;
- let (input, _) = take_while1(is_space).parse_next(input)?;
- let (input, uri) = take_while1(is_not_space).parse_next(input)?;
- let (input, _) = take_while1(is_space).parse_next(input)?;
+ let (input, method) = take_while(1.., is_token).parse_next(input)?;
+ let (input, _) = take_while(1.., is_space).parse_next(input)?;
+ let (input, uri) = take_while(1.., is_not_space).parse_next(input)?;
+ let (input, _) = take_while(1.., is_space).parse_next(input)?;
let (input, version) = http_version(input)?;
let (input, _) = line_ending(input)?;
@@ -72,23 +72,23 @@ fn request_line(input: Stream<'_>) -> IResult<Stream<'_>, Request<'_>> {
fn http_version(input: Stream<'_>) -> IResult<Stream<'_>, &[u8]> {
let (input, _) = "HTTP/".parse_next(input)?;
- let (input, version) = take_while1(is_version).parse_next(input)?;
+ let (input, version) = take_while(1.., is_version).parse_next(input)?;
Ok((input, version))
}
fn message_header_value(input: Stream<'_>) -> IResult<Stream<'_>, &[u8]> {
- let (input, _) = take_while1(is_horizontal_space).parse_next(input)?;
- let (input, data) = take_while1(not_line_ending).parse_next(input)?;
+ let (input, _) = take_while(1.., is_horizontal_space).parse_next(input)?;
+ let (input, data) = take_while(1.., not_line_ending).parse_next(input)?;
let (input, _) = line_ending(input)?;
Ok((input, data))
}
fn message_header(input: Stream<'_>) -> IResult<Stream<'_>, Header<'_>> {
- let (input, name) = take_while1(is_token).parse_next(input)?;
+ let (input, name) = take_while(1.., is_token).parse_next(input)?;
let (input, _) = ':'.parse_next(input)?;
- let (input, value) = many1(message_header_value).parse_next(input)?;
+ let (input, value) = repeat(1.., message_header_value).parse_next(input)?;
Ok((input, Header { name, value }))
}
diff --git a/vendor/winnow/examples/ini/bench.rs b/vendor/winnow/examples/ini/bench.rs
index 2eba5e2b7..cffea3b84 100644
--- a/vendor/winnow/examples/ini/bench.rs
+++ b/vendor/winnow/examples/ini/bench.rs
@@ -1,4 +1,4 @@
-use winnow::multi::many0;
+use winnow::combinator::repeat;
use winnow::prelude::*;
mod parser;
@@ -32,7 +32,7 @@ file=payroll.dat
\0";
fn acc(i: parser::Stream<'_>) -> IResult<parser::Stream<'_>, Vec<(&str, &str)>> {
- many0(parser::key_value).parse_next(i)
+ repeat(0.., parser::key_value).parse_next(i)
}
let mut group = c.benchmark_group("ini keys and values");
diff --git a/vendor/winnow/examples/ini/parser.rs b/vendor/winnow/examples/ini/parser.rs
index ae234ea91..8852b6d30 100644
--- a/vendor/winnow/examples/ini/parser.rs
+++ b/vendor/winnow/examples/ini/parser.rs
@@ -3,37 +3,40 @@ 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::opt,
- multi::many0,
- sequence::{delimited, separated_pair, terminated},
+ combinator::repeat,
+ combinator::{delimited, separated_pair, terminated},
+ token::take_while,
};
pub type Stream<'i> = &'i [u8];
pub fn categories(i: Stream<'_>) -> IResult<Stream<'_>, HashMap<&str, HashMap<&str, &str>>> {
- many0(separated_pair(
- category,
- opt(multispace),
- many0(terminated(key_value, opt(multispace))),
- ))
+ repeat(
+ 0..,
+ separated_pair(
+ category,
+ opt(multispace),
+ repeat(0.., terminated(key_value, opt(multispace))),
+ ),
+ )
.parse_next(i)
}
fn category(i: Stream<'_>) -> IResult<Stream<'_>, &str> {
- delimited('[', take_while0(|c| c != b']'), ']')
- .map_res(str::from_utf8)
+ delimited('[', take_while(0.., |c| c != b']'), ']')
+ .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)
+ let (i, val) = take_while(0.., |c| c != b'\n' && c != b';')
+ .try_map(str::from_utf8)
.parse_next(i)?;
- let (i, _) = opt((';', take_while0(|c| c != b'\n'))).parse_next(i)?;
+ let (i, _) = opt((';', take_while(0.., |c| c != b'\n'))).parse_next(i)?;
Ok((i, (key, val)))
}
diff --git a/vendor/winnow/examples/ini/parser_str.rs b/vendor/winnow/examples/ini/parser_str.rs
index 34455aa0c..eb084a9b8 100644
--- a/vendor/winnow/examples/ini/parser_str.rs
+++ b/vendor/winnow/examples/ini/parser_str.rs
@@ -2,17 +2,17 @@ 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::opt,
- multi::many0,
- sequence::{delimited, terminated},
+ combinator::repeat,
+ combinator::{delimited, terminated},
+ token::{take_till0, take_while},
};
pub type Stream<'i> = &'i str;
pub fn categories(input: Stream<'_>) -> IResult<Stream<'_>, HashMap<&str, HashMap<&str, &str>>> {
- many0(category_and_keys).parse_next(input)
+ repeat(0.., category_and_keys).parse_next(input)
}
fn category_and_keys(i: Stream<'_>) -> IResult<Stream<'_>, (&str, HashMap<&str, &str>)> {
@@ -21,14 +21,14 @@ fn category_and_keys(i: Stream<'_>) -> IResult<Stream<'_>, (&str, HashMap<&str,
fn category(i: Stream<'_>) -> IResult<Stream<'_>, &str> {
terminated(
- delimited('[', take_while0(|c| c != ']'), ']'),
- opt(take_while1(" \r\n")),
+ delimited('[', take_while(0.., |c| c != ']'), ']'),
+ opt(take_while(1.., " \r\n")),
)
.parse_next(i)
}
fn keys_and_values(input: Stream<'_>) -> IResult<Stream<'_>, HashMap<&str, &str>> {
- many0(key_value).parse_next(input)
+ repeat(0.., key_value).parse_next(input)
}
fn key_value(i: Stream<'_>) -> IResult<Stream<'_>, (&str, &str)> {
@@ -47,11 +47,11 @@ fn is_line_ending_or_comment(chr: char) -> bool {
}
fn not_line_ending(i: Stream<'_>) -> IResult<Stream<'_>, &str> {
- take_while0(|c| c != '\r' && c != '\n').parse_next(i)
+ take_while(0.., |c| c != '\r' && c != '\n').parse_next(i)
}
fn space_or_line_ending(i: Stream<'_>) -> IResult<Stream<'_>, &str> {
- take_while1(" \r\n").parse_next(i)
+ take_while(1.., " \r\n").parse_next(i)
}
#[test]
diff --git a/vendor/winnow/examples/iterator.rs b/vendor/winnow/examples/iterator.rs
index 7e14b578f..826eff3aa 100644
--- a/vendor/winnow/examples/iterator.rs
+++ b/vendor/winnow/examples/iterator.rs
@@ -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";
diff --git a/vendor/winnow/examples/json/parser.rs b/vendor/winnow/examples/json/parser.rs
index b8a2b85e4..719dea5d9 100644
--- a/vendor/winnow/examples/json/parser.rs
+++ b/vendor/winnow/examples/json/parser.rs
@@ -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_repeat, separated0},
error::{ContextError, ParseError},
- multi::{fold_many0, separated0},
- sequence::{delimited, preceded, separated_pair, terminated},
+ token::{any, none_of, take, take_while},
};
use crate::json::JsonValue;
@@ -87,7 +87,7 @@ fn string<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>
// right branch (since we found the `"` character) but encountered an error when
// parsing the string
cut_err(terminated(
- fold_many0(character, String::new, |mut string, c| {
+ fold_repeat(0.., character, String::new, |mut string, c| {
string.push(c);
string
}),
@@ -191,9 +191,9 @@ fn key_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static s
/// first we write parsers for the smallest elements (here a space character),
/// then we'll combine them in larger parsers
fn ws<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, &'i str, E> {
- // Combinators like `take_while0` return a function. That function is the
+ // Combinators like `take_while` return a function. That function is the
// parser,to which we can pass the input
- take_while0(WS).parse_next(input)
+ take_while(0.., WS).parse_next(input)
}
const WS: &str = " \t\r\n";
diff --git a/vendor/winnow/examples/json/parser_dispatch.rs b/vendor/winnow/examples/json/parser_dispatch.rs
index 1fcd30fe6..29d6d5f90 100644
--- a/vendor/winnow/examples/json/parser_dispatch.rs
+++ b/vendor/winnow/examples/json/parser_dispatch.rs
@@ -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_repeat, separated0},
error::{ContextError, ParseError},
- multi::{fold_many0, separated0},
- sequence::{delimited, preceded, separated_pair, terminated},
+ token::{any, none_of, take, take_while},
};
use crate::json::JsonValue;
@@ -96,7 +96,7 @@ fn string<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>
// right branch (since we found the `"` character) but encountered an error when
// parsing the string
cut_err(terminated(
- fold_many0(character, String::new, |mut string, c| {
+ fold_repeat(0.., character, String::new, |mut string, c| {
string.push(c);
string
}),
@@ -198,9 +198,9 @@ fn key_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static s
/// first we write parsers for the smallest elements (here a space character),
/// then we'll combine them in larger parsers
fn ws<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, &'i str, E> {
- // Combinators like `take_while0` return a function. That function is the
+ // Combinators like `take_while` return a function. That function is the
// parser,to which we can pass the input
- take_while0(WS).parse_next(input)
+ take_while(0.., WS).parse_next(input)
}
const WS: &str = " \t\r\n";
diff --git a/vendor/winnow/examples/json/parser_partial.rs b/vendor/winnow/examples/json/parser_partial.rs
index 8050de4b7..4b6d143f9 100644
--- a/vendor/winnow/examples/json/parser_partial.rs
+++ b/vendor/winnow/examples/json/parser_partial.rs
@@ -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_repeat, separated0},
error::{ContextError, ParseError},
- multi::{fold_many0, separated0},
- sequence::{delimited, preceded, separated_pair, terminated},
stream::Partial,
+ token::{any, none_of, take, take_while},
};
use crate::json::JsonValue;
@@ -88,7 +88,7 @@ fn string<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>
// right branch (since we found the `"` character) but encountered an error when
// parsing the string
cut_err(terminated(
- fold_many0(character, String::new, |mut string, c| {
+ fold_repeat(0.., character, String::new, |mut string, c| {
string.push(c);
string
}),
@@ -192,9 +192,9 @@ fn key_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static s
/// first we write parsers for the smallest elements (here a space character),
/// then we'll combine them in larger parsers
fn ws<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, &'i str, E> {
- // Combinators like `take_while0` return a function. That function is the
+ // Combinators like `take_while` return a function. That function is the
// parser,to which we can pass the input
- take_while0(WS).parse_next(input)
+ take_while(0.., WS).parse_next(input)
}
fn ws_or_eof<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, &'i str, E> {
diff --git a/vendor/winnow/examples/json_iterator.rs b/vendor/winnow/examples/json_iterator.rs
index 52f28a56c..f4d8ead2a 100644
--- a/vendor/winnow/examples/json_iterator.rs
+++ b/vendor/winnow/examples/json_iterator.rs
@@ -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_while},
IResult,
};
@@ -206,7 +206,7 @@ impl<'a, 'b: 'a> JsonValue<'a, 'b> {
fn sp<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, &'a str, E> {
let chars = " \t\r\n";
- take_while0(move |c| chars.contains(c)).parse_next(i)
+ take_while(0.., move |c| chars.contains(c)).parse_next(i)
}
fn parse_str<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, &'a str, E> {
diff --git a/vendor/winnow/examples/ndjson/parser.rs b/vendor/winnow/examples/ndjson/parser.rs
index 2c1cd2981..2a60952e3 100644
--- a/vendor/winnow/examples/ndjson/parser.rs
+++ b/vendor/winnow/examples/ndjson/parser.rs
@@ -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_repeat, separated0},
error::{ContextError, ParseError},
- multi::{fold_many0, separated0},
- sequence::{delimited, preceded, separated_pair, terminated},
stream::Partial,
+ token::{any, none_of, take, take_while},
};
#[derive(Debug, PartialEq, Clone)]
@@ -92,7 +92,7 @@ fn string<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static str>
// right branch (since we found the `"` character) but encountered an error when
// parsing the string
cut_err(terminated(
- fold_many0(character, String::new, |mut string, c| {
+ fold_repeat(0.., character, String::new, |mut string, c| {
string.push(c);
string
}),
@@ -196,9 +196,9 @@ fn key_value<'i, E: ParseError<Stream<'i>> + ContextError<Stream<'i>, &'static s
/// first we write parsers for the smallest elements (here a space character),
/// then we'll combine them in larger parsers
fn ws<'i, E: ParseError<Stream<'i>>>(input: Stream<'i>) -> IResult<Stream<'i>, &'i str, E> {
- // Combinators like `take_while0` return a function. That function is the
+ // Combinators like `take_while` return a function. That function is the
// parser,to which we can pass the input
- take_while0(WS).parse_next(input)
+ take_while(0.., WS).parse_next(input)
}
const WS: &str = " \t";
diff --git a/vendor/winnow/examples/s_expression/parser.rs b/vendor/winnow/examples/s_expression/parser.rs
index 9712c02fe..9a1686e1c 100644
--- a/vendor/winnow/examples/s_expression/parser.rs
+++ b/vendor/winnow/examples/s_expression/parser.rs
@@ -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::repeat,
combinator::{cut_err, opt},
+ combinator::{delimited, preceded, terminated},
error::VerboseError,
- multi::many0,
- sequence::{delimited, preceded, terminated},
+ token::one_of,
IResult, Parser,
};
@@ -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)
@@ -150,7 +150,7 @@ fn parse_builtin_op(i: &str) -> IResult<&str, BuiltIn, VerboseError<&str>> {
/// and `cut_err` to prevent back-tracking.
///
/// Put plainly: `preceded(":", cut_err(alpha1))` means that once we see the `:`
-/// character, we have to see one or more alphabetic chararcters or the input is invalid.
+/// character, we have to see one or more alphabetic characters or the input is invalid.
fn parse_keyword(i: &str) -> IResult<&str, Atom, VerboseError<&str>> {
preceded(":", cut_err(alpha1))
.context("keyword")
@@ -168,8 +168,8 @@ fn parse_keyword(i: &str) -> IResult<&str, Atom, VerboseError<&str>> {
/// tuples are themselves a parser, used to sequence parsers together, so we can translate this
/// directly and then map over it to transform the output into an `Expr::Application`
fn parse_application(i: &str) -> IResult<&str, Expr, VerboseError<&str>> {
- let application_inner =
- (parse_expr, many0(parse_expr)).map(|(head, tail)| Expr::Application(Box::new(head), tail));
+ let application_inner = (parse_expr, repeat(0.., parse_expr))
+ .map(|(head, tail)| Expr::Application(Box::new(head), tail));
// finally, we wrap it in an s-expression
s_exp(application_inner).parse_next(i)
}
@@ -212,7 +212,7 @@ fn parse_quote(i: &str) -> IResult<&str, Expr, VerboseError<&str>> {
// this should look very straight-forward after all we've done:
// we find the `'` (quote) character, use cut_err to say that we're unambiguously
// looking for an s-expression of 0 or more expressions, and then parse them
- preceded("'", cut_err(s_exp(many0(parse_expr))))
+ preceded("'", cut_err(s_exp(repeat(0.., parse_expr))))
.context("quote")
.map(Expr::Quote)
.parse_next(i)
diff --git a/vendor/winnow/examples/string/parser.rs b/vendor/winnow/examples/string/parser.rs
index a57dd044d..dcd87f272 100644
--- a/vendor/winnow/examples/string/parser.rs
+++ b/vendor/winnow/examples/string/parser.rs
@@ -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_repeat;
+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};
/// Parse a string. Use a loop of `parse_fragment` and push all of the fragments
/// into an output string.
@@ -23,9 +23,10 @@ pub fn parse_string<'a, E>(input: &'a str) -> IResult<&'a str, String, E>
where
E: ParseError<&'a str> + FromExternalError<&'a str, std::num::ParseIntError>,
{
- // fold_many0 is the equivalent of iterator::fold. It runs a parser in a loop,
+ // fold_repeat is the equivalent of iterator::fold. It runs a parser in a loop,
// and for each output value, calls a folding function on each output value.
- let build_string = fold_many0(
+ let build_string = fold_repeat(
+ 0..,
// Our parser function – parses a single string fragment
parse_fragment,
// Our init value, an empty string
@@ -44,7 +45,7 @@ where
// Finally, parse the string. Note that, if `build_string` could accept a raw
// " character, the closing delimiter " would never match. When using
- // `delimited` with a looping parser (like fold_many0), be sure that the
+ // `delimited` with a looping parser (like fold_repeat), be sure that the
// loop won't accidentally match your closing delimiter!
delimited('"', build_string, '"').parse_next(input)
}
@@ -129,9 +130,9 @@ fn parse_unicode<'a, E>(input: &'a str) -> IResult<&'a str, char, E>
where
E: ParseError<&'a str> + FromExternalError<&'a str, std::num::ParseIntError>,
{
- // `take_while_m_n` parses between `m` and `n` bytes (inclusive) that match
+ // `take_while` parses between `m` and `n` bytes (inclusive) that match
// a predicate. `parse_hex` here parses between 1 and 6 hexadecimal numerals.
- let parse_hex = take_while_m_n(1, 6, |c: char| c.is_ascii_hexdigit());
+ let parse_hex = take_while(1..=6, |c: char| c.is_ascii_hexdigit());
// `preceded` takes a prefix parser, and if it succeeds, returns the result
// of the body parser. In this case, it parses u{XXXX}.
@@ -143,12 +144,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.