PyF-0.9.0.2: Quasiquotations for a python like interpolated string formater

Safe HaskellNone
LanguageHaskell2010

PyF.Internal.PythonSyntax

Description

This module provides a parser for python format string mini language.

Synopsis

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))]

data Item Source #

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

Instances
Show Item Source # 
Instance details

Defined in PyF.Internal.PythonSyntax

Methods

showsPrec :: Int -> Item -> ShowS #

show :: Item -> String #

showList :: [Item] -> ShowS #

data FormatMode Source #

A Formatter, listing padding, format and and grouping char

Instances
Show FormatMode Source # 
Instance details

Defined in PyF.Internal.PythonSyntax

data Padding Source #

Padding, containing the padding width, the padding char and the alignement mode

Instances
Show Padding Source # 
Instance details

Defined in PyF.Internal.PythonSyntax

data Precision Source #

Floating point precision

Instances
Show Precision Source # 
Instance details

Defined in PyF.Internal.PythonSyntax

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 e

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: FixedF or ExponentialF depending on the number magnitude

GeneralCapsF Precision AlternateForm SignMode

Same as GeneralF but with upper case E and infinite / NaN

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 # 
Instance details

Defined in PyF.Internal.PythonSyntax

data AlternateForm Source #

If the formatter use its alternate form

Constructors

AlternateForm 
NormalForm 

pattern DefaultFormatMode :: FormatMode Source #

Default formating mode, no padding, default precision, no grouping, no sign handling

data ExprOrValue t Source #

Represents a value of type t or an Haskell expression supposed to represents that value

Constructors

Value t 
HaskellExpr Exp 
Instances
Show t => Show (ExprOrValue t) Source # 
Instance details

Defined in PyF.Internal.PythonSyntax