oak_tex/language/
mod.rs

1use crate::kind::TexSyntaxKind;
2use oak_core::Language;
3
4/// TeX 语言配置
5pub struct TexLanguage {
6    /// TeX 版本
7    pub version: TexVersion,
8    /// 是否支持数学模式
9    pub math_mode: bool,
10    /// 是否支持扩展包
11    pub packages: bool,
12    /// 是否支持自定义命令
13    pub custom_commands: bool,
14    /// 是否启用严格模式
15    pub strict: bool,
16}
17
18/// TeX 版本
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum TexVersion {
21    /// 原始 TeX
22    Tex,
23    /// LaTeX
24    LaTeX,
25    /// LaTeX2e
26    LaTeX2e,
27    /// XeTeX
28    XeTeX,
29    /// LuaTeX
30    LuaTeX,
31    /// pdfTeX
32    PdfTeX,
33}
34
35impl TexLanguage {
36    /// 创建标准 LaTeX 配置
37    pub fn standard() -> Self {
38        Self { version: TexVersion::LaTeX2e, math_mode: true, packages: true, custom_commands: true, strict: false }
39    }
40
41    /// 创建原始 TeX 配置
42    pub fn tex() -> Self {
43        Self { version: TexVersion::Tex, math_mode: true, packages: false, custom_commands: false, strict: true }
44    }
45
46    /// 创建 XeTeX 配置
47    pub fn xetex() -> Self {
48        Self { version: TexVersion::XeTeX, math_mode: true, packages: true, custom_commands: true, strict: false }
49    }
50
51    /// 创建 LuaTeX 配置
52    pub fn luatex() -> Self {
53        Self { version: TexVersion::LuaTeX, math_mode: true, packages: true, custom_commands: true, strict: false }
54    }
55
56    /// 创建 pdfTeX 配置
57    pub fn pdftex() -> Self {
58        Self { version: TexVersion::PdfTeX, math_mode: true, packages: true, custom_commands: true, strict: false }
59    }
60
61    /// 创建严格模式配置
62    pub fn strict() -> Self {
63        Self { version: TexVersion::LaTeX2e, math_mode: true, packages: true, custom_commands: false, strict: true }
64    }
65
66    /// 创建支持扩展的配置
67    pub fn with_extensions() -> Self {
68        Self { version: TexVersion::LaTeX2e, math_mode: true, packages: true, custom_commands: true, strict: false }
69    }
70}
71
72impl Language for TexLanguage {
73    type SyntaxKind = TexSyntaxKind;
74    type TypedRoot = ();
75}
76
77impl Default for TexLanguage {
78    fn default() -> Self {
79        Self::standard()
80    }
81}