use super::SectionKind;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParserState {
ExpectingSection,
InSection(SectionKind),
InEvent {
section: SectionKind,
fields_seen: usize,
},
}
impl ParserState {
#[must_use]
pub const fn is_in_section(&self) -> bool {
matches!(self, Self::InSection(_) | Self::InEvent { .. })
}
#[must_use]
pub const fn current_section(&self) -> Option<SectionKind> {
match self {
Self::ExpectingSection => None,
Self::InSection(kind) => Some(*kind),
Self::InEvent { section, .. } => Some(*section),
}
}
pub fn enter_section(&mut self, kind: SectionKind) {
*self = Self::InSection(kind);
}
pub fn enter_event(&mut self, section: SectionKind) {
*self = Self::InEvent {
section,
fields_seen: 0,
};
}
pub fn exit_section(&mut self) {
*self = Self::ExpectingSection;
}
}