Skip to main content

oak_liquid/parser/
element_type.rs

1/// Liquid Element Type module
2///
3/// This module defines the element types for Liquid templates.
4use oak_core::{ElementType, UniversalElementRole};
5
6/// Element types for Liquid templates
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub enum LiquidElementType {
10    /// Root element
11    Root,
12    /// Text content
13    Text,
14    /// Variable expression
15    Variable,
16    /// Block statement
17    Block,
18    /// Comment
19    Comment,
20    /// If statement
21    IfStatement,
22    /// For loop
23    ForStatement,
24    /// Macro definition
25    MacroDefinition,
26    /// Tag statement
27    Tag,
28    /// Filter expression
29    Filter,
30    /// Expression
31    Expression,
32    /// Identifier
33    Identifier,
34    /// Literal
35    Literal,
36    /// Function call
37    Function,
38    /// Error
39    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}