rustmax::nom::sequence

Function preceded

Source
pub fn preceded<I, O, E, F, G>(
    first: F,
    second: G,
) -> impl Parser<I, Output = O, Error = E>
where E: ParseError<I>, F: Parser<I, Error = E>, G: Parser<I, Output = O, Error = E>,
Expand description

Matches an object from the first parser and discards it, then gets an object from the second parser.

ยงArguments

  • first The opening parser.
  • second The second parser to get object.
use nom::sequence::preceded;
use nom::bytes::complete::tag;

let mut parser = preceded(tag("abc"), tag("efg"));

assert_eq!(parser.parse("abcefg"), Ok(("", "efg")));
assert_eq!(parser.parse("abcefghij"), Ok(("hij", "efg")));
assert_eq!(parser.parse(""), Err(Err::Error(("", ErrorKind::Tag))));
assert_eq!(parser.parse("123"), Err(Err::Error(("123", ErrorKind::Tag))));