diff --git a/src/combinator.rs b/src/combinator.rs index 12c25692..70617eec 100644 --- a/src/combinator.rs +++ b/src/combinator.rs @@ -2008,6 +2008,8 @@ where #[inline(always)] fn go(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult { let mut state = self.make_iter::(inp)?; + #[cfg(debug_assertions)] + let mut first_loop = true; loop { #[cfg(debug_assertions)] let before = inp.cursor(); @@ -2020,11 +2022,15 @@ where Err(()) => break Err(()), } #[cfg(debug_assertions)] - debug_assert!( - before != inp.cursor(), - "found SeparatedBy combinator making no progress at {}", - self.location, - ); + if !first_loop { + debug_assert!( + before != inp.cursor(), + "found SeparatedBy combinator making no progress at {}", + self.location, + ); + } else { + first_loop = false; + } } } diff --git a/src/lib.rs b/src/lib.rs index d361d997..c155f11e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3861,6 +3861,17 @@ mod tests { ) } + #[test] + fn separated_by() { + use crate::{error::Simple, extra}; + + let parser = just::<_, &str, extra::Err>>("a") + .or_not() + .separated_by(just("b")); + + assert_eq!(parser.parse("bba").into_result(), Ok(())); + } + #[test] fn zero_size_custom_failure() { fn my_custom<'src>() -> impl Parser<'src, &'src str, ()> {