Skip to main content

oak_fsharp/language/
mod.rs

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