metadata parse and show for transaction

This commit is contained in:
xiaoruoruo 2012-04-08 19:13:56 +00:00
parent c010448935
commit ce83876700
3 changed files with 6 additions and 2 deletions

View File

@ -93,7 +93,7 @@ showTransactionUnelided = showTransaction' False
showTransaction' :: Bool -> Transaction -> String
showTransaction' elide t =
unlines $ [description] ++ showpostings (tpostings t) ++ [""]
unlines $ [description] ++ metadata ++ showpostings (tpostings t) ++ [""]
where
description = concat [date, status, code, desc, comment]
date = showdate (tdate t) ++ maybe "" showedate (teffectivedate t)
@ -103,6 +103,8 @@ showTransaction' elide t =
code = if length (tcode t) > 0 then printf " (%s)" $ tcode t else ""
desc = if null d then "" else " " ++ d where d = tdescription t
comment = if null c then "" else " ; " ++ c where c = tcomment t
metadata = if null md then [] else showmetadata md where md = tmetadata t
showmetadata md = map (\(k,v) -> " ; " ++ k++":"++v) md
showpostings ps
| elide && length ps > 1 && isTransactionBalanced Nothing t -- imprecise balanced check
= map showposting (init ps) ++ [showpostingnoamt (last ps)]

View File

@ -415,7 +415,7 @@ ledgercode :: GenParser Char JournalContext String
ledgercode = try (do { many1 spacenonewline; char '(' <?> "code"; code <- anyChar `manyTill` char ')'; return code } ) <|> return ""
ledgermetadata :: GenParser Char JournalContext [(String,String)]
ledgermetadata = many ledgermetadataline
ledgermetadata = many $ try ledgermetadataline
-- a comment line containing a metadata declaration, eg:
-- ; name: value

View File

@ -13,6 +13,8 @@ bin/hledger -f - print
; non-metadata:
>>>
2010/01/01
; txndata1:txn val 1
; txndata2:txn val 2
a 1
b -1