Merge pull request #214 from nilcons-contrib/master

Add support for ledger3 style multi-line comments
This commit is contained in:
Simon Michael 2014-10-26 11:26:16 -07:00
commit 403ddcadc2
2 changed files with 15 additions and 0 deletions

View File

@ -204,6 +204,11 @@ samplejournal = readJournal' $ unlines
," assets:bank:checking $1"
," income:salary"
,""
,"comment"
,"multi line comment here"
,"for testing purposes"
,"end comment"
,""
,"2008/06/01 gift"
," assets:bank:checking $1"
," income:gifts"

View File

@ -164,6 +164,7 @@ journal = do
, liftM (return . addPeriodicTransaction) periodictransaction
, liftM (return . addHistoricalPrice) historicalpricedirective
, emptyorcommentlinep >> return (return id)
, multilinecommentp >> return (return id)
] <?> "journal transaction or directive"
-- cf http://ledger-cli.org/3.0/doc/ledger3.html#Command-Directives
@ -847,6 +848,15 @@ test_numberp = do
-- comment parsers
multilinecommentp :: GenParser Char JournalContext ()
multilinecommentp = do
string "comment" >> newline
go
where
go = try (string "end comment" >> newline >> return ())
<|> (anyLine >> go)
anyLine = anyChar `manyTill` newline
emptyorcommentlinep :: GenParser Char JournalContext ()
emptyorcommentlinep = do
many spacenonewline >> (comment <|> (many spacenonewline >> newline >> return ""))