mirror of
https://github.com/simonmichael/hledger.git
synced 2025-01-02 15:23:44 +03:00
make most types instances of Data (and Typeable)
This allows them to be pretty-printed with pprint (from data-pprint) when debugging, and shouldn't have much impact otherwise.
This commit is contained in:
parent
8857366854
commit
22a8020296
@ -1,4 +1,4 @@
|
|||||||
{-# LANGUAGE DeriveDataTypeable #-}
|
{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}
|
||||||
{-|
|
{-|
|
||||||
|
|
||||||
Most data types are defined here to avoid import cycles.
|
Most data types are defined here to avoid import cycles.
|
||||||
@ -24,7 +24,7 @@ import Data.Data
|
|||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Data.Time.Calendar
|
import Data.Time.Calendar
|
||||||
import Data.Time.LocalTime
|
import Data.Time.LocalTime
|
||||||
import System.Time (ClockTime)
|
import System.Time (ClockTime(..))
|
||||||
|
|
||||||
|
|
||||||
type SmartDate = (String,String,String)
|
type SmartDate = (String,String,String)
|
||||||
@ -41,7 +41,7 @@ data Interval = NoInterval
|
|||||||
|
|
||||||
type AccountName = String
|
type AccountName = String
|
||||||
|
|
||||||
data Side = L | R deriving (Eq,Show,Read,Ord)
|
data Side = L | R deriving (Eq,Show,Read,Ord,Typeable,Data)
|
||||||
|
|
||||||
type Commodity = String
|
type Commodity = String
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ type Quantity = Double
|
|||||||
|
|
||||||
-- | An amount's price (none, per unit, or total) in another commodity.
|
-- | An amount's price (none, per unit, or total) in another commodity.
|
||||||
-- Note the price should be a positive number, although this is not enforced.
|
-- Note the price should be a positive number, although this is not enforced.
|
||||||
data Price = NoPrice | UnitPrice Amount | TotalPrice Amount deriving (Eq,Ord)
|
data Price = NoPrice | UnitPrice Amount | TotalPrice Amount deriving (Eq,Ord,Typeable,Data)
|
||||||
|
|
||||||
-- | Display style for an amount.
|
-- | Display style for an amount.
|
||||||
data AmountStyle = AmountStyle {
|
data AmountStyle = AmountStyle {
|
||||||
@ -59,19 +59,19 @@ data AmountStyle = AmountStyle {
|
|||||||
asdecimalpoint :: Char, -- ^ character used as decimal point
|
asdecimalpoint :: Char, -- ^ character used as decimal point
|
||||||
asseparator :: Char, -- ^ character used for separating digit groups (eg thousands)
|
asseparator :: Char, -- ^ character used for separating digit groups (eg thousands)
|
||||||
asseparatorpositions :: [Int] -- ^ positions of digit group separators, counting leftward from decimal point
|
asseparatorpositions :: [Int] -- ^ positions of digit group separators, counting leftward from decimal point
|
||||||
} deriving (Eq,Ord,Show,Read)
|
} deriving (Eq,Ord,Read,Show,Typeable,Data)
|
||||||
|
|
||||||
data Amount = Amount {
|
data Amount = Amount {
|
||||||
acommodity :: Commodity,
|
acommodity :: Commodity,
|
||||||
aquantity :: Quantity,
|
aquantity :: Quantity,
|
||||||
aprice :: Price, -- ^ the (fixed) price for this amount, if any
|
aprice :: Price, -- ^ the (fixed) price for this amount, if any
|
||||||
astyle :: AmountStyle
|
astyle :: AmountStyle
|
||||||
} deriving (Eq,Ord)
|
} deriving (Eq,Ord,Typeable,Data)
|
||||||
|
|
||||||
newtype MixedAmount = Mixed [Amount] deriving (Eq,Ord)
|
newtype MixedAmount = Mixed [Amount] deriving (Eq,Ord,Typeable,Data)
|
||||||
|
|
||||||
data PostingType = RegularPosting | VirtualPosting | BalancedVirtualPosting
|
data PostingType = RegularPosting | VirtualPosting | BalancedVirtualPosting
|
||||||
deriving (Eq,Show)
|
deriving (Eq,Show,Typeable,Data)
|
||||||
|
|
||||||
type Tag = (String, String) -- ^ A tag name and (possibly empty) value.
|
type Tag = (String, String) -- ^ A tag name and (possibly empty) value.
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ data Posting = Posting {
|
|||||||
pbalanceassertion :: Maybe MixedAmount, -- ^ optional: the expected balance in the account after this posting
|
pbalanceassertion :: Maybe MixedAmount, -- ^ optional: the expected balance in the account after this posting
|
||||||
ptransaction :: Maybe Transaction -- ^ this posting's parent transaction (co-recursive types).
|
ptransaction :: Maybe Transaction -- ^ this posting's parent transaction (co-recursive types).
|
||||||
-- Tying this knot gets tedious, Maybe makes it easier/optional.
|
-- Tying this knot gets tedious, Maybe makes it easier/optional.
|
||||||
}
|
} deriving (Typeable,Data)
|
||||||
|
|
||||||
-- The equality test for postings ignores the parent transaction's
|
-- The equality test for postings ignores the parent transaction's
|
||||||
-- identity, to avoid infinite loops.
|
-- identity, to avoid infinite loops.
|
||||||
@ -104,31 +104,31 @@ data Transaction = Transaction {
|
|||||||
ttags :: [Tag], -- ^ tag names and values, extracted from the comment
|
ttags :: [Tag], -- ^ tag names and values, extracted from the comment
|
||||||
tpostings :: [Posting], -- ^ this transaction's postings
|
tpostings :: [Posting], -- ^ this transaction's postings
|
||||||
tpreceding_comment_lines :: String -- ^ any comment lines immediately preceding this transaction
|
tpreceding_comment_lines :: String -- ^ any comment lines immediately preceding this transaction
|
||||||
} deriving (Eq)
|
} deriving (Eq,Typeable,Data)
|
||||||
|
|
||||||
data ModifierTransaction = ModifierTransaction {
|
data ModifierTransaction = ModifierTransaction {
|
||||||
mtvalueexpr :: String,
|
mtvalueexpr :: String,
|
||||||
mtpostings :: [Posting]
|
mtpostings :: [Posting]
|
||||||
} deriving (Eq)
|
} deriving (Eq,Typeable,Data)
|
||||||
|
|
||||||
data PeriodicTransaction = PeriodicTransaction {
|
data PeriodicTransaction = PeriodicTransaction {
|
||||||
ptperiodicexpr :: String,
|
ptperiodicexpr :: String,
|
||||||
ptpostings :: [Posting]
|
ptpostings :: [Posting]
|
||||||
} deriving (Eq)
|
} deriving (Eq,Typeable,Data)
|
||||||
|
|
||||||
data TimeLogCode = SetBalance | SetRequiredHours | In | Out | FinalOut deriving (Eq,Ord)
|
data TimeLogCode = SetBalance | SetRequiredHours | In | Out | FinalOut deriving (Eq,Ord,Typeable,Data)
|
||||||
|
|
||||||
data TimeLogEntry = TimeLogEntry {
|
data TimeLogEntry = TimeLogEntry {
|
||||||
tlcode :: TimeLogCode,
|
tlcode :: TimeLogCode,
|
||||||
tldatetime :: LocalTime,
|
tldatetime :: LocalTime,
|
||||||
tlcomment :: String
|
tlcomment :: String
|
||||||
} deriving (Eq,Ord)
|
} deriving (Eq,Ord,Typeable,Data)
|
||||||
|
|
||||||
data HistoricalPrice = HistoricalPrice {
|
data HistoricalPrice = HistoricalPrice {
|
||||||
hdate :: Day,
|
hdate :: Day,
|
||||||
hcommodity :: Commodity,
|
hcommodity :: Commodity,
|
||||||
hamount :: Amount
|
hamount :: Amount
|
||||||
} deriving (Eq) -- & Show (in Amount.hs)
|
} deriving (Eq,Typeable,Data) -- & Show (in Amount.hs)
|
||||||
|
|
||||||
type Year = Integer
|
type Year = Integer
|
||||||
|
|
||||||
@ -143,7 +143,10 @@ data JournalContext = Ctx {
|
|||||||
-- specified with "account" directive(s). Concatenated, these
|
-- specified with "account" directive(s). Concatenated, these
|
||||||
-- are the account prefix prepended to parsed account names.
|
-- are the account prefix prepended to parsed account names.
|
||||||
, ctxAliases :: ![(AccountName,AccountName)] -- ^ the current list of account name aliases in effect
|
, ctxAliases :: ![(AccountName,AccountName)] -- ^ the current list of account name aliases in effect
|
||||||
} deriving (Read, Show, Eq)
|
} deriving (Read, Show, Eq, Data, Typeable)
|
||||||
|
|
||||||
|
deriving instance Data (ClockTime)
|
||||||
|
deriving instance Typeable (ClockTime)
|
||||||
|
|
||||||
data Journal = Journal {
|
data Journal = Journal {
|
||||||
jmodifiertxns :: [ModifierTransaction],
|
jmodifiertxns :: [ModifierTransaction],
|
||||||
@ -159,7 +162,7 @@ data Journal = Journal {
|
|||||||
-- order encountered (XXX reversed, cf journalAddFile).
|
-- order encountered (XXX reversed, cf journalAddFile).
|
||||||
filereadtime :: ClockTime, -- ^ when this journal was last read from its file(s)
|
filereadtime :: ClockTime, -- ^ when this journal was last read from its file(s)
|
||||||
jcommoditystyles :: M.Map Commodity AmountStyle -- ^ how to display amounts in each commodity
|
jcommoditystyles :: M.Map Commodity AmountStyle -- ^ how to display amounts in each commodity
|
||||||
} deriving (Eq, Typeable)
|
} deriving (Eq, Typeable, Data)
|
||||||
|
|
||||||
-- | A JournalUpdate is some transformation of a Journal. It can do I/O or
|
-- | A JournalUpdate is some transformation of a Journal. It can do I/O or
|
||||||
-- raise an error.
|
-- raise an error.
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
{-# LANGUAGE DeriveDataTypeable #-}
|
||||||
{-|
|
{-|
|
||||||
|
|
||||||
A general query system for matching things (accounts, postings,
|
A general query system for matching things (accounts, postings,
|
||||||
@ -32,6 +33,7 @@ module Hledger.Query (
|
|||||||
tests_Hledger_Query
|
tests_Hledger_Query
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
import Data.Data
|
||||||
import Data.Either
|
import Data.Either
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
@ -70,7 +72,7 @@ data Query = Any -- ^ always match
|
|||||||
| Depth Int -- ^ match if account depth is less than or equal to this value
|
| Depth Int -- ^ match if account depth is less than or equal to this value
|
||||||
| Tag String (Maybe String) -- ^ match if a tag with this exact name, and with value
|
| Tag String (Maybe String) -- ^ match if a tag with this exact name, and with value
|
||||||
-- matching the regexp if provided, exists
|
-- matching the regexp if provided, exists
|
||||||
deriving (Eq)
|
deriving (Eq,Data,Typeable)
|
||||||
|
|
||||||
-- custom Show implementation to show strings more accurately, eg for debugging regexps
|
-- custom Show implementation to show strings more accurately, eg for debugging regexps
|
||||||
instance Show Query where
|
instance Show Query where
|
||||||
@ -97,7 +99,7 @@ data QueryOpt = QueryOptInAcctOnly AccountName -- ^ show an account register fo
|
|||||||
| QueryOptInAcct AccountName -- ^ as above but include sub-accounts in the account register
|
| QueryOptInAcct AccountName -- ^ as above but include sub-accounts in the account register
|
||||||
-- | QueryOptCostBasis -- ^ show amounts converted to cost where possible
|
-- | QueryOptCostBasis -- ^ show amounts converted to cost where possible
|
||||||
-- | QueryOptDate2 -- ^ show secondary dates instead of primary dates
|
-- | QueryOptDate2 -- ^ show secondary dates instead of primary dates
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq, Data, Typeable)
|
||||||
|
|
||||||
-- parsing
|
-- parsing
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user