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