Enum combine::error::Commit [−][src]
pub enum Commit<T> { Commit(T), Peek(T), }
Expand description
Enum used to indicate if a parser committed any items of the stream it was given as an input.
This is used by parsers such as or
and choice
to determine if they should try to parse
with another parser as they will only be able to provide good error reporting if the preceding
parser did not commit to the parse.
Variants
Constructor indicating that the parser has committed to this parse. If a parser after this fails,
other parser alternatives will not be attempted (CommitErr
will be returned)
Constructor indicating that the parser has not committed to this parse. If a parser after this fails,
other parser alternatives will be attempted (EmptyErr
will be returned)
Implementations
Extracts the contained value.
Converts self
into the Commit
state.
Maps over the contained value without changing the committed state.
pub fn combine<F, U, E>(self, f: F) -> StdParseResult2<U, E> where
F: FnOnce(T) -> StdParseResult2<U, E>,
pub fn combine<F, U, E>(self, f: F) -> StdParseResult2<U, E> where
F: FnOnce(T) -> StdParseResult2<U, E>,
Combines the Commit
flags from self
and the result of f
.
Peek <> Peek -> Peek Commit <> Peek -> Commit Peek <> Commit -> Commit Commit <> Commit -> Commit
//Parses a character of string literal and handles the escaped characters \\ and \" as \ //and " respectively fn char<Input>(input: &mut Input) -> StdParseResult<char, Input> where Input: Stream<Token = char>, Input::Error: ParseError<Input::Token, Input::Range, Input::Position>, { let (c, committed) = satisfy(|c| c != '"').parse_stream(input).into_result()?; match c { //Since the `char` parser has already committed some of the input `combine` is used //propagate the committed state to the next part of the parser '\\' => committed.combine(|_| { satisfy(|c| c == '"' || c == '\\') .map(|c| { match c { '"' => '"', '\\' => '\\', c => c } }) .parse_stream(input) .into_result() }), _ => Ok((c, committed)) } } let result = many(parser(char)) .easy_parse(r#"abc\"\\"#); assert_eq!(result, Ok((r#"abc"\"#.to_string(), ""))); }
pub fn combine_commit<F, U, E>(self, f: F) -> ParseResult<U, E> where
F: FnOnce(T) -> ParseResult<U, E>,
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for Commit<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Commit<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more