preserve whitespace lines (except after last entry)

This commit is contained in:
Simon Michael 2008-06-28 05:40:54 +00:00
parent daff4bf09e
commit 12ad860d4c

View File

@ -152,12 +152,22 @@ ledger = do
return $ LedgerFile modifier_entries periodic_entries entries (unlines final_comment_lines) return $ LedgerFile modifier_entries periodic_entries entries (unlines final_comment_lines)
ledgernondatalines :: Parser [String] ledgernondatalines :: Parser [String]
ledgernondatalines = many (ledgerdirective <|> ledgercommentline <|> do {whiteSpace1; return []}) ledgernondatalines = many (ledgerdirective <|> -- treat as comments
commentline <|>
blankline)
ledgercommentline :: Parser String ledgerdirective :: Parser String
ledgercommentline = do ledgerdirective = char '!' >> restofline <?> "directive"
char ';'
l <- restofline <?> "comment line" blankline :: Parser String
blankline =
do {s <- many1 spacenonewline; newline; return s} <|>
do {newline; return ""} <?> "blank line"
commentline :: Parser String
commentline = do
char ';' <?> "comment line"
l <- restofline
return $ ";" ++ l return $ ";" ++ l
ledgercomment :: Parser String ledgercomment :: Parser String
@ -169,9 +179,6 @@ ledgercomment =
) )
<|> return "" <?> "comment" <|> return "" <?> "comment"
ledgerdirective :: Parser String
ledgerdirective = char '!' >> restofline <?> "directive"
ledgermodifierentry :: Parser ModifierEntry ledgermodifierentry :: Parser ModifierEntry
ledgermodifierentry = do ledgermodifierentry = do
char '=' <?> "entry" char '=' <?> "entry"
@ -191,7 +198,7 @@ ledgerperiodicentry = do
ledgerentry :: Parser LedgerEntry ledgerentry :: Parser LedgerEntry
ledgerentry = do ledgerentry = do
preceding <- ledgernondatalines preceding <- ledgernondatalines
date <- ledgerdate date <- ledgerdate <?> "entry"
status <- ledgerstatus status <- ledgerstatus
code <- ledgercode code <- ledgercode
-- ledger treats entry comments as part of the description, we will too -- ledger treats entry comments as part of the description, we will too