ENH clean up types a bit

This commit is contained in:
Nathan Dwarshuis 2023-07-07 20:20:09 -04:00
parent 2946a8f9e2
commit 00346ff8ee
3 changed files with 68 additions and 64 deletions

View File

@ -280,49 +280,50 @@ let DatePat =
let TxOpts = let TxOpts =
{- Additional metadata to use when parsing a statement -} {- Additional metadata to use when parsing a statement -}
{ Type = \(re : Type) ->
{ toDate : { Type =
{- { toDate :
Column title for date {-
-} Column title for date
Text -}
, toAmount : Text
{- , toAmount :
Column title for amount {-
-} Column title for amount
Text -}
, toDesc : Text
{- , toDesc :
Column title for description {-
-} Column title for description
Text -}
, toOther : Text
{- , toOther :
Titles of other columns to include; these will be available in {-
a map for use in downstream processing (see 'Field') Titles of other columns to include; these will be available in
-} a map for use in downstream processing (see 'Field')
List Text -}
, toDateFmt : List Text
{- , toDateFmt :
Format of the date field as specified in the {-
Data.Time.Format.formattime Haskell function. Format of the date field as specified in the
-} Data.Time.Format.formattime Haskell function.
Text -}
, toAmountFmt : Text
{- Format of the amount field. Must include three fields for the , toAmountFmt :
sign, numerator, and denominator of the amount. {- Format of the amount field. Must include three fields for the
-} sign, numerator, and denominator of the amount.
Text -}
re
}
, default =
{ toDate = "Date"
, toAmount = "Amount"
, toDesc = "Description"
, toOther = [] : List Text
, toDateFmt = "%0m/%0d/%Y"
, toAmountFmt = "([-+])?([0-9]+)\\.?([0-9]+)?"
} }
, default =
{ toDate = "Date"
, toAmount = "Amount"
, toDesc = "Description"
, toOther = [] : List Text
, toDateFmt = "%0m/%0d/%Y"
, toAmountFmt = "([-+])?([0-9]+)\\.?([0-9]+)?"
} }
}
let Field = let Field =
{- {-
@ -679,7 +680,10 @@ let Amount =
-} -}
\(w : Type) -> \(w : Type) ->
\(v : Type) -> \(v : Type) ->
{ amtWhen : w, amtValue : v, amtDesc : Text, amtPriority : Integer } { Type =
{ amtWhen : w, amtValue : v, amtDesc : Text, amtPriority : Integer }
, default.amtPriority = +0
}
let TransferType = let TransferType =
{- {-
@ -711,7 +715,7 @@ let Transfer =
{ transFrom : a { transFrom : a
, transTo : a , transTo : a
, transCurrency : c , transCurrency : c
, transAmounts : List (Amount w v) , transAmounts : List (Amount w v).Type
} }
let TaggedAcnt = let TaggedAcnt =
@ -748,7 +752,7 @@ let Statement =
file delimiter as a numeric char, usually either tab (9) or comma (44) file delimiter as a numeric char, usually either tab (9) or comma (44)
-} -}
: Natural : Natural
, stmtTxOpts : TxOpts.Type , stmtTxOpts : (TxOpts Text).Type
, stmtSkipLines , stmtSkipLines
{- {-
how many lines to skip before parsing statement how many lines to skip before parsing statement
@ -771,7 +775,7 @@ let Allocation =
\(w : Type) -> \(w : Type) ->
\(v : Type) -> \(v : Type) ->
{ alloTo : TaggedAcnt.Type { alloTo : TaggedAcnt.Type
, alloAmts : List (Amount w v) , alloAmts : List (Amount w v).Type
, alloCur : , alloCur :
{-TODO allow exchanges here-} {-TODO allow exchanges here-}
CurID CurID

View File

@ -9,7 +9,7 @@ let nullEntry =
\(v : T.EntryNumGetter) -> \(v : T.EntryNumGetter) ->
T.FromEntryGetter::{ eAcnt = a, eValue = v } T.FromEntryGetter::{ eAcnt = a, eValue = v }
let nullOpts = T.TxOpts::{=} let nullOpts = (T.TxOpts Text)::{=}
let nullVal = T.ValMatcher::{=} let nullVal = T.ValMatcher::{=}

View File

@ -19,7 +19,6 @@ import Language.Haskell.TH.Syntax (Lift)
import RIO import RIO
import qualified RIO.Map as M import qualified RIO.Map as M
import qualified RIO.Text as T import qualified RIO.Text as T
-- import RIO.Time
import Text.Regex.TDFA import Text.Regex.TDFA
makeHaskellTypesWith makeHaskellTypesWith
@ -49,12 +48,18 @@ makeHaskellTypesWith
, SingleConstructor "ModPat" "ModPat" "(./dhall/Types.dhall).ModPat.Type" , SingleConstructor "ModPat" "ModPat" "(./dhall/Types.dhall).ModPat.Type"
, SingleConstructor "CronPat" "CronPat" "(./dhall/Types.dhall).CronPat.Type" , SingleConstructor "CronPat" "CronPat" "(./dhall/Types.dhall).CronPat.Type"
, SingleConstructor "ValMatcher" "ValMatcher" "(./dhall/Types.dhall).ValMatcher.Type" , SingleConstructor "ValMatcher" "ValMatcher" "(./dhall/Types.dhall).ValMatcher.Type"
, SingleConstructor "Amount" "Amount" "(./dhall/Types.dhall).Amount" , SingleConstructor
"Amount"
"Amount"
"\\(w : Type) -> \\(v : Type) -> ((./dhall/Types.dhall).Amount w v).Type"
, SingleConstructor
"TxOpts"
"TxOpts"
"\\(re : Type) -> ((./dhall/Types.dhall).TxOpts re).Type"
, SingleConstructor "AcntSet" "AcntSet" "(./dhall/Types.dhall).AcntSet.Type" , SingleConstructor "AcntSet" "AcntSet" "(./dhall/Types.dhall).AcntSet.Type"
, SingleConstructor "TransferMatcher" "TransferMatcher" "(./dhall/Types.dhall).TransferMatcher.Type" , SingleConstructor "TransferMatcher" "TransferMatcher" "(./dhall/Types.dhall).TransferMatcher.Type"
, SingleConstructor "ShadowTransfer" "ShadowTransfer" "(./dhall/Types.dhall).ShadowTransfer" , SingleConstructor "ShadowTransfer" "ShadowTransfer" "(./dhall/Types.dhall).ShadowTransfer"
, -- , SingleConstructor "Income" "Income" "(./dhall/Types.dhall).Income.Type" , SingleConstructor "Field" "Field" "(./dhall/Types.dhall).Field"
SingleConstructor "Field" "Field" "(./dhall/Types.dhall).Field"
, SingleConstructor "Entry" "Entry" "(./dhall/Types.dhall).Entry" , SingleConstructor "Entry" "Entry" "(./dhall/Types.dhall).Entry"
, SingleConstructor "PretaxValue" "PretaxValue" "(./dhall/Types.dhall).PretaxValue" , SingleConstructor "PretaxValue" "PretaxValue" "(./dhall/Types.dhall).PretaxValue"
, SingleConstructor "TaxBracket" "TaxBracket" "(./dhall/Types.dhall).TaxBracket" , SingleConstructor "TaxBracket" "TaxBracket" "(./dhall/Types.dhall).TaxBracket"
@ -64,11 +69,6 @@ makeHaskellTypesWith
, SingleConstructor "TransferValue" "TransferValue" "(./dhall/Types.dhall).TransferValue.Type" , SingleConstructor "TransferValue" "TransferValue" "(./dhall/Types.dhall).TransferValue.Type"
, SingleConstructor "Period" "Period" "(./dhall/Types.dhall).Period" , SingleConstructor "Period" "Period" "(./dhall/Types.dhall).Period"
, SingleConstructor "HourlyPeriod" "HourlyPeriod" "(./dhall/Types.dhall).HourlyPeriod" , SingleConstructor "HourlyPeriod" "HourlyPeriod" "(./dhall/Types.dhall).HourlyPeriod"
-- , SingleConstructor "ToTx" "ToTx" "(./dhall/Types.dhall).ToTx"
-- , SingleConstructor "FieldMatcher" "FieldMatcher" "(./dhall/Types.dhall).FieldMatcher_"
-- , SingleConstructor "Match" "Match" "(./dhall/Types.dhall).Match_"
-- , SingleConstructor "Budget" "Budget" "(./dhall/Types.dhall).Budget"
-- SingleConstructor "Transfer" "Transfer" "(./dhall/Types.dhall).Transfer"
] ]
deriveProduct deriveProduct
@ -443,15 +443,15 @@ deriving instance (Hashable a, Hashable v, Hashable t) => Hashable (Entry a v t)
deriving instance (Eq a, Eq v, Eq t) => Eq (Entry a v t) deriving instance (Eq a, Eq v, Eq t) => Eq (Entry a v t)
data TxOpts re = TxOpts deriving instance Eq a => Eq (TxOpts a)
{ toDate :: !T.Text
, toAmount :: !T.Text deriving instance Generic (TxOpts a)
, toDesc :: !T.Text
, toOther :: ![T.Text] deriving instance Hashable a => Hashable (TxOpts a)
, toDateFmt :: !T.Text
, toAmountFmt :: !re deriving instance FromDhall a => FromDhall (TxOpts a)
}
deriving (Eq, Generic, Hashable, Show, FromDhall) deriving instance Show a => Show (TxOpts a)
data Statement = Statement data Statement = Statement
{ stmtPaths :: ![FilePath] { stmtPaths :: ![FilePath]