@@ 278,12 278,16 @@ fn end<'s: 't, 't>(inp: Inp<'s, 't>) -> Res<'s, 't, ()> {
fn alt2<'s: 't, 't, A>(mut f: impl Parser<'s, 't, A>, mut g: impl Parser<'s, 't, A>) -> impl Parser<'s, 't, A> {
move |inp| {
+ let dist0 = inp.dist;
f(inp.clone()).or_else(|e1| {
- use std::cmp::Ordering::*;
- g(inp).map_err(|e2| match e1.dist.cmp(&e2.dist) {
- Greater => e1,
- Less => e2,
- Equal => ParseErr { expecteds: e1.expecteds.union(&e2.expecteds).cloned().collect(), ..e2 },
+ if e1.dist > dist0 {
+ return Err(e1);
+ }
+ g(inp).map_err(|e2| {
+ if e2.dist > dist0 {
+ return e2;
+ }
+ ParseErr { expecteds: e1.expecteds.union(&e2.expecteds).cloned().collect(), ..e2 }
})
})
}