Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides a parser for python format string mini language.
Synopsis
- parseGenericFormatString :: 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
- type Parser t = ParsecT String () (Reader ParsingContext) t
- data ParsingContext = ParsingContext {
- delimiters :: Maybe (Char, Char)
- enabledExtensions :: [Extension]
- data ExprOrValue t
- = Value t
- | HaskellExpr Exp
Documentation
parseGenericFormatString :: 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
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
Instances
Show FormatMode Source # | |
Defined in PyF.Internal.PythonSyntax 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
data TypeFormat Source #
All formatting type
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 showsPrec :: Int -> TypeFormat -> ShowS # show :: TypeFormat -> String # showList :: [TypeFormat] -> ShowS # |
data AlternateForm Source #
If the formatter use its alternate form
Instances
Show AlternateForm Source # | |
Defined in PyF.Internal.PythonSyntax showsPrec :: Int -> AlternateForm -> ShowS # show :: AlternateForm -> String # showList :: [AlternateForm] -> ShowS # |
pattern DefaultFormatMode :: FormatMode Source #
Default formatting mode, no padding, default precision, no grouping, no sign handling
data ParsingContext Source #
ParsingContext | |
|
Instances
Show ParsingContext Source # | |
Defined in PyF.Internal.PythonSyntax showsPrec :: Int -> ParsingContext -> ShowS # show :: ParsingContext -> String # showList :: [ParsingContext] -> ShowS # |
data ExprOrValue t Source #
Represents a value of type t
or an Haskell expression supposed to represents that value
Instances
Show t => Show (ExprOrValue t) Source # | |
Defined in PyF.Internal.PythonSyntax showsPrec :: Int -> ExprOrValue t -> ShowS # show :: ExprOrValue t -> String # showList :: [ExprOrValue t] -> ShowS # |