1use serde::{Deserialize, Serialize};
4
5use super::data_sources::{DataSourceDecl, QueryDecl};
6use super::docs::DocComment;
7use super::docs::ProgramDocs;
8use super::expressions::Expr;
9use super::functions::{AnnotationDef, ForeignFunctionDef, FunctionDef, FunctionParameter};
10use super::modules::{ExportStmt, ImportStmt, ModuleDecl};
11use super::patterns::DestructurePattern;
12use super::queries::Query;
13use super::span::Span;
14use super::statements::Statement;
15use super::streams::StreamDef;
16use super::tests::TestDef;
17use super::types::{
18 EnumDef, ExtendStatement, ImplBlock, InterfaceDef, StructTypeDef, TraitDef, TypeAliasDef,
19 TypeAnnotation, TypeParam,
20};
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct Program {
24 pub items: Vec<Item>,
25 #[serde(default)]
26 pub docs: ProgramDocs,
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub enum Item {
31 Import(ImportStmt, Span),
33 Export(ExportStmt, Span),
35 Module(ModuleDecl, Span),
37 TypeAlias(TypeAliasDef, Span),
39 Interface(InterfaceDef, Span),
41 Trait(TraitDef, Span),
43 Enum(EnumDef, Span),
45 Extend(ExtendStatement, Span),
47 Impl(ImplBlock, Span),
49 Function(FunctionDef, Span),
51 Query(Query, Span),
53 VariableDecl(VariableDecl, Span),
55 Assignment(Assignment, Span),
57 Expression(Expr, Span),
59 Stream(StreamDef, Span),
61 Test(TestDef, Span),
63 Optimize(OptimizeStatement, Span),
65 AnnotationDef(AnnotationDef, Span),
67 StructType(StructTypeDef, Span),
69 DataSource(DataSourceDecl, Span),
71 QueryDecl(QueryDecl, Span),
73 Statement(Statement, Span),
75 Comptime(Vec<Statement>, Span),
78 BuiltinTypeDecl(BuiltinTypeDecl, Span),
80 BuiltinFunctionDecl(BuiltinFunctionDecl, Span),
82 ForeignFunction(ForeignFunctionDef, Span),
84}
85
86#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
87pub struct VariableDecl {
88 pub kind: VarKind,
89 #[serde(default)]
93 pub is_mut: bool,
94 pub pattern: DestructurePattern,
95 pub type_annotation: Option<TypeAnnotation>,
96 pub value: Option<Expr>,
97 #[serde(default)]
99 pub ownership: OwnershipModifier,
100}
101
102#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
104pub enum OwnershipModifier {
105 #[default]
109 Inferred,
110 Move,
112 Clone,
114}
115
116#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
117pub enum VarKind {
118 Let,
119 Var,
120 Const,
121}
122
123#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
124pub struct Assignment {
125 pub pattern: DestructurePattern,
126 pub value: Expr,
127}
128
129#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
131pub struct BuiltinTypeDecl {
132 pub name: String,
133 pub name_span: Span,
134 #[serde(default)]
135 pub doc_comment: Option<DocComment>,
136 pub type_params: Option<Vec<TypeParam>>,
137}
138
139#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
141pub struct BuiltinFunctionDecl {
142 pub name: String,
143 pub name_span: Span,
144 #[serde(default)]
145 pub doc_comment: Option<DocComment>,
146 pub type_params: Option<Vec<TypeParam>>,
147 pub params: Vec<FunctionParameter>,
148 pub return_type: TypeAnnotation,
149}
150
151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
153pub struct OptimizeStatement {
154 pub parameter: String,
156 pub range: (Box<Expr>, Box<Expr>),
158 pub metric: OptimizationMetric,
160}
161
162#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
164pub enum OptimizationMetric {
165 Sharpe,
166 Sortino,
167 Return,
168 Drawdown,
169 WinRate,
170 ProfitFactor,
171 Custom(Box<Expr>),
172}