macro_rules! choice { ($first : expr) => { ... }; ($first : expr, $($rest : expr),+) => { ... }; }
Expand description
Takes a number of parsers and tries to apply them each in order. Fails if all the parsers fails or if an applied parser consumes input before failing.
let mut parser = choice!(
many1(digit()),
string("let").map(|s| s.to_string()),
many1(letter()));
assert_eq!(parser.parse("let"), Ok(("let".to_string(), "")));
assert_eq!(parser.parse("123abc"), Ok(("123".to_string(), "abc")));
assert!(parser.parse(":123").is_err());