diff options
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/Matcher.hs | 4 | ||||
-rw-r--r-- | Utility/Misc.hs | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/Utility/Matcher.hs b/Utility/Matcher.hs index 9b6005767..83a2b1d61 100644 --- a/Utility/Matcher.hs +++ b/Utility/Matcher.hs @@ -19,6 +19,7 @@ module Utility.Matcher ( Token(..), Matcher, token, + tokens, generate, match, matchM, @@ -48,6 +49,9 @@ token "(" = Open token ")" = Close token t = error $ "unknown token " ++ t +tokens :: [String] +tokens = words "and or not ( )" + {- Converts a list of Tokens into a Matcher. -} generate :: [Token op] -> Matcher op generate = go MAny diff --git a/Utility/Misc.hs b/Utility/Misc.hs index 349b20efe..88d210de6 100644 --- a/Utility/Misc.hs +++ b/Utility/Misc.hs @@ -42,11 +42,15 @@ firstLine = takeWhile (/= '\n') {- Splits a list into segments that are delimited by items matching - a predicate. (The delimiters are not included in the segments.) -} segment :: (a -> Bool) -> [a] -> [[a]] -segment p l = map reverse $ go [] [] l +segment p = filter (not . all p) . segmentDelim p + +{- Includes the delimiters as segments of their own. -} +segmentDelim :: (a -> Bool) -> [a] -> [[a]] +segmentDelim p l = map reverse $ go [] [] l where go c r [] = reverse $ c:r go c r (i:is) - | p i = go [] (c:r) is + | p i = go [] ([i]:c:r) is | otherwise = go (i:c) r is {- Given two orderings, returns the second if the first is EQ and returns |