registry-options-0.2.0.0: application options parsing
Safe HaskellSafe-Inferred
LanguageGHC2021

Data.Registry.Options.TH

Description

TemplateHaskell functions for creating commands

Synopsis

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

Constructors

ParserConfiguration 

Fields

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 #

Make a Parser for a single Constructor, where each field of the constructor is parsed separately (os: FieldConfiguration) (p0::Parser fieldName0 Text) (p1::Parser fieldName1 Bool) -> Constructor $ coerce p0 * coerce p1

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 #

Apply a constructor to parsers for each of its fields The resulting parser is a command parser Parser Command DataType for a command ConstructorName $ coerce p0 * coerce p1 ...

typesOf :: Con -> Q [Type] Source #

Get the types of all the fields of a constructor

fieldsOf :: Con -> Q [(Maybe Name, Type)] Source #

Get the types of all the fields of a constructor

nameOf :: Con -> Q Name Source #

Return the name of a constructor

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

append :: ExpQ -> ExpQ -> ExpQ Source #

Append an expression to a registry

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

Orphan instances

IsString Name Source # 
Instance details

Methods

fromString :: String -> Name #

Lift Help Source # 
Instance details

Methods

lift :: Quote m => Help -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => Help -> Code m Help #

Lift OptionDescription Source # 
Instance details

Methods

lift :: Quote m => OptionDescription -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => OptionDescription -> Code m OptionDescription #