From 331ed6b407399e3b2ac7e98cbd804657607b8b12 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 14 Apr 2010 21:37:03 +0000 Subject: [PATCH] refactor: cleanup --- Hledger/Cli/Tests.hs | 2 +- hledger-lib/Hledger/Data/Dates.hs | 5 +---- hledger-lib/Hledger/Data/Utils.hs | 2 ++ 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Hledger/Cli/Tests.hs b/Hledger/Cli/Tests.hs index f38cd34f8..8aa7660ce 100644 --- a/Hledger/Cli/Tests.hs +++ b/Hledger/Cli/Tests.hs @@ -590,7 +590,7 @@ tests = TestList [ ["2009/01/01 медвежья шкура расходы:покупки 100 100" ," актив:наличные -100 0"] - ,"smart dates" ~: do + ,"fixSmartDateStr" ~: do let gives = is . fixSmartDateStr (parsedate "2008/11/26") "1999-12-02" `gives` "1999/12/02" "1999.12.02" `gives` "1999/12/02" diff --git a/hledger-lib/Hledger/Data/Dates.hs b/hledger-lib/Hledger/Data/Dates.hs index 7ed6b8bba..78b5411f5 100644 --- a/hledger-lib/Hledger/Data/Dates.hs +++ b/hledger-lib/Hledger/Data/Dates.hs @@ -246,10 +246,7 @@ Assumes any text in the parse stream has been lowercased. -} smartdate :: GenParser Char st SmartDate smartdate = do - let dateparsers = [yyyymmdd, ymd, ym, md, y, d, month, mon, today, yesterday, tomorrow, - lastthisnextthing - ] - (y,m,d) <- choice $ map try dateparsers + (y,m,d) <- choice' [yyyymmdd, ymd, ym, md, y, d, month, mon, today, yesterday, tomorrow, lastthisnextthing] return (y,m,d) -- | Like smartdate, but there must be nothing other than whitespace after the date. diff --git a/hledger-lib/Hledger/Data/Utils.hs b/hledger-lib/Hledger/Data/Utils.hs index 6a8c807c4..51ceb6397 100644 --- a/hledger-lib/Hledger/Data/Utils.hs +++ b/hledger-lib/Hledger/Data/Utils.hs @@ -241,6 +241,8 @@ tracewith f e = trace (f e) e -- parsing +choice' = choice . map Text.ParserCombinators.Parsec.try + parsewith :: Parser a -> String -> Either ParseError a parsewith p = parse p ""