From f31a65bcd1642b3f042bd906674f4064cfc9362c Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 2 Aug 2016 22:42:52 +0200 Subject: Inital work on option parsing --- src/Trivstream/Options/Utils.hs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/Trivstream/Options/Utils.hs (limited to 'src/Trivstream/Options/Utils.hs') diff --git a/src/Trivstream/Options/Utils.hs b/src/Trivstream/Options/Utils.hs new file mode 100644 index 0000000..30694d8 --- /dev/null +++ b/src/Trivstream/Options/Utils.hs @@ -0,0 +1,32 @@ +{-# LANGUAGE StandaloneDeriving #-} + +module Trivstream.Options.Utils + ( rCI + ) where + +import Options.Applicative + +import Data.Char +import Data.Maybe + +import Network.Socket + + +deriving instance Enum Family +deriving instance Bounded Family + + +rCI :: (Show a, Read a) => ReadM a +rCI = eitherReader rRep' + where + rRep' str = case mapMaybe readMaybe $ cases str of + [] -> Left $ "Could not parse `" ++ str ++ "'" + [x] -> Right x + xs -> Left $ "Ambiguous parse for `" ++ str ++ "': " ++ show xs + cases [] = [[]] + cases (c:cs) = [(c':cs') | c' <- [toLower c, c, toUpper c], cs' <- cases cs] + +rFamily :: ReadM Family +rFamily = undefined + where + families = filter isSupportedFamily [minBound..maxBound] -- cgit v1.2.3