~jojo/effem

7d0e00eabc1ad542e7c29c30c820b8afb250f66d — JoJo 1 year, 18 days ago 6a4251c
fix parse::alt2 continuing with next alternative when it shouldn't
1 files changed, 9 insertions(+), 5 deletions(-)

M src/parse.rs
M src/parse.rs => src/parse.rs +9 -5
@@ 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 }
            })
        })
    }