dev: save the parse positions of PriceDirectives

This commit is contained in:
Simon Michael 2024-11-02 15:00:47 -10:00
parent 4d38c63ec8
commit c66e901d8b
3 changed files with 6 additions and 3 deletions

View File

@ -552,7 +552,8 @@ data TimeclockEntry = TimeclockEntry {
-- It declares two things: a historical exchange rate between two commodities,
-- and an amount display style for the second commodity.
data PriceDirective = PriceDirective {
pddate :: Day
pdsourcepos :: SourcePos
,pddate :: Day
,pdcommodity :: CommoditySymbol
,pdamount :: Amount
} deriving (Eq,Ord,Generic,Show)

View File

@ -119,7 +119,7 @@ amountPriceDirectiveFromCost d amt@Amount{acommodity=fromcomm, aquantity=n} = ca
where u = amountSetFullPrecisionUpTo Nothing $ divideAmount n t
_ -> Nothing
where
pd = PriceDirective{pddate = d, pdcommodity = fromcomm, pdamount = nullamt}
pd = PriceDirective{pdsourcepos=nullsourcepos, pddate=d, pdcommodity=fromcomm, pdamount=nullamt}
------------------------------------------------------------------------------
-- Converting things to value

View File

@ -671,6 +671,7 @@ defaultcommoditydirectivep = do
marketpricedirectivep :: JournalParser m PriceDirective
marketpricedirectivep = do
pos <- getSourcePos
char 'P' <?> "market price"
lift skipNonNewlineSpaces
date <- try (do {LocalTime d _ <- datetimep; return d}) <|> datep -- a time is ignored
@ -679,7 +680,7 @@ marketpricedirectivep = do
lift skipNonNewlineSpaces
price <- amountp
lift restofline
return $ PriceDirective date symbol price
return $ PriceDirective pos date symbol price
ignoredpricecommoditydirectivep :: JournalParser m ()
ignoredpricecommoditydirectivep = do
@ -1145,6 +1146,7 @@ tests_JournalReader = testGroup "JournalReader" [
,testCase "marketpricedirectivep" $ assertParseEq marketpricedirectivep
"P 2017/01/30 BTC $922.83\n"
PriceDirective{
pdsourcepos = nullsourcepos,
pddate = fromGregorian 2017 1 30,
pdcommodity = "BTC",
pdamount = usd 922.83