rust-bakery / nom

Rust parser combinator framework
MIT License
9.38k stars 804 forks source link

Suprised by error from `is_not` on empty result #1767

Open barskern opened 3 months ago

barskern commented 3 months ago

I was suprised when using is_not that it errored when the resulting slice is empty, despite the fact that it finds the terminating character. I would think that it should only 'care' about finding the terminating character (similarly to take_till), and that it shouldn't enforce anything regarding the output. I assumed the following test case would hold. Is this the intended behaviour?

Prerequisites

Here are a few things you should provide to help me understand the issue:

Test case

#[test]
fn nom_bytes_is_not_assumption() {
    use nom::Parser;

    let input = "\n";
    let mut p = nom::bytes::complete::is_not::<_, _, nom::error::VerboseError<&str>>("\r\n\t");
    let (rem, v) = p.parse(input).unwrap();

    assert_eq!("", v);
    assert_eq!(input, rem);
}