chumsky
chumsky copied to clipboard
`separated_by()` crashes with an error when it shouldn't
Minimum example:
use chumsky::{extra, error::Simple};
fn parser() -> impl Parser<'static, &'static str, (), extra::Err<Simple<'static, char>>> + Copy {
just("a").or_not().separated_by(just("b"))
}
assert_eq!(parser().parse("bba").into_result(), Ok(()));
Gives out:
thread 'syntax::parse::whitespace::tests::test' panicked at C:\Users\Professional\.cargo\git\checkouts\chumsky-651fb76526ac39e3\11f5913\src\combinator.rs:1869:13:
found SeparatedBy combinator making no progress at src\syntax\parse\whitespace.rs:52:33
Well caught!
I think the assumption here, that every iteration should yield a change in the cursor position, is wrong. In this case, the first iteration (which looks only for the separatee) produces no progress, but the second one (which would look for the first separator and another separatee) would make progress.
One solution might be to check that the loop has already spun around at least once before producing the panic (as simple first_loop boolean that gets set to false after the first loop should be sufficient). Do you feel like opening a PR for that?
I recommend looking at #836