pub fn choice<O>(choices: impl AsRef<[Parser<O>]> + 'static) -> Parser<O> where
    O: 'static + Clone
Expand description

Applies the parsers in the slice until one succeeds.

use memoir::*;

let p = choice([symbol('?'), symbol('!'), symbol('.')]);

assert_eq!(p.to_string(), "'?' | '!' | '.'");

assert_eq!(p.parse("?").ok(), Some(('?', "")));
assert_eq!(p.parse("!").ok(), Some(('!', "")));
assert_eq!(p.parse(".").ok(), Some(('.', "")));

assert!(p.parse("@").is_err());
assert!(p.parse(",").is_err());
assert!(p.parse("").is_err());