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
use std::collections::HashMap;
use std::fmt;
#[derive(PartialEq, Clone)]
pub enum Element {
Rulename(String),
IString(String),
SString(String),
NumberValue(u32),
ValueRange((u32, u32)),
ValueSequence(Vec<u32>),
ProseValue(String),
Sequence(Vec<Repetition>),
Selection(Vec<Repetition>),
}
impl fmt::Debug for Element {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &*self {
Element::Rulename(s) => write!(f, "Element::Rulename({:?}.to_string())", s),
Element::IString(s) => write!(f, "Element::IString({:?}.to_string())", s),
Element::SString(s) => write!(f, "Element::SString({:?}.to_string())", s),
Element::NumberValue(n) => write!(f, "Element::NumberValue({:?})", n),
Element::ValueRange(t) => write!(f, "Element::ValueRange({:?})", t),
Element::ValueSequence(v) => write!(f, "Element::ValueSequence(vec!{:?})", v),
Element::ProseValue(s) => write!(f, "Element::ProseValue({:?}.to_string())", s),
Element::Sequence(v) => write!(f, "Element::Sequence(vec!{:?})", v),
Element::Selection(v) => write!(f, "Element::Selection(vec!{:?})", v),
}
}
}
#[derive(PartialEq, Debug, Clone)]
pub struct Repeat {
pub min: Option<usize>,
pub max: Option<usize>,
}
impl Repeat {
pub fn new(min: Option<usize>, max: Option<usize>) -> Repeat {
Repeat { min, max }
}
}
#[derive(PartialEq, Debug, Clone)]
pub struct Repetition {
pub repeat: Option<Repeat>,
pub element: Element,
}
impl Repetition {
pub fn new(repeat: Option<Repeat>, element: Element) -> Repetition {
Repetition { repeat, element }
}
}
pub type Rulelist = HashMap<String, Repetition>;