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.
ยงErrors
- If no initial
openwas found, a recoverable error is returned. - If the end was reached before a matching
closepattern, 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", ())));