diff options
Diffstat (limited to 'vendor/winnow/examples/ini')
-rw-r--r-- | vendor/winnow/examples/ini/bench.rs | 4 | ||||
-rw-r--r-- | vendor/winnow/examples/ini/parser.rs | 33 | ||||
-rw-r--r-- | vendor/winnow/examples/ini/parser_str.rs | 20 |
3 files changed, 30 insertions, 27 deletions
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] |