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

Float parsing with trailing e broken #1725

Open
grantslatton opened this issue Jan 31, 2024 · 1 comment
Open

Float parsing with trailing e broken #1725

grantslatton opened this issue Jan 31, 2024 · 1 comment

Comments

@grantslatton
Copy link

rustc -V
rustc 1.75.0 (82e1608df 2023-12-21)
nom 7.1.3

This code

nom::number::complete::recognize_float("123episode")

Fails with Failure(Error { input: "pisode", code: Digit }) instead of returning ("episode", 123.0)

The nom::number::complete::double parser is similarly broken

This is something to do with scientific notation (e.g. 123e6) handling

@arashatt
Copy link

Does removing the cut solve the problem?

cut(digit1)

this will make the:

nom/src/number/complete.rs

Lines 1257 to 1261 in 7afe3a8

opt((
alt((char('e'), char('E'))),
opt(alt((char('+'), char('-')))),
cut(digit1)
))

as None and will not consume e in episode.

Here is a test which successfully passes:

    #[test]
    fn _1725_test() {
        assert_eq!(
            nom::number::complete::recognize_float::<_, (_, _)>("123episode"),
            Ok(("episode", "123"))
        );
    }

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