This commit is contained in:
Simon Michael 2011-06-14 14:27:48 +00:00
parent dfce1c48d2
commit 4e9c09fb87

View File

@ -104,6 +104,33 @@ parseQuery d s = (m,qopts)
(m':[]) -> m' (m':[]) -> m'
ms -> MatchAnd ms ms -> MatchAnd ms
-- | Quote-and-prefix-aware version of words - don't split on spaces which
-- are inside quotes, including quotes which may have one of the specified
-- prefixes in front, and maybe an additional not: prefix in front of that.
words'' :: [String] -> String -> [String]
words'' prefixes = fromparse . parsewith maybeprefixedquotedphrases -- XXX
where
maybeprefixedquotedphrases = choice' [prefixedQuotedPattern, quotedPattern, pattern] `sepBy` many1 spacenonewline
prefixedQuotedPattern = do
not' <- optionMaybe $ string "not:"
prefix <- choice' $ map string prefixes
p <- quotedPattern
return $ fromMaybe "" not' ++ prefix ++ stripquotes p
quotedPattern = do
p <- between (oneOf "'\"") (oneOf "'\"") $ many $ noneOf "'\""
return $ stripquotes p
pattern = many (noneOf " \n\r\"")
-- -- | Parse the query string as a boolean tree of match patterns.
-- parseMatcher :: String -> Matcher
-- parseMatcher s = either (const (MatchAny)) id $ runParser matcher () "" $ lexmatcher s
-- lexmatcher :: String -> [String]
-- lexmatcher s = words' s
-- matcher :: GenParser String () Matcher
-- matcher = undefined
-- keep synced with patterns below, excluding "not" -- keep synced with patterns below, excluding "not"
prefixes = map (++":") [ prefixes = map (++":") [
"inacct","inacctonly", "inacct","inacctonly",
@ -146,33 +173,6 @@ parseBool s = s `elem` truestrings
truestrings :: [String] truestrings :: [String]
truestrings = ["1","t","true"] truestrings = ["1","t","true"]
-- | Quote-and-prefix-aware version of words - don't split on spaces which
-- are inside quotes, including quotes which may have one of the specified
-- prefixes in front, and maybe an additional not: prefix in front of that.
words'' :: [String] -> String -> [String]
words'' prefixes = fromparse . parsewith maybeprefixedquotedphrases -- XXX
where
maybeprefixedquotedphrases = choice' [prefixedQuotedPattern, quotedPattern, pattern] `sepBy` many1 spacenonewline
prefixedQuotedPattern = do
not' <- optionMaybe $ string "not:"
prefix <- choice' $ map string prefixes
p <- quotedPattern
return $ fromMaybe "" not' ++ prefix ++ stripquotes p
quotedPattern = do
p <- between (oneOf "'\"") (oneOf "'\"") $ many $ noneOf "'\""
return $ stripquotes p
pattern = many (noneOf " \n\r\"")
-- -- | Parse the query string as a boolean tree of match patterns.
-- parseMatcher :: String -> Matcher
-- parseMatcher s = either (const (MatchAny)) id $ runParser matcher () "" $ lexmatcher s
-- lexmatcher :: String -> [String]
-- lexmatcher s = words' s
-- matcher :: GenParser String () Matcher
-- matcher = undefined
-- | Convert a match expression to its inverse. -- | Convert a match expression to its inverse.
negateMatcher :: Matcher -> Matcher negateMatcher :: Matcher -> Matcher
negateMatcher = MatchNot negateMatcher = MatchNot