1use std::collections::HashMap;
2use std::fmt;
3
4#[derive(PartialEq, Clone)]
6pub enum Element {
7 Rulename(String),
9 IString(String),
11 SString(String),
13 NumberValue(u32),
15 ValueRange((u32, u32)),
17 ValueSequence(Vec<u32>),
19 ProseValue(String),
21 Sequence(Vec<Repetition>),
23 Selection(Vec<Repetition>),
25}
26
27impl fmt::Debug for Element {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 match &*self {
30 Element::Rulename(s) => write!(f, "Element::Rulename({:?}.to_string())", s),
31 Element::IString(s) => write!(f, "Element::IString({:?}.to_string())", s),
32 Element::SString(s) => write!(f, "Element::SString({:?}.to_string())", s),
33 Element::NumberValue(n) => write!(f, "Element::NumberValue({:?})", n),
34 Element::ValueRange(t) => write!(f, "Element::ValueRange({:?})", t),
35 Element::ValueSequence(v) => write!(f, "Element::ValueSequence(vec!{:?})", v),
36 Element::ProseValue(s) => write!(f, "Element::ProseValue({:?}.to_string())", s),
37 Element::Sequence(v) => write!(f, "Element::Sequence(vec!{:?})", v),
38 Element::Selection(v) => write!(f, "Element::Selection(vec!{:?})", v),
39 }
40 }
41}
42
43#[derive(PartialEq, Debug, Clone)]
45pub struct Repeat {
46 pub min: Option<usize>,
47 pub max: Option<usize>,
48}
49
50impl Repeat {
51 pub fn new(min: Option<usize>, max: Option<usize>) -> Repeat {
52 Repeat { min, max }
53 }
54}
55
56#[derive(PartialEq, Debug, Clone)]
58pub struct Repetition {
59 pub repeat: Option<Repeat>,
60 pub element: Element,
61}
62
63impl Repetition {
64 pub fn new(repeat: Option<Repeat>, element: Element) -> Repetition {
65 Repetition { repeat, element }
66 }
67}
68
69pub type Rulelist = HashMap<String, Repetition>;