use oak_core::{ElementType, UniversalElementRole};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum JinjaElementType {
Root,
Text,
Variable,
Block,
Comment,
IfStatement,
ForStatement,
MacroDefinition,
Tag,
Filter,
Expression,
Identifier,
Literal,
Function,
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,
}
}
}