PrefixOp have Node
This commit is contained in:
parent
2590def3be
commit
215e2bbb0d
@ -111,7 +111,7 @@ pub enum ExpressionType {
|
|||||||
StringLiteral(Rc<String>),
|
StringLiteral(Rc<String>),
|
||||||
BoolLiteral(bool),
|
BoolLiteral(bool),
|
||||||
BinExp(BinOp, Box<Node<Expression>>, Box<Node<Expression>>),
|
BinExp(BinOp, Box<Node<Expression>>, Box<Node<Expression>>),
|
||||||
PrefixExp(PrefixOp, Box<Expression>),
|
PrefixExp(PrefixOp, Box<Node<Expression>>),
|
||||||
TupleLiteral(Vec<Expression>),
|
TupleLiteral(Vec<Expression>),
|
||||||
Value(Rc<String>),
|
Value(Rc<String>),
|
||||||
NamedStruct {
|
NamedStruct {
|
||||||
|
@ -581,8 +581,9 @@ impl Parser {
|
|||||||
};
|
};
|
||||||
let expr = self.primary()?;
|
let expr = self.primary()?;
|
||||||
Ok(Expression(
|
Ok(Expression(
|
||||||
ExpressionType::PrefixExp(PrefixOp::from_sigil(sigil.as_str()), bx!(expr)),
|
ExpressionType::PrefixExp(PrefixOp::from_sigil(sigil.as_str()), bx!(expr.into())),
|
||||||
None))
|
None
|
||||||
|
))
|
||||||
},
|
},
|
||||||
_ => self.call_expr()
|
_ => self.call_expr()
|
||||||
}
|
}
|
||||||
@ -1161,7 +1162,7 @@ mod parse_tests {
|
|||||||
($op:expr, $lhs:expr, $rhs:expr) => { BinExp(BinOp::from_sigil($op), bx!(Expression($lhs, None).into()), bx!(Expression($rhs, None).into())) }
|
($op:expr, $lhs:expr, $rhs:expr) => { BinExp(BinOp::from_sigil($op), bx!(Expression($lhs, None).into()), bx!(Expression($rhs, None).into())) }
|
||||||
}
|
}
|
||||||
macro_rules! prefexp {
|
macro_rules! prefexp {
|
||||||
($op:expr, $lhs:expr) => { PrefixExp(PrefixOp::from_sigil($op), bx!(Expression($lhs, None))) }
|
($op:expr, $lhs:expr) => { PrefixExp(PrefixOp::from_sigil($op), bx!(Expression($lhs, None).into())) }
|
||||||
}
|
}
|
||||||
macro_rules! exst {
|
macro_rules! exst {
|
||||||
($expr_type:expr) => { Node::new(Statement::ExpressionStatement(Expression($expr_type, None).into())) };
|
($expr_type:expr) => { Node::new(Statement::ExpressionStatement(Expression($expr_type, None).into())) };
|
||||||
|
@ -391,8 +391,8 @@ impl BinOp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrefixOp {
|
impl PrefixOp {
|
||||||
fn reduce(&self, symbol_table: &SymbolTable, arg: &Box<Expression>) -> Expr {
|
fn reduce(&self, symbol_table: &SymbolTable, arg: &Box<Node<Expression>>) -> Expr {
|
||||||
let f = Box::new(Expr::Func(Func::BuiltIn(self.sigil().clone())));
|
let f = Box::new(Expr::Func(Func::BuiltIn(self.sigil().clone())));
|
||||||
Expr::Call { f, args: vec![arg.reduce(symbol_table)]}
|
Expr::Call { f, args: vec![arg.node().reduce(symbol_table)]}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user