nom::escaped_transform
[−]
[src]
macro_rules! escaped_transform { ($i:expr, $submac:ident!( $($args:tt)* ), $control_char: expr, $($rest:tt)+) => { ... }; ($i:expr, $f:expr, $control_char: expr, $($rest:tt)+) => { ... }; }
escaped_transform!(&[T] -> IResult<&[T], &[T]>, T, &[T] -> IResult<&[T], &[T]>) => &[T] -> IResult<&[T], Vec<T>>
matches a byte string with escaped characters.
The first argument matches the normal characters (it must not match the control character), the second argument is the control character (like \
in most languages),
the third argument matches the escaped characters and trnasforms them.
As an example, the chain abc\tdef
could be abc def
(it also consumes the control character)
fn to_s(i:Vec<u8>) -> String { String::from_utf8_lossy(&i).into_owned() } named!(transform < String >, map!( escaped_transform!(call!(alpha), '\\', alt!( tag!("\\") => { |_| &b"\\"[..] } | tag!("\"") => { |_| &b"\""[..] } | tag!("n") => { |_| &b"\n"[..] } ) ), to_s ) ); assert_eq!(transform(&b"ab\\\"cd"[..]), Done(&b""[..], String::from("ab\"cd")));