Skip to main content

shape_ast/ast/
data_refs.rs

1//! Data reference types for Shape AST
2
3use serde::{Deserialize, Serialize};
4
5use super::time::{DateTimeExpr, Timeframe};
6
7/// Data reference: data[0], data[-1], data[1:5]
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9pub struct DataRef {
10    pub index: DataIndex,
11    /// Optional timeframe for multi-timeframe access: data[0, 5m] or data(5m)[0]
12    pub timeframe: Option<Timeframe>,
13}
14
15/// DateTime-based data reference: data[@"2024-01-15"]
16#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
17pub struct DataDateTimeRef {
18    pub datetime: DateTimeExpr,
19    pub timezone: Option<String>,
20    pub timeframe: Option<Timeframe>,
21}
22
23#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
24pub enum DataIndex {
25    /// Single data row with static index: data[0]
26    Single(i32),
27    /// Range of data rows with static indices: data[1:5]
28    Range(i32, i32),
29    /// Single data row with expression index: data[variable_name]
30    Expression(Box<super::expressions::Expr>),
31    /// Range with expression indices: data[start_expr:end_expr]
32    ExpressionRange(Box<super::expressions::Expr>, Box<super::expressions::Expr>),
33}