oak_fsharp/language/
mod.rs

1use oak_core::{Language, LanguageCategory};
2
3/// F# 语言实现
4#[derive(Debug, Clone)]
5pub struct FSharpLanguage {
6    /// 是否启用 F# 4.0
7    pub fsharp_4_0: bool,
8    /// 是否启用 F# 4.1
9    pub fsharp_4_1: bool,
10    /// 是否启用 F# 4.5
11    pub fsharp_4_5: bool,
12    /// 是否启用 F# 5.0
13    pub fsharp_5_0: bool,
14    /// 是否启用 F# 6.0
15    pub fsharp_6_0: bool,
16    /// 是否启用 F# 7.0
17    pub fsharp_7_0: bool,
18    /// 是否启用计算表达
19    pub computation_expressions: bool,
20    /// 是否启用类型提供
21    pub type_providers: bool,
22    /// 是否启用异步工作
23    pub async_workflows: bool,
24    /// 是否启用查询表达    
25    pub query_expressions: bool,
26}
27
28impl Default for FSharpLanguage {
29    fn default() -> Self {
30        Self { fsharp_4_0: true, fsharp_4_1: true, fsharp_4_5: true, fsharp_5_0: true, fsharp_6_0: true, fsharp_7_0: true, computation_expressions: true, type_providers: true, async_workflows: true, query_expressions: true }
31    }
32}
33
34impl FSharpLanguage {
35    /// 创建新的 F# 语言配置
36    pub fn new() -> Self {
37        Self::default()
38    }
39
40    /// 启用所F#
41    pub fn with_all_features(mut self) -> Self {
42        self.fsharp_4_0 = true;
43        self.fsharp_4_1 = true;
44        self.fsharp_4_5 = true;
45        self.fsharp_5_0 = true;
46        self.fsharp_6_0 = true;
47        self.fsharp_7_0 = true;
48        self.computation_expressions = true;
49        self.type_providers = true;
50        self.async_workflows = true;
51        self.query_expressions = true;
52        self
53    }
54
55    /// 设置 F# 版本
56    pub fn with_version(mut self, major: u8, minor: u8) -> Self {
57        match (major, minor) {
58            (4, 0) => {
59                self.fsharp_4_0 = true;
60            }
61            (4, 1) => {
62                self.fsharp_4_0 = true;
63                self.fsharp_4_1 = true;
64            }
65            (4, 5) => {
66                self.fsharp_4_0 = true;
67                self.fsharp_4_1 = true;
68                self.fsharp_4_5 = true;
69            }
70            (5, 0) => {
71                self.fsharp_4_0 = true;
72                self.fsharp_4_1 = true;
73                self.fsharp_4_5 = true;
74                self.fsharp_5_0 = true;
75            }
76            (6, 0) => {
77                self.fsharp_4_0 = true;
78                self.fsharp_4_1 = true;
79                self.fsharp_4_5 = true;
80                self.fsharp_5_0 = true;
81                self.fsharp_6_0 = true;
82            }
83            (7, 0) => {
84                self.fsharp_4_0 = true;
85                self.fsharp_4_1 = true;
86                self.fsharp_4_5 = true;
87                self.fsharp_5_0 = true;
88                self.fsharp_6_0 = true;
89                self.fsharp_7_0 = true;
90            }
91            _ => {}
92        }
93        self
94    }
95
96    /// 启用计算表达
97    pub fn with_computation_expressions(mut self, enabled: bool) -> Self {
98        self.computation_expressions = enabled;
99        self
100    }
101
102    /// 启用类型提供
103    pub fn with_type_providers(mut self, enabled: bool) -> Self {
104        self.type_providers = enabled;
105        self
106    }
107
108    /// 启用异步工作
109    pub fn with_async_workflows(mut self, enabled: bool) -> Self {
110        self.async_workflows = enabled;
111        self
112    }
113
114    /// 启用查询表达
115    pub fn with_query_expressions(mut self, enabled: bool) -> Self {
116        self.query_expressions = enabled;
117        self
118    }
119}
120
121pub struct FSharpRoot;
122
123impl Language for FSharpLanguage {
124    const NAME: &'static str = "fsharp";
125    const CATEGORY: LanguageCategory = LanguageCategory::Programming;
126
127    type TokenType = crate::kind::FSharpSyntaxKind;
128    type ElementType = crate::kind::FSharpSyntaxKind;
129    type TypedRoot = FSharpRoot;
130}