json array

This commit is contained in:
Greg Shuflin 2022-10-20 23:37:46 -07:00
parent 7a832b6ba2
commit b7db411671

View File

@ -101,11 +101,10 @@ mod tests {
} }
fn json_array() -> impl JsonParser<'static, JsonValue> { fn json_array() -> impl JsonParser<'static, JsonValue> {
let val = whitespace() let val = json_value().delimited(whitespace(), whitespace());
.ignore_then(json_value())
.then_ignore(whitespace());
repeated(val) repeated(val)
.separated_by(literal(","), false)
.delimited(literal_char('['), literal_char(']')) .delimited(literal_char('['), literal_char(']'))
.map(JsonValue::Array) .map(JsonValue::Array)
} }
@ -120,9 +119,9 @@ mod tests {
json_string().parse(r#""yolo swagg""#).unwrap(), json_string().parse(r#""yolo swagg""#).unwrap(),
(JsonValue::Str("yolo swagg".into()), "") (JsonValue::Str("yolo swagg".into()), "")
); );
//TODO not correct! assert!(json_array().parse(r#"[ 4, 9, "ara",]"#).is_err());
assert_eq!( assert_eq!(
json_array().parse(r#"[ 4 9 "foo" ]"#).unwrap(), json_array().parse(r#"[ 4, 9, "foo" ]"#).unwrap(),
( (
JsonValue::Array(vec![ JsonValue::Array(vec![
JsonValue::Num(4.), JsonValue::Num(4.),