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 19, 2024
1 parent b18cfad commit d3abc03
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 @@ -45,7 +45,7 @@ import Data.Time.Clock (UTCTime)
import Data.Time.Format (defaultTimeLocale, parseTimeOrError)
import Data.Word
import GHC.Exts (IsList (..))
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 @@ -3188,14 +3188,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 d3abc03

Please sign in to comment.