I'm looking to apply a series of nom parsers and return the complete &str
that matches. I want to match strings of the form a+bc+
. Using the existing chain!
macro I can get pretty close:
named!(aaabccc <&[u8], &str>,
map_res!(
chain!(
a: take_while!(is_a) ~
tag!("b") ~
take_while!(is_c) ,
|| {a}
),
from_utf8
));
where
fn is_a(l: u8) -> bool {
match l {
b'a' => true,
_ => false,
}
}
fn is_c(l: u8) -> bool {
match l {
b'c' => true,
_ => false,
}
}
Say we have 'aaabccc' as input. The above parser will match the input but only 'aaa' will be returned. What I would like to do is return 'aaabccc', the original input.
chain!
is not the right macro for this, but there was not another that seemed more correct. What would the best way to do this be?
At the time of this writing I'm using nom 1.2.2
and rustc 1.9.0-nightly (a1e29daf1 2016-03-25)
.
recognize!
. Thank you! – Isidraisidro