1use crate::{ast::TwigRoot, lexer::TwigLexer, parser::TwigParser};
2use oak_core::{Language, LanguageCategory};
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, serde::Serialize, serde::Deserialize)]
6pub enum TwigMode {
7 #[default]
8 Template,
9 Expression,
10 }
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, serde::Serialize, serde::Deserialize)]
15pub struct TwigLanguage {
16 pub allow_raw_blocks: bool,
17 pub allow_custom_tags: bool,
18 pub mode: TwigMode,
19}
20
21impl Language for TwigLanguage {
22 const NAME: &'static str = "twig";
23 const CATEGORY: LanguageCategory = LanguageCategory::Markup;
24
25 type TokenType = crate::kind::TwigSyntaxKind;
26 type ElementType = crate::kind::TwigSyntaxKind;
27 type TypedRoot = TwigRoot;
28}
29
30impl TwigLanguage {
31 pub fn new() -> Self {
32 Self::standard()
33 }
34
35 pub fn standard() -> Self {
36 Self { allow_raw_blocks: true, allow_custom_tags: false, mode: TwigMode::Template }
37 }
38
39 pub fn lexer(&self) -> TwigLexer<'_> {
40 TwigLexer::new(self)
41 }
42
43 pub fn parser(&self) -> TwigParser<'_> {
44 TwigParser::new(self)
45 }
46}