y_lang/ast/
binary_expr.rs

1use pest::iterators::Pair;
2
3use super::{BinaryOp, Expression, Position, Rule};
4
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
6pub struct BinaryExpr<T> {
7    pub op: BinaryOp,
8    pub lhs: Box<Expression<T>>,
9    pub rhs: Box<Expression<T>>,
10    pub position: Position,
11    pub info: T,
12}
13
14impl BinaryExpr<()> {
15    pub fn from_lhs_op_rhs(
16        lhs: Expression<()>,
17        op_pair: Pair<Rule>,
18        rhs: Expression<()>,
19        file: &str,
20    ) -> BinaryExpr<()> {
21        let (line, col) = op_pair.line_col();
22
23        let op = BinaryOp::from(op_pair.as_rule());
24
25        BinaryExpr {
26            lhs: Box::new(lhs),
27            rhs: Box::new(rhs),
28            op,
29            position: (file.to_owned(), line, col),
30            info: (),
31        }
32    }
33}