This commit is contained in:
Joey Hess 2023-12-18 21:35:00 -04:00
parent 9a67ed0f10
commit c64db46b7f
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View 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)