-
Notifications
You must be signed in to change notification settings - Fork 834
Open
Description
I figured a good way to get experience with nom is to write a JSON parser. Part of that is the number definition which forbids leading zeros (see json.org). I'm having trouble getting it to actually work. Everything else seems to be working but the whole numbers.
Minimal Example
#[test]
fn minimal_example() {
let (un, val) = nom::combinator::recognize(nom::branch::alt((
// exactly "0"
nom::bytes::complete::tag::<_, _, nom::error::Error<&str>>("0"),
// or <non-zero digit> then zero-or-more digits
nom::combinator::recognize((
nom::character::one_of("123456789"),
nom::character::complete::digit0,
)),
)))
.parse("123")
.unwrap();
assert_eq!(un, "");
assert_eq!(val, "123");
}
Result
running 1 test
test tests::minimal_example ... FAILED
failures:
---- tests::minimal_example stdout ----
thread 'tests::minimal_example' panicked at src\main.rs:273:9:
assertion `left == right` failed
left: "1"
right: "123"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
tests::minimal_example
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 9 filtered out; finished in 0.00s
I've spent a solid 4 hours on this now and have no clue what to do.
Metadata
Metadata
Assignees
Labels
No labels