Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
TemplateHaskell functions for creating commands
Synopsis
- makeCommand :: Name -> [HelpUpdate] -> ExpQ
- makeCommandWith :: ParserConfiguration -> Name -> [HelpUpdate] -> ExpQ
- makeParser :: Name -> ExpQ
- data ParserConfiguration = ParserConfiguration {
- makeCommandName :: Text -> Text
- makeFieldType :: Text -> Maybe Text -> Text
- defaultParserConfiguration :: ParserConfiguration
- makeParserWith :: ParserConfiguration -> Bool -> Name -> [HelpUpdate] -> ExpQ
- makeSingleConstructor :: ParserConfiguration -> Bool -> Name -> [HelpUpdate] -> Con -> ExpQ
- addToRegistry :: [ExpQ] -> ExpQ
- funOf :: ExpQ -> ExpQ
- makeConstructorParser :: ParserConfiguration -> Bool -> Name -> Con -> Help -> ExpQ
- makeConstructorsParser :: ParserConfiguration -> Name -> [Con] -> Help -> ExpQ
- applyParser :: ParserConfiguration -> Bool -> Bool -> Name -> [Int] -> ExpQ
- typesOf :: Con -> Q [Type]
- fieldsOf :: Con -> Q [(Maybe Name, Type)]
- nameOf :: Con -> Q Name
- indexConstructorTypes :: [(Maybe Name, Type)] -> [(Maybe Name, Type)] -> Q [Int]
- makeFieldParser :: ParserConfiguration -> Name -> Maybe Name -> Type -> ExpQ
- makeNoDefaultValues :: ParserConfiguration -> Name -> Maybe Name -> Type -> ExpQ
- fieldNameTypeT :: ParserConfiguration -> Name -> Maybe Name -> Q Type
- append :: ExpQ -> ExpQ -> ExpQ
- appOf :: Text -> ExpQ -> ExpQ -> ExpQ
- displayType :: Type -> Text
- getTypeName :: Type -> Name
Documentation
makeCommand :: Name -> [HelpUpdate] -> ExpQ Source #
Make a command parser for a given data type - the data type name is used to get the command name to parse - each alternative in the data type defines an alternative parser
Usage: $(makeCommand ''MyDataType [shortDescription "copy a file"]) <: otherParsers
The type of the resulting parser is Parser "dataType" MyDataType
makeCommandWith :: ParserConfiguration -> Name -> [HelpUpdate] -> ExpQ Source #
Make a command parser with some specific parser options
makeParser :: Name -> ExpQ Source #
Make a Parser for a given data type, without using the data type as a command name
data ParserConfiguration Source #
Options for creating a command parser
ParserConfiguration | |
|
defaultParserConfiguration :: ParserConfiguration Source #
Default parser configuration
if the data type is mypackage.DataType { dataTypeFieldName :: FieldType }
then
- makeCommandName -> "type"
- makeFieldType -> "fieldName"
makeParserWith :: ParserConfiguration -> Bool -> Name -> [HelpUpdate] -> ExpQ Source #
Main TemplateHaskell function for creating a command parser
makeSingleConstructor :: ParserConfiguration -> Bool -> Name -> [HelpUpdate] -> Con -> ExpQ Source #
Make a parser for a single constructor, either a newtype with or without a field name or a regular data constructor
addToRegistry :: [ExpQ] -> ExpQ Source #
Add a list of parser functions to the registry
funOf :: ExpQ -> ExpQ Source #
Take an expression representing a function and apply fun
in front, in order
to add it to a registry
makeConstructorParser :: ParserConfiguration -> Bool -> Name -> Con -> Help -> ExpQ Source #
makeConstructorsParser :: ParserConfiguration -> Name -> [Con] -> Help -> ExpQ Source #
Make a Parser for a several Constructors, where each field of each the constructor is parsed separately and an alternative is taken between all the parsers (os: FieldConfiguration) (p0::Parser fieldName1 Text) (p1::Parser fieldName1 Bool) (p2::Parser fieldName2 Bool) -> (Constructor1 $ coerce p0 * coerce p1) | (Constructor2 $ coerce p1 * coerce p3)
applyParser :: ParserConfiguration -> Bool -> Bool -> Name -> [Int] -> ExpQ Source #
indexConstructorTypes :: [(Maybe Name, Type)] -> [(Maybe Name, Type)] -> Q [Int] Source #
Given the list of all possible fields and their types, across all the alternatives of an ADT, return the indices for a specific subset
makeFieldParser :: ParserConfiguration -> Name -> Maybe Name -> Type -> ExpQ Source #
Make a Parser for a given field
makeNoDefaultValues :: ParserConfiguration -> Name -> Maybe Name -> Type -> ExpQ Source #
Add no default values for a given field name to the registry
fieldNameTypeT :: ParserConfiguration -> Name -> Maybe Name -> Q Type Source #
Return the singleton string type for a given field parser
appOf :: Text -> ExpQ -> ExpQ -> ExpQ Source #
Apply an operator (described as Text) to 2 expressions
displayType :: Type -> Text Source #
Display a type name
getTypeName :: Type -> Name Source #
Return the name of a type in the most frequent cases