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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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 SFVResult<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 items: Vec<Item>,
pub params: Parameters,
}
impl InnerList {
fn new(items: Vec<Item>) -> InnerList {
InnerList {
items,
params: Parameters::new(),
}
}
pub fn with_params(items: Vec<Item>, params: Parameters) -> InnerList {
InnerList { items, params }
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct Item {
pub bare_item: BareItem,
pub params: Parameters,
}
impl Item {
fn new(bare_item: BareItem) -> Item {
Item {
bare_item,
params: Parameters::new(),
}
}
pub fn with_params(bare_item: BareItem, params: Parameters) -> Item {
Item { bare_item, params }
}
}
#[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))
}
}