Safe Haskell | None |
---|---|
Language | Haskell2010 |
PyF.Internal.PythonSyntax
Description
This module provides a parser for python format string mini language.
Synopsis
- parsePythonFormatString :: [Extension] -> Parser [Item]
- parseGenericFormatString :: [Extension] -> (Char, Char) -> Parser [Item]
- data Item
- = Raw String
- | Replacement Exp (Maybe FormatMode)
- data FormatMode = FormatMode Padding TypeFormat (Maybe Char)
- data Padding
- data Precision
- data TypeFormat
- = DefaultF Precision SignMode
- | BinaryF AlternateForm SignMode
- | CharacterF
- | DecimalF SignMode
- | ExponentialF Precision AlternateForm SignMode
- | ExponentialCapsF Precision AlternateForm SignMode
- | FixedF Precision AlternateForm SignMode
- | FixedCapsF Precision AlternateForm SignMode
- | GeneralF Precision AlternateForm SignMode
- | GeneralCapsF Precision AlternateForm SignMode
- | OctalF AlternateForm SignMode
- | StringF Precision
- | HexF AlternateForm SignMode
- | HexCapsF AlternateForm SignMode
- | PercentF Precision AlternateForm SignMode
- data AlternateForm
- pattern DefaultFormatMode :: FormatMode
Documentation
parsePythonFormatString :: [Extension] -> Parser [Item] Source #
Parse a string, returns a list of raw string or replacement fields
>>>
import Text.Megaparsec
>>>
parse parsePythonFormatString "" "hello {1+1:>10.2f}"
Right [ Raw "hello ", Replacement "1+1" ( Just (FormatMode (Padding 10 (Just (Nothing,AnyAlign AlignRight))) (FixedF (Precision 2) NormalForm Minus) Nothing))]
A format string is composed of many chunks of raw string or replacement
Constructors
Raw String | A raw string |
Replacement Exp (Maybe FormatMode) | A replacement string, composed of an arbitrary Haskell expression followed by an optional formatter |
data FormatMode Source #
A Formatter, listing padding, format and and grouping char
Constructors
FormatMode Padding TypeFormat (Maybe Char) |
Instances
Show FormatMode Source # | |
Defined in PyF.Internal.PythonSyntax Methods showsPrec :: Int -> FormatMode -> ShowS # show :: FormatMode -> String # showList :: [FormatMode] -> ShowS # |
Padding, containing the padding width, the padding char and the alignement mode
Floating point precision
Constructors
PrecisionDefault | |
Precision Integer |
data TypeFormat Source #
All formating type
Constructors
DefaultF Precision SignMode | Default, depends on the infered type of the expression |
BinaryF AlternateForm SignMode | Binary, such as `0b0121` |
CharacterF | Character, will convert an integer to its character representation |
DecimalF SignMode | Decimal, base 10 integer formatting |
ExponentialF Precision AlternateForm SignMode | Exponential notation for floatting points |
ExponentialCapsF Precision AlternateForm SignMode | Exponential notation with capitalised |
FixedF Precision AlternateForm SignMode | Fixed number of digits floating point |
FixedCapsF Precision AlternateForm SignMode | Capitalized version of the previous |
GeneralF Precision AlternateForm SignMode | General formatting: |
GeneralCapsF Precision AlternateForm SignMode | Same as |
OctalF AlternateForm SignMode | Octal, such as 00245 |
StringF Precision | Simple string |
HexF AlternateForm SignMode | Hexadecimal, such as 0xaf3e |
HexCapsF AlternateForm SignMode | Hexadecimal with capitalized letters, such as 0XAF3E |
PercentF Precision AlternateForm SignMode | Percent representation |
Instances
Show TypeFormat Source # | |
Defined in PyF.Internal.PythonSyntax Methods showsPrec :: Int -> TypeFormat -> ShowS # show :: TypeFormat -> String # showList :: [TypeFormat] -> ShowS # |
data AlternateForm Source #
If the formatter use its alternate form
Constructors
AlternateForm | |
NormalForm |
Instances
Show AlternateForm Source # | |
Defined in PyF.Internal.PythonSyntax Methods showsPrec :: Int -> AlternateForm -> ShowS # show :: AlternateForm -> String # showList :: [AlternateForm] -> ShowS # |
pattern DefaultFormatMode :: FormatMode Source #
Default formating mode, no padding, default precision, no grouping, no sign handling