Function parse_group_ex

Source
pub fn parse_group_ex<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 excluded in the output. See parse_group for a parser that includes 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_ex, ParsingError};
let src = "(foo ()) bar";
assert_eq!(parse_group_ex('(', ')')(src), Ok((" bar", "foo ()")));

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