oak_typst/language/
mod.rs

1use crate::{ast::TypstRoot, kind::TypstSyntaxKind};
2use oak_core::Language;
3
4/// Typst 语言配置
5pub struct TypstLanguage {
6    /// 是否启用数学模式
7    pub math_mode: bool,
8    /// 是否支持脚本
9    pub scripting: bool,
10    /// 是否启用严格模式
11    pub strict: bool,
12    /// 目标 Typst 版本
13    pub target: TypstVersion,
14    /// 是否允许实验性语法
15    pub experimental: bool,
16}
17
18/// Typst 版本
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum TypstVersion {
21    V0_1,
22    V0_2,
23    V0_3,
24    V0_4,
25    V0_5,
26    V0_6,
27    V0_7,
28    V0_8,
29    V0_9,
30    V0_10,
31    V0_11,
32    Latest,
33}
34
35impl TypstLanguage {
36    /// 创建标准 Typst 配置
37    pub fn standard() -> Self {
38        Self { math_mode: false, scripting: false, strict: false, target: TypstVersion::V0_11, experimental: false }
39    }
40
41    /// 创建支持数学模式的 Typst 配置
42    pub fn with_math() -> Self {
43        Self { math_mode: true, scripting: false, strict: false, target: TypstVersion::V0_11, experimental: false }
44    }
45
46    /// 创建支持脚本的 Typst 配置
47    pub fn with_scripting() -> Self {
48        Self { math_mode: false, scripting: true, strict: false, target: TypstVersion::V0_11, experimental: false }
49    }
50
51    /// 创建严格模式 Typst 配置
52    pub fn strict() -> Self {
53        Self { math_mode: false, scripting: false, strict: true, target: TypstVersion::V0_11, experimental: false }
54    }
55
56    /// 创建实验性语法的 Typst 配置
57    pub fn experimental() -> Self {
58        Self { math_mode: true, scripting: true, strict: true, target: TypstVersion::Latest, experimental: true }
59    }
60}
61
62impl Language for TypstLanguage {
63    type SyntaxKind = TypstSyntaxKind;
64    type TypedRoot = TypstRoot;
65}