Function shrimple_parser::parse_group
source ยท pub fn parse_group<'input>(
open: char,
close: char
) -> impl Parser<'input, &'input str, ()>Expand description
Parse a balanced group of open & close characters.
Returns the group without the initial open & the final close, or:
- If no initial
openwas found, a recoverable error is returned. - If the end was reached before a matching
closecharacter, a fatal error is returned. An example use of this is parsing balanced parentheses:
use shrimple_parsing::{parse_group, ParsingError};
let input = "(foo) bar";
assert_eq!(parse_group('(', ')')(input), Ok((" bar", "foo")));
let input = "(oops";
assert_eq!(parse_group('(', ')')(input), Err(ParsingError::new("(oops", ())));