[][src]Function sexpy::tag

pub fn tag<'a, T, Input, Error>(tag: T) -> impl Fn(Input) where
    Error: ParseError<Input>,
    Input: 'a + InputTake + Compare<T>,
    T: 'a + InputLength + Clone

Recognizes a pattern

The input data will be compared to the tag combinator's argument and will return the part of the input that matches the argument

It will return Err(Err::Error((_, ErrorKind::Tag))) if the input doesn't match the pattern

Example

use nom::bytes::complete::tag;

fn parser(s: &str) -> IResult<&str, &str> {
  tag("Hello")(s)
}

assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello")));
assert_eq!(parser("Something"), Err(Err::Error(("Something", ErrorKind::Tag))));
assert_eq!(parser(""), Err(Err::Error(("", ErrorKind::Tag))));