From ae3109a4baaf85c22552291f999b847bd2a279e5 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Sat, 25 Feb 2023 22:56:23 -0500 Subject: [PATCH] ENH kinda finalize shadow match rules --- dhall/common.dhall | 2 +- lib/Internal/Insert.hs | 2 +- lib/Internal/Types.hs | 5 +++-- lib/Internal/Utils.hs | 12 ++++++++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/dhall/common.dhall b/dhall/common.dhall index 00e3403..dfcc338 100644 --- a/dhall/common.dhall +++ b/dhall/common.dhall @@ -4,7 +4,7 @@ let List/map = let T = ./Types.dhall - sha256:381b63c7dc210ab55f61a4ff6198fcd5d3922ba587b19dbd8e0834f269f05e13 + sha256:3c6121710cb1d4ed84d9cb7ab6589fdcea79d1e4e07b33b22bd84e52506ea80f let nullSplit = \(a : T.SplitAcnt) -> diff --git a/lib/Internal/Insert.hs b/lib/Internal/Insert.hs index 5383f44..7872c53 100644 --- a/lib/Internal/Insert.hs +++ b/lib/Internal/Insert.hs @@ -442,7 +442,7 @@ checkAcntTypes ts i f = (go =<<) <$> lookupAccountType i where go t | t `L.elem` ts = Right $ f i - | otherwise = Left $ AccountError i t + | otherwise = Left $ AccountError i ts -------------------------------------------------------------------------------- -- statements diff --git a/lib/Internal/Types.hs b/lib/Internal/Types.hs index 21b9d45..203aa4b 100644 --- a/lib/Internal/Types.hs +++ b/lib/Internal/Types.hs @@ -12,6 +12,7 @@ import Dhall.TH import Language.Haskell.TH.Syntax (Lift) import RIO import qualified RIO.Map as M +import qualified RIO.NonEmpty as NE import qualified RIO.Text as T import RIO.Time import Text.Regex.TDFA @@ -53,7 +54,7 @@ makeHaskellTypesWith , SingleConstructor "Income" "Income" "(./dhall/Types.dhall).Income" , SingleConstructor "Budget" "Budget" "(./dhall/Types.dhall).Budget" , SingleConstructor "Transfer" "Transfer" "(./dhall/Types.dhall).Transfer" - , SingleConstructor "ShadowMatch" "ShadowMatch" "(./dhall/Types.dhall).ShadowMatch" + , SingleConstructor "ShadowMatch" "ShadowMatch" "(./dhall/Types.dhall).ShadowMatch.Type" , SingleConstructor "ShadowTransfer" "ShadowTransfer" "(./dhall/Types.dhall).ShadowTransfer" ] @@ -597,7 +598,7 @@ data PatternSuberr = ZeroLength | ZeroRepeats deriving (Show) data InsertError = RegexError !T.Text | MatchValPrecisionError !Natural !Natural - | AccountError !AcntID !AcntType + | AccountError !AcntID !(NE.NonEmpty AcntType) | InsertIOError !T.Text | ParseError !T.Text | ConversionError !T.Text diff --git a/lib/Internal/Utils.hs b/lib/Internal/Utils.hs index 6cacc74..97d5e21 100644 --- a/lib/Internal/Utils.hs +++ b/lib/Internal/Utils.hs @@ -43,6 +43,7 @@ import Internal.Types import RIO import qualified RIO.List as L import qualified RIO.Map as M +import qualified RIO.NonEmpty as NE import qualified RIO.Text as T import RIO.Time import Text.Regex.TDFA @@ -319,8 +320,15 @@ showError other = (: []) $ case other of where showGreg (Just g) = showGregorian_ g showGreg Nothing = "Inf" - -- TODO define - (AccountError _ _) -> undefined + (AccountError a ts) -> + T.unwords + [ "account type of key" + , singleQuote a + , "is not one of:" + , ts_ + ] + where + ts_ = T.intercalate ", " $ NE.toList $ fmap atName ts (PatternError s b r p) -> T.unwords [msg, "in pattern: ", pat] where pat =