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 :: JournalParser m ()
|
||||||
dayp = label "timedot day entry" $ do
|
dayp = label "timedot day entry" $ do
|
||||||
lift $ traceparse "dayp"
|
lift $ traceparse "dayp"
|
||||||
(d,desc) <- datelinep
|
(date,desc,comment,tags) <- datelinep
|
||||||
commentlinesp
|
commentlinesp
|
||||||
ts <- many $ entryp <* 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"
|
lift $ traceparse' "dayp"
|
||||||
where
|
where
|
||||||
addTransactions :: [Transaction] -> Journal -> Journal
|
addTransactions :: [Transaction] -> Journal -> Journal
|
||||||
addTransactions ts j = foldl' (flip ($)) j (map addTransaction ts)
|
addTransactions ts j = foldl' (flip ($)) j (map addTransaction ts)
|
||||||
|
|
||||||
datelinep :: JournalParser m (Day,Text)
|
datelinep :: JournalParser m (Day,Text,Text,[Tag])
|
||||||
datelinep = do
|
datelinep = do
|
||||||
lift $ traceparse "datelinep"
|
lift $ traceparse "datelinep"
|
||||||
lift $ optional orgheadingprefixp
|
lift $ optional orgheadingprefixp
|
||||||
d <- datep
|
date <- datep
|
||||||
desc <- strip <$> lift restofline
|
desc <- T.strip <$> lift descriptionp
|
||||||
|
(comment, tags) <- lift transactioncommentp
|
||||||
lift $ traceparse' "datelinep"
|
lift $ traceparse' "datelinep"
|
||||||
return (d, T.pack desc)
|
return (date, desc, comment, tags)
|
||||||
|
|
||||||
-- | Zero or more empty lines or hash/semicolon comment lines
|
-- | Zero or more empty lines or hash/semicolon comment lines
|
||||||
-- or org headlines which do not start a new day.
|
-- or org headlines which do not start a new day.
|
||||||
@ -172,10 +173,16 @@ entryp = do
|
|||||||
lift $ optional $ choice [orgheadingprefixp, skipNonNewlineSpaces1]
|
lift $ optional $ choice [orgheadingprefixp, skipNonNewlineSpaces1]
|
||||||
a <- modifiedaccountnamep
|
a <- modifiedaccountnamep
|
||||||
lift skipNonNewlineSpaces
|
lift skipNonNewlineSpaces
|
||||||
hours <-
|
(hours, comment, tags) <-
|
||||||
try (lift followingcommentp >> return 0)
|
try (do
|
||||||
<|> (lift durationp <*
|
(c,ts) <- lift transactioncommentp -- or postingp, but let's not bother supporting date:/date2:
|
||||||
(try (lift followingcommentp) <|> (newline >> return "")))
|
return (0, c, ts)
|
||||||
|
)
|
||||||
|
<|> (do
|
||||||
|
h <- lift durationp
|
||||||
|
(c,ts) <- try (lift transactioncommentp) <|> (newline >> return ("",[]))
|
||||||
|
return (h,c,ts)
|
||||||
|
)
|
||||||
mcs <- getDefaultCommodityAndStyle
|
mcs <- getDefaultCommodityAndStyle
|
||||||
let
|
let
|
||||||
(c,s) = case mcs of
|
(c,s) = case mcs of
|
||||||
@ -188,6 +195,8 @@ entryp = do
|
|||||||
nullposting{paccount=a
|
nullposting{paccount=a
|
||||||
,pamount=mixedAmount $ nullamt{acommodity=c, aquantity=hours, astyle=s}
|
,pamount=mixedAmount $ nullamt{acommodity=c, aquantity=hours, astyle=s}
|
||||||
,ptype=VirtualPosting
|
,ptype=VirtualPosting
|
||||||
|
,pcomment=comment
|
||||||
|
,ptags=tags
|
||||||
,ptransaction=Just t
|
,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
|
Optionally this can be followed on the same line by
|
||||||
|
|
||||||
- a common **transaction description** for this day
|
- a **common description** for this day's transactions.
|
||||||
- a common **transaction comment** for this day, after a semicolon (`;`).
|
- a **common comment** for this day's transactions, following a semicolon (`;`).
|
||||||
|
|
||||||
After the date line are zero or more optionally-indented
|
After the date line are zero or more optionally-indented time transactions, consisting of:
|
||||||
time transaction lines, consisting of:
|
|
||||||
|
|
||||||
- an **account name** - any word or phrase, usually a
|
- an **account name** - any word or phrase, usually a hledger-style [account name](#account-names).
|
||||||
hledger-style [account name](#account-names).
|
- **two or more spaces** - a field separator, required if there is an amount (as in journal format).
|
||||||
- **two or more spaces** - a field separator,
|
- a **timedot amount** - dots representing quarter hours, or a number representing hours, optionally with a unit suffix.
|
||||||
required if there is an amount (as in journal format).
|
- an **posting comment** for this transaction, following with semicolon.
|
||||||
- a **timedot amount** - dots representing quarter hours,
|
|
||||||
or a number representing hours.
|
|
||||||
- an optional **comment** beginning with semicolon. This is ignored.
|
|
||||||
|
|
||||||
In more detail, timedot amounts can be:
|
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
|
# 1. basic timedot entry
|
||||||
<
|
<
|
||||||
# comment
|
# file comment
|
||||||
|
; another file comment
|
||||||
|
|
||||||
; another comment
|
|
||||||
2020-01-01
|
2020-01-01
|
||||||
a:aa 1
|
a:aa 1
|
||||||
b:bb 2
|
b:bb 2
|
||||||
|
|
||||||
$ hledger -ftimedot:- print
|
$ hledger -ftimedot:- print
|
||||||
2020-01-01 *
|
2020-01-01 *
|
||||||
@ -35,3 +33,26 @@ $ hledger -ftimedot:- print --alias a=b
|
|||||||
(b:aa) 1.00
|
(b:aa) 1.00
|
||||||
|
|
||||||
>=0
|
>=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