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)
ledgernondatalines :: Parser [String]
ledgernondatalines = many (ledgerdirective <|> ledgercommentline <|> do {whiteSpace1; return []})
ledgernondatalines = many (ledgerdirective <|> -- treat as comments
commentline <|>
blankline)
ledgercommentline :: Parser String
ledgercommentline = do
char ';'
l <- restofline <?> "comment line"
ledgerdirective :: Parser String
ledgerdirective = char '!' >> restofline <?> "directive"
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
ledgercomment :: Parser String
@ -169,9 +179,6 @@ ledgercomment =
)
<|> return "" <?> "comment"
ledgerdirective :: Parser String
ledgerdirective = char '!' >> restofline <?> "directive"
ledgermodifierentry :: Parser ModifierEntry
ledgermodifierentry = do
char '=' <?> "entry"
@ -191,7 +198,7 @@ ledgerperiodicentry = do
ledgerentry :: Parser LedgerEntry
ledgerentry = do
preceding <- ledgernondatalines
date <- ledgerdate
date <- ledgerdate <?> "entry"
status <- ledgerstatus
code <- ledgercode
-- ledger treats entry comments as part of the description, we will too