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

pub fn escaped<Input, P, Q>(
    parser: P,
    escape: <Input as StreamOnce>::Token,
    escape_parser: Q
) -> Escaped<P, Q, Input::Token> where
    Input: Stream,
    P: Parser<Input>,
    <Input as StreamOnce>::Token: PartialEq,
    Q: Parser<Input>, 
Expand description

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 token 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());
}