cortex_lang/preprocessing/ast/
expression.rs

1use crate::parsing::ast::expression::{BinaryOperator, IdentExpression, UnaryOperator};
2
3use super::{function::RInterpretedBody, statement::RConditionBody};
4
5pub enum RExpression {
6    Number(f64),
7    Boolean(bool),
8    Void,
9    None,
10    String(String),
11    Identifier(String),
12    Call(usize, Vec<RExpression>),
13    Construction {
14        assignments: Vec<(String, RExpression)>,
15        is_heap_allocated: bool,
16    },
17    IfStatement {
18        first: Box<RConditionBody>,
19        conds: Vec<RConditionBody>,
20        last: Option<Box<RInterpretedBody>>,
21    },
22    UnaryOperation {
23        op: UnaryOperator,
24        exp: Box<RExpression>,
25    },
26    ListLiteral(Vec<RExpression>),
27    Bang(Box<RExpression>),
28    MemberAccess(Box<RExpression>, String),
29    BinaryOperation {
30        left: Box<RExpression>,
31        op: BinaryOperator,
32        right: Box<RExpression>,
33    },
34}
35
36pub struct RIdentExpression {
37    pub(crate) base: String,
38    pub(crate) chain: Vec<String>,
39}
40impl From<IdentExpression> for RIdentExpression {
41    fn from(value: IdentExpression) -> Self {
42        RIdentExpression {
43            base: value.base,
44            chain: value.chain,
45        }
46    }
47}
48impl RIdentExpression {
49    pub fn is_simple(&self) -> bool {
50        self.chain.is_empty()
51    }
52}