extern crate honeycomb; use honeycomb::{ atoms::{rec, seq_no_ws}, language, transform::{to_btree, to_number}, Parser, }; use std::collections::BTreeMap; #[derive(Debug, Clone, PartialEq)] pub enum JsonValue { Null, Bool(bool), Str(String), Num(f64), Array(Vec), Object(BTreeMap), } fn boolean() -> Parser { (seq_no_ws("true") - |_| JsonValue::Bool(true)) | (seq_no_ws("false") - |_| JsonValue::Bool(false)) } fn string() -> Parser { language::string() } fn number() -> Parser { language::number() - to_number - JsonValue::Num } fn null() -> Parser { seq_no_ws("null") - |_| JsonValue::Null } fn array() -> Parser { language::array("[", json(), "]") - JsonValue::Array } fn object() -> Parser { language::array("{", string() << seq_no_ws(":") & rec(json), "}") - to_btree - JsonValue::Object } fn json() -> Parser { null() | boolean() | number() | (string() - JsonValue::Str) | rec(array) | rec(object) } fn main() { println!( "{:#?}", json().parse( r#" { "testing" : null, "recursion" : { "WOW": 1.2345 }, "array": [1, 2, {"test": "123"}, 4], "test": "testing" } "# ) ); }