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>;