-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Declarative command line parser using type-driven pattern matching. -- -- Declarative command line parser using type-driven pattern matching. @package lambda-options @version 0.9.1.0 module Text.LambdaOptions.Internal.Opaque data Opaque [Opaque] :: (Typeable a) => a -> Opaque type OpaqueCallback r = [Opaque] -> r module Text.LambdaOptions.Internal.Wrap class Wrap r f | f -> r wrap :: Wrap r f => f -> OpaqueCallback r instance GHC.Base.Monad m => Text.LambdaOptions.Internal.Wrap.Wrap (m b) (m b) instance (GHC.Base.Monad m, Data.Typeable.Internal.Typeable a, Text.LambdaOptions.Internal.Wrap.Wrap (m b) f) => Text.LambdaOptions.Internal.Wrap.Wrap (m b) (a -> f) module Text.LambdaOptions.Keyword -- | An option keyword, such as "--help" data Keyword Keyword :: [String] -> String -> String -> Keyword -- | All the aliases for this keyword. [kwNames] :: Keyword -> [String] -- | Text to describe the arguments to the option given by this keyword. [kwArgText] :: Keyword -> String -- | Text to describe the function of the option given by this keyword. [kwText] :: Keyword -> String -- | Convenience Keyword creation class. class ToKeyword a toKeyword :: ToKeyword a => a -> Keyword -- | Shorthand for toKeyword. kw :: (ToKeyword a) => a -> Keyword -- | Sets the kwArgText field in the keyword. Intended to be used -- infix: -- --
-- kw "--directory" `argText` "DIR" `text` "Write files to DIR." --argText :: Keyword -> String -> Keyword -- | Sets the kwText field in the keyword. Intended to be used -- infix. -- --
-- kw "--quiet" `text` "Suppress message display." --text :: Keyword -> String -> Keyword instance GHC.Classes.Ord Text.LambdaOptions.Keyword.Keyword instance GHC.Classes.Eq Text.LambdaOptions.Keyword.Keyword instance GHC.Show.Show Text.LambdaOptions.Keyword.Keyword instance Data.Data.Data Text.LambdaOptions.Keyword.Keyword instance Text.LambdaOptions.Keyword.ToKeyword Text.LambdaOptions.Keyword.Keyword instance Text.LambdaOptions.Keyword.ToKeyword GHC.Base.String instance Text.LambdaOptions.Keyword.ToKeyword [GHC.Base.String] instance Data.String.IsString Text.LambdaOptions.Keyword.Keyword module Text.LambdaOptions.Formatter -- | User configuration for formatting. data FormatConfig FormatConfig :: Int -> FormatConfig [fmtMaxWidth] :: FormatConfig -> Int -- |
-- FormatConfig { fmtMaxWidth = 80 }
--
defaultFormatConfig :: FormatConfig
-- | Formats the given string with the given configuration.
format :: FormatConfig -> String -> String
-- | Formats the given keywords with the given configuration.
formatKeywords :: FormatConfig -> [Keyword] -> String
instance GHC.Classes.Ord Text.LambdaOptions.Formatter.FormatConfig
instance GHC.Classes.Eq Text.LambdaOptions.Formatter.FormatConfig
instance GHC.Read.Read Text.LambdaOptions.Formatter.FormatConfig
instance GHC.Show.Show Text.LambdaOptions.Formatter.FormatConfig
module Text.LambdaOptions.Parseable
-- | Class describing parseable values. Much like the Read class.
class Parseable a
-- | Given a sequence of strings, parse returns Nothing and
-- the number of strings consumed if the parse failed. Otherwise,
-- parse returns Just the parsed value and the number of
-- strings consumed.
--
-- Element-wise, an entire string must be parsed in the sequence to be
-- considered a successful parse.
parse :: Parseable a => [String] -> (Maybe a, Int)
-- | Turns a parser of a single string into a parser suitable for a
-- Parseable instance.
--
-- Useful for implementing a Parseable for a type with a
-- Read instance by supplying readMaybe to this function.
--
-- Note: The string is not tokenized in any way before
-- being passed into the input parser.
simpleParse :: (String -> Maybe a) -> ([String] -> (Maybe a, Int))
-- | Repeatedly applies parse the given number of times,
-- accumulating the results.
--
-- Useful for implementing new parsers.
--
-- Example:
--
-- -- data Point = Point Float Float Float -- -- instance Parseable Point where -- parse strs = case repeatedParse 3 strs of -- (Just [x,y,z], n) -> (Just (Point x y z), n)` -- (Nothing, n) -> (Nothing, n) --repeatedParse :: (Parseable a) => Int -> [String] -> (Maybe [a], Int) instance Text.LambdaOptions.Parseable.Parseable GHC.Types.Word instance Text.LambdaOptions.Parseable.Parseable GHC.Types.Int instance Text.LambdaOptions.Parseable.Parseable GHC.Integer.Type.Integer instance Text.LambdaOptions.Parseable.Parseable GHC.Types.Char instance Text.LambdaOptions.Parseable.Parseable GHC.Base.String instance Text.LambdaOptions.Parseable.Parseable GHC.Types.Float instance Text.LambdaOptions.Parseable.Parseable a => Text.LambdaOptions.Parseable.Parseable (GHC.Base.Maybe a) instance Text.LambdaOptions.Parseable.Parseable () instance (Text.LambdaOptions.Parseable.Parseable a, Text.LambdaOptions.Parseable.Parseable b) => Text.LambdaOptions.Parseable.Parseable (a, b) instance (Text.LambdaOptions.Parseable.Parseable a, Text.LambdaOptions.Parseable.Parseable b, Text.LambdaOptions.Parseable.Parseable c) => Text.LambdaOptions.Parseable.Parseable (a, b, c) module Text.LambdaOptions.List -- | A simple wrapper over [a]. Used to avoid overlapping -- instances for Parseable [a] and Parseable String newtype List a List :: [a] -> List a [unList] :: List a -> [a] instance GHC.Classes.Ord a => GHC.Classes.Ord (Text.LambdaOptions.List.List a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.LambdaOptions.List.List a) instance GHC.Read.Read a => GHC.Read.Read (Text.LambdaOptions.List.List a) instance GHC.Show.Show a => GHC.Show.Show (Text.LambdaOptions.List.List a) instance Data.Data.Data a => Data.Data.Data (Text.LambdaOptions.List.List a) instance Text.LambdaOptions.Parseable.Parseable a => Text.LambdaOptions.Parseable.Parseable (Text.LambdaOptions.List.List a) module Text.LambdaOptions.Internal.OpaqueParser type OpaqueParser = [String] -> (Maybe Opaque, Int) class GetOpaqueParsers r f | f -> r getOpaqueParsers :: GetOpaqueParsers r f => Proxy f -> [(TypeRep, OpaqueParser)] instance (Text.LambdaOptions.Parseable.Parseable a, Data.Typeable.Internal.Typeable a, Text.LambdaOptions.Internal.OpaqueParser.GetOpaqueParsers r b) => Text.LambdaOptions.Internal.OpaqueParser.GetOpaqueParsers r (a -> b) instance GHC.Base.Monad m => Text.LambdaOptions.Internal.OpaqueParser.GetOpaqueParsers r (m r) module Text.LambdaOptions.Core -- | Tries to parse the supplied options against input arguments. If -- successful, parsed option callbacks are returned in Right. -- Otherwise an OptionsError is returned in Left. -- -- Example program: -- --
-- import System.Environment
-- import Text.LambdaOptions
--
--
-- options :: Options IO () ()
-- options = do
-- addOption (kw ["--help", "-h"] `text` "Display this help text.") $ do
-- putStrLn "Usage:"
-- putStrLn $ getHelpDescription options
-- addOption (kw "--user" `argText` "NAME" `text` "Prints name.") $ \name -> do
-- putStrLn $ "Name:" ++ name
-- addOption (kw "--user" `argText` "NAME AGE" `text` "Prints name and age.") $ \name age -> do
-- putStrLn $ "Name:" ++ name ++ " Age:" ++ show (age :: Int)
--
--
-- main :: IO ()
-- main = do
-- args <- getArgs
-- case runOptions options args of
-- Left (e @ ParseFailed{}) -> do
-- putStrLn $ parseFailedMessage e
-- putStrLn $ getHelpDescription options
-- Right actions -> sequence_ actions
--
--
-- -- >>> example.exe --user HaskellCurry 81 --user GraceHopper -- Name:HaskellCurry Age:81 -- Name:GraceHopper -- -- >>> example.exe -h -- Usage: -- -h, --help Display this help text. -- --user NAME Prints name. -- --user NAME AGE Prints name and age. -- -- >>> example.exe --user Pythagoras LXXV -- Unknown option at index 2: `LXXV' -- Usage: -- -h, --help Display this help text. -- --user NAME Prints name. -- --user NAME AGE Prints name and age. --runOptions :: (Monad m) => Options m a () -> [String] -> Either OptionsError [m a] -- | A monad for parsing options. data Options m a b -- | Contains information about what went wrong during an unsuccessful -- options parse. data OptionsError ParseFailed :: String -> Int -> Int -> OptionsError [parseFailedMessage] :: OptionsError -> String [parseFailedBeginArgsIndex] :: OptionsError -> Int [parseFailedEndArgsIndex] :: OptionsError -> Int -- | Describes the callback f to be called for a successfully -- parsed option. -- -- The function (or value) f can have any arity and ultimately -- returns a value with type Monad m => m a -- -- Each of the callback's arguments must have a type t which -- implements Parseable and Typeable. -- -- Think of this as the following constraint synonym: -- --
-- type OptionCallback m a f = (Monad m, f ~ (Parseable t*, Typeable t*) => t0 -> t1 -> ... -> tN -> m a) ---- -- Example callbacks: -- --
-- f0 = putStrLn "Option parsed!" :: IO () -- f1 = put :: String -> State String () -- f2 n = liftIO (print n) :: (MonadIO m) => Int -> m () -- f3 name year ratio = lift (print (name, year, ratio)) :: (MonadTrans m) => String -> Int -> Float -> m IO () -- f4 = return 7 :: Identity Int --type OptionCallback m a f = (Monad m, GetOpaqueParsers a f, Wrap (m a) f) -- | Adds the supplied option to the Options m a () context. -- -- If the keyword is matched and the types of the callback's parameters -- can successfully be parsed, the callback is called with the parsed -- arguments. addOption :: (OptionCallback m a f) => Keyword -> f -> Options m a () -- | Produces the help description given by the input options. getHelpDescription :: (Monad m) => Options m a () -> String -- | Produces the Keywords inserted into the input options. getKeywords :: (Monad m) => Options m a () -> [Keyword] instance GHC.Show.Show Text.LambdaOptions.Core.OptionsError instance Control.Monad.State.Class.MonadState (Text.LambdaOptions.Core.OptionsState m a) (Text.LambdaOptions.Core.Options m a) instance GHC.Base.Monad (Text.LambdaOptions.Core.Options m a) instance GHC.Base.Functor (Text.LambdaOptions.Core.Options m a) instance GHC.Base.Applicative (Text.LambdaOptions.Core.Options m a) module Text.LambdaOptions