Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suprised by error from is_not on empty result #1767

Open
barskern opened this issue Jun 26, 2024 · 1 comment
Open

Suprised by error from is_not on empty result #1767

barskern opened this issue Jun 26, 2024 · 1 comment

Comments

@barskern
Copy link

barskern commented Jun 26, 2024

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:

  • Rust version : rustc 1.78.0 (9b00956e5 2024-04-29)
  • nom version : 7.1.3
  • nom compilation features used: default

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);
}
@docwilco
Copy link

is_not wants at least one character to match. It's basically is_not1 and not is_not0.

Now I would suggest making two parsers, is_not0 and is_not1. To make this distinction clear, and make it consistent with all the other foo0 and foo1 functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants