diff --git a/src/jsonparser.rs b/src/jsonparser.rs index 9ccf937..71119f2 100644 --- a/src/jsonparser.rs +++ b/src/jsonparser.rs @@ -495,5 +495,17 @@ mod tests { assert_eq!(rows[6].range, 40..44); // true assert_eq!(rows[7].range, 46..51); // false assert_eq!(rows[8].range, 51..52); // ] + + // 01 6 12 18 24 33 + let json = r#"[nan, +Nan, -NaN, -inf, +infinity]"#.to_owned(); + let (rows, _, _) = parse(json).unwrap(); + + assert_eq!(rows[0].range, 0..34); // Array + assert_eq!(rows[1].range, 1..4); // nan + assert_eq!(rows[2].range, 6..10); // +Nan + assert_eq!(rows[3].range, 12..16); // +Nan + assert_eq!(rows[4].range, 18..22); // -inf + assert_eq!(rows[5].range, 24..33); // +infinity + assert_eq!(rows[6].range, 33..34); // ] } } diff --git a/src/jsontokenizer.rs b/src/jsontokenizer.rs index e35e708..ced51d7 100644 --- a/src/jsontokenizer.rs +++ b/src/jsontokenizer.rs @@ -23,7 +23,23 @@ pub enum JsonToken { True, #[token("false")] False, - #[regex(r"-?(0|([1-9][0-9]*))(\.[0-9]+)?([eE][-+]?[0-9]+)?")] + #[regex( + r"(?x)(?i) + [-+]? + ( + 0 | + ([1-9][0-9]*) | + nan | + inf(inity)? + ) + ( + \.[0-9]+ + )? + ( + e[-+]?[0-9]+ + )? + " + )] Number, // I get an error when I do [0-9a-fA-F]{4}. #[regex("\"((\\\\([\"\\\\/bfnrt]|u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]))|[^\"\\\\\x00-\x1F])*\"")]