From bb1350cff5f1cf4da0332b72ec0703689645649c Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Sat, 18 Jul 2020 14:04:58 +0200 Subject: Parsing mathematical expressions :heavy_plus_sign: --- src/syntax/test.rs | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'src/syntax/test.rs') 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 { fn spanless_eq(&self, other: &Rhs) -> bool; } -impl SpanlessEq for Vec> { - fn spanless_eq(&self, other: &Vec>) -> 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 SpanlessEq for Vec { + fn spanless_eq(&self, other: &Vec) -> bool { + self.len() == other.len() + && self.iter().zip(other).all(|(x, y)| x.spanless_eq(&y)) + } +} + +impl SpanlessEq for Spanned { + fn spanless_eq(&self, other: &Spanned) -> bool { + self.v.spanless_eq(&other.v) + } +} + +impl SpanlessEq for Box { + fn spanless_eq(&self, other: &Box) -> bool { + (&**self).spanless_eq(&**other) + } +} + /// Implement `SpanlessEq` by just forwarding to `PartialEq`. macro_rules! forward { ($type:ty) => { -- cgit v1.2.3