PyF-0.11.1.1: Quasiquotations for a python like interpolated string formatter
Safe HaskellSafe-Inferred
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 (HsExpr GhcPs, 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

data Padding Source #

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

data Precision Source #

Floating point precision

Instances

Instances details
Data Precision Source # 
Instance details

Defined in PyF.Internal.PythonSyntax

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Precision -> c Precision #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Precision #

toConstr :: Precision -> Constr #

dataTypeOf :: Precision -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Precision) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Precision) #

gmapT :: (forall b. Data b => b -> b) -> Precision -> Precision #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Precision -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Precision -> r #

gmapQ :: (forall d. Data d => d -> u) -> Precision -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Precision -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Precision -> m Precision #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Precision -> m Precision #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Precision -> m Precision #

data TypeFormat Source #

All formatting 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

Instances details
Data TypeFormat Source # 
Instance details

Defined in PyF.Internal.PythonSyntax

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> TypeFormat -> c TypeFormat #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c TypeFormat #

toConstr :: TypeFormat -> Constr #

dataTypeOf :: TypeFormat -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c TypeFormat) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c TypeFormat) #

gmapT :: (forall b. Data b => b -> b) -> TypeFormat -> TypeFormat #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TypeFormat -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TypeFormat -> r #

gmapQ :: (forall d. Data d => d -> u) -> TypeFormat -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> TypeFormat -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> TypeFormat -> m TypeFormat #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> TypeFormat -> m TypeFormat #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> TypeFormat -> m TypeFormat #

data AlternateForm Source #

If the formatter use its alternate form

Constructors

AlternateForm 
NormalForm 

Instances

Instances details
Data AlternateForm Source # 
Instance details

Defined in PyF.Internal.PythonSyntax

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> AlternateForm -> c AlternateForm #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c AlternateForm #

toConstr :: AlternateForm -> Constr #

dataTypeOf :: AlternateForm -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c AlternateForm) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c AlternateForm) #

gmapT :: (forall b. Data b => b -> b) -> AlternateForm -> AlternateForm #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> AlternateForm -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> AlternateForm -> r #

gmapQ :: (forall d. Data d => d -> u) -> AlternateForm -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> AlternateForm -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> AlternateForm -> m AlternateForm #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> AlternateForm -> m AlternateForm #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> AlternateForm -> m AlternateForm #

Show AlternateForm Source # 
Instance details

Defined in PyF.Internal.PythonSyntax

pattern DefaultFormatMode :: FormatMode Source #

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

data ParsingContext Source #

Instances

Instances details
Show ParsingContext Source # 
Instance details

Defined in PyF.Internal.PythonSyntax

data ExprOrValue t Source #

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

Constructors

Value t 
HaskellExpr (HsExpr GhcPs, Exp) 

Instances

Instances details
Data t => Data (ExprOrValue t) Source # 
Instance details

Defined in PyF.Internal.PythonSyntax

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ExprOrValue t -> c (ExprOrValue t) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (ExprOrValue t) #

toConstr :: ExprOrValue t -> Constr #

dataTypeOf :: ExprOrValue t -> DataType #

dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (ExprOrValue t)) #

dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (ExprOrValue t)) #

gmapT :: (forall b. Data b => b -> b) -> ExprOrValue t -> ExprOrValue t #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ExprOrValue t -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ExprOrValue t -> r #

gmapQ :: (forall d. Data d => d -> u) -> ExprOrValue t -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ExprOrValue t -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ExprOrValue t -> m (ExprOrValue t) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ExprOrValue t -> m (ExprOrValue t) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ExprOrValue t -> m (ExprOrValue t) #