Skip to main content

recognize

Function recognize 

Source
pub fn recognize<'a, 'b, O, F>(
    f: F,
) -> impl FnMut(Input<'a>) -> ParseResult<'a, &'a str>
where O: 'b, F: Parser<'a, 'b, O>,
Expand description

Executes a parser and returns the input that was parsed as a string slice of the original input.

ยงExamples

let mut parser = recognize(delimited(char('('), tag("foo"), char(')')));

assert_eq!(parser.parse("(foo)bar".into()),
    Ok(("(foo)", Input::from("bar"))));
assert_eq!(parser.parse("bar".into()), Err(ParseError::new(
    Position::new(0, 1, 1),
    code::ERR_RECOGNIZE,
    CombinatorError::Recognize
)));