Macro nom::escaped_transform [−][src]
macro_rules! escaped_transform { (__impl $i: expr, $normal:ident!( $($args:tt)* ), $control_char: expr, $transform:ident!( $($args2:tt)* )) => { ... }; (__impl_1 $i:expr, $submac1:ident!( $($args:tt)* ), $control_char: expr, $submac2:ident!( $($args2:tt)*) ) => { ... }; (__impl_1 $i:expr, $submac1:ident!( $($args:tt)* ), $control_char: expr, $g:expr) => { ... }; ($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 transforms them.
As an example, the chain abc\tdef
could be abc def
(it also consumes the control character)
WARNING: if you do not use the verbose-errors
feature, this combinator will currently fail to build
because of a type inference error
Example
ⓘThis example is not tested
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"[..]), Ok((&b""[..], String::from("ab\"cd"))));