From 2505c69f802faa49246465a2722a803813223fb5 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 3 Mar 2021 06:44:25 -0800 Subject: [PATCH] lib: transactionFile --- hledger-lib/Hledger/Data/Transaction.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index cf380a170..e839954dc 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -14,6 +14,7 @@ tags. {-# LANGUAGE Rank2Types #-} {-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE NamedFieldPuns #-} module Hledger.Data.Transaction ( -- * Transaction nulltransaction, @@ -55,6 +56,7 @@ module Hledger.Data.Transaction ( sourceFirstLine, showGenericSourcePos, annotateErrorWithTransaction, + transactionFile, -- * tests tests_Transaction ) @@ -628,6 +630,13 @@ transactionMapPostings f t@Transaction{tpostings=ps} = t{tpostings=map f ps} transactionMapPostingAmounts :: (Amount -> Amount) -> Transaction -> Transaction transactionMapPostingAmounts f = transactionMapPostings (postingTransformAmount (mapMixedAmount f)) +-- | The file path from which this transaction was parsed. +transactionFile :: Transaction -> FilePath +transactionFile Transaction{tsourcepos} = + case tsourcepos of + GenericSourcePos f _ _ -> f + JournalSourcePos f _ -> f + -- tests tests_Transaction :: TestTree