In regex there exists the ?
-operator that can be put behind expressions to indicate that they can be there or not. They are essentially the same as “this pattern repeats 0 or 1 times”. I want to do this in nom.
Technically I have a solution for this problem, but it feels like a workaround:
If I want to have a parser that
a) returns the parsed string if successful, or
b) returns an empty string if not successful
my go-to method now is to do this:
let (rest, parsed_thing_vec) = many_m_n(0,1, parser_function)(i)?;
let parsed_thing = parsed_thing_vec.into_iter().collect::<String>();
Is there a simpler – more “nom-y” – method?