From 1116261f5abf58c1cf1f39cd310b2aecffaa5cdc Mon Sep 17 00:00:00 2001 From: Alex Chen Date: Sat, 26 May 2018 22:54:31 -0600 Subject: [PATCH] lib: simplify `fromRawNumber` --- hledger-lib/Hledger/Read/Common.hs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 7cd7271cb..9a7eec1ba 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -691,21 +691,25 @@ fromRawNumber fromRawNumber raw mExp = case raw of NoSeparators digitGrp mDecimals -> - let decimalGrp = maybe mempty snd mDecimals + let mDecPt = fmap fst mDecimals + decimalGrp = maybe mempty snd mDecimals + (quantity, precision) = maybe id applyExp mExp $ toQuantity digitGrp decimalGrp - in Right (quantity, precision, fmap fst mDecimals, Nothing) + in Right (quantity, precision, mDecPt, Nothing) - WithSeparators digitSep digitGrps mDecimals -> do - let decimalGrp = maybe mempty snd mDecimals - digitGroupStyle = DigitGroups digitSep (groupSizes digitGrps) + WithSeparators digitSep digitGrps mDecimals -> case mExp of + Nothing -> + let mDecPt = fmap fst mDecimals + decimalGrp = maybe mempty snd mDecimals + digitGroupStyle = DigitGroups digitSep (groupSizes digitGrps) - let errMsg = "mixing digit separators with exponents is not allowed" - (quantity, precision) <- maybe Right (const $ const $ Left errMsg) mExp - $ toQuantity (mconcat digitGrps) decimalGrp + (quantity, precision) = toQuantity (mconcat digitGrps) decimalGrp - Right (quantity, precision, fmap fst mDecimals, Just digitGroupStyle) + in Right (quantity, precision, mDecPt, Just digitGroupStyle) + Just _ -> + Left "mixing digit separators with exponents is not allowed" where -- Outputs digit group sizes from least significant to most significant