Function parse_group

Source
pub fn parse_group<In: Input>(
    open: impl Pattern,
    close: impl Pattern,
) -> impl Parser<In, In, ()>
Expand description

Parse a balanced group of open & close patterns.

The start & end of the group are included in the output. See parse_group_ex for a parser that excludes them.

ยงErrors

  • If no initial open was found, a recoverable error is returned.
  • If the end was reached before a matching close pattern, a fatal error is returned.

An example use of this is parsing balanced parentheses:

use shrimple_parser::{pattern::parse_group, ParsingError};
let src = "(foo ()) bar";
assert_eq!(parse_group('(', ')')(src), Ok((" bar", "(foo ())")));

let src = "(oops";
assert_eq!(parse_group('(', ')')(src), Err(ParsingError::new("oops", ())));