[][src]Function combine::parser::repeat::escaped

pub fn escaped<P, Q>(
    parser: P,
    escape: <P::Input as StreamOnce>::Item,
    escape_parser: Q
) -> Escaped<P, Q> where
    P: Parser,
    <P::Input as StreamOnce>::Item: PartialEq,
    Q: Parser<Input = P::Input>, 

Parses an escaped string by first applying parser which accept the normal characters which do not need escaping. Once parser can not consume any more input it checks if the next item is escape. If it is then escape_parser is used to parse the escaped character and then resumes parsing using parser. If escape was not found then the parser finishes successfully.

This returns () since there isn't a good way to collect the output of the parsers so it is best paired with one of the recognize parsers.

    let mut parser = recognize(
        escaped(take_while1(|c| c != '"' && c != '\\'), '\\', one_of(r#"nr"\"#.chars()))
    );
    assert_eq!(parser.parse(r#"ab\"12\n\rc""#), Ok((r#"ab\"12\n\rc"#, r#"""#)));
    assert!(parser.parse(r#"\"#).is_err());
    assert!(parser.parse(r#"\a"#).is_err());
}