oak_fsharp/language/
mod.rs1#![doc = include_str!("readme.md")]
2use oak_core::{Language, LanguageCategory};
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9pub struct FSharpLanguage {
10 pub fsharp_4_0: bool,
12 pub fsharp_4_1: bool,
14 pub fsharp_4_5: bool,
16 pub fsharp_5_0: bool,
18 pub fsharp_6_0: bool,
20 pub fsharp_7_0: bool,
22 pub computation_expressions: bool,
24 pub type_providers: bool,
26 pub async_workflows: bool,
28 pub query_expressions: bool,
30}
31
32impl Default for FSharpLanguage {
33 fn default() -> Self {
34 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 }
35 }
36}
37
38impl FSharpLanguage {
39 pub fn new() -> Self {
41 Self::default()
42 }
43
44 pub fn with_all_features(mut self) -> Self {
46 self.fsharp_4_0 = true;
47 self.fsharp_4_1 = true;
48 self.fsharp_4_5 = true;
49 self.fsharp_5_0 = true;
50 self.fsharp_6_0 = true;
51 self.fsharp_7_0 = true;
52 self.computation_expressions = true;
53 self.type_providers = true;
54 self.async_workflows = true;
55 self.query_expressions = true;
56 self
57 }
58
59 pub fn with_version(mut self, major: u8, minor: u8) -> Self {
61 match (major, minor) {
62 (4, 0) => self.fsharp_4_0 = true,
63 (4, 1) => {
64 self.fsharp_4_0 = true;
65 self.fsharp_4_1 = true
66 }
67 (4, 5) => {
68 self.fsharp_4_0 = true;
69 self.fsharp_4_1 = true;
70 self.fsharp_4_5 = true
71 }
72 (5, 0) => {
73 self.fsharp_4_0 = true;
74 self.fsharp_4_1 = true;
75 self.fsharp_4_5 = true;
76 self.fsharp_5_0 = true
77 }
78 (6, 0) => {
79 self.fsharp_4_0 = true;
80 self.fsharp_4_1 = true;
81 self.fsharp_4_5 = true;
82 self.fsharp_5_0 = true;
83 self.fsharp_6_0 = true
84 }
85 (7, 0) => {
86 self.fsharp_4_0 = true;
87 self.fsharp_4_1 = true;
88 self.fsharp_4_5 = true;
89 self.fsharp_5_0 = true;
90 self.fsharp_6_0 = true;
91 self.fsharp_7_0 = true
92 }
93 _ => {}
94 }
95 self
96 }
97
98 pub fn with_computation_expressions(mut self, enabled: bool) -> Self {
100 self.computation_expressions = enabled;
101 self
102 }
103
104 pub fn with_type_providers(mut self, enabled: bool) -> Self {
106 self.type_providers = enabled;
107 self
108 }
109
110 pub fn with_async_workflows(mut self, enabled: bool) -> Self {
112 self.async_workflows = enabled;
113 self
114 }
115
116 pub fn with_query_expressions(mut self, enabled: bool) -> Self {
118 self.query_expressions = enabled;
119 self
120 }
121}
122
123impl Language for FSharpLanguage {
124 const NAME: &'static str = "fsharp";
125 const CATEGORY: LanguageCategory = LanguageCategory::Programming;
126
127 type TokenType = crate::lexer::token_type::FSharpTokenType;
128 type ElementType = crate::parser::element_type::FSharpElementType;
129 type TypedRoot = crate::ast::FSharpRoot;
130}