imp: timedot: fix day description/comment parsing; parse posting comments/tags
This commit is contained in:
parent
1b19f3d330
commit
f7f86a709b
@ -123,23 +123,24 @@ preamblep = do
|
||||
dayp :: JournalParser m ()
|
||||
dayp = label "timedot day entry" $ do
|
||||
lift $ traceparse "dayp"
|
||||
(d,desc) <- datelinep
|
||||
(date,desc,comment,tags) <- datelinep
|
||||
commentlinesp
|
||||
ts <- many $ entryp <* commentlinesp
|
||||
modify' $ addTransactions $ map (\t -> t{tdate=d, tdescription=desc}) ts
|
||||
modify' $ addTransactions $ map (\t -> t{tdate=date, tdescription=desc, tcomment=comment, ttags=tags}) ts
|
||||
lift $ traceparse' "dayp"
|
||||
where
|
||||
addTransactions :: [Transaction] -> Journal -> Journal
|
||||
addTransactions ts j = foldl' (flip ($)) j (map addTransaction ts)
|
||||
|
||||
datelinep :: JournalParser m (Day,Text)
|
||||
datelinep :: JournalParser m (Day,Text,Text,[Tag])
|
||||
datelinep = do
|
||||
lift $ traceparse "datelinep"
|
||||
lift $ optional orgheadingprefixp
|
||||
d <- datep
|
||||
desc <- strip <$> lift restofline
|
||||
date <- datep
|
||||
desc <- T.strip <$> lift descriptionp
|
||||
(comment, tags) <- lift transactioncommentp
|
||||
lift $ traceparse' "datelinep"
|
||||
return (d, T.pack desc)
|
||||
return (date, desc, comment, tags)
|
||||
|
||||
-- | Zero or more empty lines or hash/semicolon comment lines
|
||||
-- or org headlines which do not start a new day.
|
||||
@ -172,10 +173,16 @@ entryp = do
|
||||
lift $ optional $ choice [orgheadingprefixp, skipNonNewlineSpaces1]
|
||||
a <- modifiedaccountnamep
|
||||
lift skipNonNewlineSpaces
|
||||
hours <-
|
||||
try (lift followingcommentp >> return 0)
|
||||
<|> (lift durationp <*
|
||||
(try (lift followingcommentp) <|> (newline >> return "")))
|
||||
(hours, comment, tags) <-
|
||||
try (do
|
||||
(c,ts) <- lift transactioncommentp -- or postingp, but let's not bother supporting date:/date2:
|
||||
return (0, c, ts)
|
||||
)
|
||||
<|> (do
|
||||
h <- lift durationp
|
||||
(c,ts) <- try (lift transactioncommentp) <|> (newline >> return ("",[]))
|
||||
return (h,c,ts)
|
||||
)
|
||||
mcs <- getDefaultCommodityAndStyle
|
||||
let
|
||||
(c,s) = case mcs of
|
||||
@ -188,6 +195,8 @@ entryp = do
|
||||
nullposting{paccount=a
|
||||
,pamount=mixedAmount $ nullamt{acommodity=c, aquantity=hours, astyle=s}
|
||||
,ptype=VirtualPosting
|
||||
,pcomment=comment
|
||||
,ptags=tags
|
||||
,ptransaction=Just t
|
||||
}
|
||||
]
|
||||
|
||||
@ -4201,19 +4201,15 @@ A day entry begins with a date line:
|
||||
|
||||
Optionally this can be followed on the same line by
|
||||
|
||||
- a common **transaction description** for this day
|
||||
- a common **transaction comment** for this day, after a semicolon (`;`).
|
||||
- a **common description** for this day's transactions.
|
||||
- a **common comment** for this day's transactions, following a semicolon (`;`).
|
||||
|
||||
After the date line are zero or more optionally-indented
|
||||
time transaction lines, consisting of:
|
||||
After the date line are zero or more optionally-indented time transactions, consisting of:
|
||||
|
||||
- an **account name** - any word or phrase, usually a
|
||||
hledger-style [account name](#account-names).
|
||||
- **two or more spaces** - a field separator,
|
||||
required if there is an amount (as in journal format).
|
||||
- a **timedot amount** - dots representing quarter hours,
|
||||
or a number representing hours.
|
||||
- an optional **comment** beginning with semicolon. This is ignored.
|
||||
- an **account name** - any word or phrase, usually a hledger-style [account name](#account-names).
|
||||
- **two or more spaces** - a field separator, required if there is an amount (as in journal format).
|
||||
- a **timedot amount** - dots representing quarter hours, or a number representing hours, optionally with a unit suffix.
|
||||
- an **posting comment** for this transaction, following with semicolon.
|
||||
|
||||
In more detail, timedot amounts can be:
|
||||
|
||||
|
||||
@ -1,13 +1,11 @@
|
||||
# Note since 1.17 we need to specify stdin's format explicitly.
|
||||
|
||||
# 1. basic timedot entry
|
||||
<
|
||||
# comment
|
||||
# file comment
|
||||
; another file comment
|
||||
|
||||
; another comment
|
||||
2020-01-01
|
||||
a:aa 1
|
||||
b:bb 2
|
||||
a:aa 1
|
||||
b:bb 2
|
||||
|
||||
$ hledger -ftimedot:- print
|
||||
2020-01-01 *
|
||||
@ -35,3 +33,26 @@ $ hledger -ftimedot:- print --alias a=b
|
||||
(b:aa) 1.00
|
||||
|
||||
>=0
|
||||
|
||||
# 4. A common day description and comment, and posting comments are supported.
|
||||
<
|
||||
2023-01-01 day description ; day comment, day-tag:
|
||||
a ....
|
||||
b .... ; posting comment, posting-tag:
|
||||
|
||||
$ hledger -ftimedot:- print
|
||||
2023-01-01 * day description ; day comment, day-tag:
|
||||
(a) 1.00
|
||||
|
||||
2023-01-01 * day description ; day comment, day-tag:
|
||||
(b) 1.00 ; posting comment, posting-tag:
|
||||
|
||||
>=
|
||||
|
||||
# 5. Transaction descriptions, comments and tags are parsed properly.
|
||||
$ hledger -ftimedot:- descriptions tag:day-tag
|
||||
day description
|
||||
|
||||
# 6. Posting comments and tags are parsed properly.
|
||||
$ hledger -ftimedot:- reg tag:posting-tag
|
||||
2023-01-01 day description (b) 1.00 1.00
|
||||
|
||||
Loading…
Reference in New Issue
Block a user