From c64db46b7f9429f889f8d77e0f6c31a126b1c653 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 18 Dec 2023 21:35:00 -0400 Subject: [PATCH] refactor --- Utility/Matcher.hs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Utility/Matcher.hs b/Utility/Matcher.hs index c5eec539fb..38864e05fd 100644 --- a/Utility/Matcher.hs +++ b/Utility/Matcher.hs @@ -105,16 +105,8 @@ pruneMatcher :: (op -> Bool) -> Matcher op -> Matcher op pruneMatcher f = fst . go where go MAny = (MAny, False) - go (MAnd a b) = case (go a, go b) of - ((_, True), (_, True)) -> (MAny, True) - ((a', False), (b', False)) -> (MAnd a' b', False) - ((_, True), (b', False)) -> (b', False) - ((a', False), (_, True)) -> (a', False) - go (MOr a b) = case (go a, go b) of - ((_, True), (_, True)) -> (MAny, True) - ((a', False), (b', False)) -> (MOr a' b', False) - ((_, True), (b', False)) -> (b', False) - ((a', False), (_, True)) -> (a', False) + go (MAnd a b) = go2 a b MAnd + go (MOr a b) = go2 a b MOr go (MNot a) = case go a of (_, True) -> (MAny, True) (a', False) -> (MNot a', False) @@ -122,6 +114,12 @@ pruneMatcher f = fst . go | f op = (MAny, True) | otherwise = (MOp op, False) + go2 a b g = case (go a, go b) of + ((_, True), (_, True)) -> (MAny, True) + ((a', False), (b', False)) -> (g a' b', False) + ((_, True), (b', False)) -> (b', False) + ((a', False), (_, True)) -> (a', False) + data TokenGroup op = One (Token op) | Group [TokenGroup op] deriving (Show, Eq)