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, -- It declares two things: a historical exchange rate between two commodities,
-- and an amount display style for the second commodity. -- and an amount display style for the second commodity.
data PriceDirective = PriceDirective { data PriceDirective = PriceDirective {
pddate :: Day pdsourcepos :: SourcePos
,pddate :: Day
,pdcommodity :: CommoditySymbol ,pdcommodity :: CommoditySymbol
,pdamount :: Amount ,pdamount :: Amount
} deriving (Eq,Ord,Generic,Show) } 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 where u = amountSetFullPrecisionUpTo Nothing $ divideAmount n t
_ -> Nothing _ -> Nothing
where where
pd = PriceDirective{pddate = d, pdcommodity = fromcomm, pdamount = nullamt} pd = PriceDirective{pdsourcepos=nullsourcepos, pddate=d, pdcommodity=fromcomm, pdamount=nullamt}
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- Converting things to value -- Converting things to value

View File

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