oak-fsharp 0.0.11

High-performance incremental F# (F Sharp) parser for the oak ecosystem with flexible configuration, supporting functional programming and .NET ecosystem integration.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#![doc = include_str!("readme.md")]

use core::range::Range;

/// The root node of an F# program
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FSharpRoot {
    /// Items in the compilation unit
    pub items: Vec<Item>,
}

/// Top-level items in an F# program
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Item {
    /// Namespace declaration
    Namespace(NamespaceDeclaration),
    /// Module declaration
    Module(ModuleDeclaration),
    /// Open directive (open)
    Open(OpenDirective),
    /// Binding (let)
    Binding(Binding),
    /// Type definition (type)
    Type(TypeDefinition),
    /// Class definition (type ... = class)
    Class(ClassDefinition),
    /// Interface definition (type ... = interface)
    Interface(InterfaceDefinition),
    /// Exception definition (exception)
    Exception(ExceptionDefinition),
}

/// Namespace declaration
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct NamespaceDeclaration {
    /// Namespace name
    pub name: String,
    /// Members
    pub items: Vec<Item>,
    /// Source span
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Module declaration
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ModuleDeclaration {
    /// Module name
    pub name: String,
    /// Whether it is a top-level module
    pub is_top_level: bool,
    /// Whether it is a nested module
    pub is_nested: bool,
    /// Members
    pub items: Vec<Item>,
    /// Source span
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Open directive (open)
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct OpenDirective {
    /// Import path
    pub path: String,
    /// Source span
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Binding (let)
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Binding {
    /// Binding name
    pub name: String,
    /// Whether it is a recursive binding (rec)
    pub is_rec: bool,
    /// Whether it is mutable (mutable)
    pub is_mutable: bool,
    /// Parameter list
    pub parameters: Vec<Parameter>,
    /// Type annotation
    pub type_annotation: Option<String>,
    /// Bound expression
    pub expression: Expression,
    /// Source span
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Parameter
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Parameter {
    /// Parameter name
    pub name: String,
    /// Type annotation
    pub type_annotation: Option<String>,
}

/// Type definition
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TypeDefinition {
    /// Type name
    pub name: String,
    /// Type parameters
    pub type_parameters: Vec<String>,
    /// Type body
    pub body: TypeBody,
    /// Source span
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Type body
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TypeBody {
    /// Record type
    Record(Vec<RecordField>),
    /// Union type
    Union(Vec<UnionCase>),
    /// Alias
    Alias(String),
    /// Struct
    Struct(Vec<RecordField>),
}

/// Record field
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RecordField {
    /// Field name
    pub name: String,
    /// Field type
    pub field_type: String,
}

/// Union case
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UnionCase {
    /// Case name
    pub name: String,
    /// Case fields
    pub fields: Vec<RecordField>,
}

/// Class definition
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ClassDefinition {
    /// Class name
    pub name: String,
    /// Type parameters
    pub type_parameters: Vec<String>,
    /// Base class
    pub base_class: Option<String>,
    /// Interfaces
    pub interfaces: Vec<String>,
    /// Members
    pub members: Vec<ClassMember>,
    /// Source span
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Class member
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ClassMember {
    /// Constructor
    Constructor(Constructor),
    /// Method
    Method(Method),
    /// Property
    Property(Property),
    /// Field
    Field(Field),
}

/// Constructor
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Constructor {
    /// Parameters
    pub parameters: Vec<Parameter>,
    /// Body
    pub body: Expression,
}

/// Method
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Method {
    /// Method name
    pub name: String,
    /// Parameters
    pub parameters: Vec<Parameter>,
    /// Return type
    pub return_type: Option<String>,
    /// Body
    pub body: Expression,
}

/// Property
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Property {
    /// Property name
    pub name: String,
    /// Property type
    pub property_type: String,
    /// Getter
    pub getter: Option<Expression>,
    /// Setter
    pub setter: Option<Expression>,
}

/// Field
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Field {
    /// Field name
    pub name: String,
    /// Field type
    pub field_type: String,
    /// Initial value
    pub initial_value: Option<Expression>,
}

/// Interface definition
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct InterfaceDefinition {
    /// Interface name
    pub name: String,
    /// Type parameters
    pub type_parameters: Vec<String>,
    /// Base interfaces
    pub base_interfaces: Vec<String>,
    /// Members
    pub members: Vec<InterfaceMember>,
    /// Source span
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// Interface member
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum InterfaceMember {
    /// Method signature
    MethodSignature(Method),
    /// Property signature
    PropertySignature(Property),
}

/// Exception definition
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExceptionDefinition {
    /// Exception name
    pub name: String,
    /// Fields
    pub fields: Vec<RecordField>,
    /// Source span
    #[cfg_attr(feature = "serde", serde(with = "oak_core::serde_range"))]
    pub span: Range<usize>,
}

/// F# expression
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Expression {
    /// Literal
    Literal(Literal),
    /// Identifier
    Identifier(String),
    /// If expression
    If {
        /// Condition expression
        condition: Box<Expression>,
        /// Then branch
        then_branch: Box<Expression>,
        /// Else branch
        else_branch: Option<Box<Expression>>,
    },
    /// Match expression
    Match {
        /// Expression to match
        expression: Box<Expression>,
        /// Match cases
        cases: Vec<MatchCase>,
    },
    /// Lambda expression
    Lambda {
        /// Parameters
        parameters: Vec<Parameter>,
        /// Body
        body: Box<Expression>,
    },
    /// Function application
    Application {
        /// Function
        function: Box<Expression>,
        /// Argument
        argument: Box<Expression>,
    },
    /// Binary expression
    Binary {
        /// Left operand
        left: Box<Expression>,
        /// Operator
        op: String,
        /// Right operand
        right: Box<Expression>,
    },
    /// Unary expression
    Unary {
        /// Operator
        op: String,
        /// Operand
        operand: Box<Expression>,
    },
    /// Let expression
    Let {
        /// Bindings
        bindings: Vec<Binding>,
        /// Body
        body: Box<Expression>,
    },
    /// Pipe forward operator (|>)
    PipeForward {
        /// Expression
        expression: Box<Expression>,
        /// Function
        function: Box<Expression>,
    },
    /// Pipe backward operator (<|)
    PipeBackward {
        /// Function
        function: Box<Expression>,
        /// Expression
        expression: Box<Expression>,
    },
    /// Tuple
    Tuple(Vec<Expression>),
    /// List
    List(Vec<Expression>),
    /// Array
    Array(Vec<Expression>),
    /// Record expression
    Record {
        /// Type name
        type_name: Option<String>,
        /// Fields
        fields: Vec<(String, Expression)>,
    },
    /// Union case expression
    UnionCase {
        /// Case name
        case_name: String,
        /// Arguments
        arguments: Vec<Expression>,
    },
    /// Sequential expressions
    Sequential(Vec<Expression>),
    /// Parenthesized expression
    Parenthesized(Box<Expression>),
    /// Async expression
    Async(Box<Expression>),
    /// Computation expression
    Computation {
        /// Builder name
        builder: String,
        /// Body
        body: Vec<ComputationItem>,
    },
}

/// Literal
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Literal {
    /// Integer
    Integer(i64),
    /// Float
    Float(f64),
    /// String
    String(String),
    /// Char
    Char(char),
    /// Boolean
    Boolean(bool),
    /// Unit
    Unit,
}

/// Match case
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MatchCase {
    /// Pattern
    pub pattern: Pattern,
    /// Guard
    pub guard: Option<Expression>,
    /// Body
    pub body: Expression,
}

/// Pattern
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Pattern {
    /// Wildcard (_)
    Wildcard,
    /// Identifier
    Identifier(String),
    /// Literal
    Literal(Literal),
    /// Tuple pattern
    Tuple(Vec<Pattern>),
    /// List pattern
    List(Vec<Pattern>),
    /// Union case pattern
    UnionCase {
        /// Case name
        case_name: String,
        /// Patterns
        patterns: Vec<Pattern>,
    },
    /// Record pattern
    Record(Vec<String>),
    /// As pattern
    As {
        /// Pattern
        pattern: Box<Pattern>,
        /// Identifier
        identifier: String,
    },
    /// Or pattern
    Or(Box<Pattern>, Box<Pattern>),
}

/// Computation item
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ComputationItem {
    /// Let binding
    Let(Binding),
    /// Yield
    Yield(Expression),
    /// Return
    Return(Expression),
    /// Expression
    Expression(Expression),
    /// Custom operation
    CustomOperation {
        /// Operation name
        name: String,
        /// Arguments
        arguments: Vec<Expression>,
    },
}