diff options
Diffstat (limited to 'vendor/winnow/src/_topic')
-rw-r--r-- | vendor/winnow/src/_topic/language.rs | 101 | ||||
-rw-r--r-- | vendor/winnow/src/_topic/mod.rs | 3 | ||||
-rw-r--r-- | vendor/winnow/src/_topic/partial.rs | 6 | ||||
-rw-r--r-- | vendor/winnow/src/_topic/performance.rs | 54 | ||||
-rw-r--r-- | vendor/winnow/src/_topic/stream.rs | 2 |
5 files changed, 110 insertions, 56 deletions
diff --git a/vendor/winnow/src/_topic/language.rs b/vendor/winnow/src/_topic/language.rs index d257c0b18..245bab4c7 100644 --- a/vendor/winnow/src/_topic/language.rs +++ b/vendor/winnow/src/_topic/language.rs @@ -28,8 +28,8 @@ //! use winnow::prelude::*; //! use winnow::{ //! error::ParseError, -//! sequence::delimited, -//! character::multispace0, +//! combinator::delimited, +//! ascii::multispace0, //! }; //! //! /// A combinator that takes a parser `inner` and produces a parser that also consumes both leading and @@ -62,7 +62,7 @@ //! use winnow::prelude::*; //! use winnow::{ //! error::ParseError, -//! bytes::take_till1, +//! token::take_till1, //! }; //! //! pub fn peol_comment<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, (), E> @@ -82,7 +82,7 @@ //! use winnow::prelude::*; //! use winnow::{ //! error::ParseError, -//! bytes::{tag, take_until0}, +//! token::{tag, take_until0}, //! }; //! //! pub fn pinline_comment<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, (), E> { @@ -107,14 +107,14 @@ //! use winnow::prelude::*; //! use winnow::{ //! stream::AsChar, -//! bytes::take_while0, -//! bytes::one_of, +//! token::take_while, +//! token::one_of, //! }; //! //! pub fn identifier(input: &str) -> IResult<&str, &str> { //! ( //! one_of(|c: char| c.is_alpha() || c == '_'), -//! take_while0(|c: char| c.is_alphanum() || c == '_') +//! take_while(0.., |c: char| c.is_alphanum() || c == '_') //! ) //! .recognize() //! .parse_next(input) @@ -122,8 +122,8 @@ //! ``` //! //! Let's say we apply this to the identifier `hello_world123abc`. The first element of the tuple -//! would uses [`one_of`][crate::bytes::one_of] which would recognize `h`. The tuple ensures that -//! `ello_world123abc` will be piped to the next [`take_while0`][crate::bytes::take_while0] parser, +//! would uses [`one_of`][crate::token::one_of] which would recognize `h`. The tuple ensures that +//! `ello_world123abc` will be piped to the next [`take_while`][crate::token::take_while] parser, //! which recognizes every remaining character. However, the tuple returns a tuple of the results //! of its sub-parsers. The [`recognize`][crate::Parser::recognize] parser produces a `&str` of the //! input text that was parsed, which in this case is the entire `&str` `hello_world123abc`. @@ -146,9 +146,6 @@ //! string slice to an integer value is slightly simpler. You can also strip the `_` from the string //! slice that is returned, which is demonstrated in the second hexadecimal number parser. //! -//! If you wish to limit the number of digits in a valid integer literal, replace `many1` with -//! `many_m_n` in the recipes. -//! //! #### Hexadecimal //! //! The parser outputs the string slice of the digits without the leading `0x`/`0X`. @@ -156,18 +153,18 @@ //! ```rust //! use winnow::prelude::*; //! use winnow::{ -//! branch::alt, -//! multi::{many0, many1}, -//! sequence::{preceded, terminated}, -//! bytes::one_of, -//! bytes::tag, +//! combinator::alt, +//! combinator::{repeat}, +//! combinator::{preceded, terminated}, +//! token::one_of, +//! token::tag, //! }; //! //! fn hexadecimal(input: &str) -> IResult<&str, &str> { // <'a, E: ParseError<&'a str>> //! preceded( //! alt(("0x", "0X")), -//! many1( -//! terminated(one_of("0123456789abcdefABCDEF"), many0('_').map(|()| ())) +//! repeat(1.., +//! terminated(one_of("0123456789abcdefABCDEF"), repeat(0.., '_').map(|()| ())) //! ).map(|()| ()).recognize() //! ).parse_next(input) //! } @@ -178,20 +175,20 @@ //! ```rust //! use winnow::prelude::*; //! use winnow::{ -//! branch::alt, -//! multi::{many0, many1}, -//! sequence::{preceded, terminated}, -//! bytes::one_of, -//! bytes::tag, +//! combinator::alt, +//! combinator::{repeat}, +//! combinator::{preceded, terminated}, +//! token::one_of, +//! token::tag, //! }; //! //! fn hexadecimal_value(input: &str) -> IResult<&str, i64> { //! preceded( //! alt(("0x", "0X")), -//! many1( -//! terminated(one_of("0123456789abcdefABCDEF"), many0('_').map(|()| ())) +//! repeat(1.., +//! terminated(one_of("0123456789abcdefABCDEF"), repeat(0.., '_').map(|()| ())) //! ).map(|()| ()).recognize() -//! ).map_res( +//! ).try_map( //! |out: &str| i64::from_str_radix(&str::replace(&out, "_", ""), 16) //! ).parse_next(input) //! } @@ -202,18 +199,18 @@ //! ```rust //! use winnow::prelude::*; //! use winnow::{ -//! branch::alt, -//! multi::{many0, many1}, -//! sequence::{preceded, terminated}, -//! bytes::one_of, -//! bytes::tag, +//! combinator::alt, +//! combinator::{repeat}, +//! combinator::{preceded, terminated}, +//! token::one_of, +//! token::tag, //! }; //! //! fn octal(input: &str) -> IResult<&str, &str> { //! preceded( //! alt(("0o", "0O")), -//! many1( -//! terminated(one_of("01234567"), many0('_').map(|()| ())) +//! repeat(1.., +//! terminated(one_of("01234567"), repeat(0.., '_').map(|()| ())) //! ).map(|()| ()).recognize() //! ).parse_next(input) //! } @@ -224,18 +221,18 @@ //! ```rust //! use winnow::prelude::*; //! use winnow::{ -//! branch::alt, -//! multi::{many0, many1}, -//! sequence::{preceded, terminated}, -//! bytes::one_of, -//! bytes::tag, +//! combinator::alt, +//! combinator::{repeat}, +//! combinator::{preceded, terminated}, +//! token::one_of, +//! token::tag, //! }; //! //! fn binary(input: &str) -> IResult<&str, &str> { //! preceded( //! alt(("0b", "0B")), -//! many1( -//! terminated(one_of("01"), many0('_').map(|()| ())) +//! repeat(1.., +//! terminated(one_of("01"), repeat(0.., '_').map(|()| ())) //! ).map(|()| ()).recognize() //! ).parse_next(input) //! } @@ -247,14 +244,14 @@ //! use winnow::prelude::*; //! use winnow::{ //! IResult, -//! multi::{many0, many1}, -//! sequence::terminated, -//! bytes::one_of, +//! combinator::{repeat}, +//! combinator::terminated, +//! token::one_of, //! }; //! //! fn decimal(input: &str) -> IResult<&str, &str> { -//! many1( -//! terminated(one_of("0123456789"), many0('_').map(|()| ())) +//! repeat(1.., +//! terminated(one_of("0123456789"), repeat(0.., '_').map(|()| ())) //! ).map(|()| ()) //! .recognize() //! .parse_next(input) @@ -268,11 +265,11 @@ //! ```rust //! use winnow::prelude::*; //! use winnow::{ -//! branch::alt, -//! multi::{many0, many1}, +//! combinator::alt, +//! combinator::{repeat}, //! combinator::opt, -//! sequence::{preceded, terminated}, -//! bytes::one_of, +//! combinator::{preceded, terminated}, +//! token::one_of, //! }; //! //! fn float(input: &str) -> IResult<&str, &str> { @@ -308,8 +305,8 @@ //! } //! //! fn decimal(input: &str) -> IResult<&str, &str> { -//! many1( -//! terminated(one_of("0123456789"), many0('_').map(|()| ())) +//! repeat(1.., +//! terminated(one_of("0123456789"), repeat(0.., '_').map(|()| ())) //! ). //! map(|()| ()) //! .recognize() diff --git a/vendor/winnow/src/_topic/mod.rs b/vendor/winnow/src/_topic/mod.rs index 76687277a..72c8145fe 100644 --- a/vendor/winnow/src/_topic/mod.rs +++ b/vendor/winnow/src/_topic/mod.rs @@ -12,6 +12,7 @@ //! - [HTTP][http] //! - Special Topics: //! - [Implementing `FromStr`][fromstr] +//! - [Performance][performance] //! - [Parsing Partial Input][partial] //! - [Custom stream][stream] //! - [Custom errors][error] @@ -19,6 +20,7 @@ //! See also parsers written with `winnow`: //! //! - [`toml_edit`](https://crates.io/crates/toml_edit) +//! - [`hcl-edit`](https://crates.io/crates/hcl-edit) pub mod arithmetic; pub mod error; @@ -28,6 +30,7 @@ pub mod ini; pub mod json; pub mod language; pub mod partial; +pub mod performance; pub mod s_expression; pub mod stream; pub mod why; diff --git a/vendor/winnow/src/_topic/partial.rs b/vendor/winnow/src/_topic/partial.rs index 263d7f127..19895d35a 100644 --- a/vendor/winnow/src/_topic/partial.rs +++ b/vendor/winnow/src/_topic/partial.rs @@ -21,7 +21,7 @@ //! Caveats: //! - `winnow` takes the approach of re-parsing from scratch. Chunks should be relatively small to //! prevent the re-parsing overhead from dominating. -//! - Parsers like [`many0`] do not know when an `eof` is from insufficient data or the end of the +//! - Parsers like [`repeat`] do not know when an `eof` is from insufficient data or the end of the //! stream, causing them to always report [`Incomplete`]. //! //! # Example @@ -38,9 +38,9 @@ #![allow(unused_imports)] // Used for intra-doc links +use crate::binary::length_value; +use crate::combinator::repeat; use crate::error::ErrMode::Incomplete; use crate::error::Needed; -use crate::multi::length_value; -use crate::multi::many0; use crate::stream::Partial; use crate::stream::StreamIsPartial; diff --git a/vendor/winnow/src/_topic/performance.rs b/vendor/winnow/src/_topic/performance.rs new file mode 100644 index 000000000..fac12da4c --- /dev/null +++ b/vendor/winnow/src/_topic/performance.rs @@ -0,0 +1,54 @@ +//! # Performance +//! +//! ## Runtime Performance +//! +//! See also the general Rust [Performance Book](https://nnethercote.github.io/perf-book/) +//! +//! Tips +//! - When enough cases of an [`alt`] have unique prefixes, prefer [`dispatch`] +//! - When parsing text, try to parse is as bytes (`u8`) rather than `char`s ([`BStr`] can make +//! debugging easier) +//! - Find simplified subsets of the grammar to parse, falling back to the full grammar when it +//! doesn't work. For example, when parsing json strings, parse them without support for escapes, +//! falling back to escape support if it fails. +//! - Watch for large return types. A surprising place these can show up is when chaining parsers +//! with a tuple. +//! +//! ## Built-time Performance +//! +//! Returning complex types as `impl Trait` can negatively impact build times. This can hit in +//! surprising cases like: +//! ```rust +//! # use winnow::prelude::*; +//! fn foo<I, O, E>() -> impl Parser<I, O, E> +//! # where +//! # I: winnow::stream::Stream<Token=O>, +//! # I: winnow::stream::StreamIsPartial, +//! # E: winnow::error::ParseError<I>, +//! { +//! // ...some chained combinators... +//! # winnow::token::any +//! } +//! ``` +//! +//! Instead, wrap the combinators in a closure to simplify the type: +//! ```rust +//! # use winnow::prelude::*; +//! fn foo<I, O, E>() -> impl Parser<I, O, E> +//! # where +//! # I: winnow::stream::Stream<Token=O>, +//! # I: winnow::stream::StreamIsPartial, +//! # E: winnow::error::ParseError<I>, +//! { +//! move |input: I| { +//! // ...some chained combinators... +//! # winnow::token::any +//! .parse_next(input) +//! } +//! } +//! ``` + +#![allow(unused_imports)] +use crate::combinator::alt; +use crate::combinator::dispatch; +use crate::stream::BStr; diff --git a/vendor/winnow/src/_topic/stream.rs b/vendor/winnow/src/_topic/stream.rs index 92841eda2..7455e185b 100644 --- a/vendor/winnow/src/_topic/stream.rs +++ b/vendor/winnow/src/_topic/stream.rs @@ -17,7 +17,7 @@ //! //! ```rust //! # use winnow::prelude::*; -//! # use winnow::bytes::tag; +//! # use winnow::token::tag; //! # type MyStream<'i> = &'i str; //! # type Output<'i> = &'i str; //! fn parser(i: MyStream<'_>) -> IResult<MyStream<'_>, Output<'_>> { |