xshade_parser/ast/expressions/
binary_expression.rs

1use ::ast::*;
2
3#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
4pub struct BinaryExpression {
5    pub span: Span,
6    pub operator: OperatorType,
7    pub left_hand: Box<Expression>,
8    pub right_hand: Box<Expression>,
9}
10
11impl Spanned for BinaryExpression {
12    fn get_span(&self) -> Span {
13        self.span
14    }
15}
16
17impl Execute for BinaryExpression {
18    fn execute(&self) -> Option<i32> {
19        let left = self.left_hand.execute()?;
20        let right = self.right_hand.execute()?;
21
22        match self.operator {
23            OperatorType::Plus => Some(left + right),
24            OperatorType::Minus => Some(left - right),
25            OperatorType::Multiply => Some(left * right),
26            OperatorType::Divide => Some(left / right),
27            _ => None,
28        }
29    }
30}