hpython-0.1: Syntax tree and DSL for Python

Copyright(C) CSIRO 2017-2018
LicenseBSD3
MaintainerIsaac Elliott <isaace71295@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Language.Python.DSL

Contents

Description

Passing [] to a function which expects a [Raw Line] is the same as passing [line_ pass_]

Synopsis

Documentation

(&) :: a -> (a -> b) -> b infixl 1 #

& is a reverse application operator. This provides notational convenience. Its precedence is one higher than that of the forward application operator $, which allows & to be nested in $.

>>> 5 & (+1) & show
"6"

Since: base-4.8.0.0

type Raw f = f '[] () Source #

Raw represents unvalidated, un-annotated terms.

data Module v a Source #

A Python Module, which is stored as a sequence of statements. A module corresponds to one source file of Python code.

Instances
HasStatements Module Source # 
Instance details

Defined in Language.Python.Syntax.Module

Methods

_Statements :: Traversal (Module v a) (Module [] a) (Statement v a) (Statement [] a) Source #

Functor (Module v) Source # 
Instance details

Defined in Language.Python.Syntax.Module

Methods

fmap :: (a -> b) -> Module v a -> Module v b #

(<$) :: a -> Module v b -> Module v a #

Foldable (Module v) Source # 
Instance details

Defined in Language.Python.Syntax.Module

Methods

fold :: Monoid m => Module v m -> m #

foldMap :: Monoid m => (a -> m) -> Module v a -> m #

foldr :: (a -> b -> b) -> b -> Module v a -> b #

foldr' :: (a -> b -> b) -> b -> Module v a -> b #

foldl :: (b -> a -> b) -> b -> Module v a -> b #

foldl' :: (b -> a -> b) -> b -> Module v a -> b #

foldr1 :: (a -> a -> a) -> Module v a -> a #

foldl1 :: (a -> a -> a) -> Module v a -> a #

toList :: Module v a -> [a] #

null :: Module v a -> Bool #

length :: Module v a -> Int #

elem :: Eq a => a -> Module v a -> Bool #

maximum :: Ord a => Module v a -> a #

minimum :: Ord a => Module v a -> a #

sum :: Num a => Module v a -> a #

product :: Num a => Module v a -> a #

Traversable (Module v) Source # 
Instance details

Defined in Language.Python.Syntax.Module

Methods

traverse :: Applicative f => (a -> f b) -> Module v a -> f (Module v b) #

sequenceA :: Applicative f => Module v (f a) -> f (Module v a) #

mapM :: Monad m => (a -> m b) -> Module v a -> m (Module v b) #

sequence :: Monad m => Module v (m a) -> m (Module v a) #

Eq a => Eq (Module v a) Source # 
Instance details

Defined in Language.Python.Syntax.Module

Methods

(==) :: Module v a -> Module v a -> Bool #

(/=) :: Module v a -> Module v a -> Bool #

Show a => Show (Module v a) Source # 
Instance details

Defined in Language.Python.Syntax.Module

Methods

showsPrec :: Int -> Module v a -> ShowS #

show :: Module v a -> String #

showList :: [Module v a] -> ShowS #

HasNewlines (Module v a) Source # 
Instance details

Defined in Language.Python.Optics.Newlines

Methods

_Newlines :: Traversal' (Module v a) Newline Source #

data Statement (v :: [*]) a Source #

Instances
Validated Statement Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

unvalidated :: Getter (Statement v a) (Statement [] a) Source #

HasTrailingNewline Statement Source # 
Instance details

Defined in Language.Python.Syntax.Statement

HasExprs Statement Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

_Exprs :: Traversal (Statement v a) (Statement [] a) (Expr v a) (Expr [] a) Source #

HasBlocks Statement Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

_Blocks :: Traversal (Statement v a) (Statement [] a) (Block v a) (Block [] a) Source #

HasWith Statement Source # 
Instance details

Defined in Language.Python.Optics

Methods

_With :: Prism (Statement v a) (Statement [] a) (With v a) (With [] a) Source #

HasClassDef Statement Source # 
Instance details

Defined in Language.Python.Optics

Methods

_ClassDef :: Prism (Statement v a) (Statement [] a) (ClassDef v a) (ClassDef [] a) Source #

HasFor Statement Source # 
Instance details

Defined in Language.Python.Optics

Methods

_For :: Prism (Statement v a) (Statement [] a) (For v a) (For [] a) Source #

HasTryFinally Statement Source # 
Instance details

Defined in Language.Python.Optics

Methods

_TryFinally :: Prism (Statement v a) (Statement [] a) (TryFinally v a) (TryFinally [] a) Source #

HasTryExcept Statement Source # 
Instance details

Defined in Language.Python.Optics

Methods

_TryExcept :: Prism (Statement v a) (Statement [] a) (TryExcept v a) (TryExcept [] a) Source #

HasIf Statement Source # 
Instance details

Defined in Language.Python.Optics

Methods

_If :: Prism (Statement v a) (Statement [] a) (If v a) (If [] a) Source #

HasWhile Statement Source # 
Instance details

Defined in Language.Python.Optics

Methods

_While :: Prism (Statement v a) (Statement [] a) (While v a) (While [] a) Source #

HasFundef Statement Source # 
Instance details

Defined in Language.Python.Optics

Methods

_Fundef :: Prism (Statement v a) (Statement [] a) (Fundef v a) (Fundef [] a) Source #

HasCompoundStatement Statement Source # 
Instance details

Defined in Language.Python.Optics

AsLine Statement Source # 
Instance details

Defined in Language.Python.DSL

Functor (Statement v) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

fmap :: (a -> b) -> Statement v a -> Statement v b #

(<$) :: a -> Statement v b -> Statement v a #

Foldable (Statement v) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

fold :: Monoid m => Statement v m -> m #

foldMap :: Monoid m => (a -> m) -> Statement v a -> m #

foldr :: (a -> b -> b) -> b -> Statement v a -> b #

foldr' :: (a -> b -> b) -> b -> Statement v a -> b #

foldl :: (b -> a -> b) -> b -> Statement v a -> b #

foldl' :: (b -> a -> b) -> b -> Statement v a -> b #

foldr1 :: (a -> a -> a) -> Statement v a -> a #

foldl1 :: (a -> a -> a) -> Statement v a -> a #

toList :: Statement v a -> [a] #

null :: Statement v a -> Bool #

length :: Statement v a -> Int #

elem :: Eq a => a -> Statement v a -> Bool #

maximum :: Ord a => Statement v a -> a #

minimum :: Ord a => Statement v a -> a #

sum :: Num a => Statement v a -> a #

product :: Num a => Statement v a -> a #

Traversable (Statement v) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

traverse :: Applicative f => (a -> f b) -> Statement v a -> f (Statement v b) #

sequenceA :: Applicative f => Statement v (f a) -> f (Statement v a) #

mapM :: Monad m => (a -> m b) -> Statement v a -> m (Statement v b) #

sequence :: Monad m => Statement v (m a) -> m (Statement v a) #

Eq a => Eq (Statement v a) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

(==) :: Statement v a -> Statement v a -> Bool #

(/=) :: Statement v a -> Statement v a -> Bool #

Show a => Show (Statement v a) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

showsPrec :: Int -> Statement v a -> ShowS #

show :: Statement v a -> String #

showList :: [Statement v a] -> ShowS #

Plated (Statement ([] :: [Type]) a) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

plate :: Traversal' (Statement [] a) (Statement [] a)

HasNewlines (Statement v a) Source # 
Instance details

Defined in Language.Python.Optics.Newlines

Methods

_Newlines :: Traversal' (Statement v a) Newline Source #

HasIndents (Statement ([] :: [Type]) a) a Source # 
Instance details

Defined in Language.Python.Optics.Indents

Methods

_Indents :: Traversal' (Statement [] a) (Indents a) Source #

data Expr (v :: [*]) a Source #

This large sum type covers all valid Python expressions

Instances
Validated Expr Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

unvalidated :: Getter (Expr v a) (Expr [] a) Source #

HasExprs Expr Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

_Exprs :: Traversal (Expr v a) (Expr [] a) (Expr v a) (Expr [] a) Source #

AsTupleItem Expr Source # 
Instance details

Defined in Language.Python.DSL

AsWithItem Expr Source # 
Instance details

Defined in Language.Python.DSL

AsExceptAs Expr Source # 
Instance details

Defined in Language.Python.DSL

AsSetItem Expr Source # 
Instance details

Defined in Language.Python.DSL

Methods

si_ :: Raw Expr -> Raw SetItem Source #

AsListItem Expr Source # 
Instance details

Defined in Language.Python.DSL

Methods

li_ :: Raw Expr -> Raw ListItem Source #

AsLine Expr Source # 
Instance details

Defined in Language.Python.DSL

Methods

line_ :: Raw Expr -> Raw Line Source #

DoubleStarSyntax Expr DictItem Source #

See dict_

Instance details

Defined in Language.Python.DSL

Methods

ss_ :: Raw Expr -> Raw DictItem Source #

DoubleStarSyntax Expr Arg Source #

See call_

Instance details

Defined in Language.Python.DSL

Methods

ss_ :: Raw Expr -> Raw Arg Source #

StarSyntax Expr TupleItem Source #

See tuple_

Instance details

Defined in Language.Python.DSL

Methods

s_ :: Raw Expr -> Raw TupleItem Source #

StarSyntax Expr SetItem Source #

See set_

Instance details

Defined in Language.Python.DSL

Methods

s_ :: Raw Expr -> Raw SetItem Source #

StarSyntax Expr ListItem Source #

See list_

Instance details

Defined in Language.Python.DSL

Methods

s_ :: Raw Expr -> Raw ListItem Source #

StarSyntax Expr Arg Source #

See call_

Instance details

Defined in Language.Python.DSL

Methods

s_ :: Raw Expr -> Raw Arg Source #

PositionalSyntax Arg Expr Source #

See call_

Instance details

Defined in Language.Python.DSL

Methods

p_ :: Raw Expr -> Raw Arg Source #

ColonSyntax Expr DictItem Source #

Constructing dictionary items

(.:) :: Raw SimpleStatement -> Raw SimpleStatement -> Raw DictItem
Instance details

Defined in Language.Python.DSL

Methods

(.:) :: Raw Expr -> Raw Expr -> Raw DictItem Source #

As Expr Ident ExceptAs Source #

See exceptAs_

Instance details

Defined in Language.Python.DSL

Methods

as_ :: Raw Expr -> Raw Ident -> Raw ExceptAs Source #

As Expr Expr WithItem Source #

See with_

Instance details

Defined in Language.Python.DSL

Methods

as_ :: Raw Expr -> Raw Expr -> Raw WithItem Source #

InSyntax Expr (Raw Expr) Source #
>>> var_ "a" `in_` var_ "b"
a in b
Instance details

Defined in Language.Python.DSL

Methods

in_ :: Raw Expr -> Raw Expr -> Raw Expr Source #

Functor (Expr v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fmap :: (a -> b) -> Expr v a -> Expr v b #

(<$) :: a -> Expr v b -> Expr v a #

Foldable (Expr v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fold :: Monoid m => Expr v m -> m #

foldMap :: Monoid m => (a -> m) -> Expr v a -> m #

foldr :: (a -> b -> b) -> b -> Expr v a -> b #

foldr' :: (a -> b -> b) -> b -> Expr v a -> b #

foldl :: (b -> a -> b) -> b -> Expr v a -> b #

foldl' :: (b -> a -> b) -> b -> Expr v a -> b #

foldr1 :: (a -> a -> a) -> Expr v a -> a #

foldl1 :: (a -> a -> a) -> Expr v a -> a #

toList :: Expr v a -> [a] #

null :: Expr v a -> Bool #

length :: Expr v a -> Int #

elem :: Eq a => a -> Expr v a -> Bool #

maximum :: Ord a => Expr v a -> a #

minimum :: Ord a => Expr v a -> a #

sum :: Num a => Expr v a -> a #

product :: Num a => Expr v a -> a #

Traversable (Expr v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

traverse :: Applicative f => (a -> f b) -> Expr v a -> f (Expr v b) #

sequenceA :: Applicative f => Expr v (f a) -> f (Expr v a) #

mapM :: Monad m => (a -> m b) -> Expr v a -> m (Expr v b) #

sequence :: Monad m => Expr v (m a) -> m (Expr v a) #

Eq a => Eq (Expr v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

(==) :: Expr v a -> Expr v a -> Bool #

(/=) :: Expr v a -> Expr v a -> Bool #

Num (Expr ([] :: [Type]) ()) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

(+) :: Expr [] () -> Expr [] () -> Expr [] () #

(-) :: Expr [] () -> Expr [] () -> Expr [] () #

(*) :: Expr [] () -> Expr [] () -> Expr [] () #

negate :: Expr [] () -> Expr [] () #

abs :: Expr [] () -> Expr [] () #

signum :: Expr [] () -> Expr [] () #

fromInteger :: Integer -> Expr [] () #

Show a => Show (Expr v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

showsPrec :: Int -> Expr v a -> ShowS #

show :: Expr v a -> String #

showList :: [Expr v a] -> ShowS #

IsString (Expr ([] :: [Type]) ()) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fromString :: String -> Expr [] () #

Generic (Expr v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Associated Types

type Rep (Expr v a) :: Type -> Type #

Methods

from :: Expr v a -> Rep (Expr v a) x #

to :: Rep (Expr v a) x -> Expr v a #

HasTrailingWhitespace (Expr v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

trailingWhitespace :: Lens' (Expr v a) [Whitespace] Source #

Plated (Expr ([] :: [Type]) a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

plate :: Traversal' (Expr [] a) (Expr [] a)

HasNewlines (Expr v a) Source # 
Instance details

Defined in Language.Python.Optics.Newlines

Methods

_Newlines :: Traversal' (Expr v a) Newline Source #

type Rep (Expr v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

type Rep (Expr v a) = D1 (MetaData "Expr" "Language.Python.Syntax.Expr" "hpython-0.1-inplace" False) ((((C1 (MetaCons "Unit" PrefixI True) (S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: (S1 (MetaSel (Just "_unsafeUnitWhitespaceInner") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]) :*: S1 (MetaSel (Just "_unsafeUnitWhitespaceRight") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))) :+: (C1 (MetaCons "Lambda" PrefixI True) ((S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeLambdaWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :*: (S1 (MetaSel (Just "_unsafeLambdaArgs") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (CommaSep (Param v a))) :*: (S1 (MetaSel (Just "_unsafeLambdaColon") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Colon) :*: S1 (MetaSel (Just "_unsafeLambdaBody") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Expr v a))))) :+: C1 (MetaCons "Yield" PrefixI True) (S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: (S1 (MetaSel (Just "_unsafeYieldWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]) :*: S1 (MetaSel (Just "_unsafeYieldValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (CommaSep (Expr v a))))))) :+: ((C1 (MetaCons "YieldFrom" PrefixI True) ((S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeYieldWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :*: (S1 (MetaSel (Just "_unsafeFromWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]) :*: S1 (MetaSel (Just "_unsafeYieldFromValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Expr v a)))) :+: C1 (MetaCons "Ternary" PrefixI True) ((S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: (S1 (MetaSel (Just "_unsafeTernaryValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Expr v a)) :*: S1 (MetaSel (Just "_unsafeTernaryWhitespaceIf") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))) :*: (S1 (MetaSel (Just "_unsafeTernaryCond") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Expr v a)) :*: (S1 (MetaSel (Just "_unsafeTernaryWhitespaceElse") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]) :*: S1 (MetaSel (Just "_unsafeTernaryElse") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Expr v a)))))) :+: (C1 (MetaCons "ListComp" PrefixI True) ((S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeListCompWhitespaceLeft") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :*: (S1 (MetaSel (Just "_unsafeListCompValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Comprehension Expr v a)) :*: S1 (MetaSel (Just "_unsafeListCompWhitespaceRight") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))) :+: C1 (MetaCons "List" PrefixI True) ((S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeListWhitespaceLeft") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :*: (S1 (MetaSel (Just "_unsafeListValues") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe (CommaSep1' (ListItem v a)))) :*: S1 (MetaSel (Just "_unsafeListWhitespaceRight") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])))))) :+: ((C1 (MetaCons "DictComp" PrefixI True) ((S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeDictCompWhitespaceLeft") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :*: (S1 (MetaSel (Just "_unsafeDictCompValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Comprehension DictItem v a)) :*: S1 (MetaSel (Just "_unsafeDictCompWhitespaceRight") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))) :+: (C1 (MetaCons "Dict" PrefixI True) ((S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeDictWhitespaceLeft") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :*: (S1 (MetaSel (Just "_unsafeDictValues") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe (CommaSep1' (DictItem v a)))) :*: S1 (MetaSel (Just "_unsafeDictWhitespaceRight") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))) :+: C1 (MetaCons "SetComp" PrefixI True) ((S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeSetCompWhitespaceLeft") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :*: (S1 (MetaSel (Just "_unsafeSetCompValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Comprehension SetItem v a)) :*: S1 (MetaSel (Just "_unsafeSetCompWhitespaceRight") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))))) :+: ((C1 (MetaCons "Set" PrefixI True) ((S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeSetWhitespaceLeft") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :*: (S1 (MetaSel (Just "_unsafeSetValues") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (CommaSep1' (SetItem v a))) :*: S1 (MetaSel (Just "_unsafeSetWhitespaceRight") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))) :+: C1 (MetaCons "Deref" PrefixI True) ((S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeDerefValueLeft") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Expr v a))) :*: (S1 (MetaSel (Just "_unsafeDerefWhitespaceLeft") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]) :*: S1 (MetaSel (Just "_unsafeDerefValueRight") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ident v a))))) :+: (C1 (MetaCons "Subscript" PrefixI True) ((S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeSubscriptValueLeft") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Expr v a))) :*: (S1 (MetaSel (Just "_unsafeSubscriptWhitespaceLeft") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]) :*: (S1 (MetaSel (Just "_unsafeSubscriptValueRight") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (CommaSep1' (Subscript v a))) :*: S1 (MetaSel (Just "_unsafeSubscriptWhitespaceRight") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])))) :+: C1 (MetaCons "Call" PrefixI True) ((S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeCallFunction") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Expr v a))) :*: (S1 (MetaSel (Just "_unsafeCallWhitespaceLeft") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]) :*: (S1 (MetaSel (Just "_unsafeCallArguments") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe (CommaSep1' (Arg v a)))) :*: S1 (MetaSel (Just "_unsafeCallWhitespaceRight") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])))))))) :+: (((C1 (MetaCons "None" PrefixI True) (S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeNoneWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: (C1 (MetaCons "Ellipsis" PrefixI True) (S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeEllipsisWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: C1 (MetaCons "BinOp" PrefixI True) ((S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeBinOpExprLeft") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Expr v a))) :*: (S1 (MetaSel (Just "_unsafeBinOpOp") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (BinOp a)) :*: S1 (MetaSel (Just "_unsafeBinOpExprRight") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Expr v a)))))) :+: ((C1 (MetaCons "UnOp" PrefixI True) (S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: (S1 (MetaSel (Just "_unsafeUnOpOp") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (UnOp a)) :*: S1 (MetaSel (Just "_unsafeUnOpValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Expr v a)))) :+: C1 (MetaCons "Parens" PrefixI True) ((S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeParensWhitespaceLeft") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :*: (S1 (MetaSel (Just "_unsafeParensValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Expr v a)) :*: S1 (MetaSel (Just "_unsafeParensWhitespaceAfter") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])))) :+: (C1 (MetaCons "Ident" PrefixI True) (S1 (MetaSel (Just "_unsafeIdentValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ident v a))) :+: C1 (MetaCons "Int" PrefixI True) (S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: (S1 (MetaSel (Just "_unsafeIntValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (IntLiteral a)) :*: S1 (MetaSel (Just "_unsafeIntWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])))))) :+: (((C1 (MetaCons "Float" PrefixI True) (S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: (S1 (MetaSel (Just "_unsafeFloatValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (FloatLiteral a)) :*: S1 (MetaSel (Just "_unsafeFloatWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))) :+: C1 (MetaCons "Imag" PrefixI True) (S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: (S1 (MetaSel (Just "_unsafeImagValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (ImagLiteral a)) :*: S1 (MetaSel (Just "_unsafeImagWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])))) :+: (C1 (MetaCons "Bool" PrefixI True) (S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: (S1 (MetaSel (Just "_unsafeBoolValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Bool) :*: S1 (MetaSel (Just "_unsafeBoolWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))) :+: C1 (MetaCons "String" PrefixI True) (S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeStringValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (NonEmpty (StringLiteral a)))))) :+: ((C1 (MetaCons "Tuple" PrefixI True) ((S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_unsafeTupleHead") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (TupleItem v a))) :*: (S1 (MetaSel (Just "_unsafeTupleWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Comma) :*: S1 (MetaSel (Just "_unsafeTupleTail") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe (CommaSep1' (TupleItem v a)))))) :+: C1 (MetaCons "Not" PrefixI True) (S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: (S1 (MetaSel (Just "_unsafeNotWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]) :*: S1 (MetaSel (Just "_unsafeNotValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Expr v a))))) :+: (C1 (MetaCons "Generator" PrefixI True) (S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "_generatorValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Comprehension Expr v a))) :+: C1 (MetaCons "Await" PrefixI True) (S1 (MetaSel (Just "_unsafeExprAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: (S1 (MetaSel (Just "_unsafeAwaitWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]) :*: S1 (MetaSel (Just "_unsafeAwaitValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Expr v a)))))))))

Modules

module_ :: [Raw Line] -> Raw Module Source #

Create a Module

>>> module_
>>> [ line_ $ def_ "a" [] [line_ pass_]
>>> , blank_
>>> , line_ $ def_ "b" [] [line_ pass_]
>>> ]
def a():
    pass

def b():
    pass

Lines of code

blank_ :: Raw Line Source #

Create a blank Line

class AsLine s where Source #

Convert some data to a Line

Methods

line_ :: Raw s -> Raw Line Source #

Instances
AsLine Expr Source # 
Instance details

Defined in Language.Python.DSL

Methods

line_ :: Raw Expr -> Raw Line Source #

AsLine CompoundStatement Source # 
Instance details

Defined in Language.Python.DSL

AsLine SimpleStatement Source # 
Instance details

Defined in Language.Python.DSL

AsLine Statement Source # 
Instance details

Defined in Language.Python.DSL

AsLine SmallStatement Source # 
Instance details

Defined in Language.Python.DSL

AsLine Fundef Source # 
Instance details

Defined in Language.Python.DSL

Methods

line_ :: Raw Fundef -> Raw Line Source #

AsLine While Source # 
Instance details

Defined in Language.Python.DSL

Methods

line_ :: Raw While -> Raw Line Source #

AsLine If Source # 
Instance details

Defined in Language.Python.DSL

Methods

line_ :: Raw If -> Raw Line Source #

AsLine For Source # 
Instance details

Defined in Language.Python.DSL

Methods

line_ :: Raw For -> Raw Line Source #

AsLine TryExcept Source # 
Instance details

Defined in Language.Python.DSL

AsLine TryFinally Source # 
Instance details

Defined in Language.Python.DSL

AsLine ClassDef Source # 
Instance details

Defined in Language.Python.DSL

AsLine With Source # 
Instance details

Defined in Language.Python.DSL

Methods

line_ :: Raw With -> Raw Line Source #

newtype Line v a Source #

One or more lines of Python code

Constructors

Line 

Fields

Instances
HasExprs Line Source # 
Instance details

Defined in Language.Python.DSL

Methods

_Exprs :: Traversal (Line v a) (Line [] a) (Expr v a) (Expr [] a) Source #

HasStatements Line Source # 
Instance details

Defined in Language.Python.DSL

Methods

_Statements :: Traversal (Line v a) (Line [] a) (Statement v a) (Statement [] a) Source #

Eq a => Eq (Line v a) Source # 
Instance details

Defined in Language.Python.DSL

Methods

(==) :: Line v a -> Line v a -> Bool #

(/=) :: Line v a -> Line v a -> Bool #

Show a => Show (Line v a) Source # 
Instance details

Defined in Language.Python.DSL

Methods

showsPrec :: Int -> Line v a -> ShowS #

show :: Line v a -> String #

showList :: [Line v a] -> ShowS #

Wrapped (Line v a) Source # 
Instance details

Defined in Language.Python.DSL

Associated Types

type Unwrapped (Line v a) :: Type

Methods

_Wrapped' :: Iso' (Line v a) (Unwrapped (Line v a))

Line v1 a1 ~ t => Rewrapped (Line v2 a2) t Source # 
Instance details

Defined in Language.Python.DSL

type Unwrapped (Line v a) Source # 
Instance details

Defined in Language.Python.DSL

type Unwrapped (Line v a) = Either (Blank a, Newline) (Statement v a)

Identifiers

id_ :: String -> Raw Ident Source #

Expr has an IsString instance, but when a type class dispatches on an Expr we will run into ambiguity if we try to use OverloadedStrings. In these cases we can use id_ to provide the extra type information

data Ident (v :: [*]) a Source #

An identifier. Like many types in hpython, it has an optional annotation and tracks its trailing whitespace.

Raw Idents have an IsString instance.

See https://docs.python.org/3.5/reference/lexical_analysis.html#identifiers

Constructors

MkIdent 
Instances
Validated Ident Source # 
Instance details

Defined in Language.Python.Syntax.Ident

Methods

unvalidated :: Getter (Ident v a) (Ident [] a) Source #

DoubleStarSyntax Ident Param Source #

See def_

Instance details

Defined in Language.Python.DSL

Methods

ss_ :: Raw Ident -> Raw Param Source #

StarSyntax Ident Param Source #

See def_

Instance details

Defined in Language.Python.DSL

Methods

s_ :: Raw Ident -> Raw Param Source #

PositionalSyntax Param Ident Source #

See def_

Instance details

Defined in Language.Python.DSL

Methods

p_ :: Raw Ident -> Raw Param Source #

As Expr Ident ExceptAs Source #

See exceptAs_

Instance details

Defined in Language.Python.DSL

Methods

as_ :: Raw Expr -> Raw Ident -> Raw ExceptAs Source #

Functor (Ident v) Source # 
Instance details

Defined in Language.Python.Syntax.Ident

Methods

fmap :: (a -> b) -> Ident v a -> Ident v b #

(<$) :: a -> Ident v b -> Ident v a #

IsString (Raw Ident) Source # 
Instance details

Defined in Language.Python.Syntax.Ident

Methods

fromString :: String -> Raw Ident #

Foldable (Ident v) Source # 
Instance details

Defined in Language.Python.Syntax.Ident

Methods

fold :: Monoid m => Ident v m -> m #

foldMap :: Monoid m => (a -> m) -> Ident v a -> m #

foldr :: (a -> b -> b) -> b -> Ident v a -> b #

foldr' :: (a -> b -> b) -> b -> Ident v a -> b #

foldl :: (b -> a -> b) -> b -> Ident v a -> b #

foldl' :: (b -> a -> b) -> b -> Ident v a -> b #

foldr1 :: (a -> a -> a) -> Ident v a -> a #

foldl1 :: (a -> a -> a) -> Ident v a -> a #

toList :: Ident v a -> [a] #

null :: Ident v a -> Bool #

length :: Ident v a -> Int #

elem :: Eq a => a -> Ident v a -> Bool #

maximum :: Ord a => Ident v a -> a #

minimum :: Ord a => Ident v a -> a #

sum :: Num a => Ident v a -> a #

product :: Num a => Ident v a -> a #

Traversable (Ident v) Source # 
Instance details

Defined in Language.Python.Syntax.Ident

Methods

traverse :: Applicative f => (a -> f b) -> Ident v a -> f (Ident v b) #

sequenceA :: Applicative f => Ident v (f a) -> f (Ident v a) #

mapM :: Monad m => (a -> m b) -> Ident v a -> m (Ident v b) #

sequence :: Monad m => Ident v (m a) -> m (Ident v a) #

Eq a => Eq (Ident v a) Source # 
Instance details

Defined in Language.Python.Syntax.Ident

Methods

(==) :: Ident v a -> Ident v a -> Bool #

(/=) :: Ident v a -> Ident v a -> Bool #

Show a => Show (Ident v a) Source # 
Instance details

Defined in Language.Python.Syntax.Ident

Methods

showsPrec :: Int -> Ident v a -> ShowS #

show :: Ident v a -> String #

showList :: [Ident v a] -> ShowS #

HasTrailingWhitespace (Ident v a) Source # 
Instance details

Defined in Language.Python.Syntax.Ident

Methods

trailingWhitespace :: Lens' (Ident v a) [Whitespace] Source #

HasNewlines (Ident v a) Source # 
Instance details

Defined in Language.Python.Optics.Newlines

Methods

_Newlines :: Traversal' (Ident v a) Newline Source #

Lenses

identAnn :: Lens (Ident v a) (Ident v a) a a Source #

identValue :: Lens (Ident v a) (Ident '[] a) String String Source #

Starred values

class StarSyntax s t | t -> s where Source #

Methods

s_ :: Raw s -> Raw t Source #

Instances
StarSyntax Ident Param Source #

See def_

Instance details

Defined in Language.Python.DSL

Methods

s_ :: Raw Ident -> Raw Param Source #

StarSyntax Expr TupleItem Source #

See tuple_

Instance details

Defined in Language.Python.DSL

Methods

s_ :: Raw Expr -> Raw TupleItem Source #

StarSyntax Expr SetItem Source #

See set_

Instance details

Defined in Language.Python.DSL

Methods

s_ :: Raw Expr -> Raw SetItem Source #

StarSyntax Expr ListItem Source #

See list_

Instance details

Defined in Language.Python.DSL

Methods

s_ :: Raw Expr -> Raw ListItem Source #

StarSyntax Expr Arg Source #

See call_

Instance details

Defined in Language.Python.DSL

Methods

s_ :: Raw Expr -> Raw Arg Source #

star_ :: Raw Param Source #

Unnamed starred parameter

>>> def_ "a" [ p_ "b", star_ ] [ line_ pass_ ]
def a(b, *):
    pass

Double-starred values

class DoubleStarSyntax s t | t -> s where Source #

Methods

ss_ :: Raw s -> Raw t Source #

Instances
DoubleStarSyntax Ident Param Source #

See def_

Instance details

Defined in Language.Python.DSL

Methods

ss_ :: Raw Ident -> Raw Param Source #

DoubleStarSyntax Expr DictItem Source #

See dict_

Instance details

Defined in Language.Python.DSL

Methods

ss_ :: Raw Expr -> Raw DictItem Source #

DoubleStarSyntax Expr Arg Source #

See call_

Instance details

Defined in Language.Python.DSL

Methods

ss_ :: Raw Expr -> Raw Arg Source #

as syntax

class As s t u | s t -> u, u -> s t where Source #

Methods

as_ :: Raw s -> Raw t -> Raw u Source #

Instances
As Expr Ident ExceptAs Source #

See exceptAs_

Instance details

Defined in Language.Python.DSL

Methods

as_ :: Raw Expr -> Raw Ident -> Raw ExceptAs Source #

As Expr Expr WithItem Source #

See with_

Instance details

Defined in Language.Python.DSL

Methods

as_ :: Raw Expr -> Raw Expr -> Raw WithItem Source #

if syntax

class IfSyntax a where Source #

Methods

if_ :: Raw Expr -> a Source #

Instances
IfSyntax (Raw Guard) Source #
if_ :: Raw SimpleStatement -> Raw Guard
>>> comp_ (var_ "a") (for_ $ var_ "a" `in_` var_ "b") [if_ $ var_ "c" .== var_ "d"]
a for a in b if c == d
Instance details

Defined in Language.Python.DSL

Methods

if_ :: Raw Expr -> Raw Guard Source #

(l ~ Raw Line, s ~ Raw If) => IfSyntax ([l] -> s) Source #
if_ :: Raw SimpleStatement -> [Raw Line] -> Raw If
>>> if_ (var_ "a" .< 10) [var_ "a" .+= 1]
if a < 10:
    a += 1
Instance details

Defined in Language.Python.DSL

Methods

if_ :: Raw Expr -> [l] -> s Source #

for syntax

class ForSyntax a x | a -> x where Source #

Methods

for_ :: Raw x -> a Source #

Instances
ForSyntax (Raw CompFor) In Source #
for_ :: Raw In -> Raw CompFor
>>> comp_ (var_ "a") (for_ $ var_ "a" `in_` var_ "b") []
a for a in b
Instance details

Defined in Language.Python.DSL

Methods

for_ :: Raw In -> Raw CompFor Source #

ForSyntax (Raw Guard) In Source #
for_ :: Raw In -> Raw Guard
>>> comp_ (var_ "a") (for_ $ var_ "a" `in_` var_ "b") [for_ $ var_ "c" `in_` var_ "d"]
a for a in b for c in d
Instance details

Defined in Language.Python.DSL

Methods

for_ :: Raw In -> Raw Guard Source #

(l ~ [Raw Line], s ~ Raw For) => ForSyntax (l -> s) InList Source #
for_ :: Raw InList -> [Raw Line] -> Raw Statement
>>> for_ (var_ "a" `in_` [var_ "b"]) [line_ (var_ "c" .+= var_ "a")]
for a in b:
    c += a
Instance details

Defined in Language.Python.DSL

Methods

for_ :: Raw InList -> l -> s Source #

in syntax

class InSyntax a x | a -> x, x -> a where Source #

Methods

in_ :: Raw Expr -> x -> Raw a infixl 1 Source #

Instances
InSyntax Expr (Raw Expr) Source #
>>> var_ "a" `in_` var_ "b"
a in b
Instance details

Defined in Language.Python.DSL

Methods

in_ :: Raw Expr -> Raw Expr -> Raw Expr Source #

e ~ Raw Expr => InSyntax InList [e] Source #

See for_

Instance details

Defined in Language.Python.DSL

Methods

in_ :: Raw Expr -> [e] -> Raw InList Source #

data In v a Source #

>>> var_ "a" `in_` var_ "b"
a in b

Constructors

MkIn (Expr v a) (Expr v a) 
Instances
ForSyntax (Raw CompFor) In Source #
for_ :: Raw In -> Raw CompFor
>>> comp_ (var_ "a") (for_ $ var_ "a" `in_` var_ "b") []
a for a in b
Instance details

Defined in Language.Python.DSL

Methods

for_ :: Raw In -> Raw CompFor Source #

ForSyntax (Raw Guard) In Source #
for_ :: Raw In -> Raw Guard
>>> comp_ (var_ "a") (for_ $ var_ "a" `in_` var_ "b") [for_ $ var_ "c" `in_` var_ "d"]
a for a in b for c in d
Instance details

Defined in Language.Python.DSL

Methods

for_ :: Raw In -> Raw Guard Source #

data InList v a Source #

>>> var_ "a" `in_` [var_ "b", var_ "c"]
a in b, c

Constructors

MkInList (Expr v a) [Expr v a] 
Instances
e ~ Raw Expr => InSyntax InList [e] Source #

See for_

Instance details

Defined in Language.Python.DSL

Methods

in_ :: Raw Expr -> [e] -> Raw InList Source #

(l ~ [Raw Line], s ~ Raw For) => ForSyntax (l -> s) InList Source #
for_ :: Raw InList -> [Raw Line] -> Raw Statement
>>> for_ (var_ "a" `in_` [var_ "b"]) [line_ (var_ "c" .+= var_ "a")]
for a in b:
    c += a
Instance details

Defined in Language.Python.DSL

Methods

for_ :: Raw InList -> l -> s Source #

: syntax

class ColonSyntax s t | s -> t, t -> s where Source #

Methods

(.:) :: Raw s -> Raw Expr -> Raw t infix 0 Source #

Instances
ColonSyntax Expr DictItem Source #

Constructing dictionary items

(.:) :: Raw SimpleStatement -> Raw SimpleStatement -> Raw DictItem
Instance details

Defined in Language.Python.DSL

Methods

(.:) :: Raw Expr -> Raw Expr -> Raw DictItem Source #

ColonSyntax Param Param Source #

Function parameter type annotations

(.:) :: Raw Param -> Raw SimpleStatement -> Raw Param

star_ can be annotated using .:, but it will have no effect on the output program, as unnamed starred parameters cannot have type annotations.

See def_

Instance details

Defined in Language.Python.DSL

Methods

(.:) :: Raw Param -> Raw Expr -> Raw Param Source #

Comprehensions

newtype Guard v a Source #

Constructors

MkGuard 

Fields

Instances
IfSyntax (Raw Guard) Source #
if_ :: Raw SimpleStatement -> Raw Guard
>>> comp_ (var_ "a") (for_ $ var_ "a" `in_` var_ "b") [if_ $ var_ "c" .== var_ "d"]
a for a in b if c == d
Instance details

Defined in Language.Python.DSL

Methods

if_ :: Raw Expr -> Raw Guard Source #

ForSyntax (Raw Guard) In Source #
for_ :: Raw In -> Raw Guard
>>> comp_ (var_ "a") (for_ $ var_ "a" `in_` var_ "b") [for_ $ var_ "c" `in_` var_ "d"]
a for a in b for c in d
Instance details

Defined in Language.Python.DSL

Methods

for_ :: Raw In -> Raw Guard Source #

Parameters and arguments

Parameters

data Param (v :: [*]) a Source #

Instances
Validated Param Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

unvalidated :: Getter (Param v a) (Param [] a) Source #

HasExprs Param Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

_Exprs :: Traversal (Param v a) (Param [] a) (Expr v a) (Expr [] a) Source #

KeywordSyntax Param Source #

See def_

Instance details

Defined in Language.Python.DSL

Methods

k_ :: Raw Ident -> Raw Expr -> Raw Param Source #

DoubleStarSyntax Ident Param Source #

See def_

Instance details

Defined in Language.Python.DSL

Methods

ss_ :: Raw Ident -> Raw Param Source #

StarSyntax Ident Param Source #

See def_

Instance details

Defined in Language.Python.DSL

Methods

s_ :: Raw Ident -> Raw Param Source #

PositionalSyntax Param Ident Source #

See def_

Instance details

Defined in Language.Python.DSL

Methods

p_ :: Raw Ident -> Raw Param Source #

ColonSyntax Param Param Source #

Function parameter type annotations

(.:) :: Raw Param -> Raw SimpleStatement -> Raw Param

star_ can be annotated using .:, but it will have no effect on the output program, as unnamed starred parameters cannot have type annotations.

See def_

Instance details

Defined in Language.Python.DSL

Methods

(.:) :: Raw Param -> Raw Expr -> Raw Param Source #

Functor (Param v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fmap :: (a -> b) -> Param v a -> Param v b #

(<$) :: a -> Param v b -> Param v a #

Foldable (Param v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fold :: Monoid m => Param v m -> m #

foldMap :: Monoid m => (a -> m) -> Param v a -> m #

foldr :: (a -> b -> b) -> b -> Param v a -> b #

foldr' :: (a -> b -> b) -> b -> Param v a -> b #

foldl :: (b -> a -> b) -> b -> Param v a -> b #

foldl' :: (b -> a -> b) -> b -> Param v a -> b #

foldr1 :: (a -> a -> a) -> Param v a -> a #

foldl1 :: (a -> a -> a) -> Param v a -> a #

toList :: Param v a -> [a] #

null :: Param v a -> Bool #

length :: Param v a -> Int #

elem :: Eq a => a -> Param v a -> Bool #

maximum :: Ord a => Param v a -> a #

minimum :: Ord a => Param v a -> a #

sum :: Num a => Param v a -> a #

product :: Num a => Param v a -> a #

Traversable (Param v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

traverse :: Applicative f => (a -> f b) -> Param v a -> f (Param v b) #

sequenceA :: Applicative f => Param v (f a) -> f (Param v a) #

mapM :: Monad m => (a -> m b) -> Param v a -> m (Param v b) #

sequence :: Monad m => Param v (m a) -> m (Param v a) #

Eq a => Eq (Param v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

(==) :: Param v a -> Param v a -> Bool #

(/=) :: Param v a -> Param v a -> Bool #

Show a => Show (Param v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

showsPrec :: Int -> Param v a -> ShowS #

show :: Param v a -> String #

showList :: [Param v a] -> ShowS #

IsString (Param ([] :: [Type]) ()) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fromString :: String -> Param [] () #

HasTrailingWhitespace (Param v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

trailingWhitespace :: Lens' (Param v a) [Whitespace] Source #

HasNewlines (Param v a) Source # 
Instance details

Defined in Language.Python.Optics.Newlines

Methods

_Newlines :: Traversal' (Param v a) Newline Source #

class ParametersSyntax s where Source #

Methods

parameters_ :: Functor f => ([Raw Param] -> f [Raw Param]) -> Raw s -> f (Raw s) Source #

A faux-Lens that allows targeting Params in-between existing formatting, and adding appropriate formatting when extra parameters are introduced.

>>> showStatement myStatement
"def a(b ,  c   ):\n    pass"
>>> showStatement (myStatement & _Fundef.parameters_ .~ [p_ "d", p_ "e"]
"def a(d ,  e   ):\n    pass"
>>> showStatement (myStatement & _Fundef.parameters_ .~ [p_ "d", p_ "e", p_ "f"]
"def a(d ,  e   , f):\n    pass"

---

It's not a Lens because repeated sets can drop trailing commas, violating the Lens laws. For example:

>>> someFunction
def a(b, c,):
    pass
>>> set parameters_ [var_ "d", var_ "e"] someFunction
def a(d, e,):
    pass
>>> set parameters_ [] someFunction
def a():
    pass
>>> set parameters_ [var_ "d", var_ "e"] (set parameters_ [] someFunction)
def a(d, e):
    pass

parameters :: Lens' (Raw s) (CommaSep (Raw Param)) Source #

Instances
ParametersSyntax Fundef Source # 
Instance details

Defined in Language.Python.DSL

Methods

parameters_ :: Functor f => ([Raw Param] -> f [Raw Param]) -> Raw Fundef -> f (Raw Fundef) Source #

parameters :: Lens' (Raw Fundef) (CommaSep (Raw Param)) Source #

Arguments

data Arg (v :: [*]) a Source #

Actual parameters for functions

In the following examples, x is an actual parameter.

y = foo(x)
y = bar(quux=x)
y = baz(*x)
y = flux(**x)
Instances
Validated Arg Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

unvalidated :: Getter (Arg v a) (Arg [] a) Source #

HasExprs Arg Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

_Exprs :: Traversal (Arg v a) (Arg [] a) (Expr v a) (Expr [] a) Source #

KeywordSyntax Arg Source #

See call_

Instance details

Defined in Language.Python.DSL

Methods

k_ :: Raw Ident -> Raw Expr -> Raw Arg Source #

DoubleStarSyntax Expr Arg Source #

See call_

Instance details

Defined in Language.Python.DSL

Methods

ss_ :: Raw Expr -> Raw Arg Source #

StarSyntax Expr Arg Source #

See call_

Instance details

Defined in Language.Python.DSL

Methods

s_ :: Raw Expr -> Raw Arg Source #

PositionalSyntax Arg Expr Source #

See call_

Instance details

Defined in Language.Python.DSL

Methods

p_ :: Raw Expr -> Raw Arg Source #

Functor (Arg v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fmap :: (a -> b) -> Arg v a -> Arg v b #

(<$) :: a -> Arg v b -> Arg v a #

Foldable (Arg v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fold :: Monoid m => Arg v m -> m #

foldMap :: Monoid m => (a -> m) -> Arg v a -> m #

foldr :: (a -> b -> b) -> b -> Arg v a -> b #

foldr' :: (a -> b -> b) -> b -> Arg v a -> b #

foldl :: (b -> a -> b) -> b -> Arg v a -> b #

foldl' :: (b -> a -> b) -> b -> Arg v a -> b #

foldr1 :: (a -> a -> a) -> Arg v a -> a #

foldl1 :: (a -> a -> a) -> Arg v a -> a #

toList :: Arg v a -> [a] #

null :: Arg v a -> Bool #

length :: Arg v a -> Int #

elem :: Eq a => a -> Arg v a -> Bool #

maximum :: Ord a => Arg v a -> a #

minimum :: Ord a => Arg v a -> a #

sum :: Num a => Arg v a -> a #

product :: Num a => Arg v a -> a #

Traversable (Arg v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

traverse :: Applicative f => (a -> f b) -> Arg v a -> f (Arg v b) #

sequenceA :: Applicative f => Arg v (f a) -> f (Arg v a) #

mapM :: Monad m => (a -> m b) -> Arg v a -> m (Arg v b) #

sequence :: Monad m => Arg v (m a) -> m (Arg v a) #

Eq a => Eq (Arg v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

(==) :: Arg v a -> Arg v a -> Bool #

(/=) :: Arg v a -> Arg v a -> Bool #

Show a => Show (Arg v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

showsPrec :: Int -> Arg v a -> ShowS #

show :: Arg v a -> String #

showList :: [Arg v a] -> ShowS #

IsString (Arg ([] :: [Type]) ()) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fromString :: String -> Arg [] () #

HasNewlines (Arg v a) Source # 
Instance details

Defined in Language.Python.Optics.Newlines

Methods

_Newlines :: Traversal' (Arg v a) Newline Source #

Positional

class PositionalSyntax p v | p -> v, v -> p where Source #

Positional parameters/arguments

p_ :: Raw SimpleStatement -> Raw Arg
p_ :: Raw Expr -> Raw Param

Methods

p_ :: Raw v -> Raw p Source #

Instances
PositionalSyntax Arg Expr Source #

See call_

Instance details

Defined in Language.Python.DSL

Methods

p_ :: Raw Expr -> Raw Arg Source #

PositionalSyntax Param Ident Source #

See def_

Instance details

Defined in Language.Python.DSL

Methods

p_ :: Raw Ident -> Raw Param Source #

data PositionalParam v a Source #

Constructors

MkPositionalParam 

Fields

Instances
Eq a => Eq (PositionalParam v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Show a => Show (PositionalParam v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

_PositionalParam :: Prism (Param v a) (Param '[] a) (PositionalParam v a) (PositionalParam '[] a) Source #

Lenses

ppAnn :: forall v a. Lens' (PositionalParam v a) a Source #

ppName :: forall v a. Lens' (PositionalParam v a) (Ident v a) Source #

ppType :: forall v a. Lens' (PositionalParam v a) (Maybe (Colon, Expr v a)) Source #

Keyword

class KeywordSyntax p where Source #

Keyword parameters/arguments

p_ :: Raw SimpleStatement -> Raw SimpleStatement -> Raw Arg
p_ :: Raw Expr -> Raw SimpleStatement -> Raw Param

Methods

k_ :: Raw Ident -> Raw Expr -> Raw p Source #

Instances
KeywordSyntax Arg Source #

See call_

Instance details

Defined in Language.Python.DSL

Methods

k_ :: Raw Ident -> Raw Expr -> Raw Arg Source #

KeywordSyntax Param Source #

See def_

Instance details

Defined in Language.Python.DSL

Methods

k_ :: Raw Ident -> Raw Expr -> Raw Param Source #

data KeywordParam v a Source #

Constructors

MkKeywordParam 

Fields

Instances
Eq a => Eq (KeywordParam v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: KeywordParam v a -> KeywordParam v a -> Bool #

(/=) :: KeywordParam v a -> KeywordParam v a -> Bool #

Show a => Show (KeywordParam v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

_KeywordParam :: Prism (Param v a) (Param '[] a) (KeywordParam v a) (KeywordParam '[] a) Source #

Lenses

kpAnn :: forall v a. Lens' (KeywordParam v a) a Source #

kpName :: forall v a. Lens' (KeywordParam v a) (Ident v a) Source #

kpType :: forall v a. Lens' (KeywordParam v a) (Maybe (Colon, Expr v a)) Source #

kpEquals :: forall v a. Lens' (KeywordParam v a) [Whitespace] Source #

kpExpr :: forall v a. Lens' (KeywordParam v a) (Expr v a) Source #

Decorators

Statements

async

class AsyncSyntax s where Source #

Methods

async_ :: Raw s -> Raw s Source #

Instances
AsyncSyntax Fundef Source # 
Instance details

Defined in Language.Python.DSL

AsyncSyntax For Source # 
Instance details

Defined in Language.Python.DSL

Methods

async_ :: Raw For -> Raw For Source #

AsyncSyntax With Source # 
Instance details

Defined in Language.Python.DSL

Methods

async_ :: Raw With -> Raw With Source #

Block bodies

class BodySyntax s where Source #

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw s -> f (Raw s) Source #

A faux-Lens that targets lines in the body of some statement-piece, but does so 'around' indentation.

>>> def_ "a" [] [ line_ pass_, line_ pass_ ]
def a ():
    pass
    pass
>>> def_ "a" [] [ line_ pass_, line_ pass_ ] ^. body_
pass
pass
>>> def_ "a" [] [ line_ pass_, line_ pass_ ] & body_ .~ [ line_ $ var_ "b" += 1 ]
def a():
    b += 1
>>> def_ "a" [] [ line_ pass_, line_ pass_ ] & body_ <>~ [ line_ $ var_ "b" += 1 ]
def a():
    pass
    pass
    b += 1
>>> def_ "a" [] [ line_ pass_, line_ pass_ ] & body_ .~ []
def a():
    pass

---

It's a fake Lens because it violates some of the laws. The most obvious violation is that setting the body_ to the empty list actually sets it to a singleton list containing pass_. (This is because blocks must contain one or more statements)

body :: Lens' (Raw s) (Raw Suite) Source #

Instances
BodySyntax Fundef Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw Fundef -> f (Raw Fundef) Source #

body :: Lens' (Raw Fundef) (Raw Suite) Source #

BodySyntax Else Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw Else -> f (Raw Else) Source #

body :: Lens' (Raw Else) (Raw Suite) Source #

BodySyntax While Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw While -> f (Raw While) Source #

body :: Lens' (Raw While) (Raw Suite) Source #

BodySyntax Elif Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw Elif -> f (Raw Elif) Source #

body :: Lens' (Raw Elif) (Raw Suite) Source #

BodySyntax If Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw If -> f (Raw If) Source #

body :: Lens' (Raw If) (Raw Suite) Source #

BodySyntax For Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw For -> f (Raw For) Source #

body :: Lens' (Raw For) (Raw Suite) Source #

BodySyntax TryExcept Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw TryExcept -> f (Raw TryExcept) Source #

body :: Lens' (Raw TryExcept) (Raw Suite) Source #

BodySyntax TryFinally Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw TryFinally -> f (Raw TryFinally) Source #

body :: Lens' (Raw TryFinally) (Raw Suite) Source #

BodySyntax ClassDef Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw ClassDef -> f (Raw ClassDef) Source #

body :: Lens' (Raw ClassDef) (Raw Suite) Source #

BodySyntax With Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw With -> f (Raw With) Source #

body :: Lens' (Raw With) (Raw Suite) Source #

Function definitions

def_ :: Raw Ident -> [Raw Param] -> [Raw Line] -> Raw Fundef Source #

>>> def_ "f" [p_ "x"] [line_ $ return_ "x"]
def f(x):
    return x
>>> def_ "f" [p_ "x", k_ "y" 2] [line_ $ return_ "x"]
def f(x, y=2):
    return x
>>> def_ "f" [p_ "x", k_ "y" 2, s_ "z"] [line_ $ return_ "x"]
def f(x, y=2, *z):
    return x
>>> def_ "f" [p_ "x", k_ "y" 2, s_ "z", ss_ "w"] [line_ $ return_ "x"]
def f(x, y=2, *z, **w)
    return x
>>> def_ "f" [p_ "x" .: "String"] [line_ $ return_ "x"]
def f(x: String):
    return x

data Fundef v a Source #

Instances
HasFundef Fundef Source # 
Instance details

Defined in Language.Python.Optics

Methods

_Fundef :: Prism (Fundef v a) (Fundef [] a) (Fundef v a) (Fundef [] a) Source #

AsyncSyntax Fundef Source # 
Instance details

Defined in Language.Python.DSL

DecoratorsSyntax Fundef Source # 
Instance details

Defined in Language.Python.DSL

ParametersSyntax Fundef Source # 
Instance details

Defined in Language.Python.DSL

Methods

parameters_ :: Functor f => ([Raw Param] -> f [Raw Param]) -> Raw Fundef -> f (Raw Fundef) Source #

parameters :: Lens' (Raw Fundef) (CommaSep (Raw Param)) Source #

BodySyntax Fundef Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw Fundef -> f (Raw Fundef) Source #

body :: Lens' (Raw Fundef) (Raw Suite) Source #

AsLine Fundef Source # 
Instance details

Defined in Language.Python.DSL

Methods

line_ :: Raw Fundef -> Raw Line Source #

Eq a => Eq (Fundef v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: Fundef v a -> Fundef v a -> Bool #

(/=) :: Fundef v a -> Fundef v a -> Bool #

Show a => Show (Fundef v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

showsPrec :: Int -> Fundef v a -> ShowS #

show :: Fundef v a -> String #

showList :: [Fundef v a] -> ShowS #

HasIndents (Fundef ([] :: [Type]) a) a Source # 
Instance details

Defined in Language.Python.Optics.Indents

Methods

_Indents :: Traversal' (Fundef [] a) (Indents a) Source #

mkFundef :: Raw Ident -> [Raw Line] -> Raw Fundef Source #

Create a minimal valid function definition

Lenses

fdAnn :: forall v a. Lens' (Fundef v a) a Source #

fdDecorators :: forall v a. Lens' (Fundef v a) [Decorator v a] Source #

fdIndents :: forall v a. Lens' (Fundef v a) (Indents a) Source #

fdAsync :: forall v a. Lens' (Fundef v a) (Maybe (NonEmpty Whitespace)) Source #

fdDefSpaces :: forall v a. Lens' (Fundef v a) (NonEmpty Whitespace) Source #

fdName :: forall v a. Lens' (Fundef v a) (Ident v a) Source #

fdLeftParenSpaces :: forall v a. Lens' (Fundef v a) [Whitespace] Source #

fdParameters :: forall v a. Lens' (Fundef v a) (CommaSep (Param v a)) Source #

fdRightParenSpaces :: forall v a. Lens' (Fundef v a) [Whitespace] Source #

fdReturnType :: forall v a. Lens' (Fundef v a) (Maybe ([Whitespace], Expr v a)) Source #

fdBody :: forall v a. Lens' (Fundef v a) (Suite v a) Source #

Class definitions

class_ :: Raw Ident -> [Raw Arg] -> [Raw Line] -> Raw ClassDef Source #

>>> class_ "A" [] [line_ pass_]
class A:
    pass

data ClassDef v a Source #

Instances
HasClassDef ClassDef Source # 
Instance details

Defined in Language.Python.Optics

Methods

_ClassDef :: Prism (ClassDef v a) (ClassDef [] a) (ClassDef v a) (ClassDef [] a) Source #

DecoratorsSyntax ClassDef Source # 
Instance details

Defined in Language.Python.DSL

ArgumentsSyntax ClassDef Source # 
Instance details

Defined in Language.Python.DSL

BodySyntax ClassDef Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw ClassDef -> f (Raw ClassDef) Source #

body :: Lens' (Raw ClassDef) (Raw Suite) Source #

AsLine ClassDef Source # 
Instance details

Defined in Language.Python.DSL

Eq a => Eq (ClassDef v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: ClassDef v a -> ClassDef v a -> Bool #

(/=) :: ClassDef v a -> ClassDef v a -> Bool #

Show a => Show (ClassDef v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

showsPrec :: Int -> ClassDef v a -> ShowS #

show :: ClassDef v a -> String #

showList :: [ClassDef v a] -> ShowS #

HasIndents (ClassDef ([] :: [Type]) a) a Source # 
Instance details

Defined in Language.Python.Optics.Indents

Methods

_Indents :: Traversal' (ClassDef [] a) (Indents a) Source #

mkClassDef :: Raw Ident -> [Raw Line] -> Raw ClassDef Source #

Create a minimal ClassDef

Lenses

cdAnn :: forall v a. Lens' (ClassDef v a) a Source #

cdDecorators :: forall v a. Lens' (ClassDef v a) [Decorator v a] Source #

cdIndents :: forall v a. Lens' (ClassDef v a) (Indents a) Source #

cdClass :: forall v a. Lens' (ClassDef v a) (NonEmpty Whitespace) Source #

cdName :: forall v a. Lens' (ClassDef v a) (Ident v a) Source #

cdArguments :: forall v a. Lens' (ClassDef v a) (Maybe ([Whitespace], Maybe (CommaSep1' (Arg v a)), [Whitespace])) Source #

cdBody :: forall v a. Lens' (ClassDef v a) (Suite v a) Source #

Assignment

chainEq :: Raw Expr -> [Raw Expr] -> Raw Statement Source #

Chained assignment

>>> chainEq (var_ "a") []
a
>>> chainEq (var_ "a") [var_ "b", var_ "c"]
a = b = c

(.=) :: Raw Expr -> Raw Expr -> Raw Statement infix 0 Source #

a = b

(.+=) :: Raw Expr -> Raw Expr -> Raw Statement infix 0 Source #

a += b

(.-=) :: Raw Expr -> Raw Expr -> Raw Statement infix 0 Source #

a -= b

(.*=) :: Raw Expr -> Raw Expr -> Raw Statement infix 0 Source #

a *= b

(.@=) :: Raw Expr -> Raw Expr -> Raw Statement infix 0 Source #

a = b@

(./=) :: Raw Expr -> Raw Expr -> Raw Statement infix 0 Source #

a /= b

(.%=) :: Raw Expr -> Raw Expr -> Raw Statement infix 0 Source #

a %= b

(.&=) :: Raw Expr -> Raw Expr -> Raw Statement infix 0 Source #

a &= b

(.|=) :: Raw Expr -> Raw Expr -> Raw Statement infix 0 Source #

a |= b

(.^=) :: Raw Expr -> Raw Expr -> Raw Statement infix 0 Source #

a ^= b

(.<<=) :: Raw Expr -> Raw Expr -> Raw Statement infix 0 Source #

a <<= b

(.>>=) :: Raw Expr -> Raw Expr -> Raw Statement infix 0 Source #

a >>= b

(.**=) :: Raw Expr -> Raw Expr -> Raw Statement infix 0 Source #

a **= b

(.//=) :: Raw Expr -> Raw Expr -> Raw Statement infix 0 Source #

a //= b

Exceptions

tryE_ :: [Raw Line] -> Raw Except -> Raw TryExcept Source #

try ... except with optional else and optional finally

>>> tryE_ [line_ pass_] [line_ ("a" .+= 1)]
try:
    pass
except
    a += 1

tryF_ :: [Raw Line] -> [Raw Line] -> Raw TryFinally Source #

try ... finally
>>> tryF_ [line_ pass_] [line_ ("a" .+= 1)]
try:
    pass
finally:
    a += 1

class ExceptSyntax s where Source #

Methods

except_ :: [Raw Line] -> s -> Raw TryExcept Source #

exceptAs_ :: AsExceptAs e => Raw e -> [Raw Line] -> s -> Raw TryExcept Source #

You can use exceptAs_ without a binder:

exceptAs_ :: Raw SimpleStatement -> [Raw Line] -> Raw s -> Raw TryExcept
exceptAs_ (var_ "Exception") body

or with a binder:

exceptAs_ :: Raw ExceptAs -> [Raw Line] -> Raw s -> Raw TryExcept
exceptAs_ (var_ "Exception" `as_` id_ "a") body
Instances
ExceptSyntax (Raw TryExcept) Source #
except_ :: [Raw Line] -> Raw TryExcept -> Raw TryExcept
exceptAs_ :: AsExceptAs => Raw e -> [Raw Line] -> Raw TryExcept -> Raw TryExcept
(someTryStatement :: Raw TryExcept) &
  except_ [line_ pass_]
(someTryStatement :: Raw TryExcept) &
  exceptAs_ (var_ "Exception" `as_` id_ "b") [line_ pass_]
Instance details

Defined in Language.Python.DSL

ExceptSyntax (Raw TryFinally) Source #
except_ :: [Raw Line] -> Raw TryFinally -> Raw TryExcept
exceptAs_ :: AsExceptAs => Raw e -> [Raw Line] -> Raw TryFinally -> Raw TryExcept
(someTryStatement :: Raw TryFinally) &
  except_ [line_ pass_]
(someTryStatement :: Raw TryFinally) &
  exceptAs_ (var_ "Exception" `as_` id_ "b") [line_ pass_]
Instance details

Defined in Language.Python.DSL

(e ~ Raw Except, s ~ Raw TryExcept) => ExceptSyntax (e -> s) Source #
except_ :: [Raw Line] -> (Raw Except -> Raw TryExcept) -> Raw TryExcept
exceptAs_ :: AsExceptAs e => Raw e -> [Raw Line] -> (Raw Except -> Raw TryExcept) -> Raw TryExcept
>>> tryE_ [var_ "a" .= 2] & except_ [var_ "a" .= 3]
try:
    a = 2
except:
    a = 3
>>> tryE_ [var_ "a" .= 2] & exceptAs_ (var_ "Exception" `as_` id_ "b") [var_ "a" .= 3]
try:
    a = 2
except Exception as b:
    a = 3
Instance details

Defined in Language.Python.DSL

Methods

except_ :: [Raw Line] -> (e -> s) -> Raw TryExcept Source #

exceptAs_ :: AsExceptAs e0 => Raw e0 -> [Raw Line] -> (e -> s) -> Raw TryExcept Source #

class FinallySyntax s t | s -> t where Source #

Methods

finally_ :: [Raw Line] -> s -> Raw t Source #

Instances
FinallySyntax (Raw TryExcept) TryExcept Source #
>>> tryE_ [line_ pass_] & finally_ [line_ pass_]
try:
    pass
finally:
    pass
>>> tryF_ [line_ pass_] [line_ (a .+= 1)] & finally_ [line_ pass_]
try:
    pass
finally:
    pass
>>> tryF_ [line_ pass_] & finally_ [line_ pass_]
try:
    pass
finally:
    pass
Instance details

Defined in Language.Python.DSL

FinallySyntax (Raw TryFinally) TryFinally Source # 
Instance details

Defined in Language.Python.DSL

(a ~ [Raw Line], b ~ Raw TryFinally) => FinallySyntax (a -> b) TryFinally Source # 
Instance details

Defined in Language.Python.DSL

Methods

finally_ :: [Raw Line] -> (a -> b) -> Raw TryFinally Source #

data TryExcept v a Source #

Constructors

MkTryExcept 

Fields

Instances
HasTryExcept TryExcept Source # 
Instance details

Defined in Language.Python.Optics

Methods

_TryExcept :: Prism (TryExcept v a) (TryExcept [] a) (TryExcept v a) (TryExcept [] a) Source #

ElseSyntax TryExcept Source # 
Instance details

Defined in Language.Python.DSL

BodySyntax TryExcept Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw TryExcept -> f (Raw TryExcept) Source #

body :: Lens' (Raw TryExcept) (Raw Suite) Source #

AsLine TryExcept Source # 
Instance details

Defined in Language.Python.DSL

ExceptSyntax (Raw TryExcept) Source #
except_ :: [Raw Line] -> Raw TryExcept -> Raw TryExcept
exceptAs_ :: AsExceptAs => Raw e -> [Raw Line] -> Raw TryExcept -> Raw TryExcept
(someTryStatement :: Raw TryExcept) &
  except_ [line_ pass_]
(someTryStatement :: Raw TryExcept) &
  exceptAs_ (var_ "Exception" `as_` id_ "b") [line_ pass_]
Instance details

Defined in Language.Python.DSL

FinallySyntax (Raw TryExcept) TryExcept Source #
>>> tryE_ [line_ pass_] & finally_ [line_ pass_]
try:
    pass
finally:
    pass
>>> tryF_ [line_ pass_] [line_ (a .+= 1)] & finally_ [line_ pass_]
try:
    pass
finally:
    pass
>>> tryF_ [line_ pass_] & finally_ [line_ pass_]
try:
    pass
finally:
    pass
Instance details

Defined in Language.Python.DSL

Eq a => Eq (TryExcept v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: TryExcept v a -> TryExcept v a -> Bool #

(/=) :: TryExcept v a -> TryExcept v a -> Bool #

Show a => Show (TryExcept v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

showsPrec :: Int -> TryExcept v a -> ShowS #

show :: TryExcept v a -> String #

showList :: [TryExcept v a] -> ShowS #

HasIndents (TryExcept ([] :: [Type]) a) a Source # 
Instance details

Defined in Language.Python.Optics.Indents

Methods

_Indents :: Traversal' (TryExcept [] a) (Indents a) Source #

mkTryExcept :: [Raw Line] -> Raw Except -> Raw TryExcept Source #

Create a minimal valid TryExcept

data TryFinally v a Source #

Constructors

MkTryFinally 

Fields

Instances
HasTryFinally TryFinally Source # 
Instance details

Defined in Language.Python.Optics

Methods

_TryFinally :: Prism (TryFinally v a) (TryFinally [] a) (TryFinally v a) (TryFinally [] a) Source #

BodySyntax TryFinally Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw TryFinally -> f (Raw TryFinally) Source #

body :: Lens' (Raw TryFinally) (Raw Suite) Source #

AsLine TryFinally Source # 
Instance details

Defined in Language.Python.DSL

ExceptSyntax (Raw TryFinally) Source #
except_ :: [Raw Line] -> Raw TryFinally -> Raw TryExcept
exceptAs_ :: AsExceptAs => Raw e -> [Raw Line] -> Raw TryFinally -> Raw TryExcept
(someTryStatement :: Raw TryFinally) &
  except_ [line_ pass_]
(someTryStatement :: Raw TryFinally) &
  exceptAs_ (var_ "Exception" `as_` id_ "b") [line_ pass_]
Instance details

Defined in Language.Python.DSL

FinallySyntax (Raw TryFinally) TryFinally Source # 
Instance details

Defined in Language.Python.DSL

Eq a => Eq (TryFinally v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: TryFinally v a -> TryFinally v a -> Bool #

(/=) :: TryFinally v a -> TryFinally v a -> Bool #

Show a => Show (TryFinally v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

showsPrec :: Int -> TryFinally v a -> ShowS #

show :: TryFinally v a -> String #

showList :: [TryFinally v a] -> ShowS #

HasIndents (TryFinally ([] :: [Type]) a) a Source # 
Instance details

Defined in Language.Python.Optics.Indents

Methods

_Indents :: Traversal' (TryFinally [] a) (Indents a) Source #

(a ~ [Raw Line], b ~ Raw TryFinally) => FinallySyntax (a -> b) TryFinally Source # 
Instance details

Defined in Language.Python.DSL

Methods

finally_ :: [Raw Line] -> (a -> b) -> Raw TryFinally Source #

mkTryFinally :: [Raw Line] -> [Raw Line] -> Raw TryFinally Source #

Create a minimal valid TryFinally

data ExceptAs (v :: [*]) a Source #

Constructors

ExceptAs 

Fields

Instances
Validated ExceptAs Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

unvalidated :: Getter (ExceptAs v a) (ExceptAs [] a) Source #

HasExprs ExceptAs Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

_Exprs :: Traversal (ExceptAs v a) (ExceptAs [] a) (Expr v a) (Expr [] a) Source #

AsExceptAs ExceptAs Source # 
Instance details

Defined in Language.Python.DSL

As Expr Ident ExceptAs Source #

See exceptAs_

Instance details

Defined in Language.Python.DSL

Methods

as_ :: Raw Expr -> Raw Ident -> Raw ExceptAs Source #

Functor (ExceptAs v) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

fmap :: (a -> b) -> ExceptAs v a -> ExceptAs v b #

(<$) :: a -> ExceptAs v b -> ExceptAs v a #

Foldable (ExceptAs v) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

fold :: Monoid m => ExceptAs v m -> m #

foldMap :: Monoid m => (a -> m) -> ExceptAs v a -> m #

foldr :: (a -> b -> b) -> b -> ExceptAs v a -> b #

foldr' :: (a -> b -> b) -> b -> ExceptAs v a -> b #

foldl :: (b -> a -> b) -> b -> ExceptAs v a -> b #

foldl' :: (b -> a -> b) -> b -> ExceptAs v a -> b #

foldr1 :: (a -> a -> a) -> ExceptAs v a -> a #

foldl1 :: (a -> a -> a) -> ExceptAs v a -> a #

toList :: ExceptAs v a -> [a] #

null :: ExceptAs v a -> Bool #

length :: ExceptAs v a -> Int #

elem :: Eq a => a -> ExceptAs v a -> Bool #

maximum :: Ord a => ExceptAs v a -> a #

minimum :: Ord a => ExceptAs v a -> a #

sum :: Num a => ExceptAs v a -> a #

product :: Num a => ExceptAs v a -> a #

Traversable (ExceptAs v) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

traverse :: Applicative f => (a -> f b) -> ExceptAs v a -> f (ExceptAs v b) #

sequenceA :: Applicative f => ExceptAs v (f a) -> f (ExceptAs v a) #

mapM :: Monad m => (a -> m b) -> ExceptAs v a -> m (ExceptAs v b) #

sequence :: Monad m => ExceptAs v (m a) -> m (ExceptAs v a) #

Eq a => Eq (ExceptAs v a) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

(==) :: ExceptAs v a -> ExceptAs v a -> Bool #

(/=) :: ExceptAs v a -> ExceptAs v a -> Bool #

Show a => Show (ExceptAs v a) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

showsPrec :: Int -> ExceptAs v a -> ShowS #

show :: ExceptAs v a -> String #

showList :: [ExceptAs v a] -> ShowS #

HasNewlines (ExceptAs v a) Source # 
Instance details

Defined in Language.Python.Optics.Newlines

Methods

_Newlines :: Traversal' (ExceptAs v a) Newline Source #

class AsExceptAs s where Source #

Instances
AsExceptAs Expr Source # 
Instance details

Defined in Language.Python.DSL

AsExceptAs ExceptAs Source # 
Instance details

Defined in Language.Python.DSL

data Except v a Source #

Instances
Eq a => Eq (Except v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: Except v a -> Except v a -> Bool #

(/=) :: Except v a -> Except v a -> Bool #

Show a => Show (Except v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

showsPrec :: Int -> Except v a -> ShowS #

show :: Except v a -> String #

showList :: [Except v a] -> ShowS #

HasIndents (Except ([] :: [Type]) a) a Source # 
Instance details

Defined in Language.Python.Optics.Indents

Methods

_Indents :: Traversal' (Except [] a) (Indents a) Source #

mkExcept :: [Raw Line] -> Raw Except Source #

Create a minimal valid Except

data Finally v a Source #

Instances
Eq a => Eq (Finally v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: Finally v a -> Finally v a -> Bool #

(/=) :: Finally v a -> Finally v a -> Bool #

Show a => Show (Finally v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

showsPrec :: Int -> Finally v a -> ShowS #

show :: Finally v a -> String #

showList :: [Finally v a] -> ShowS #

HasIndents (Finally ([] :: [Type]) a) a Source # 
Instance details

Defined in Language.Python.Optics.Indents

Methods

_Indents :: Traversal' (Finally [] a) (Indents a) Source #

mkFinally :: [Raw Line] -> Raw Finally Source #

Create a minimal valid Finally

Lenses

teAnn :: forall v a. Lens' (TryExcept v a) a Source #

teIndents :: forall v a. Lens' (TryExcept v a) (Indents a) Source #

teTry :: forall v a. Lens' (TryExcept v a) [Whitespace] Source #

teBody :: forall v a. Lens' (TryExcept v a) (Suite v a) Source #

teExcepts :: forall v a. Lens' (TryExcept v a) (NonEmpty (Except v a)) Source #

teElse :: forall v a. Lens' (TryExcept v a) (Maybe (Else v a)) Source #

teFinally :: forall v a. Lens' (TryExcept v a) (Maybe (Finally v a)) Source #

exceptIndents :: forall v a. Lens' (Except v a) (Indents a) Source #

exceptExcept :: forall v a. Lens' (Except v a) [Whitespace] Source #

exceptExceptAs :: forall v a. Lens' (Except v a) (Maybe (ExceptAs v a)) Source #

exceptBody :: forall v a. Lens' (Except v a) (Suite v a) Source #

finallyIndents :: forall v a. Lens' (Finally v a) (Indents a) Source #

finallyFinally :: forall v a. Lens' (Finally v a) [Whitespace] Source #

finallyBody :: forall v a v. Lens (Finally v a) (Finally v a) (Suite v a) (Suite v a) Source #

With statements

with_ :: AsWithItem e => NonEmpty (Raw e) -> [Raw Line] -> Raw With Source #

with_ :: NonEmpty (Raw SimpleStatement) -> [Raw Line] -> Raw Statement
with_ :: NonEmpty (Raw WithItem) -> [Raw Line] -> Raw Statement
>>> with_ [var_ "a"] [line_ $ var_ "b"]
with a:
    b
>>> with_ [var_ "a" `as_` id_ "name"] [line_ $ var_ "b"]
with a as name:
    b
>>> with_ [withItem_ e Nothing] [line_ $ var_ "b"]
with a:
    b

data With v a Source #

Instances
HasWith With Source # 
Instance details

Defined in Language.Python.Optics

Methods

_With :: Prism (With v a) (With [] a) (With v a) (With [] a) Source #

AsyncSyntax With Source # 
Instance details

Defined in Language.Python.DSL

Methods

async_ :: Raw With -> Raw With Source #

BodySyntax With Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw With -> f (Raw With) Source #

body :: Lens' (Raw With) (Raw Suite) Source #

AsLine With Source # 
Instance details

Defined in Language.Python.DSL

Methods

line_ :: Raw With -> Raw Line Source #

Eq a => Eq (With v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: With v a -> With v a -> Bool #

(/=) :: With v a -> With v a -> Bool #

Show a => Show (With v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

showsPrec :: Int -> With v a -> ShowS #

show :: With v a -> String #

showList :: [With v a] -> ShowS #

HasIndents (With ([] :: [Type]) a) a Source # 
Instance details

Defined in Language.Python.Optics.Indents

Methods

_Indents :: Traversal' (With [] a) (Indents a) Source #

mkWith :: NonEmpty (Raw WithItem) -> [Raw Line] -> Raw With Source #

Create a minimal valid With

class AsWithItem s where Source #

Instances
AsWithItem Expr Source # 
Instance details

Defined in Language.Python.DSL

AsWithItem WithItem Source # 
Instance details

Defined in Language.Python.DSL

data WithItem (v :: [*]) a Source #

Constructors

WithItem 

Fields

Instances
Validated WithItem Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

unvalidated :: Getter (WithItem v a) (WithItem [] a) Source #

HasExprs WithItem Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

_Exprs :: Traversal (WithItem v a) (WithItem [] a) (Expr v a) (Expr [] a) Source #

AsWithItem WithItem Source # 
Instance details

Defined in Language.Python.DSL

As Expr Expr WithItem Source #

See with_

Instance details

Defined in Language.Python.DSL

Methods

as_ :: Raw Expr -> Raw Expr -> Raw WithItem Source #

Functor (WithItem v) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

fmap :: (a -> b) -> WithItem v a -> WithItem v b #

(<$) :: a -> WithItem v b -> WithItem v a #

Foldable (WithItem v) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

fold :: Monoid m => WithItem v m -> m #

foldMap :: Monoid m => (a -> m) -> WithItem v a -> m #

foldr :: (a -> b -> b) -> b -> WithItem v a -> b #

foldr' :: (a -> b -> b) -> b -> WithItem v a -> b #

foldl :: (b -> a -> b) -> b -> WithItem v a -> b #

foldl' :: (b -> a -> b) -> b -> WithItem v a -> b #

foldr1 :: (a -> a -> a) -> WithItem v a -> a #

foldl1 :: (a -> a -> a) -> WithItem v a -> a #

toList :: WithItem v a -> [a] #

null :: WithItem v a -> Bool #

length :: WithItem v a -> Int #

elem :: Eq a => a -> WithItem v a -> Bool #

maximum :: Ord a => WithItem v a -> a #

minimum :: Ord a => WithItem v a -> a #

sum :: Num a => WithItem v a -> a #

product :: Num a => WithItem v a -> a #

Traversable (WithItem v) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

traverse :: Applicative f => (a -> f b) -> WithItem v a -> f (WithItem v b) #

sequenceA :: Applicative f => WithItem v (f a) -> f (WithItem v a) #

mapM :: Monad m => (a -> m b) -> WithItem v a -> m (WithItem v b) #

sequence :: Monad m => WithItem v (m a) -> m (WithItem v a) #

Eq a => Eq (WithItem v a) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

(==) :: WithItem v a -> WithItem v a -> Bool #

(/=) :: WithItem v a -> WithItem v a -> Bool #

Show a => Show (WithItem v a) Source # 
Instance details

Defined in Language.Python.Syntax.Statement

Methods

showsPrec :: Int -> WithItem v a -> ShowS #

show :: WithItem v a -> String #

showList :: [WithItem v a] -> ShowS #

HasNewlines (WithItem v a) Source # 
Instance details

Defined in Language.Python.Optics.Newlines

Methods

_Newlines :: Traversal' (WithItem v a) Newline Source #

Lenses

withAnn :: forall v a. Lens' (With v a) a Source #

withIndents :: forall v a. Lens' (With v a) (Indents a) Source #

withAsync :: forall v a. Lens' (With v a) (Maybe (NonEmpty Whitespace)) Source #

withWith :: forall v a. Lens' (With v a) [Whitespace] Source #

withItems :: forall v a. Lens' (With v a) (CommaSep1 (WithItem v a)) Source #

withBody :: forall v a. Lens' (With v a) (Suite v a) Source #

Flow control

Else clauses

If, While, For, and TryExcept statements can have an Else component.

else_ is considered to be a modifier on these structures.

---

If ... Else:

>>> if_ false_ [line_ pass_] & else_ [line_ pass_]
if False:
    pass
else:
    pass

---

While ... Else:

>>> while_ false_ [line_ pass_] & else_ [line_ pass_]
while False:
    pass
else:
    pass

---

For ... Else:

>>> for_ (var_ "a" `in_` [var_ b]) [line_ pass_] & else_ [line_ pass_]
for a in b:
    pass
else:
    pass

---

TryExcept ... Else:

>>> tryE_ [line_ pass_] & except_ [line_ pass_] & else_ [line_ pass_]
try:
    pass
except:
    pass
else:
    pass

else_ :: ElseSyntax s => [Raw Line] -> Raw s -> Raw s Source #

class ElseSyntax s where Source #

Methods

getElse :: Raw s -> Maybe (Raw Else) Source #

setElse :: [Whitespace] -> Maybe (Raw Else) -> Raw s -> Raw s Source #

Instances
ElseSyntax While Source # 
Instance details

Defined in Language.Python.DSL

ElseSyntax If Source # 
Instance details

Defined in Language.Python.DSL

ElseSyntax For Source # 
Instance details

Defined in Language.Python.DSL

ElseSyntax TryExcept Source # 
Instance details

Defined in Language.Python.DSL

Break

For loops

For loops are built using for_ syntax:

>>> for_ (var_ "a" `in_` [1, 2, 3]) [line_ (call_ "print" [var_ "a"])]
for a in 1, 2, 3:
    print(a)

See also: ForSyntax

data For v a Source #

Instances
HasFor For Source # 
Instance details

Defined in Language.Python.Optics

Methods

_For :: Prism (For v a) (For [] a) (For v a) (For [] a) Source #

AsyncSyntax For Source # 
Instance details

Defined in Language.Python.DSL

Methods

async_ :: Raw For -> Raw For Source #

ElseSyntax For Source # 
Instance details

Defined in Language.Python.DSL

BodySyntax For Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw For -> f (Raw For) Source #

body :: Lens' (Raw For) (Raw Suite) Source #

AsLine For Source # 
Instance details

Defined in Language.Python.DSL

Methods

line_ :: Raw For -> Raw Line Source #

Eq a => Eq (For v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: For v a -> For v a -> Bool #

(/=) :: For v a -> For v a -> Bool #

Show a => Show (For v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

showsPrec :: Int -> For v a -> ShowS #

show :: For v a -> String #

showList :: [For v a] -> ShowS #

HasIndents (For ([] :: [Type]) a) a Source # 
Instance details

Defined in Language.Python.Optics.Indents

Methods

_Indents :: Traversal' (For [] a) (Indents a) Source #

_For :: HasFor s => Prism (s v a) (s '[] a) (For v a) (For '[] a) Source #

mkFor :: Raw Expr -> [Raw Expr] -> [Raw Line] -> Raw For Source #

If statements

elif_ :: Raw Expr -> [Raw Line] -> Raw If -> Raw If Source #

data If v a Source #

Constructors

MkIf 

Fields

Instances
HasIf If Source # 
Instance details

Defined in Language.Python.Optics

Methods

_If :: Prism (If v a) (If [] a) (If v a) (If [] a) Source #

ElseSyntax If Source # 
Instance details

Defined in Language.Python.DSL

BodySyntax If Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw If -> f (Raw If) Source #

body :: Lens' (Raw If) (Raw Suite) Source #

AsLine If Source # 
Instance details

Defined in Language.Python.DSL

Methods

line_ :: Raw If -> Raw Line Source #

Eq a => Eq (If v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: If v a -> If v a -> Bool #

(/=) :: If v a -> If v a -> Bool #

Show a => Show (If v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

showsPrec :: Int -> If v a -> ShowS #

show :: If v a -> String #

showList :: [If v a] -> ShowS #

HasIndents (If ([] :: [Type]) a) a Source # 
Instance details

Defined in Language.Python.Optics.Indents

Methods

_Indents :: Traversal' (If [] a) (Indents a) Source #

mkIf :: Raw Expr -> [Raw Line] -> Raw If Source #

Create a minimal valid If

data Elif v a Source #

Constructors

MkElif 
Instances
BodySyntax Elif Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw Elif -> f (Raw Elif) Source #

body :: Lens' (Raw Elif) (Raw Suite) Source #

Eq a => Eq (Elif v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: Elif v a -> Elif v a -> Bool #

(/=) :: Elif v a -> Elif v a -> Bool #

Show a => Show (Elif v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

showsPrec :: Int -> Elif v a -> ShowS #

show :: Elif v a -> String #

showList :: [Elif v a] -> ShowS #

HasIndents (Elif ([] :: [Type]) a) a Source # 
Instance details

Defined in Language.Python.Optics.Indents

Methods

_Indents :: Traversal' (Elif [] a) (Indents a) Source #

mkElif :: Raw Expr -> [Raw Line] -> Raw Elif Source #

Create a minimal valid Elif

data Else v a Source #

Constructors

MkElse 
Instances
BodySyntax Else Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw Else -> f (Raw Else) Source #

body :: Lens' (Raw Else) (Raw Suite) Source #

Eq a => Eq (Else v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: Else v a -> Else v a -> Bool #

(/=) :: Else v a -> Else v a -> Bool #

Show a => Show (Else v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

showsPrec :: Int -> Else v a -> ShowS #

show :: Else v a -> String #

showList :: [Else v a] -> ShowS #

HasIndents (Else ([] :: [Type]) a) a Source # 
Instance details

Defined in Language.Python.Optics.Indents

Methods

_Indents :: Traversal' (Else [] a) (Indents a) Source #

mkElse :: [Raw Line] -> Raw Else Source #

Create a minimal valid Else

Lenses

ifAnn :: forall v a. Lens' (If v a) a Source #

ifIndents :: forall v a. Lens' (If v a) (Indents a) Source #

ifIf :: forall v a. Lens' (If v a) [Whitespace] Source #

ifCond :: forall v a. Lens' (If v a) (Expr v a) Source #

ifBody :: forall v a. Lens' (If v a) (Suite v a) Source #

ifElifs :: forall v a. Lens' (If v a) [Elif v a] Source #

ifElse :: forall v a. Lens' (If v a) (Maybe (Else v a)) Source #

elifIndents :: forall v a. Lens' (Elif v a) (Indents a) Source #

elifElif :: forall v a. Lens' (Elif v a) [Whitespace] Source #

elifCond :: forall v a. Lens' (Elif v a) (Expr v a) Source #

elifBody :: forall v a. Lens' (Elif v a) (Suite v a) Source #

elseIndents :: forall v a. Lens' (Else v a) (Indents a) Source #

elseElse :: forall v a. Lens' (Else v a) [Whitespace] Source #

elseBody :: forall v a v. Lens (Else v a) (Else v a) (Suite v a) (Suite v a) Source #

Pass

pass_ :: Raw Statement Source #

>>> pass_
pass

Return

return_ :: Raw Expr -> Raw Statement Source #

>>> return_ (var_ "a")
return a

While loops

data While v a Source #

Constructors

MkWhile 
Instances
HasWhile While Source # 
Instance details

Defined in Language.Python.Optics

Methods

_While :: Prism (While v a) (While [] a) (While v a) (While [] a) Source #

ElseSyntax While Source # 
Instance details

Defined in Language.Python.DSL

BodySyntax While Source # 
Instance details

Defined in Language.Python.DSL

Methods

body_ :: Functor f => ([Raw Line] -> f [Raw Line]) -> Raw While -> f (Raw While) Source #

body :: Lens' (Raw While) (Raw Suite) Source #

AsLine While Source # 
Instance details

Defined in Language.Python.DSL

Methods

line_ :: Raw While -> Raw Line Source #

Eq a => Eq (While v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: While v a -> While v a -> Bool #

(/=) :: While v a -> While v a -> Bool #

Show a => Show (While v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

showsPrec :: Int -> While v a -> ShowS #

show :: While v a -> String #

showList :: [While v a] -> ShowS #

HasIndents (While ([] :: [Type]) a) a Source # 
Instance details

Defined in Language.Python.Optics.Indents

Methods

_Indents :: Traversal' (While [] a) (Indents a) Source #

mkWhile :: Raw Expr -> [Raw Line] -> Raw While Source #

Create a minimal valid While

Lenses

whileAnn :: forall v a. Lens' (While v a) a Source #

whileIndents :: forall v a. Lens' (While v a) (Indents a) Source #

whileWhile :: forall v a. Lens' (While v a) [Whitespace] Source #

whileCond :: forall v a. Lens' (While v a) (Expr v a) Source #

whileBody :: forall v a. Lens' (While v a) (Suite v a) Source #

Expressions

expr_ :: Raw Expr -> Raw Statement Source #

Turns an SimpleStatement into a Statement

>>> expr_ (int_ 3)
3

await

await_ :: Raw Expr -> Raw Expr Source #

>>> await (var_ "a")
await a

... if ... else ...

ifThenElse_ :: Raw Expr -> Raw Expr -> Raw Expr -> Raw Expr Source #

>>> ifThenElse_ (var_ "a") (var_ "b") (var_ "c")
a if b else c

Generators

gen_ :: Raw (Comprehension Expr) -> Raw Expr Source #

>>> gen_ $ comp_ (var_ "a") (for_ $ var_ "a" `in_` list_ [li_ $ int_ 1, li_ $ int_ 2, li_ $ int_ 3]) [if_ $ var_ "a" .== 2]
(a for a in [1, 2, 3] if a == 2)

yield

yield_ :: [Raw Expr] -> Raw Expr Source #

>>> yield_ []
yield
>>> yield_ [var_ "a"]
yield a
>>> yield_ [var_ "a", var_ "b"]
yield a, b

yield from ...

yieldFrom_ :: Raw Expr -> Raw Expr Source #

>>> yieldFrom_ (var_ "a")
yield from a

Tuples

tuple_ :: [Raw TupleItem] -> Raw Expr Source #

>>> tuple_ []
()
>>> tuple_ [ti_ $ var_ "a"]
a,
>>> tuple_ [s_ $ var_ "a"]
(*a),
>>> tuple_ [ti_ $ var_ "a", ti_ $ var_ "b"]
a, b
>>> tuple_ [ti_ $ var_ "a", s_ $ var_ "b"]
a, *b

data Tuple v a Source #

Constructors

MkTuple 
Instances
Eq a => Eq (Tuple v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: Tuple v a -> Tuple v a -> Bool #

(/=) :: Tuple v a -> Tuple v a -> Bool #

Show a => Show (Tuple v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

showsPrec :: Int -> Tuple v a -> ShowS #

show :: Tuple v a -> String #

showList :: [Tuple v a] -> ShowS #

class AsTupleItem e where Source #

Methods

ti_ :: Raw e -> Raw TupleItem Source #

Create a TupleItem

Instances
AsTupleItem Expr Source # 
Instance details

Defined in Language.Python.DSL

AsTupleItem TupleItem Source # 
Instance details

Defined in Language.Python.DSL

data TupleItem (v :: [*]) a Source #

a or *a

Used to construct tuples, e.g. (1, x, **c)

Instances
Validated TupleItem Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

unvalidated :: Getter (TupleItem v a) (TupleItem [] a) Source #

HasExprs TupleItem Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

_Exprs :: Traversal (TupleItem v a) (TupleItem [] a) (Expr v a) (Expr [] a) Source #

AsTupleItem TupleItem Source # 
Instance details

Defined in Language.Python.DSL

StarSyntax Expr TupleItem Source #

See tuple_

Instance details

Defined in Language.Python.DSL

Methods

s_ :: Raw Expr -> Raw TupleItem Source #

Functor (TupleItem v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fmap :: (a -> b) -> TupleItem v a -> TupleItem v b #

(<$) :: a -> TupleItem v b -> TupleItem v a #

Foldable (TupleItem v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fold :: Monoid m => TupleItem v m -> m #

foldMap :: Monoid m => (a -> m) -> TupleItem v a -> m #

foldr :: (a -> b -> b) -> b -> TupleItem v a -> b #

foldr' :: (a -> b -> b) -> b -> TupleItem v a -> b #

foldl :: (b -> a -> b) -> b -> TupleItem v a -> b #

foldl' :: (b -> a -> b) -> b -> TupleItem v a -> b #

foldr1 :: (a -> a -> a) -> TupleItem v a -> a #

foldl1 :: (a -> a -> a) -> TupleItem v a -> a #

toList :: TupleItem v a -> [a] #

null :: TupleItem v a -> Bool #

length :: TupleItem v a -> Int #

elem :: Eq a => a -> TupleItem v a -> Bool #

maximum :: Ord a => TupleItem v a -> a #

minimum :: Ord a => TupleItem v a -> a #

sum :: Num a => TupleItem v a -> a #

product :: Num a => TupleItem v a -> a #

Traversable (TupleItem v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

traverse :: Applicative f => (a -> f b) -> TupleItem v a -> f (TupleItem v b) #

sequenceA :: Applicative f => TupleItem v (f a) -> f (TupleItem v a) #

mapM :: Monad m => (a -> m b) -> TupleItem v a -> m (TupleItem v b) #

sequence :: Monad m => TupleItem v (m a) -> m (TupleItem v a) #

Eq a => Eq (TupleItem v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

(==) :: TupleItem v a -> TupleItem v a -> Bool #

(/=) :: TupleItem v a -> TupleItem v a -> Bool #

Show a => Show (TupleItem v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

showsPrec :: Int -> TupleItem v a -> ShowS #

show :: TupleItem v a -> String #

showList :: [TupleItem v a] -> ShowS #

HasTrailingWhitespace (TupleItem v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

HasNewlines (TupleItem v a) Source # 
Instance details

Defined in Language.Python.Optics.Newlines

Methods

_Newlines :: Traversal' (TupleItem v a) Newline Source #

Function calls

call_ :: Raw Expr -> [Raw Arg] -> Raw Expr Source #

>>> call_ "f" [p_ $ var_ "x"]
f(x)
>>> call_ "f" [p_ $ var_ "x", k_ "y" 2]
f(x, y=2)
>>> call_ "f" [p_ $ var_ "x", k_ "y" 2, s_ "z"]
f(x, y=2, *z)
>>> call_ "f" [p_ $ var_ "x", k_ "y" 2, s_ "z", ss_ "w"]
f(x, y=2, *z, **w)

data Call v a Source #

Instances
ArgumentsSyntax Call Source # 
Instance details

Defined in Language.Python.DSL

Eq a => Eq (Call v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: Call v a -> Call v a -> Bool #

(/=) :: Call v a -> Call v a -> Bool #

Show a => Show (Call v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

showsPrec :: Int -> Call v a -> ShowS #

show :: Call v a -> String #

showList :: [Call v a] -> ShowS #

mkCall :: Raw Expr -> Raw Call Source #

Create a minimal valid Call

Lenses

callAnn :: forall v a. Lens' (Call v a) a Source #

callFunction :: forall v a. Lens' (Call v a) (Expr v a) Source #

callLeftParen :: forall v a. Lens' (Call v a) [Whitespace] Source #

callArguments :: forall v a. Lens' (Call v a) (Maybe (CommaSep1' (Arg v a))) Source #

callRightParen :: forall v a. Lens' (Call v a) [Whitespace] Source #

Literals

None

none_ :: Raw Expr Source #

>>> none_
None

data None (v :: [*]) a Source #

Constructors

MkNone 
Instances
Eq a => Eq (None v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

(==) :: None v a -> None v a -> Bool #

(/=) :: None v a -> None v a -> Bool #

Show a => Show (None v a) Source # 
Instance details

Defined in Language.Python.Syntax.Types

Methods

showsPrec :: Int -> None v a -> ShowS #

show :: None v a -> String #

showList :: [None v a] -> ShowS #

_None :: Prism (Expr v a) (Expr '[] a) (None v a) (None '[] a) Source #

Lenses

noneAnn :: forall v a v a. Lens (None v a) (None v a) a a Source #

noneWhitespace :: forall v a v. Lens (None v a) (None v a) [Whitespace] [Whitespace] Source #

Strings

str_ :: String -> Raw Expr Source #

Double-quoted string

>>> str_ "asdf"
"asdf"

str'_ :: String -> Raw Expr Source #

Single-quoted string

>>> str_ "asdf"
'asdf'

longStr_ :: String -> Raw Expr Source #

Long double-quoted string

>>> longStr_ "asdf"
"""asdf"""

longStr'_ :: String -> Raw Expr Source #

Long single-quoted string

>>> longStr'_ "asdf"
'''asdf'''

Integers

int_ :: Integer -> Raw Expr Source #

Raw SimpleStatement has a Num instance, but sometimes we need to name integers explicitly

>>> int_ 10
10

Booleans

true_ :: Raw Expr Source #

>>> true_
True

false_ :: Raw Expr Source #

>>> false_
False

Ellipses

ellipsis_ :: Raw Expr Source #

>>> ellipsis_
...

Lists

class AsList s where Source #

>>> list_ [li_ $ var_ "a"]
[a]
>>> list_ [s_ $ var_ "a"]
[*a]
>>> list_ [li_ $ var_ "a", s_ $ var_ "b"]
[a, *b]
>>> list_ $ comp_ (var_ "a") (for_ $ var_ "a" `in_` list_ [li_ $ int_ 1, li_ $ int_ 2, li_ $ int_ 3]) [if_ $ var_ "a" .== 2]
[a for a in [1, 2, 3] if a == 2]

Methods

list_ :: s -> Raw Expr Source #

Instances
e ~ Raw ListItem => AsList [e] Source # 
Instance details

Defined in Language.Python.DSL

Methods

list_ :: [e] -> Raw Expr Source #

e ~ Comprehension Expr => AsList (Raw e) Source # 
Instance details

Defined in Language.Python.DSL

Methods

list_ :: Raw e -> Raw Expr Source #

class AsListItem s where Source #

Methods

li_ :: Raw s -> Raw ListItem Source #

Create a ListItem

Instances
AsListItem Expr Source # 
Instance details

Defined in Language.Python.DSL

Methods

li_ :: Raw Expr -> Raw ListItem Source #

AsListItem ListItem Source # 
Instance details

Defined in Language.Python.DSL

data ListItem (v :: [*]) a Source #

a or *a

Used to construct lists, e.g. [ 1, x, **c ]

https://docs.python.org/3/reference/expressions.html#list-displays

Instances
Validated ListItem Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

unvalidated :: Getter (ListItem v a) (ListItem [] a) Source #

HasExprs ListItem Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

_Exprs :: Traversal (ListItem v a) (ListItem [] a) (Expr v a) (Expr [] a) Source #

AsListItem ListItem Source # 
Instance details

Defined in Language.Python.DSL

StarSyntax Expr ListItem Source #

See list_

Instance details

Defined in Language.Python.DSL

Methods

s_ :: Raw Expr -> Raw ListItem Source #

Functor (ListItem v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fmap :: (a -> b) -> ListItem v a -> ListItem v b #

(<$) :: a -> ListItem v b -> ListItem v a #

Foldable (ListItem v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fold :: Monoid m => ListItem v m -> m #

foldMap :: Monoid m => (a -> m) -> ListItem v a -> m #

foldr :: (a -> b -> b) -> b -> ListItem v a -> b #

foldr' :: (a -> b -> b) -> b -> ListItem v a -> b #

foldl :: (b -> a -> b) -> b -> ListItem v a -> b #

foldl' :: (b -> a -> b) -> b -> ListItem v a -> b #

foldr1 :: (a -> a -> a) -> ListItem v a -> a #

foldl1 :: (a -> a -> a) -> ListItem v a -> a #

toList :: ListItem v a -> [a] #

null :: ListItem v a -> Bool #

length :: ListItem v a -> Int #

elem :: Eq a => a -> ListItem v a -> Bool #

maximum :: Ord a => ListItem v a -> a #

minimum :: Ord a => ListItem v a -> a #

sum :: Num a => ListItem v a -> a #

product :: Num a => ListItem v a -> a #

Traversable (ListItem v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

traverse :: Applicative f => (a -> f b) -> ListItem v a -> f (ListItem v b) #

sequenceA :: Applicative f => ListItem v (f a) -> f (ListItem v a) #

mapM :: Monad m => (a -> m b) -> ListItem v a -> m (ListItem v b) #

sequence :: Monad m => ListItem v (m a) -> m (ListItem v a) #

Eq a => Eq (ListItem v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

(==) :: ListItem v a -> ListItem v a -> Bool #

(/=) :: ListItem v a -> ListItem v a -> Bool #

Show a => Show (ListItem v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

showsPrec :: Int -> ListItem v a -> ShowS #

show :: ListItem v a -> String #

showList :: [ListItem v a] -> ShowS #

HasTrailingWhitespace (ListItem v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

HasNewlines (ListItem v a) Source # 
Instance details

Defined in Language.Python.Optics.Newlines

Methods

_Newlines :: Traversal' (ListItem v a) Newline Source #

Dictionaries

class AsDict s where Source #

>>> dict_ [var_ "a" .: 1]
{a: 1}
>>> dict_ [ss_ $ var_ "a"]
{**a}
>>> dict_ [var_ "a" .: 1, ss_ $ var_ "b"]
{a: 1, **b}
>>> dict_ $ comp_ (var_ "a" .: 1) (for_ $ var_ "a" `in_` list_ [li_ $ int_ 1, li_ $ int_ 2, li_ $ int_ 3]) [if_ $ var_ "a" .== 2]
{a: 1 for a in [1, 2, 3] if a == 2}

Methods

dict_ :: s -> Raw Expr Source #

Instances
e ~ Raw DictItem => AsDict [e] Source #
dict_ :: [Raw DictItem] -> Raw SimpleStatement
Instance details

Defined in Language.Python.DSL

Methods

dict_ :: [e] -> Raw Expr Source #

e ~ Comprehension DictItem => AsDict (Raw e) Source #
dict_ :: Raw (Comprehension DictItem) -> Raw SimpleStatement
Instance details

Defined in Language.Python.DSL

Methods

dict_ :: Raw e -> Raw Expr Source #

data DictItem (v :: [*]) a Source #

a : b or **a

Used to construct dictionaries, e.g. { 1: a, 2: b, **c }

https://docs.python.org/3/reference/expressions.html#dictionary-displays

Instances
Validated DictItem Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

unvalidated :: Getter (DictItem v a) (DictItem [] a) Source #

DoubleStarSyntax Expr DictItem Source #

See dict_

Instance details

Defined in Language.Python.DSL

Methods

ss_ :: Raw Expr -> Raw DictItem Source #

ColonSyntax Expr DictItem Source #

Constructing dictionary items

(.:) :: Raw SimpleStatement -> Raw SimpleStatement -> Raw DictItem
Instance details

Defined in Language.Python.DSL

Methods

(.:) :: Raw Expr -> Raw Expr -> Raw DictItem Source #

Functor (DictItem v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fmap :: (a -> b) -> DictItem v a -> DictItem v b #

(<$) :: a -> DictItem v b -> DictItem v a #

Foldable (DictItem v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fold :: Monoid m => DictItem v m -> m #

foldMap :: Monoid m => (a -> m) -> DictItem v a -> m #

foldr :: (a -> b -> b) -> b -> DictItem v a -> b #

foldr' :: (a -> b -> b) -> b -> DictItem v a -> b #

foldl :: (b -> a -> b) -> b -> DictItem v a -> b #

foldl' :: (b -> a -> b) -> b -> DictItem v a -> b #

foldr1 :: (a -> a -> a) -> DictItem v a -> a #

foldl1 :: (a -> a -> a) -> DictItem v a -> a #

toList :: DictItem v a -> [a] #

null :: DictItem v a -> Bool #

length :: DictItem v a -> Int #

elem :: Eq a => a -> DictItem v a -> Bool #

maximum :: Ord a => DictItem v a -> a #

minimum :: Ord a => DictItem v a -> a #

sum :: Num a => DictItem v a -> a #

product :: Num a => DictItem v a -> a #

Traversable (DictItem v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

traverse :: Applicative f => (a -> f b) -> DictItem v a -> f (DictItem v b) #

sequenceA :: Applicative f => DictItem v (f a) -> f (DictItem v a) #

mapM :: Monad m => (a -> m b) -> DictItem v a -> m (DictItem v b) #

sequence :: Monad m => DictItem v (m a) -> m (DictItem v a) #

Eq a => Eq (DictItem v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

(==) :: DictItem v a -> DictItem v a -> Bool #

(/=) :: DictItem v a -> DictItem v a -> Bool #

Show a => Show (DictItem v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

showsPrec :: Int -> DictItem v a -> ShowS #

show :: DictItem v a -> String #

showList :: [DictItem v a] -> ShowS #

HasTrailingWhitespace (DictItem v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

HasNewlines (DictItem v a) Source # 
Instance details

Defined in Language.Python.Optics.Newlines

Methods

_Newlines :: Traversal' (DictItem v a) Newline Source #

Sets

class AsSet s where Source #

>>> set_ []
set()
>>> set_ [si_ $ var_ "a"]
{a}
>>> set_ [s_ $ var_ "a"]
{*a}
>>> set_ [si_ $ var_ "a", s_ $ var_ "b"]
{a, *b}
>>> set_ $ comp_ (var_ "a") (for_ $ var_ "a" `in_` set_ [si_ $ int_ 1, si_ $ int_ 2, si_ $ int_ 3]) [if_ $ var_ "a" .== 2]
{a for a in [1, 2, 3] if a == 2}

Methods

set_ :: s -> Raw Expr Source #

Instances
e ~ Raw SetItem => AsSet [e] Source # 
Instance details

Defined in Language.Python.DSL

Methods

set_ :: [e] -> Raw Expr Source #

e ~ Comprehension SetItem => AsSet (Raw e) Source # 
Instance details

Defined in Language.Python.DSL

Methods

set_ :: Raw e -> Raw Expr Source #

class AsSetItem s where Source #

Methods

si_ :: Raw s -> Raw SetItem Source #

Create a SetItem

Instances
AsSetItem Expr Source # 
Instance details

Defined in Language.Python.DSL

Methods

si_ :: Raw Expr -> Raw SetItem Source #

AsSetItem SetItem Source # 
Instance details

Defined in Language.Python.DSL

data SetItem (v :: [*]) a Source #

a or *a

Used to construct sets, e.g. { 1, x, **c }

https://docs.python.org/3/reference/expressions.html#set-displays

Instances
Validated SetItem Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

unvalidated :: Getter (SetItem v a) (SetItem [] a) Source #

HasExprs SetItem Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

_Exprs :: Traversal (SetItem v a) (SetItem [] a) (Expr v a) (Expr [] a) Source #

AsSetItem SetItem Source # 
Instance details

Defined in Language.Python.DSL

StarSyntax Expr SetItem Source #

See set_

Instance details

Defined in Language.Python.DSL

Methods

s_ :: Raw Expr -> Raw SetItem Source #

Functor (SetItem v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fmap :: (a -> b) -> SetItem v a -> SetItem v b #

(<$) :: a -> SetItem v b -> SetItem v a #

Foldable (SetItem v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

fold :: Monoid m => SetItem v m -> m #

foldMap :: Monoid m => (a -> m) -> SetItem v a -> m #

foldr :: (a -> b -> b) -> b -> SetItem v a -> b #

foldr' :: (a -> b -> b) -> b -> SetItem v a -> b #

foldl :: (b -> a -> b) -> b -> SetItem v a -> b #

foldl' :: (b -> a -> b) -> b -> SetItem v a -> b #

foldr1 :: (a -> a -> a) -> SetItem v a -> a #

foldl1 :: (a -> a -> a) -> SetItem v a -> a #

toList :: SetItem v a -> [a] #

null :: SetItem v a -> Bool #

length :: SetItem v a -> Int #

elem :: Eq a => a -> SetItem v a -> Bool #

maximum :: Ord a => SetItem v a -> a #

minimum :: Ord a => SetItem v a -> a #

sum :: Num a => SetItem v a -> a #

product :: Num a => SetItem v a -> a #

Traversable (SetItem v) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

traverse :: Applicative f => (a -> f b) -> SetItem v a -> f (SetItem v b) #

sequenceA :: Applicative f => SetItem v (f a) -> f (SetItem v a) #

mapM :: Monad m => (a -> m b) -> SetItem v a -> m (SetItem v b) #

sequence :: Monad m => SetItem v (m a) -> m (SetItem v a) #

Eq a => Eq (SetItem v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

(==) :: SetItem v a -> SetItem v a -> Bool #

(/=) :: SetItem v a -> SetItem v a -> Bool #

Show a => Show (SetItem v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

showsPrec :: Int -> SetItem v a -> ShowS #

show :: SetItem v a -> String #

showList :: [SetItem v a] -> ShowS #

HasTrailingWhitespace (SetItem v a) Source # 
Instance details

Defined in Language.Python.Syntax.Expr

Methods

trailingWhitespace :: Lens' (SetItem v a) [Whitespace] Source #

HasNewlines (SetItem v a) Source # 
Instance details

Defined in Language.Python.Optics.Newlines

Methods

_Newlines :: Traversal' (SetItem v a) Newline Source #

Lambdas

lambda_ :: [Raw Param] -> Raw Expr -> Raw Expr Source #

>>> lambda_ [p_ "x"] "x"
lambda x: x
>>> lambda_ [p_ "x", k_ "y" 2] ("x" .+ "y")
lambda x, y=2: x + y
>>> lambda_ [p_ "x", k_ "y" 2, s_ "z"] "a"
lambda x, y=2, *z: a
>>> lambda_ [p_ "x", k_ "y" 2, s_ "z", ss_ "w"] "a"
lambda x, y=2, *z, **w: a

Subscripting

subs_ :: Raw Expr -> Raw Expr -> Raw Expr Source #

>>> subs_ (var_ "a") (int_ 1)
a[1]
>>> subs_ (var_ "a") (tuple_ [ti_ $ int_ 1])
a[1,]
>>> subs_ (var_ "a") (tuple_ [ti_ $ int_ 1, ti_ $ int_ 2])
a[1, 2]
>>> subs_ (var_ "a") (tuple_ [s_ $ var_ "b"])
a[((*b),)]
>>> subs_ (var_ "a") (tuple_ [ti_ $ int_ 1, s_ $ var_ "b"])
a[(1, *b)]

Slicing

sliceF_ :: Raw Expr -> Raw Expr Source #

Slice *from* x

>>> subs_ (var_ "a") (sliceF_ $ int_ 0)
a[1:]
>>> sliceF_ $ int_ 0
slice(1, None, None)

sliceFS_ :: Raw Expr -> Raw Expr -> Raw Expr Source #

Slice *from* x, with *step* y

>>> subs_ (var_ "a") (sliceFS_ (int_ 0) (int_ 2))
a[1::2]
>>> sliceFS_ (int_ 0) (int_ 2)
slice(1, None, 2)

sliceT_ :: Raw Expr -> Raw Expr Source #

Slice To x

>>> subs_ (var_ "a") (sliceT_ $ int_ 10)
a[:10]
>>> sliceT_ $ int_ 10
slice(None, 10, None)

sliceTS_ :: Raw Expr -> Raw Expr -> Raw Expr Source #

Slice To x, with Step y

>>> subs_ (var_ "a") (sliceTS_ (int_ 10) (int_ 2))
a[:10:2]
>>> sliceTS_ (int_ 10) (int_ 2)
slice(None, 10, 2)

sliceFT_ :: Raw Expr -> Raw Expr -> Raw Expr Source #

Slice From x To y

>>> subs_ (var_ "a") (sliceFT_ (int_ 1) (int_ 10))
a[1:10]
>>> sliceFT_ (int_ 1) (int_ 10)
slice(1, 10, None)

sliceFTS_ :: Raw Expr -> Raw Expr -> Raw Expr -> Raw Expr Source #

Slice From x To y, with Step z

>>> subs_ (var_ "a") (sliceFTS_ (int_ 1) (int_ 10) (int_ 2))
a[1:10:2]
>>> sliceFTS_ (int_ 1) (int_ 10) (int_ 2)
slice(1, 10, 2)

sliceS_ :: Raw Expr -> Raw Expr Source #

Slice with *step* x

>>> subs_ (var_ "a") (sliceS_ $ int_ (-1))
a[::-1]
>>> sliceS_ $ int_ (-1)
slice(None, None, -1)

fullSlice_ :: Raw Expr Source #

The slice with no bounds

>>> subs_ (var_ "a") fullSlice_
a[:]
>>> fullSlice_
slice(None, None, None)

slice_ :: Maybe (Raw Expr) -> Maybe (Raw Expr) -> Maybe (Raw Expr) -> Raw Expr Source #

A slice object

Represents a call to a function named slice, with 3 arguments. If an argument is a Nothing then it becomes None, and if the argument is a Just then the contents are extracted.

Dereferencing

(/>) :: Raw Expr -> Raw Ident -> Raw Expr infixl 9 Source #

>>> var_ "a" /> var_ "b"
a.b

Unary operators

not_ :: Raw Expr -> Raw Expr Source #

not a

Binary operators

Comparison, bitwise, and arithmetic operators have precedences that are consistent with their Python counterparts. This meansPython expressions can be translated to kellSyntax with minimal parentheses.

Note: this doesn't apply to unary operators (because kellSyntax doesn't have unary operators), or the boolean operations and_ and or_ (because we ran out of precedence levels)

Boolean operations

or_ :: Raw Expr -> Raw Expr -> Raw Expr Source #

a or b

Does not have a precedence

and_ :: Raw Expr -> Raw Expr -> Raw Expr Source #

a and b

Does not have a precedence

Comparison operations

is_ :: Raw Expr -> Raw Expr -> Raw Expr infixl 1 Source #

a is b

isNot_ :: Raw Expr -> Raw Expr -> Raw Expr infixl 1 Source #

a is not b

notIn_ :: Raw Expr -> Raw Expr -> Raw Expr infixl 1 Source #

a not in b

(.==) :: Raw Expr -> Raw Expr -> Raw Expr infixl 1 Source #

a == b

(.>) :: Raw Expr -> Raw Expr -> Raw Expr infixl 1 Source #

a > b

(.>=) :: Raw Expr -> Raw Expr -> Raw Expr infixl 1 Source #

a >= b

(.<) :: Raw Expr -> Raw Expr -> Raw Expr infixl 1 Source #

a < b

(.<=) :: Raw Expr -> Raw Expr -> Raw Expr infixl 1 Source #

a <= b

(.!=) :: Raw Expr -> Raw Expr -> Raw Expr infixl 1 Source #

a != b

Bitwise operations

(.|) :: Raw Expr -> Raw Expr -> Raw Expr infixl 2 Source #

a | b

(.^) :: Raw Expr -> Raw Expr -> Raw Expr infixl 3 Source #

a ^ b

(.&) :: Raw Expr -> Raw Expr -> Raw Expr infixl 4 Source #

a & b

(.<<) :: Raw Expr -> Raw Expr -> Raw Expr infixl 5 Source #

a << b

(.>>) :: Raw Expr -> Raw Expr -> Raw Expr infixl 5 Source #

a >> b

Arithmetic operations

(.-) :: Raw Expr -> Raw Expr -> Raw Expr infixl 6 Source #

a - b

(.+) :: Raw Expr -> Raw Expr -> Raw Expr infixl 6 Source #

a + b

(.*) :: Raw Expr -> Raw Expr -> Raw Expr infixl 7 Source #

a * b

(.@) :: Raw Expr -> Raw Expr -> Raw Expr infixl 7 Source #

a @ b

(./) :: Raw Expr -> Raw Expr -> Raw Expr infixl 7 Source #

a / b

(.//) :: Raw Expr -> Raw Expr -> Raw Expr infixl 7 Source #

a // b

(.%) :: Raw Expr -> Raw Expr -> Raw Expr infixl 7 Source #

a % b

(.**) :: Raw Expr -> Raw Expr -> Raw Expr infixr 8 Source #

a ** b

Miscellaneous

linesToBlock :: [Raw Line] -> Raw Block Source #

Convert a list of Lines to a Block, without indenting them