Skip to main content

oak_yaml/parser/
element_type.rs

1use oak_core::{ElementType, UniversalElementRole};
2
3/// Element types for the YAML language.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[repr(u16)]
7pub enum YamlElementType {
8    /// A leaf node containing a single token.
9    Token(crate::lexer::token_type::YamlTokenType),
10    /// A YAML document.
11    Document,
12    /// The root node of a YAML file.
13    Root,
14    /// An error node.
15    Error,
16}
17
18impl ElementType for YamlElementType {
19    type Role = UniversalElementRole;
20
21    fn role(&self) -> Self::Role {
22        match self {
23            Self::Root => UniversalElementRole::Root,
24            Self::Document => UniversalElementRole::Container,
25            _ => UniversalElementRole::None,
26        }
27    }
28}
29
30impl From<crate::lexer::token_type::YamlTokenType> for YamlElementType {
31    fn from(token: crate::lexer::token_type::YamlTokenType) -> Self {
32        Self::Token(token)
33    }
34}