Skip to main content

oak_tailwind/language/
mod.rs

1#![doc = include_str!("readme.md")]
2use crate::{ast::TailwindRoot, lexer::TailwindLexer, parser::TailwindParser};
3use oak_core::{Language, LanguageCategory};
4
5/// Tailwind engine configuration modes.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub enum TailwindMode {
9    /// Template mode (e.g., HTML with Tailwind classes).
10    #[default]
11    Template,
12    /// Expression mode (e.g., inside a template tag).
13    Expression,
14}
15
16/// Tailwind language definition.
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19pub struct TailwindLanguage {
20    /// Whether to allow raw blocks.
21    pub allow_raw_blocks: bool,
22    /// Whether to allow custom tags.
23    pub allow_custom_tags: bool,
24    /// The current mode of the engine.
25    pub mode: TailwindMode,
26}
27
28impl Language for TailwindLanguage {
29    const NAME: &'static str = "tailwind";
30    const CATEGORY: LanguageCategory = LanguageCategory::Markup;
31
32    type TokenType = crate::lexer::token_type::TailwindTokenType;
33    type ElementType = crate::parser::element_type::TailwindElementType;
34    type TypedRoot = TailwindRoot;
35}
36
37impl TailwindLanguage {
38    /// Creates a new `TailwindLanguage` with standard settings.
39    pub fn new() -> Self {
40        Self::standard()
41    }
42
43    /// Creates a new `TailwindLanguage` with standard settings.
44    pub fn standard() -> Self {
45        Self { allow_raw_blocks: true, allow_custom_tags: false, mode: TailwindMode::Template }
46    }
47
48    /// Creates a new lexer for this language configuration.
49    pub fn lexer(&self) -> TailwindLexer<'_> {
50        TailwindLexer::new(self)
51    }
52
53    /// Creates a new parser for this language configuration.
54    pub fn parser(&self) -> TailwindParser<'_> {
55        TailwindParser::new(self)
56    }
57}