Skip to main content

oak_dsv/parser/
element_type.rs

1use crate::lexer::DsvTokenType;
2use oak_core::{ElementType, UniversalElementRole};
3
4/// DSV element type
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub enum DsvElementType {
8    /// Source file (root)
9    SourceFile,
10    /// Record (row)
11    Record,
12    /// Field
13    Field,
14}
15
16impl ElementType for DsvElementType {
17    type Role = UniversalElementRole;
18
19    fn role(&self) -> Self::Role {
20        match self {
21            Self::SourceFile => UniversalElementRole::Root,
22            Self::Record => UniversalElementRole::Container,
23            Self::Field => UniversalElementRole::Value,
24        }
25    }
26}
27
28impl From<DsvTokenType> for DsvElementType {
29    fn from(token: DsvTokenType) -> Self {
30        match token {
31            _ => Self::Field,
32        }
33    }
34}