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)]
6#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7pub enum IniElementType {
8 Whitespace,
10 Newline,
11 Comment,
12 Error,
13 Eof,
14
15 LeftBrace,
17 RightBrace,
18 LeftBracket,
19 RightBracket,
20 DoubleLeftBracket,
21 DoubleRightBracket,
22 Comma,
23 Dot,
24 Equal,
25
26 Identifier,
28 String,
29 Integer,
30 Float,
31 Boolean,
32 DateTime,
33
34 Root,
36 Document,
37 Section,
38 Table,
39 ArrayOfTables,
40 KeyValue,
41 Key,
42 Value,
43 Array,
44 InlineTable,
45}
46
47impl ElementType for IniElementType {
48 type Role = UniversalElementRole;
49
50 fn role(&self) -> Self::Role {
51 match self {
52 Self::Root | Self::Document => UniversalElementRole::Root,
53 Self::Section | Self::Table | Self::ArrayOfTables | Self::Array | Self::InlineTable => UniversalElementRole::Container,
54 Self::KeyValue => UniversalElementRole::Attribute,
55 Self::Key => UniversalElementRole::AttributeKey,
56 Self::Value => UniversalElementRole::Value,
57 _ => UniversalElementRole::None,
58 }
59 }
60}
61
62impl From<crate::lexer::token_type::IniTokenType> for IniElementType {
63 fn from(token: crate::lexer::token_type::IniTokenType) -> Self {
64 match token {
65 crate::lexer::token_type::IniTokenType::Whitespace => Self::Whitespace,
66 crate::lexer::token_type::IniTokenType::Newline => Self::Newline,
67 crate::lexer::token_type::IniTokenType::Comment => Self::Comment,
68 crate::lexer::token_type::IniTokenType::Error => Self::Error,
69 crate::lexer::token_type::IniTokenType::Eof => Self::Eof,
70 crate::lexer::token_type::IniTokenType::LeftBrace => Self::LeftBrace,
71 crate::lexer::token_type::IniTokenType::RightBrace => Self::RightBrace,
72 crate::lexer::token_type::IniTokenType::LeftBracket => Self::LeftBracket,
73 crate::lexer::token_type::IniTokenType::RightBracket => Self::RightBracket,
74 crate::lexer::token_type::IniTokenType::DoubleLeftBracket => Self::DoubleLeftBracket,
75 crate::lexer::token_type::IniTokenType::DoubleRightBracket => Self::DoubleRightBracket,
76 crate::lexer::token_type::IniTokenType::Comma => Self::Comma,
77 crate::lexer::token_type::IniTokenType::Dot => Self::Dot,
78 crate::lexer::token_type::IniTokenType::Equal => Self::Equal,
79 crate::lexer::token_type::IniTokenType::Identifier => Self::Identifier,
80 crate::lexer::token_type::IniTokenType::String => Self::String,
81 crate::lexer::token_type::IniTokenType::Integer => Self::Integer,
82 crate::lexer::token_type::IniTokenType::Float => Self::Float,
83 crate::lexer::token_type::IniTokenType::Boolean => Self::Boolean,
84 crate::lexer::token_type::IniTokenType::DateTime => Self::DateTime,
85 }
86 }
87}