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)]
95 pub is_mut: bool,
96 pub pattern: DestructurePattern,
97 pub type_annotation: Option<TypeAnnotation>,
98 pub value: Option<Expr>,
99 #[serde(default)]
101 pub ownership: OwnershipModifier,
102}
103
104#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
106pub enum OwnershipModifier {
107 #[default]
111 Inferred,
112 Move,
114 Clone,
116}
117
118#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
119pub enum VarKind {
120 Let,
121 Var,
122 Const,
123}
124
125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
126pub struct Assignment {
127 pub pattern: DestructurePattern,
128 pub value: Expr,
129}
130
131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
133pub struct BuiltinTypeDecl {
134 pub name: String,
135 pub name_span: Span,
136 #[serde(default)]
137 pub doc_comment: Option<DocComment>,
138 pub type_params: Option<Vec<TypeParam>>,
139}
140
141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
143pub struct BuiltinFunctionDecl {
144 pub name: String,
145 pub name_span: Span,
146 #[serde(default)]
147 pub doc_comment: Option<DocComment>,
148 pub type_params: Option<Vec<TypeParam>>,
149 pub params: Vec<FunctionParameter>,
150 pub return_type: TypeAnnotation,
151}
152
153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
155pub struct OptimizeStatement {
156 pub parameter: String,
158 pub range: (Box<Expr>, Box<Expr>),
160 pub metric: OptimizationMetric,
162}
163
164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
166pub enum OptimizationMetric {
167 Sharpe,
168 Sortino,
169 Return,
170 Drawdown,
171 WinRate,
172 ProfitFactor,
173 Custom(Box<Expr>),
174}