ginger2
Safe HaskellNone
LanguageHaskell2010

Language.Ginger.StringFormatting.Python

Description

Python-style string formatting. See https://docs.python.org/3/library/string.html#formatstrings for spec.

Synopsis

Running

formatList :: Text -> [(Maybe Text, FormatArg)] -> Either String Text Source #

Apply format string, passing arguments as a list of optional key / value pairs. All arguments can be addressed positionally; those that have a key that is a valid identifier can also be addressed by that.

data FormattingGroup Source #

Formatting group; this determines the interpretation of formatting types such as g, which will behave differently depending on the type of argument.

Instances

Instances details
Bounded FormattingGroup Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Enum FormattingGroup Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Show FormattingGroup Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Eq FormattingGroup Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Ord FormattingGroup Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

data FormatArg Source #

Formattable argument. We reduce potential inputs to a limited set of representations; it is the responsibility of the caller to convert whatever values they want to use as formatting args to this type.

Constructors

IntArg !Integer

Integer arguments

FloatArg !Double

Floating-point arguments

StringArg !Text

Any scalar argument that is best represented as a string

ListArg !(Vector FormatArg)

List argument; cannot be formatted directly, but can be accessed using index syntax ({0[0]})

DictArg !(Map Text FormatArg)

Dictionary argument; cannot be formatted directly, but can be accessed using index syntax ({0[key]}) or attribute syntax (0.key).

PolyArg

Polymorphic argument; may offer any of the available representations, allowing the formatter to pick the most appropriate one.

Fields

Parsing

parseFormat :: Text -> Either String [FormatItem] Source #

Parse a format string.

Rendering

renderFormat :: [FormatItem] -> [(Maybe Text, FormatArg)] -> Either String Text Source #

Render a format string against the given arguments.

renderFormatItem :: Integer -> Vector FormatArg -> Map Text FormatArg -> FormatItem -> Either String Text Source #

Render a single formatting item using the provided arguments.

AST

data FieldZeroCoercion Source #

Instances

Instances details
Bounded FieldZeroCoercion Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Enum FieldZeroCoercion Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Show FieldZeroCoercion Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Eq FieldZeroCoercion Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Ord FieldZeroCoercion Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

data FieldAlternateForm Source #

Constructors

NormalForm 
AlternateForm 

Instances

Instances details
Bounded FieldAlternateForm Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Enum FieldAlternateForm Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Show FieldAlternateForm Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Eq FieldAlternateForm Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Ord FieldAlternateForm Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

data FieldZeroPadding Source #

Constructors

NoZeroPadding 
ZeroPadding 

Instances

Instances details
Bounded FieldZeroPadding Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Enum FieldZeroPadding Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Show FieldZeroPadding Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Eq FieldZeroPadding Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Ord FieldZeroPadding Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

data FieldGrouping Source #

Instances

Instances details
Bounded FieldGrouping Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Enum FieldGrouping Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Show FieldGrouping Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Eq FieldGrouping Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Ord FieldGrouping Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

data FieldSign Source #

Constructors

SignNegative

Default: show sign only when negative

SignSpacePadded

Show sign if negative, add padding space if positive

SignAlways

Always show sign

data FieldType Source #

data FieldAlign Source #

data OrDefault a Source #

Constructors

Default 
Specific a 

Instances

Instances details
Functor OrDefault Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Methods

fmap :: (a -> b) -> OrDefault a -> OrDefault b #

(<$) :: a -> OrDefault b -> OrDefault a #

Show a => Show (OrDefault a) Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Eq a => Eq (OrDefault a) Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

Methods

(==) :: OrDefault a -> OrDefault a -> Bool #

(/=) :: OrDefault a -> OrDefault a -> Bool #

Ord a => Ord (OrDefault a) Source # 
Instance details

Defined in Language.Ginger.StringFormatting.Python

fromDefault :: a -> OrDefault a -> a Source #