Nom: take everything until end of input [solved]


#1

I’m trying to write a nom parser that takes all input (of unknown length) until the end of string.

It seems that in nom the end of input is a magical poison that kills every macro that even accidentally touches it. If I use a regular string, I get Incomplete error. If I use CompleteStr wrapper, I get Complete error. How can I get a successful parse when reaching end of input?

Specifically, take_while!() expects to find a character that is non-matchnig, but not end of input. How can I take as much as there is, and if there’s EOF, just keep what has been matched so far?

named!(take<&str, &str>,
    take_while1!(char::is_alphanumeric));

assert_eq!(Ok(("!", "aaa")), altest("aaa!")); // matches
assert_eq!(Ok(("", "aaa")), altest("aaa")); // error - doesn't match!

#2

named!(take<&str, &str> needs to be changed to named!(take<CompleteStr, CompleteStr>.

Previously I’ve tried &CompleteStr, which due to Deref changed back to regular &str.