Skip to main content

oak_liquid/language/
mod.rs

1/// Liquid Language module
2///
3/// This module defines the language characteristics and configuration for Liquid templates.
4use oak_core::language::{Language, LanguageCategory};
5
6use crate::{ast::LiquidRoot, lexer::token_type::LiquidTokenType, parser::element_type::LiquidElementType};
7
8/// Language definition for Liquid templates
9#[derive(Debug, Clone, PartialEq, Eq, Hash)]
10pub struct LiquidLanguage {
11    /// Whether to trim whitespace around delimiters
12    pub trim_blocks: bool,
13    /// Whether to lstrip blocks
14    pub lstrip_blocks: bool,
15    /// Whether to keep trailing newlines
16    pub keep_trailing_newline: bool,
17    /// Variable start delimiter
18    pub variable_start: String,
19    /// Variable end delimiter
20    pub variable_end: String,
21    /// Tag start delimiter
22    pub tag_start: String,
23    /// Tag end delimiter
24    pub tag_end: String,
25    /// Comment start delimiter
26    pub comment_start: String,
27    /// Comment end delimiter
28    pub comment_end: String,
29}
30
31impl Default for LiquidLanguage {
32    fn default() -> Self {
33        Self {
34            trim_blocks: false,
35            lstrip_blocks: false,
36            keep_trailing_newline: false,
37            variable_start: "{{".to_string(),
38            variable_end: "}}".to_string(),
39            tag_start: "{%".to_string(),
40            tag_end: "%}".to_string(),
41            comment_start: "{#".to_string(),
42            comment_end: "#}".to_string(),
43        }
44    }
45}
46
47impl Language for LiquidLanguage {
48    const NAME: &'static str = "Liquid2";
49    const CATEGORY: LanguageCategory = LanguageCategory::Markup;
50
51    type TokenType = LiquidTokenType;
52    type ElementType = LiquidElementType;
53    type TypedRoot = LiquidRoot<'static>;
54}
55
56impl LiquidLanguage {
57    /// Create a new Liquid language instance
58    pub fn new() -> Self {
59        Self::default()
60    }
61}