use crate::Parser; pub fn choice<'a, I, O, E>(parsers: &'a [&'a dyn Parser]) -> impl Parser + 'a where I: Clone, { move |input: I| { //TODO need a more principled way to return an error when no choices work let mut err = None; for parser in parsers.iter() { match parser.parse(input.clone()) { Ok(res) => return Ok(res), Err(e) => { err = Some(e); } } } Err(err.unwrap()) } }