Skip to content

Commit

Permalink
Common.hs: implement wordReader using Parsec
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Aug 14, 2024
1 parent 62973d5 commit 55f7f57
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import qualified Data.Text as Text
import Data.Time.Clock (UTCTime)
import Data.Time.Format (defaultTimeLocale, parseTimeOrError)
import Data.Word
import GHC.Natural (Natural, naturalToWordMaybe)
import GHC.Natural (Natural)
import Network.Socket (PortNumber)
import Options.Applicative hiding (help, str)
import qualified Options.Applicative as Opt
Expand Down Expand Up @@ -3189,14 +3189,14 @@ pMaxTransactionSize =
-- to avoid the overflow issues of 'Opt.auto' described in https://github.com/IntersectMBO/cardano-cli/issues/860.
wordReader :: forall a. (Typeable a, Integral a, Bits a) => ReadM a
wordReader =
Opt.eitherReader parser
readerFromParsecParser parsecParser
where
parser s =
case readMaybe s >>= naturalToWordMaybe >>= toIntegralSized of
Nothing ->
Left $ "Cannot parse " <> s <> " as a " <> typeName
Just a ->
Right a
parsecParser :: Parsec.Parser a
parsecParser = do
i <- decimal
case toIntegralSized i of
Nothing -> fail $ "Cannot parse " <> show i <> " as a " <> typeName
Just n -> return n
typeName = show $ typeRep (Proxy @a)

pMaxBlockHeaderSize :: Parser Word16
Expand Down

0 comments on commit 55f7f57

Please sign in to comment.