summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-10-24 00:09:02 -0400
committerJohn Turner <jturner.usa@gmail.com>2025-10-24 00:09:02 -0400
commit675b511c836163efee201fc0bb9ca67d1db28823 (patch)
treecedbb839876383d91ef7f639703b157c9c5f2ebb
parent60f8e11769864befc1f116f5f2896cdbf16609f1 (diff)
downloadmon-675b511c836163efee201fc0bb9ca67d1db28823.tar.gz
short circuit Or combinator instead of running both parsers
-rw-r--r--src/lib.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 1de814c..6f16148 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -296,14 +296,15 @@ where
) -> ParserResult<I, Self::Output, OM, EM> {
Tracer::trace("or", it.clone());
- match (
- self.left.run::<OM, EM, Tracer>(it.clone()),
- self.right.run::<OM, EM, Tracer>(it.clone()),
- ) {
- (Ok((rest, output)), _) => Ok((rest, output)),
- (_, Ok((rest, output))) => Ok((rest, output)),
- (_, Err(rest)) => Err(rest),
- }
+ if let Ok((rest, output)) = self.left.run::<OM, EM, Tracer>(it.clone()) {
+ return Ok((rest, output));
+ };
+
+ if let Ok((rest, output)) = self.right.run::<OM, EM, Tracer>(it.clone()) {
+ return Ok((rest, output));
+ };
+
+ Err(EM::bind(|| it))
}
}