oak_ini/parser/
element_type.rs1use oak_core::{ElementType, UniversalElementRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum IniElementType {
7 Whitespace,
9 Newline,
11 Comment,
13 Error,
15 Eof,
17
18 LeftBrace,
20 RightBrace,
22 LeftBracket,
24 RightBracket,
26 DoubleLeftBracket,
28 DoubleRightBracket,
30 Comma,
32 Dot,
34 Equal,
36
37 Identifier,
39 String,
41 Integer,
43 Float,
45 Boolean,
47 DateTime,
49
50 Root,
52 Document,
54 Section,
56 Table,
58 ArrayOfTables,
60 KeyValue,
62 Key,
64 Value,
66 Array,
68 InlineTable,
70}
71
72impl ElementType for IniElementType {
73 type Role = UniversalElementRole;
74
75 fn role(&self) -> Self::Role {
76 match self {
77 Self::Root | Self::Document => UniversalElementRole::Root,
78 Self::Section | Self::Table | Self::ArrayOfTables | Self::Array | Self::InlineTable => UniversalElementRole::Container,
79 Self::KeyValue => UniversalElementRole::Attribute,
80 Self::Key => UniversalElementRole::AttributeKey,
81 Self::Value => UniversalElementRole::Value,
82 _ => UniversalElementRole::None,
83 }
84 }
85}
86
87impl From<crate::lexer::token_type::IniTokenType> for IniElementType {
88 fn from(token: crate::lexer::token_type::IniTokenType) -> Self {
89 match token {
90 crate::lexer::token_type::IniTokenType::Whitespace => Self::Whitespace,
91 crate::lexer::token_type::IniTokenType::Newline => Self::Newline,
92 crate::lexer::token_type::IniTokenType::Comment => Self::Comment,
93 crate::lexer::token_type::IniTokenType::Error => Self::Error,
94 crate::lexer::token_type::IniTokenType::Eof => Self::Eof,
95 crate::lexer::token_type::IniTokenType::LeftBrace => Self::LeftBrace,
96 crate::lexer::token_type::IniTokenType::RightBrace => Self::RightBrace,
97 crate::lexer::token_type::IniTokenType::LeftBracket => Self::LeftBracket,
98 crate::lexer::token_type::IniTokenType::RightBracket => Self::RightBracket,
99 crate::lexer::token_type::IniTokenType::DoubleLeftBracket => Self::DoubleLeftBracket,
100 crate::lexer::token_type::IniTokenType::DoubleRightBracket => Self::DoubleRightBracket,
101 crate::lexer::token_type::IniTokenType::Comma => Self::Comma,
102 crate::lexer::token_type::IniTokenType::Dot => Self::Dot,
103 crate::lexer::token_type::IniTokenType::Equal => Self::Equal,
104 crate::lexer::token_type::IniTokenType::Identifier => Self::Identifier,
105 crate::lexer::token_type::IniTokenType::String => Self::String,
106 crate::lexer::token_type::IniTokenType::Integer => Self::Integer,
107 crate::lexer::token_type::IniTokenType::Float => Self::Float,
108 crate::lexer::token_type::IniTokenType::Boolean => Self::Boolean,
109 crate::lexer::token_type::IniTokenType::DateTime => Self::DateTime,
110 }
111 }
112}