Skip to content

Commit

Permalink
docs(multi): Clarify how to recognize with a parser
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 17, 2023
1 parent 356483e commit d7695ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/bytes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ where
///
/// *Partial version*: will return a `ErrMode::Incomplete(Needed::new(1))` if the pattern reaches the end of the input.
///
/// To recognize a series of tokens, use [`many0`][crate::multi::many0] to [`Accumulate`][crate::stream::Accumulate] into a `()` and then [`Parser::recognize`][crate::Parser::recognize].
///
/// # Example
///
/// ```rust
Expand Down Expand Up @@ -334,6 +336,8 @@ where
///
/// *Partial version* will return a `ErrMode::Incomplete(Needed::new(1))` or if the pattern reaches the end of the input.
///
/// To recognize a series of tokens, use [`many1`][crate::multi::many1] to [`Accumulate`][crate::stream::Accumulate] into a `()` and then [`Parser::recognize`][crate::Parser::recognize].
///
/// # Example
///
/// ```rust
Expand Down Expand Up @@ -409,6 +413,8 @@ where
///
/// *Partial version* will return a `ErrMode::Incomplete(Needed::new(1))` if the pattern reaches the end of the input or is too short.
///
/// To recognize a series of tokens, use [`many_m_n`][crate::multi::many_m_n] to [`Accumulate`][crate::stream::Accumulate] into a `()` and then [`Parser::recognize`][crate::Parser::recognize].
///
/// # Example
///
/// ```rust
Expand Down
18 changes: 13 additions & 5 deletions src/multi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ use crate::stream::{Stream, StreamIsPartial, ToUsize, UpdateSlice};
use crate::trace::trace;
use crate::{IResult, Parser};

/// Repeats the embedded parser, gathering the results in a `Vec`.
/// [`Accumulate`] the output of a parser into a container, like `Vec`
///
/// This stops on [`ErrMode::Backtrack`]. To instead chain an error up, see
/// [`cut_err`][crate::combinator::cut_err].
///
/// # Arguments
/// * `f` The parser to apply.
/// To recognize a series of tokens, [`Accumulate`] into a `()` and then [`Parser::recognize`].
///
/// **Warning:** if the parser passed in accepts empty inputs (like `alpha0` or `digit0`), `many0` will
/// return an error, to prevent going into an infinite loop
Expand Down Expand Up @@ -67,14 +66,17 @@ where
})
}

/// Runs the specified parser, gathering the results in a `Vec`.
/// [`Accumulate`] the output of a parser into a container, like `Vec`
///
///
/// This stops on [`ErrMode::Backtrack`] if there is at least one result. To instead chain an error up,
/// see [`cut_err`][crate::combinator::cut_err].
///
/// # Arguments
/// * `f` The parser to apply.
///
/// To recognize a series of tokens, [`Accumulate`] into a `()` and then [`Parser::recognize`].
///
/// **Warning:** If the parser passed to `many1` accepts empty inputs
/// (like `alpha0` or `digit0`), `many1` will return an error,
/// to prevent going into an infinite loop.
Expand Down Expand Up @@ -149,6 +151,8 @@ where
///
/// `f` keeps going so long as `g` produces [`ErrMode::Backtrack`]. To instead chain an error up, see [`cut_err`][crate::combinator::cut_err].
///
/// To recognize a series of tokens, [`Accumulate`] into a `()` and then [`Parser::recognize`].
///
/// # Example
///
#[cfg_attr(not(feature = "std"), doc = "```ignore")]
Expand Down Expand Up @@ -506,6 +510,8 @@ where
/// * `n` The maximum number of iterations.
/// * `f` The parser to apply.
///
/// To recognize a series of tokens, [`Accumulate`] into a `()` and then [`Parser::recognize`].
///
/// **Warning:** If the parser passed to `many1` accepts empty inputs
/// (like `alpha0` or `digit0`), `many1` will return an error,
/// to prevent going into an infinite loop.
Expand Down Expand Up @@ -704,12 +710,14 @@ where
}
}

/// Runs the embedded parser `count` times, gathering the results in a `Vec`
/// [`Accumulate`] the output of a parser into a container, like `Vec`
///
/// # Arguments
/// * `f` The parser to apply.
/// * `count` How often to apply the parser.
///
/// To recognize a series of tokens, [`Accumulate`] into a `()` and then [`Parser::recognize`].
///
/// # Example
///
#[cfg_attr(not(feature = "std"), doc = "```ignore")]
Expand Down

0 comments on commit d7695ed

Please sign in to comment.