From bdaf712a25aa9211502e6d792db141bc604d45a3 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Thu, 20 Oct 2022 23:39:51 -0700 Subject: [PATCH] need choice for 6-tuple --- src/choice.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/choice.rs b/src/choice.rs index ec01c0d..4ed3fe4 100644 --- a/src/choice.rs +++ b/src/choice.rs @@ -144,6 +144,48 @@ where } } +impl Choice for (P1, P2, P3, P4, P5, P6) +where + P1: Parser, + P2: Parser, + P3: Parser, + P4: Parser, + P5: Parser, + P6: Parser, + I: Clone, +{ + fn parse(&self, input: I) -> ParseResult { + let parser1 = &self.0; + let parser2 = &self.1; + let parser3 = &self.2; + let parser4 = &self.3; + let parser5 = &self.4; + let parser6 = &self.5; + + //TODO need a more principled way to return an error when no choices work + let mut err = None; + + for parser in [ + parser1 as &dyn Parser, + parser2, + parser3, + parser4, + parser5, + parser6, + ] + .iter() + { + match parser.parse(input.clone()) { + Ok(result) => return Ok(result), + Err(e) => { + err = Some(e); + } + } + } + Err(err.unwrap()) + } +} + #[cfg(test)] mod tests { use super::*;