From d4234b461ba23c0815a4e2def625124af95110e1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 25 May 2013 13:50:27 -0400 Subject: [PATCH] fix handling of Not in the matcher --- Utility/Matcher.hs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Utility/Matcher.hs b/Utility/Matcher.hs index d872d9234b..e0a51ff6ab 100644 --- a/Utility/Matcher.hs +++ b/Utility/Matcher.hs @@ -64,14 +64,18 @@ generate = simplify . process MAny . tokenGroups process m [] = m process m ts = uncurry process $ consume m ts - consume m ((One And):y:rest) = (m `MAnd` process MAny [y], rest) - consume m ((One Or):y:rest) = (m `MOr` process MAny [y], rest) - consume m ((One Not):x:rest) = (m `MAnd` MNot (process MAny [x]), rest) + consume m ((One And):rest) = term (m `MAnd`) rest + consume m ((One Or):rest) = term (m `MOr`) rest + consume m ((One Not):rest) = term (\p -> m `MAnd` (MNot p)) rest consume m ((One (Operation o)):rest) = (m `MAnd` MOp o, rest) consume m (Group g:rest) = (process m g, rest) consume m (_:rest) = consume m rest consume m [] = (m, []) + term a l = + let (p, l') = consume MAny l + in (a p, l') + simplify (MAnd MAny x) = simplify x simplify (MAnd x MAny) = simplify x simplify (MAnd x y) = MAnd (simplify x) (simplify y) @@ -148,6 +152,18 @@ prop_matcher_sane = all (\m -> match dummy m ()) $ map generate , [Not, Open, Operation True, And, Operation False, Close] , [Not, Open, Not, Open, Not, Operation False, Close, Close] , [Not, Open, Not, Open, Not, Open, Not, Operation True, Close, Close] + , [Operation True, And, Not, Operation False] + , [Operation True, Not, Operation False] + , [Operation True, Not, Not, Not, Operation False] + , [Operation True, Not, Not, Not, Operation False, And, Operation True] + , [Operation True, Not, Not, Not, Operation False, Operation True] + , [Not, Open, Operation True, And, Operation False, Close, + And, Open, + Open, Operation True, And, Operation False, Close, + Or, + Open, Operation True, And, Open, Not, Operation False, Close, Close, + Close, And, + Open, Not, Operation False, Close] ] where dummy b _ = b