Skip to main content

group

Function group 

Source
pub fn group<In: Input>(
    open: impl IntoPattern,
    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 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::{parser::group, ParsingError};
let src = "(foo ()) bar";
assert_eq!(group('(', ')')(src), Ok((" bar", "(foo ())")));

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