From 619c2dc3e49602155ef13cf9f99ff9a1c94e66cd Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sun, 6 Oct 2024 14:39:05 +0200 Subject: [PATCH] check if term is empty --- src/sugar.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/sugar.rs b/src/sugar.rs index dea73ba..4734b6f 100644 --- a/src/sugar.rs +++ b/src/sugar.rs @@ -2,7 +2,7 @@ use { crate::{TypeTerm, TypeID, parser::ParseLadderType} }; -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub enum SugaredTypeTerm { TypeID(TypeID), Num(i64), @@ -92,5 +92,23 @@ impl SugaredTypeTerm { ).collect()), } } + + pub fn is_empty(&self) -> bool { + match self { + SugaredTypeTerm::TypeID(_) => false, + SugaredTypeTerm::Num(_) => false, + SugaredTypeTerm::Char(_) => false, + SugaredTypeTerm::Univ(t) => t.is_empty(), + SugaredTypeTerm::Spec(ts) | + SugaredTypeTerm::Ladder(ts) | + SugaredTypeTerm::Func(ts) | + SugaredTypeTerm::Morph(ts) | + SugaredTypeTerm::Struct(ts) | + SugaredTypeTerm::Enum(ts) | + SugaredTypeTerm::Seq(ts) => { + ts.iter().fold(true, |s,t|s&&t.is_empty()) + } + } + } }