Skip to content

Changed behaviour of recognize from nom 7 to nom 8 #1876

@a-maier

Description

@a-maier

In nom 7 recognize returns the complete consumed input:

#!/usr/bin/env rust-script
//! ```cargo
//! [dependencies]
//! nom = "7"
//! ```

use nom::{
    IResult,
    character::complete::{alpha1, alphanumeric0},
    combinator::recognize,
};

fn main() {
    let id = "x11";

    use nom::sequence::tuple;
    fn var(input: &str) -> IResult<&str, &str> {
        recognize(tuple((alpha1, alphanumeric0)))(input)
    }
    assert_eq!(var(id), Ok(("", "x11")));
}

In nom 8 only the first character is returned:

#!/usr/bin/env rust-script
//! ```cargo
//! [dependencies]
//! nom = "8"
//! ```

use nom::{
    IResult,
    character::complete::{alpha1, alphanumeric0},
    combinator::recognize,
};

fn main() {
    let id = "x11";

    use nom::Parser;
    fn var(input: &str) -> IResult<&str, &str> {
        recognize((alpha1, alphanumeric0)).parse(input)
    }
    assert_eq!(var(id), Ok(("", "x")));
}

Is this intended? Is there a way to get back the old behaviour?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions