module System.Console.ArgParser.Parser
( ParamSpec (..)
, liftParam
, parsedBy
, andBy
, subParser
) where
import Control.Applicative
import System.Console.ArgParser.BaseType
class ParamSpec spec where
getParser :: spec res -> Parser res
getParamDescr :: spec res -> [ParamDescr]
liftParam :: ParamSpec spec => spec res -> ParserSpec res
liftParam param = ParserSpec
(getParamDescr param)
$ getParser param
instance ParamSpec ParserSpec where
getParser = getParserFun
getParamDescr = getParserParams
infixl 1 `andBy`
andBy
:: ParamSpec spec
=> ParserSpec (a -> b)
-> spec a
-> ParserSpec b
andBy parser param = parser <*> liftParam param
infixl 1 `parsedBy`
parsedBy
:: ParamSpec spec
=> (a -> b)
-> spec a
-> ParserSpec b
parsedBy constr firstarg = constr <$> liftParam firstarg
infixr 3 `subParser`
subParser
:: ParamSpec spec
=> (a -> b)
-> spec a
-> ParserSpec b
subParser = parsedBy