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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// use crate::parse::*;
// extern crate pretty;
// use pretty::Pretty;
// use std::collections::HashMap;
// #[derive(Pretty, Debug, Clone, PartialEq)]
// pub enum TomlValue<'a> {
// String(&'a str),
// Integer(i64),
// Float(f64),
// Boolean(bool),
// DateTime(&'a str),
// Array(Vec<TomlValue<'a>>),
// InlineTable(HashMap<&'a str, TomlValue<'a>>),
// }
// type TomlKeyValue<'a> = (&'a str, TomlValue<'a>);
// pub fn toml_value<'a>() -> Parser<'a, TomlValue<'a>> {
// let string_char = || {
// let not_quote = take_while_span(|c| c != '"' && c != '\\');
// let string = (not_quote | escaped_span())
// .many_span(..)
// .wrap_span(string_span("\""), string_span("\""));
// return string.map(|s| s.as_str());
// };
// let toml_string = || string_char().map(TomlValue::String);
// let toml_integer = || {
// let sign = || string_span("-").opt_span();
// let digits = || take_while_span(|c| c.is_digit(10));
// let integer = digits();
// return sign()
// .then_span(integer)
// .map(|s| s.as_str().parse().unwrap())
// .map(TomlValue::Integer);
// };
// let toml_float = || {
// let sign = || string_span("-").opt_span();
// let digits = || take_while_span(|c| c.is_digit(10));
// let integer = digits();
// let fraction = string_span(".").then_span(digits());
// let exponent = (string_span("e") | string_span("E"))
// .then_span(sign())
// .then_span(digits());
// return sign()
// .then_span(integer)
// .then_span(fraction)
// .then_span(exponent.opt_span())
// .map(|s| s.as_str().parse().unwrap())
// .map(TomlValue::Float);
// };
// let toml_boolean = string_span("true").map(|_| TomlValue::Boolean(true))
// | string_span("false").map(|_| TomlValue::Boolean(false));
// let toml_datetime =
// take_while_span(|c| c.is_digit(10) || c == ':' || c == '-' || c == 'T' || c == 'Z')
// .map(|s| TomlValue::DateTime(s.as_str()));
// let toml_array = lazy(|| {
// let comma = string_span(",").trim_whitespace();
// toml_value()
// .sep_by(comma, ..)
// .or_else(|| vec![])
// .trim_whitespace()
// .wrap(string_span("["), string_span("]"))
// .map(TomlValue::Array)
// });
// let toml_inline_table = lazy(move || {
// let equals = string_span("=").trim_whitespace();
// let comma = string_span(",").trim_whitespace();
// let key_value = string_char().skip(equals).with(toml_value());
// key_value
// .sep_by(comma, ..)
// .or_else(|| vec![])
// .trim_whitespace()
// .wrap(string_span("{"), string_span("}"))
// .map(|pairs| TomlValue::InlineTable(pairs.into_iter().collect()))
// });
// toml_inline_table
// | toml_array
// | toml_string()
// | toml_float()
// | toml_integer()
// | toml_boolean
// | toml_datetime
// }
// pub fn toml_key_value<'a>() -> Parser<'a, TomlKeyValue<'a>> {
// let string_char = || {
// let not_quote = take_while_span(|c| c != '"' && c != '\\');
// let string = (not_quote | escaped_span())
// .many_span(..)
// .wrap_span(string_span("\""), string_span("\""));
// return string;
// };
// let bare_key = take_while_span(|c| c.is_alphanumeric() || c == ' ' || c == '-');
// let key = (bare_key | string_char()).map(|s| s.as_str());
// let equals = string_span("=").trim_whitespace();
// key.skip(equals).with(toml_value())
// }
// pub fn toml_table<'a>() -> Parser<'a, (Vec<&'a str>, HashMap<&'a str, TomlValue<'a>>)> {
// let table_start = string_span("[").trim_whitespace();
// let table_end = string_span("]").trim_whitespace();
// let dot = string_span(".").trim_whitespace();
// let table_name = toml_key_value()
// .map(|(key, _)| key)
// .sep_by(dot, ..)
// .trim_whitespace()
// .wrap(table_start, table_end);
// let key_values = toml_key_value()
// .sep_by(string_span("\n"), ..)
// .or_else(|| vec![])
// .trim_whitespace();
// table_name
// .with(key_values)
// .map(|(path, pairs)| (path, pairs.into_iter().collect()))
// }
// pub fn toml_parser<'a>() -> Parser<
// 'a,
// (
// Vec<(Vec<&'a str>, HashMap<&'a str, TomlValue<'a>>)>,
// HashMap<&'a str, TomlValue<'a>>,
// ),
// > {
// let new_line = string_span("\n").trim_whitespace();
// let tables = toml_table().sep_by(new_line, ..).or_else(|| vec![]);
// let key_values = toml_key_value().sep_by(new_line, ..).or_else(|| vec![]);
// tables
// .then(key_values)
// .map(|(tables, kvs)| (tables, kvs.into_iter().collect()))
// }