oak_liquid/parser/
element_type.rs1use oak_core::{ElementType, UniversalElementRole};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub enum LiquidElementType {
10 Root,
12 Text,
14 Variable,
16 Block,
18 Comment,
20 IfStatement,
22 ForStatement,
24 MacroDefinition,
26 Tag,
28 Filter,
30 Expression,
32 Identifier,
34 Literal,
36 Function,
38 Error,
40}
41
42impl ElementType for LiquidElementType {
43 type Role = UniversalElementRole;
44
45 fn role(&self) -> Self::Role {
46 match self {
47 Self::Error => UniversalElementRole::Error,
48 _ => UniversalElementRole::None,
49 }
50 }
51}
52
53impl From<crate::lexer::token_type::LiquidTokenType> for LiquidElementType {
54 fn from(token_type: crate::lexer::token_type::LiquidTokenType) -> Self {
55 match token_type {
56 crate::lexer::token_type::LiquidTokenType::Text => Self::Text,
57 crate::lexer::token_type::LiquidTokenType::DoubleLeftBrace => Self::Variable,
58 crate::lexer::token_type::LiquidTokenType::DoubleRightBrace => Self::Variable,
59 crate::lexer::token_type::LiquidTokenType::LeftBracePercent => Self::Tag,
60 crate::lexer::token_type::LiquidTokenType::PercentRightBrace => Self::Tag,
61 crate::lexer::token_type::LiquidTokenType::Identifier => Self::Identifier,
62 crate::lexer::token_type::LiquidTokenType::String => Self::Literal,
63 crate::lexer::token_type::LiquidTokenType::Number => Self::Literal,
64 crate::lexer::token_type::LiquidTokenType::Boolean => Self::Literal,
65 crate::lexer::token_type::LiquidTokenType::Whitespace => Self::Text,
66 crate::lexer::token_type::LiquidTokenType::Comment => Self::Comment,
67 crate::lexer::token_type::LiquidTokenType::Eof => Self::Text,
68 crate::lexer::token_type::LiquidTokenType::Error => Self::Error,
69 _ => Self::Expression,
70 }
71 }
72}