Fixed TimeLog handling and certain blank lines

This commit is contained in:
nick 2008-12-08 03:45:35 +00:00
parent 958c4eb891
commit 0be862f760
3 changed files with 15 additions and 18 deletions

View File

@ -48,7 +48,7 @@ emptyCtx = Ctx { ctxYear = Nothing, ctxCommod = Nothing, ctxAccount = [] }
parseLedger :: FilePath -> String -> ErrorT String IO RawLedger
parseLedger inname intxt = case runParser ledgerFile emptyCtx inname intxt of
Right m -> m `ap` (return rawLedgerEmpty)
Right m -> liftM rawLedgerConvertTimeLog $ m `ap` (return rawLedgerEmpty)
Left err -> throwError $ show err
ledgerFile :: GenParser Char LedgerFileCtx (ErrorT String IO (RawLedger -> RawLedger))
@ -59,8 +59,8 @@ ledgerFile = do entries <- many1 ledgerAnyEntry
, liftM (return . addEntry) ledgerEntry
, liftM (return . addModifierEntry) ledgerModifierEntry
, liftM (return . addPeriodicEntry) ledgerPeriodicEntry
, blankline >> return (return id)
, commentline >> return (return id)
, emptyLine >> return (return id)
, liftM (return . addTimeLogEntry) timelogentry
]
ledgerInclude :: GenParser Char LedgerFileCtx (ErrorT String IO (RawLedger -> RawLedger))
@ -189,15 +189,11 @@ i, o, b, h
See "Tests" for sample data.
-}
blankline :: GenParser Char st String
blankline = (do { s <- many spacenonewline; newline; return s }) <?> "blank line"
commentline :: GenParser Char st String
commentline = do
many spacenonewline
char ';' <?> "comment line"
l <- restofline
return $ ";" ++ l
emptyLine :: GenParser Char st ()
emptyLine = do many spacenonewline
optional $ char ';' >> spacenonewline >> many (noneOf "\n")
newline
return ()
ledgercomment :: GenParser Char st String
ledgercomment =
@ -453,7 +449,6 @@ timelog = do
timelogentry :: GenParser Char st TimeLogEntry
timelogentry = do
many (commentline <|> blankline)
code <- oneOf "bhioO"
many1 spacenonewline
datetime <- ledgerdatetime

View File

@ -15,6 +15,7 @@ import Ledger.Amount
import Ledger.Entry
import Ledger.Transaction
import Ledger.RawTransaction
import Ledger.TimeLog
instance Show RawLedger where
@ -125,3 +126,9 @@ rawLedgerAmounts = map amount . rawLedgerTransactions
rawLedgerPrecisions :: RawLedger -> [Int]
rawLedgerPrecisions = map precision . rawLedgerCommodities
rawLedgerConvertTimeLog :: RawLedger -> RawLedger
rawLedgerConvertTimeLog l0 = l0 { entries = convertedTimeLog ++ entries l0
, open_timelog_entries = []
}
where convertedTimeLog = entriesFromTimeLogEntries $ open_timelog_entries l0

View File

@ -14,17 +14,12 @@ import Ledger.Dates
import Ledger.Commodity
import Ledger.Amount
instance Show TimeLogEntry where
show t = printf "%s %s %s" (show $ tlcode t) (show $ tldatetime t) (tlcomment t)
instance Show TimeLog where
show tl = printf "TimeLog with %d entries" $ length $ timelog_entries tl
-- | Convert a time log to a ledger.
ledgerFromTimeLog :: TimeLog -> RawLedger
ledgerFromTimeLog tl = RawLedger [] [] (entriesFromTimeLogEntries $ timelog_entries tl) ""
-- | Convert time log entries to ledger entries.
entriesFromTimeLogEntries :: [TimeLogEntry] -> [Entry]
entriesFromTimeLogEntries [] = []