diff --git a/hledger-lib/Hledger/Data/Posting.hs b/hledger-lib/Hledger/Data/Posting.hs index 5f5fe302d..7b3c78a41 100644 --- a/hledger-lib/Hledger/Data/Posting.hs +++ b/hledger-lib/Hledger/Data/Posting.hs @@ -137,29 +137,16 @@ postingDate2 p = headDef nulldate $ catMaybes dates ,maybe Nothing (Just . tdate) $ ptransaction p ] --- | Get a posting's cleared status: cleared or pending if explicitly set, --- otherwise the cleared status of its parent transaction, or uncleared --- if there is no parent transaction. --- (Note Uncleared's ambiguity, can mean "uncleared" or "don't know". +-- | Get a posting's cleared status: cleared or pending if those are +-- explicitly set, otherwise the cleared status of its parent +-- transaction, or uncleared if there is no parent transaction. (Note +-- Uncleared's ambiguity, it can mean "uncleared" or "don't know". postingStatus :: Posting -> ClearedStatus postingStatus Posting{pstatus=s, ptransaction=mt} | s == Uncleared = case mt of Just t -> tstatus t Nothing -> Uncleared | otherwise = s --- -- | Is this posting cleared? True if the posting is explicitly marked --- -- cleared, false if it is marked pending, otherwise true if the --- -- parent transaction is marked cleared or false if there is no parent --- -- transaction. --- -- (Note Uncleared's ambiguity, can mean "uncleared" or "don't know". --- postingIsCleared :: Posting -> Bool --- postingIsCleared p --- | pstatus p == Cleared = True --- | pstatus p == Pending = False --- | otherwise = case ptransaction p of --- Just t -> tstatus t == Cleared --- Nothing -> False - -- | Tags for this posting including any inherited from its parent transaction. postingAllTags :: Posting -> [Tag] postingAllTags p = ptags p ++ maybe [] ttags (ptransaction p) diff --git a/hledger-lib/Hledger/Query.hs b/hledger-lib/Hledger/Query.hs index ce53425db..250ae0180 100644 --- a/hledger-lib/Hledger/Query.hs +++ b/hledger-lib/Hledger/Query.hs @@ -73,7 +73,7 @@ data Query = Any -- ^ always match | Acct String -- ^ match postings whose account matches this regexp | Date DateSpan -- ^ match if primary date in this date span | Date2 DateSpan -- ^ match if secondary date in this date span - | Status ClearedStatus -- ^ match if cleared status has this value + | Status ClearedStatus -- ^ match txns/postings with this cleared status (Status Uncleared matches all states except cleared) | Real Bool -- ^ match if "realness" (involves a real non-virtual account ?) has this value | Amt OrdPlus Quantity -- ^ match if the amount's numeric quantity is less than/greater than/equal to/unsignedly equal to some value | Sym String -- ^ match if the entire commodity symbol is matched by this regexp @@ -249,7 +249,9 @@ parseQueryTerm d ('d':'a':'t':'e':'2':':':s) = parseQueryTerm d ('d':'a':'t':'e':':':s) = case parsePeriodExpr d s of Left e -> error' $ "\"date:"++s++"\" gave a "++showDateParseError e Right (_,span) -> Left $ Date span -parseQueryTerm _ ('s':'t':'a':'t':'u':'s':':':s) = Left $ Status $ parseStatus s +parseQueryTerm _ ('s':'t':'a':'t':'u':'s':':':s) = + case parseStatus s of Left e -> error' $ "\"status:"++s++"\" gave a parse error: " ++ e + Right st -> Left $ Status st parseQueryTerm _ ('r':'e':'a':'l':':':s) = Left $ Real $ parseBool s parseQueryTerm _ ('a':'m':'t':':':s) = Left $ Amt ord q where (ord, q) = parseAmountQueryTerm s parseQueryTerm _ ('e':'m':'p':'t':'y':':':s) = Left $ Empty $ parseBool s @@ -333,12 +335,12 @@ parseTag s | '=' `elem` s = (n, Just $ tail v) | otherwise = (s, Nothing) where (n,v) = break (=='=') s --- -- , treating "*" or "!" as synonyms for "1". --- | Parse the boolean value part of a "status:" query. -parseStatus :: String -> ClearedStatus -parseStatus s | s `elem` ["1","*"] = Cleared - | s == "!" = Pending - | otherwise = Uncleared +-- | Parse the value part of a "status:" query, or return an error. +parseStatus :: String -> Either String ClearedStatus +parseStatus s | s `elem` ["*","1"] = Right Cleared + | s `elem` ["!"] = Right Pending + | s `elem` ["","0"] = Right Uncleared + | otherwise = Left $ "could not parse "++show s++" as a status (should be *, ! or empty)" -- | Parse the boolean value part of a "status:" query. "1" means true, -- anything else will be parsed as false without error.