remove excess doubled parens in match description
authorJoey Hess <joeyh@joeyh.name>
Tue, 25 Jul 2023 17:55:01 +0000 (13:55 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 25 Jul 2023 17:55:01 +0000 (13:55 -0400)
Sponsored-by: Dartmouth College's DANDI project
Utility/Matcher.hs

index 3ef8397ce62d7f1d7bfabb95d7a4e4f1db229c37..e8bb2535d7ed97ceb37b90f3c4da29d8ea70fb8d 100644 (file)
@@ -237,9 +237,20 @@ describeMatchDesc descop = unwords . go . simplify True
        -- (not foo) => not foo
        simplify _ (MatchedOpen:MatchedNot:o@(MatchedOperation {}):MatchedClose:rest) =
                MatchedNot:o:simplify False rest
+       -- ((foo bar)) => (foo bar)
+       simplify _ (MatchedOpen:MatchedOpen:rest) =
+               MatchedOpen : simplify False (removeclose (0 :: Int) rest)
        simplify _ (v:rest) = v : simplify False rest
        simplify _ v = v
 
+       removeclose n (MatchedOpen:rest) =
+               MatchedOpen : removeclose (n+1) rest
+       removeclose n (MatchedClose:rest)
+               | n > 0 = MatchedClose : removeclose (n-1) rest
+               | otherwise = rest
+       removeclose n (v:rest) = v : removeclose n rest
+       removeclose _ [] = []
+
 prop_matcher_sane :: Bool
 prop_matcher_sane = and
        [ all (\m -> match (\b _ -> b) m ()) (map generate evaltrue)