diff options
| author | Martin Haug <mhaug@live.de> | 2020-07-18 14:04:58 +0200 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2020-07-18 14:07:53 +0200 |
| commit | bb1350cff5f1cf4da0332b72ec0703689645649c (patch) | |
| tree | 4bfdc717bc24294be5a2f53aca183ea30689d4aa /src/syntax/test.rs | |
| parent | 6f1319e91fe18289c4f9193a4157bde9ee3c53b8 (diff) | |
Parsing mathematical expressions :heavy_plus_sign:
Diffstat (limited to 'src/syntax/test.rs')
| -rw-r--r-- | src/syntax/test.rs | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/syntax/test.rs b/src/syntax/test.rs index ca47c0c5..109b5ef6 100644 --- a/src/syntax/test.rs +++ b/src/syntax/test.rs @@ -88,13 +88,6 @@ pub trait SpanlessEq<Rhs=Self> { fn spanless_eq(&self, other: &Rhs) -> bool; } -impl<T: SpanlessEq> SpanlessEq for Vec<Spanned<T>> { - fn spanless_eq(&self, other: &Vec<Spanned<T>>) -> bool { - self.len() == other.len() - && self.iter().zip(other).all(|(x, y)| x.v.spanless_eq(&y.v)) - } -} - impl SpanlessEq for SyntaxModel { fn spanless_eq(&self, other: &SyntaxModel) -> bool { self.nodes.spanless_eq(&other.nodes) @@ -130,6 +123,11 @@ impl SpanlessEq for Expr { (Expr::NamedTuple(a), Expr::NamedTuple(b)) => a.spanless_eq(b), (Expr::Tuple(a), Expr::Tuple(b)) => a.spanless_eq(b), (Expr::Object(a), Expr::Object(b)) => a.spanless_eq(b), + (Expr::Neg(a), Expr::Neg(b)) => a.spanless_eq(&b), + (Expr::Add(a1, a2), Expr::Add(b1, b2)) => a1.spanless_eq(&b1) && a2.spanless_eq(&b2), + (Expr::Sub(a1, a2), Expr::Sub(b1, b2)) => a1.spanless_eq(&b1) && a2.spanless_eq(&b2), + (Expr::Mul(a1, a2), Expr::Mul(b1, b2)) => a1.spanless_eq(&b1) && a2.spanless_eq(&b2), + (Expr::Div(a1, a2), Expr::Div(b1, b2)) => a1.spanless_eq(&b1) && a2.spanless_eq(&b2), (a, b) => a == b, } } @@ -158,6 +156,25 @@ impl SpanlessEq for Object { } } +impl<T: SpanlessEq> SpanlessEq for Vec<T> { + fn spanless_eq(&self, other: &Vec<T>) -> bool { + self.len() == other.len() + && self.iter().zip(other).all(|(x, y)| x.spanless_eq(&y)) + } +} + +impl<T: SpanlessEq> SpanlessEq for Spanned<T> { + fn spanless_eq(&self, other: &Spanned<T>) -> bool { + self.v.spanless_eq(&other.v) + } +} + +impl<T: SpanlessEq> SpanlessEq for Box<T> { + fn spanless_eq(&self, other: &Box<T>) -> bool { + (&**self).spanless_eq(&**other) + } +} + /// Implement `SpanlessEq` by just forwarding to `PartialEq`. macro_rules! forward { ($type:ty) => { |
