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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
pub mod lexical;
pub mod value;
pub use value::*;
pub enum PrimitiveDatatype {
String,
Boolean,
Decimal,
Float,
Double,
Duration,
DateTime,
Time,
Date,
GYearMonth,
GYear,
GMonthDay,
GDay,
GMonth,
HexBinary,
Base64Binary,
AnyUri,
QName,
Notation,
}
macro_rules! impl_from {
{
$ty:ty {
$($input:ident : $from_ty:ty => Self::$variant:ident($output:expr)),*
}
} => {
$(
impl From<$from_ty> for $ty {
fn from($input: $from_ty) -> Self {
Self::$variant(Some($output))
}
}
impl From<Option<$from_ty>> for $ty {
fn from(input_opt: Option<$from_ty>) -> Self {
Self::$variant(input_opt.map(|$input| $output))
}
}
)*
};
}
pub enum Datatype {
String(Option<StringDatatype>),
Boolean,
Decimal(Option<DecimalDatatype>),
Float,
Double,
Duration(Option<DurationDatatype>),
DateTime(Option<DateTimeDatatype>),
Time,
Date,
GYearMonth,
GYear,
GMonthDay,
GDay,
GMonth,
HexBinary,
Base64Binary,
AnyUri,
QName,
Notation,
}
impl_from!(Datatype {
ty: StringDatatype => Self::String(ty),
ty: DecimalDatatype => Self::Decimal(ty),
ty: IntegerDatatype => Self::Decimal(ty.into()),
ty: NonPositiveIntegerDatatype => Self::Decimal(ty.into()),
ty: LongDatatype => Self::Decimal(ty.into()),
ty: IntDatatype => Self::Decimal(ty.into()),
ty: ShortDatatype => Self::Decimal(ty.into()),
ty: NonNegativeIntegerDatatype => Self::Decimal(ty.into()),
ty: UnsignedLongDatatype => Self::Decimal(ty.into()),
ty: UnsignedIntDatatype => Self::Decimal(ty.into()),
ty: UnsignedShortDatatype => Self::Decimal(ty.into()),
ty: DurationDatatype => Self::Duration(ty),
ty: DateTimeDatatype => Self::DateTime(ty)
});
pub enum StringDatatype {
NormalizedString(Option<NormalizedStringDatatype>),
}
pub enum NormalizedStringDatatype {
Token(Option<TokenDatatype>),
}
pub enum TokenDatatype {
Language,
NMToken,
Name(Option<NameDatatype>),
}
pub enum NameDatatype {
NCName(Option<NCNameDatatype>),
}
pub enum NCNameDatatype {
Id,
IdRef,
Entity,
}
pub enum DecimalDatatype {
Integer(Option<IntegerDatatype>),
}
impl_from!(DecimalDatatype {
ty: IntegerDatatype => Self::Integer(ty),
ty: NonPositiveIntegerDatatype => Self::Integer(ty.into()),
ty: LongDatatype => Self::Integer(ty.into()),
ty: IntDatatype => Self::Integer(ty.into()),
ty: ShortDatatype => Self::Integer(ty.into()),
ty: NonNegativeIntegerDatatype => Self::Integer(ty.into()),
ty: UnsignedLongDatatype => Self::Integer(ty.into()),
ty: UnsignedIntDatatype => Self::Integer(ty.into()),
ty: UnsignedShortDatatype => Self::Integer(ty.into())
});
pub enum IntegerDatatype {
NonPositiveInteger(Option<NonPositiveIntegerDatatype>),
Long(Option<LongDatatype>),
NonNegativeInteger(Option<NonNegativeIntegerDatatype>),
}
impl_from!(IntegerDatatype {
ty: NonPositiveIntegerDatatype => Self::NonPositiveInteger(ty),
ty: LongDatatype => Self::Long(ty),
ty: IntDatatype => Self::Long(ty.into()),
ty: ShortDatatype => Self::Long(ty.into()),
ty: NonNegativeIntegerDatatype => Self::NonNegativeInteger(ty),
ty: UnsignedLongDatatype => Self::NonNegativeInteger(ty.into()),
ty: UnsignedIntDatatype => Self::NonNegativeInteger(ty.into()),
ty: UnsignedShortDatatype => Self::NonNegativeInteger(ty.into())
});
pub enum NonPositiveIntegerDatatype {
NegativeInteger,
}
pub enum LongDatatype {
Int(Option<IntDatatype>),
}
impl_from!(LongDatatype {
ty: IntDatatype => Self::Int(ty),
ty: ShortDatatype => Self::Int(ty.into())
});
pub enum IntDatatype {
Short(Option<ShortDatatype>),
}
impl_from!(IntDatatype {
ty: ShortDatatype => Self::Short(ty)
});
pub enum ShortDatatype {
Byte,
}
pub enum NonNegativeIntegerDatatype {
UnsignedLong(Option<UnsignedLongDatatype>),
PositiveInteger,
}
impl_from!(NonNegativeIntegerDatatype {
ty: UnsignedLongDatatype => Self::UnsignedLong(ty),
ty: UnsignedIntDatatype => Self::UnsignedLong(ty.into()),
ty: UnsignedShortDatatype => Self::UnsignedLong(ty.into())
});
pub enum UnsignedLongDatatype {
UnsignedInt(Option<UnsignedIntDatatype>),
}
impl_from!(UnsignedLongDatatype {
ty: UnsignedIntDatatype => Self::UnsignedInt(ty),
ty: UnsignedShortDatatype => Self::UnsignedInt(ty.into())
});
pub enum UnsignedIntDatatype {
UnsignedShort(Option<UnsignedShortDatatype>),
}
impl_from!(UnsignedIntDatatype {
ty: UnsignedShortDatatype => Self::UnsignedShort(ty)
});
pub enum UnsignedShortDatatype {
UnsignedByte,
}
pub enum DurationDatatype {
YearMonth,
DayTime,
}
pub enum DateTimeDatatype {
DateTimeStamp,
}