Compare Expressions
This commit is contained in:
parent
a55fdedd1c
commit
2e3306b67b
1 changed files with 40 additions and 0 deletions
|
@ -35,3 +35,43 @@ impl fmt::Debug for Expression {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Expression {
|
||||
fn eq(&self, other: &Expression) -> bool {
|
||||
match *self {
|
||||
Expression::EOF => self.eq_eof(other),
|
||||
Expression::Atom(ref value) => self.eq_atom(other, value.deref()),
|
||||
Expression::List { ref left, ref expr, ref right } => {
|
||||
self.eq_list(other, left, expr, right)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Expression {
|
||||
fn eq_eof(&self, other: &Expression) -> bool {
|
||||
match *other {
|
||||
Expression::EOF => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn eq_atom(&self, other: &Expression, value: &types::Value) -> bool {
|
||||
match *other {
|
||||
Expression::Atom(ref ovalue) => value == ovalue.deref(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn eq_list(&self, other: &Expression, left: &Token, expr: &Vec<Box<Expression>>, right: &Token) -> bool {
|
||||
match *other {
|
||||
Expression::List { left: ref olt, expr: ref oexpr, right: ref ort } => {
|
||||
let left_eq = left == olt;
|
||||
let right_eq = right == ort;
|
||||
let expr_eq = expr == oexpr;
|
||||
left_eq && expr_eq && right_eq
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue