refactor
authorJoey Hess <joeyh@joeyh.name>
Tue, 19 Dec 2023 01:35:00 +0000 (21:35 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 19 Dec 2023 01:35:00 +0000 (21:35 -0400)
Utility/Matcher.hs

index c5eec539fb81311e84c88131af5d9c2d4febdca8..38864e05fd16f6a50b3c44a422f42e632da107bc 100644 (file)
@@ -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)