More Node-wrapping

This commit is contained in:
greg 2019-01-05 15:54:03 -08:00
parent 879a7de83d
commit 2590def3be
3 changed files with 7 additions and 7 deletions

View File

@ -110,7 +110,7 @@ pub enum ExpressionType {
FloatLiteral(f64),
StringLiteral(Rc<String>),
BoolLiteral(bool),
BinExp(BinOp, Box<Expression>, Box<Expression>),
BinExp(BinOp, Box<Node<Expression>>, Box<Node<Expression>>),
PrefixExp(PrefixOp, Box<Expression>),
TupleLiteral(Vec<Expression>),
Value(Rc<String>),

View File

@ -565,7 +565,7 @@ impl Parser {
None => unreachable!()
};
let rhs = self.precedence_expr(new_precedence)?;
lhs = Expression(ExpressionType::BinExp(operation, bx!(lhs), bx!(rhs)), None);
lhs = Expression(ExpressionType::BinExp(operation, bx!(lhs.into()), bx!(rhs.into())), None);
}
self.parse_level -= 1;
Ok(lhs)
@ -1158,7 +1158,7 @@ mod parse_tests {
}
macro_rules! binexp {
($op:expr, $lhs:expr, $rhs:expr) => { BinExp(BinOp::from_sigil($op), bx!(Expression($lhs, None)), bx!(Expression($rhs, None))) }
($op:expr, $lhs:expr, $rhs:expr) => { BinExp(BinOp::from_sigil($op), bx!(Expression($lhs, None).into()), bx!(Expression($rhs, None).into())) }
}
macro_rules! prefexp {
($op:expr, $lhs:expr) => { PrefixExp(PrefixOp::from_sigil($op), bx!(Expression($lhs, None))) }

View File

@ -377,15 +377,15 @@ impl Declaration {
}
impl BinOp {
fn reduce(&self, symbol_table: &SymbolTable, lhs: &Box<Expression>, rhs: &Box<Expression>) -> Expr {
fn reduce(&self, symbol_table: &SymbolTable, lhs: &Box<Node<Expression>>, rhs: &Box<Node<Expression>>) -> Expr {
if **self.sigil() == "=" {
Expr::Assign {
val: Box::new(lhs.reduce(symbol_table)),
expr: Box::new(rhs.reduce(symbol_table)),
val: Box::new(lhs.node().reduce(symbol_table)),
expr: Box::new(rhs.node().reduce(symbol_table)),
}
} else {
let f = Box::new(Expr::Func(Func::BuiltIn(self.sigil().clone())));
Expr::Call { f, args: vec![lhs.reduce(symbol_table), rhs.reduce(symbol_table)]}
Expr::Call { f, args: vec![lhs.node().reduce(symbol_table), rhs.node().reduce(symbol_table)]}
}
}
}