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