oak-jinja 0.0.11

High-performance incremental Jinja2 parser for the oak ecosystem with flexible configuration, supporting template rendering and syntax analysis.
Documentation
/// Jinja Element Type module
///
/// This module defines the element types for Jinja templates.
use oak_core::{ElementType, UniversalElementRole};

/// Element types for Jinja templates
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum JinjaElementType {
    /// Root element
    Root,
    /// Text content
    Text,
    /// Variable expression
    Variable,
    /// Block statement
    Block,
    /// Comment
    Comment,
    /// If statement
    IfStatement,
    /// For loop
    ForStatement,
    /// Macro definition
    MacroDefinition,
    /// Tag statement
    Tag,
    /// Filter expression
    Filter,
    /// Expression
    Expression,
    /// Identifier
    Identifier,
    /// Literal
    Literal,
    /// Function call
    Function,
    /// Error
    Error,
}

impl ElementType for JinjaElementType {
    type Role = UniversalElementRole;

    fn role(&self) -> Self::Role {
        match self {
            Self::Error => UniversalElementRole::Error,
            _ => UniversalElementRole::None,
        }
    }
}

impl From<crate::lexer::token_type::JinjaTokenType> for JinjaElementType {
    fn from(token_type: crate::lexer::token_type::JinjaTokenType) -> Self {
        match token_type {
            crate::lexer::token_type::JinjaTokenType::Text => Self::Text,
            crate::lexer::token_type::JinjaTokenType::DoubleLeftBrace => Self::Variable,
            crate::lexer::token_type::JinjaTokenType::DoubleRightBrace => Self::Variable,
            crate::lexer::token_type::JinjaTokenType::LeftBracePercent => Self::Tag,
            crate::lexer::token_type::JinjaTokenType::PercentRightBrace => Self::Tag,
            crate::lexer::token_type::JinjaTokenType::Identifier => Self::Identifier,
            crate::lexer::token_type::JinjaTokenType::String => Self::Literal,
            crate::lexer::token_type::JinjaTokenType::Number => Self::Literal,
            crate::lexer::token_type::JinjaTokenType::Boolean => Self::Literal,
            crate::lexer::token_type::JinjaTokenType::Whitespace => Self::Text,
            crate::lexer::token_type::JinjaTokenType::Comment => Self::Comment,
            crate::lexer::token_type::JinjaTokenType::Eof => Self::Text,
            crate::lexer::token_type::JinjaTokenType::Error => Self::Error,
            _ => Self::Expression,
        }
    }
}