more metadata -> tag renaming in the parser

This commit is contained in:
Simon Michael 2012-05-28 00:24:49 +00:00
parent 1062e2f9a4
commit 9524e6d927

View File

@ -315,17 +315,17 @@ transaction = do
code <- code <?> "transaction code" code <- code <?> "transaction code"
-- now there can be whitespace followed by a description and/or comment/tag comment -- now there can be whitespace followed by a description and/or comment/tag comment
let pdescription = many (noneOf ";\n") >>= return . strip let pdescription = many (noneOf ";\n") >>= return . strip
(description, inlinecomment, inlinemd) <- (description, inlinecomment, inlinetag) <-
try (do many1 spacenonewline try (do many1 spacenonewline
d <- pdescription d <- pdescription
(c, m) <- inlinecomment (c, m) <- inlinecomment
return (d,c,m)) return (d,c,m))
<|> (newline >> return ("", [], [])) <|> (newline >> return ("", [], []))
(nextlinecomments, nextlinemds) <- commentlines (nextlinecomments, nextlinetags) <- commentlines
let comment = unlines $ inlinecomment ++ nextlinecomments let comment = unlines $ inlinecomment ++ nextlinecomments
mds = inlinemd ++ nextlinemds tags = inlinetag ++ nextlinetags
postings <- postings postings <- postings
return $ txnTieKnot $ Transaction date edate status code description comment mds postings "" return $ txnTieKnot $ Transaction date edate status code description comment tags postings ""
tests_transaction = [ tests_transaction = [
"transaction" ~: do "transaction" ~: do
@ -486,11 +486,11 @@ posting = do
let (ptype, account') = (accountNamePostingType account, unbracket account) let (ptype, account') = (accountNamePostingType account, unbracket account)
amount <- spaceandamountormissing amount <- spaceandamountormissing
many spacenonewline many spacenonewline
(inlinecomment, inlinemd) <- inlinecomment (inlinecomment, inlinetag) <- inlinecomment
(nextlinecomments, nextlinemds) <- commentlines (nextlinecomments, nextlinetags) <- commentlines
let comment = unlines $ inlinecomment ++ nextlinecomments let comment = unlines $ inlinecomment ++ nextlinecomments
mds = inlinemd ++ nextlinemds tags = inlinetag ++ nextlinetags
return (Posting status account' amount comment ptype mds Nothing) return (Posting status account' amount comment ptype tags Nothing)
tests_posting = [ tests_posting = [
"posting" ~: do "posting" ~: do
@ -754,7 +754,7 @@ commentline = do
-- newer comment parsers -- newer comment parsers
inlinecomment :: GenParser Char JournalContext ([String],[Tag]) inlinecomment :: GenParser Char JournalContext ([String],[Tag])
inlinecomment = try (do {md <- tagcomment; newline; return ([], [md])}) inlinecomment = try (do {tag <- tagcomment; newline; return ([], [tag])})
<|> (do {c <- comment; newline; return ([rstrip c], [])}) <|> (do {c <- comment; newline; return ([rstrip c], [])})
<|> (newline >> return ([], [])) <|> (newline >> return ([], []))
@ -767,10 +767,10 @@ tests_inlinecomment = [
commentlines :: GenParser Char JournalContext ([String],[Tag]) commentlines :: GenParser Char JournalContext ([String],[Tag])
commentlines = do commentlines = do
comormds <- many $ choice' [(liftM Right tagline) comortags <- many $ choice' [(liftM Right tagline)
,(do {many1 spacenonewline; c <- comment; newline; return $ Left c }) -- XXX fix commentnewline ,(do {many1 spacenonewline; c <- comment; newline; return $ Left c }) -- XXX fix commentnewline
] ]
return $ partitionEithers comormds return $ partitionEithers comortags
tests_commentlines = [ tests_commentlines = [
"commentlines" ~: do "commentlines" ~: do
@ -781,15 +781,15 @@ tests_commentlines = [
-- a comment line containing a tag declaration, eg: -- a comment line containing a tag declaration, eg:
-- ; name: value -- ; name: value
tagline :: GenParser Char JournalContext (String,String) tagline :: GenParser Char JournalContext Tag
tagline = do tagline = do
many1 spacenonewline many1 spacenonewline
md <- tagcomment tag <- tagcomment
newline newline
return md return tag
-- a comment containing a tag, like "; name: some value" -- a comment containing a tag, like "; name: some value"
tagcomment :: GenParser Char JournalContext (String,String) tagcomment :: GenParser Char JournalContext Tag
tagcomment = do tagcomment = do
many1 $ char ';' many1 $ char ';'
many spacenonewline many spacenonewline