mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
preserve whitespace lines (except after last entry)
This commit is contained in:
parent
daff4bf09e
commit
12ad860d4c
25
Parse.hs
25
Parse.hs
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user