/
main.rs
41 lines (32 loc) · 1.04 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#![allow(unused)]
use std::{collections::HashMap, fs};
use parseal::{
data_formats::{NamedValue, Node, ParseNode, TreeData},
parsing::{
self,
charstream::CharStream,
tokens::{Brace, Bracket, Colon, Comma},
Group, Identifier, List, Number, Parse, StringValue,
},
Parsable,
};
#[derive(Clone, Parsable, Debug)]
pub struct JSON {
value: ParseNode<<JSON as TreeData>::Object, <JSON as TreeData>::List>,
}
impl TreeData for JSON {
type Object = Group<Brace, List<NamedValue<StringValue, Colon, JSON>, Comma>>;
type List = Group<Bracket, List<JSON, Comma>>;
fn value(&self) -> ParseNode<Self::Object, Self::List> {
self.value.clone()
}
}
fn main() {
let file =
fs::read_to_string("examples/json/example.json").expect("Expected example file to exist.");
let mut buffer = CharStream::new(file).build();
let value = JSON::parse(&mut buffer).unwrap();
let node: Node = value.clone().into();
println!("value: {:#?}", value);
println!("node: {:#?}", node);
}