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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
mod parser;
mod serializer;
mod utils;
#[cfg(test)]
mod test_parser;
#[cfg(test)]
mod test_serializer;
use indexmap::IndexMap;
pub use rust_decimal::{
prelude::{FromPrimitive, FromStr},
Decimal,
};
pub use parser::{ParseMore, ParseValue, Parser};
pub use serializer::SerializeValue;
type Result<T> = std::result::Result<T, &'static str>;
pub type Dictionary = IndexMap<String, ListEntry>;
pub type Parameters = IndexMap<String, BareItem>;
pub type List = Vec<ListEntry>;
#[derive(Debug, PartialEq, Clone)]
pub enum ListEntry {
Item(Item),
InnerList(InnerList),
}
impl From<Item> for ListEntry {
fn from(item: Item) -> Self {
ListEntry::Item(item)
}
}
impl From<InnerList> for ListEntry {
fn from(item: InnerList) -> Self {
ListEntry::InnerList(item)
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct InnerList(pub Vec<Item>, pub Parameters);
#[derive(Debug, PartialEq, Clone)]
pub struct Item(pub BareItem, pub Parameters);
#[derive(Debug, PartialEq, Clone)]
pub enum Num {
Decimal(Decimal),
Integer(i64),
}
#[derive(Debug, PartialEq, Clone)]
pub enum BareItem {
Number(Num),
String(String),
ByteSeq(Vec<u8>),
Boolean(bool),
Token(String),
}
impl From<i64> for BareItem {
fn from(item: i64) -> Self {
BareItem::Number(Num::Integer(item))
}
}
impl From<Decimal> for BareItem {
fn from(item: Decimal) -> Self {
BareItem::Number(Num::Decimal(item))
}
}