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    Char(u8),
12    Identifier(String),
13    Call(usize, Vec<RExpression>),
14    Construction {
15        assignments: Vec<(String, RExpression)>,
16        is_heap_allocated: bool,
17    },
18    IfStatement {
19        first: Box<RConditionBody>,
20        conds: Vec<RConditionBody>,
21        last: Option<Box<RInterpretedBody>>,
22    },
23    UnaryOperation {
24        op: UnaryOperator,
25        exp: Box<RExpression>,
26    },
27    ListLiteral(Vec<RExpression>),
28    Bang(Box<RExpression>),
29    MemberAccess(Box<RExpression>, String),
30    BinaryOperation {
31        left: Box<RExpression>,
32        op: BinaryOperator,
33        right: Box<RExpression>,
34    },
35    Tuple(Vec<RExpression>),
36}
37
38pub struct RIdentExpression {
39    pub(crate) base: String,
40    pub(crate) chain: Vec<String>,
41}
42impl From<IdentExpression> for RIdentExpression {
43    fn from(value: IdentExpression) -> Self {
44        RIdentExpression {
45            base: value.base,
46            chain: value.chain,
47        }
48    }
49}
50impl RIdentExpression {
51    pub fn is_simple(&self) -> bool {
52        self.chain.is_empty()
53    }
54}