Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/combinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2008,6 +2008,8 @@ where
#[inline(always)]
fn go<M: Mode>(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult<M, ()> {
let mut state = self.make_iter::<Check>(inp)?;
#[cfg(debug_assertions)]
let mut first_loop = true;
loop {
#[cfg(debug_assertions)]
let before = inp.cursor();
Expand All @@ -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;
}
Comment on lines +2025 to +2033

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Maybe this logic should be moved to the IterParser implementation so it works for .separated_by(...).collect() too? What do you think?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Maybe this logic should be moved to the IterParser implementation so it works for .separated_by(...).collect() too? What do you think?

I've been thinking, I think we need the ability to call next by telling it whether to respond to a lack of progress.

}
}

Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3861,6 +3861,17 @@ mod tests {
)
}

#[test]
fn separated_by() {
use crate::{error::Simple, extra};

let parser = just::<_, &str, extra::Err<Simple<_>>>("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, ()> {
Expand Down