oak_tailwind/parser/
element_type.rs1use oak_core::{ElementType, UniversalElementRole};
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7pub enum TailwindElementType {
8 Root,
10 Class,
12 Modifier,
14 Utility,
16 ArbitraryValue,
18 Directive,
20 Declaration,
22 Comment,
24 ErrorNode,
26}
27
28impl core::fmt::Display for TailwindElementType {
29 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
30 match self {
31 Self::Root => f.write_str("Root"),
32 Self::Class => f.write_str("Class"),
33 Self::Modifier => f.write_str("Modifier"),
34 Self::Utility => f.write_str("Utility"),
35 Self::ArbitraryValue => f.write_str("ArbitraryValue"),
36 Self::Directive => f.write_str("Directive"),
37 Self::Declaration => f.write_str("Declaration"),
38 Self::Comment => f.write_str("Comment"),
39 Self::ErrorNode => f.write_str("ErrorNode"),
40 }
41 }
42}
43
44impl ElementType for TailwindElementType {
45 type Role = UniversalElementRole;
46
47 fn role(&self) -> Self::Role {
48 match self {
49 Self::Root => UniversalElementRole::Root,
50 Self::Class => UniversalElementRole::Attribute,
51 Self::Modifier => UniversalElementRole::AttributeKey,
52 Self::Utility => UniversalElementRole::Name,
53 Self::ArbitraryValue => UniversalElementRole::Value,
54 Self::Directive => UniversalElementRole::Metadata,
55 Self::Declaration => UniversalElementRole::Metadata,
56 Self::Comment => UniversalElementRole::Documentation,
57 Self::ErrorNode => UniversalElementRole::Error,
58 }
59 }
60}
61
62impl From<crate::lexer::token_type::TailwindTokenType> for TailwindElementType {
63 fn from(token: crate::lexer::token_type::TailwindTokenType) -> Self {
64 match token {
65 crate::lexer::token_type::TailwindTokenType::Root => Self::Root,
66 crate::lexer::token_type::TailwindTokenType::Directive => Self::Directive,
67 crate::lexer::token_type::TailwindTokenType::Modifier => Self::Modifier,
68 crate::lexer::token_type::TailwindTokenType::Utility => Self::Utility,
69 crate::lexer::token_type::TailwindTokenType::ArbitraryValue => Self::ArbitraryValue,
70 crate::lexer::token_type::TailwindTokenType::Comment => Self::Comment,
71 _ => Self::ErrorNode,
72 }
73 }
74}