air_script_core/
variable.rs

1use super::{Expression, Identifier, Range};
2
3#[derive(Debug, Clone, Eq, PartialEq)]
4pub struct Variable {
5    name: Identifier,
6    value: VariableType,
7}
8
9impl Variable {
10    pub fn new(name: Identifier, value: VariableType) -> Self {
11        Self { name, value }
12    }
13
14    pub fn name(&self) -> &str {
15        self.name.name()
16    }
17
18    pub fn value(&self) -> &VariableType {
19        &self.value
20    }
21}
22
23#[derive(Debug, Clone, Eq, PartialEq)]
24pub enum VariableType {
25    Scalar(Expression),
26    Vector(Vec<Expression>),
27    Matrix(Vec<Vec<Expression>>),
28    ListComprehension(ListComprehension),
29}
30
31#[derive(Debug, Clone, Eq, PartialEq)]
32pub struct ListComprehension {
33    expression: Box<Expression>,
34    context: Vec<(Identifier, Iterable)>,
35}
36
37impl ListComprehension {
38    /// Creates a new list comprehension.
39    pub fn new(expression: Expression, context: Vec<(Identifier, Iterable)>) -> Self {
40        Self {
41            expression: Box::new(expression),
42            context,
43        }
44    }
45
46    /// Returns the expression that is evaluated for each member of the list.
47    pub fn expression(&self) -> &Expression {
48        &self.expression
49    }
50
51    /// Returns the context of the list comprehension.
52    pub fn context(&self) -> &[(Identifier, Iterable)] {
53        &self.context
54    }
55}
56
57#[derive(Debug, Clone, Eq, PartialEq)]
58pub enum Iterable {
59    Identifier(Identifier),
60    Range(Range),
61    Slice(Identifier, Range),
62}