Copyright | (C) CSIRO 2017-2018 |
---|---|
License | BSD3 |
Maintainer | Isaac Elliott <isaace71295@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- data Expr (v :: [*]) a
- = Unit { }
- | Lambda {
- _unsafeExprAnn :: a
- _unsafeLambdaWhitespace :: [Whitespace]
- _unsafeLambdaArgs :: CommaSep (Param v a)
- _unsafeLambdaColon :: Colon
- _unsafeLambdaBody :: Expr v a
- | Yield {
- _unsafeExprAnn :: a
- _unsafeYieldWhitespace :: [Whitespace]
- _unsafeYieldValue :: CommaSep (Expr v a)
- | YieldFrom { }
- | Ternary {
- _unsafeExprAnn :: a
- _unsafeTernaryValue :: Expr v a
- _unsafeTernaryWhitespaceIf :: [Whitespace]
- _unsafeTernaryCond :: Expr v a
- _unsafeTernaryWhitespaceElse :: [Whitespace]
- _unsafeTernaryElse :: Expr v a
- | ListComp { }
- | List { }
- | DictComp { }
- | Dict { }
- | SetComp { }
- | Set { }
- | Deref {
- _unsafeExprAnn :: a
- _unsafeDerefValueLeft :: Expr v a
- _unsafeDerefWhitespaceLeft :: [Whitespace]
- _unsafeDerefValueRight :: Ident v a
- | Subscript { }
- | Call {
- _unsafeExprAnn :: a
- _unsafeCallFunction :: Expr v a
- _unsafeCallWhitespaceLeft :: [Whitespace]
- _unsafeCallArguments :: Maybe (CommaSep1' (Arg v a))
- _unsafeCallWhitespaceRight :: [Whitespace]
- | None { }
- | Ellipsis { }
- | BinOp {
- _unsafeExprAnn :: a
- _unsafeBinOpExprLeft :: Expr v a
- _unsafeBinOpOp :: BinOp a
- _unsafeBinOpExprRight :: Expr v a
- | UnOp {
- _unsafeExprAnn :: a
- _unsafeUnOpOp :: UnOp a
- _unsafeUnOpValue :: Expr v a
- | Parens { }
- | Ident {
- _unsafeIdentValue :: Ident v a
- | Int { }
- | Float { }
- | Imag { }
- | Bool { }
- | String {
- _unsafeExprAnn :: a
- _unsafeStringValue :: NonEmpty (StringLiteral a)
- | Tuple {
- _unsafeExprAnn :: a
- _unsafeTupleHead :: TupleItem v a
- _unsafeTupleWhitespace :: Comma
- _unsafeTupleTail :: Maybe (CommaSep1' (TupleItem v a))
- | Not {
- _unsafeExprAnn :: a
- _unsafeNotWhitespace :: [Whitespace]
- _unsafeNotValue :: Expr v a
- | Generator {
- _unsafeExprAnn :: a
- _generatorValue :: Comprehension Expr v a
- | Await {
- _unsafeExprAnn :: a
- _unsafeAwaitWhitespace :: [Whitespace]
- _unsafeAwaitValue :: Expr v a
- class HasExprs s where
- exprAnn :: Lens' (Expr v a) a
- shouldGroupLeft :: BinOp a -> Expr v a -> Bool
- shouldGroupRight :: BinOp a -> Expr v a -> Bool
- data Param (v :: [*]) a
- = PositionalParam {
- _paramAnn :: a
- _paramName :: Ident v a
- _paramType :: Maybe (Colon, Expr v a)
- | KeywordParam {
- _paramAnn :: a
- _paramName :: Ident v a
- _paramType :: Maybe (Colon, Expr v a)
- _unsafeKeywordParamWhitespaceRight :: [Whitespace]
- _unsafeKeywordParamExpr :: Expr v a
- | StarParam {
- _paramAnn :: a
- _unsafeStarParamWhitespace :: [Whitespace]
- _unsafeStarParamName :: Ident v a
- _paramType :: Maybe (Colon, Expr v a)
- | UnnamedStarParam { }
- | DoubleStarParam {
- _paramAnn :: a
- _unsafeDoubleStarParamWhitespace :: [Whitespace]
- _paramName :: Ident v a
- _paramType :: Maybe (Colon, Expr v a)
- = PositionalParam {
- paramAnn :: Lens' (Param v a) a
- paramType_ :: Functor f => (Maybe (Colon, Expr v a) -> f (Maybe (Colon, Expr '[] a))) -> Param v a -> f (Param '[] a)
- paramType :: Traversal (Param v a) (Param '[] a) (Colon, Expr v a) (Colon, Expr '[] a)
- paramName :: Traversal (Param v a) (Param '[] a) (Ident v a) (Ident '[] a)
- data Arg (v :: [*]) a
- = PositionalArg { }
- | KeywordArg {
- _argAnn :: a
- _unsafeKeywordArgName :: Ident v a
- _unsafeKeywordArgWhitespaceRight :: [Whitespace]
- _argExpr :: Expr v a
- | StarArg {
- _argAnn :: a
- _unsafeStarArgWhitespace :: [Whitespace]
- _argExpr :: Expr v a
- | DoubleStarArg {
- _argAnn :: a
- _unsafeDoubleStarArgWhitespace :: [Whitespace]
- _argExpr :: Expr v a
- argExpr :: Lens (Arg v a) (Arg '[] a) (Expr v a) (Expr '[] a)
- data Comprehension e (v :: [*]) a = Comprehension a (e v a) (CompFor v a) [Either (CompFor v a) (CompIf v a)]
- data CompIf (v :: [*]) a = CompIf a [Whitespace] (Expr v a)
- data CompFor (v :: [*]) a = CompFor a [Whitespace] (Expr v a) [Whitespace] (Expr v a)
- data DictItem (v :: [*]) a
- = DictItem {
- _dictItemAnn :: a
- _unsafeDictItemKey :: Expr v a
- _unsafeDictItemColon :: Colon
- _unsafeDictItemValue :: Expr v a
- | DictUnpack { }
- = DictItem {
- data ListItem (v :: [*]) a
- = ListItem {
- _listItemAnn :: a
- _unsafeListItemValue :: Expr v a
- | ListUnpack {
- _listItemAnn :: a
- _unsafeListUnpackParens :: [([Whitespace], [Whitespace])]
- _unsafeListUnpackWhitespace :: [Whitespace]
- _unsafeListUnpackValue :: Expr v a
- = ListItem {
- data SetItem (v :: [*]) a
- = SetItem {
- _setItemAnn :: a
- _unsafeSetItemValue :: Expr v a
- | SetUnpack {
- _setItemAnn :: a
- _unsafeSetUnpackParens :: [([Whitespace], [Whitespace])]
- _unsafeSetUnpackWhitespace :: [Whitespace]
- _unsafeSetUnpackValue :: Expr v a
- = SetItem {
- data TupleItem (v :: [*]) a
- = TupleItem {
- _tupleItemAnn :: a
- _unsafeTupleItemValue :: Expr v a
- | TupleUnpack {
- _tupleItemAnn :: a
- _unsafeTupleUnpackParens :: [([Whitespace], [Whitespace])]
- _unsafeTupleUnpackWhitespace :: [Whitespace]
- _unsafeTupleUnpackValue :: Expr v a
- = TupleItem {
- data Subscript (v :: [*]) a
Expressions
data Expr (v :: [*]) a Source #
This large sum type covers all valid Python expressions
Instances
class HasExprs s where Source #
Traversal
over all the expressions in a term
Instances
HasExprs Expr Source # | |
HasExprs TupleItem Source # | |
HasExprs SetItem Source # | |
HasExprs ListItem Source # | |
HasExprs Arg Source # | |
HasExprs Param Source # | |
HasExprs CompoundStatement Source # | |
Defined in Language.Python.Syntax.Statement _Exprs :: Traversal (CompoundStatement v a) (CompoundStatement [] a) (Expr v a) (Expr [] a) Source # | |
HasExprs Decorator Source # | |
HasExprs WithItem Source # | |
HasExprs Suite Source # | |
HasExprs ExceptAs Source # | |
HasExprs SimpleStatement Source # | |
Defined in Language.Python.Syntax.Statement _Exprs :: Traversal (SimpleStatement v a) (SimpleStatement [] a) (Expr v a) (Expr [] a) Source # | |
HasExprs Statement Source # | |
HasExprs SmallStatement Source # | |
Defined in Language.Python.Syntax.Statement _Exprs :: Traversal (SmallStatement v a) (SmallStatement [] a) (Expr v a) (Expr [] a) Source # | |
HasExprs Block Source # | |
HasExprs Line Source # | |
shouldGroupLeft :: BinOp a -> Expr v a -> Bool Source #
shouldGroupLeft op left
returns true if left
needs to be parenthesised
when it is the left argument of op
shouldGroupRight :: BinOp a -> Expr v a -> Bool Source #
shouldGroupRight op right
returns true if right
needs to be parenthesised
when it is the right argument of op
Parameters and arguments
data Param (v :: [*]) a Source #
Formal parameters for functions
See https://docs.python.org/3.5/reference/compound_stmts.html#function-definitions
PositionalParam | def foo(a): |
| |
KeywordParam | def foo(bar=None): |
| |
StarParam | def foo(*xs): |
| |
UnnamedStarParam | def foo(*): |
DoubleStarParam | def foo(**dict): |
|
Instances
paramType_ :: Functor f => (Maybe (Colon, Expr v a) -> f (Maybe (Colon, Expr '[] a))) -> Param v a -> f (Param '[] a) Source #
A faux-lens on the optional Python type annotation which may follow a parameter
This is not a lawful Lens
because setting an UnnamedStarParam'
s type won't
have any effect.
This optic, like many others in hpython, loses validation information
(the v
type parameter)
The following is an example, where int
is the paramtype:
def foo(x: int):
paramType :: Traversal (Param v a) (Param '[] a) (Colon, Expr v a) (Colon, Expr '[] a) Source #
Traversal
targeting the Python type annotations which may follow a parameter
paramName :: Traversal (Param v a) (Param '[] a) (Ident v a) (Ident '[] a) Source #
(affine) Traversal
on the name of a parameter
The name is x
in the following examples:
def foo(x): def foo(x=None): def foo(*x): def foo(**x):
But the following example does not have a paramName
:
def foo(*):
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)
PositionalArg | |
KeywordArg | |
| |
StarArg | |
| |
DoubleStarArg | |
|
Instances
argExpr :: Lens (Arg v a) (Arg '[] a) (Expr v a) (Expr '[] a) Source #
Lens on the Python expression which is passed as the argument
Comprehension expressions
data Comprehension e (v :: [*]) a Source #
A Python for comprehension, such as
x for y in z
Comprehension a (e v a) (CompFor v a) [Either (CompFor v a) (CompIf v a)] |
Instances
data CompIf (v :: [*]) a Source #
A condition inside a comprehension, e.g. [x for x in xs if even(x)]
CompIf a [Whitespace] (Expr v a) |
Instances
Functor (CompIf v) Source # | |
Foldable (CompIf v) Source # | |
Defined in Language.Python.Syntax.Expr fold :: Monoid m => CompIf v m -> m # foldMap :: Monoid m => (a -> m) -> CompIf v a -> m # foldr :: (a -> b -> b) -> b -> CompIf v a -> b # foldr' :: (a -> b -> b) -> b -> CompIf v a -> b # foldl :: (b -> a -> b) -> b -> CompIf v a -> b # foldl' :: (b -> a -> b) -> b -> CompIf v a -> b # foldr1 :: (a -> a -> a) -> CompIf v a -> a # foldl1 :: (a -> a -> a) -> CompIf v a -> a # elem :: Eq a => a -> CompIf v a -> Bool # maximum :: Ord a => CompIf v a -> a # minimum :: Ord a => CompIf v a -> a # | |
Traversable (CompIf v) Source # | |
Eq a => Eq (CompIf v a) Source # | |
Show a => Show (CompIf v a) Source # | |
HasTrailingWhitespace (CompIf v a) Source # | |
Defined in Language.Python.Syntax.Expr trailingWhitespace :: Lens' (CompIf v a) [Whitespace] Source # | |
HasNewlines (CompIf v a) Source # | |
data CompFor (v :: [*]) a Source #
A nested comprehesion, e.g. [(x, y) for x in xs for y in ys]
CompFor a [Whitespace] (Expr v a) [Whitespace] (Expr v a) |
Instances
Functor (CompFor v) Source # | |
Foldable (CompFor v) Source # | |
Defined in Language.Python.Syntax.Expr fold :: Monoid m => CompFor v m -> m # foldMap :: Monoid m => (a -> m) -> CompFor v a -> m # foldr :: (a -> b -> b) -> b -> CompFor v a -> b # foldr' :: (a -> b -> b) -> b -> CompFor v a -> b # foldl :: (b -> a -> b) -> b -> CompFor v a -> b # foldl' :: (b -> a -> b) -> b -> CompFor v a -> b # foldr1 :: (a -> a -> a) -> CompFor v a -> a # foldl1 :: (a -> a -> a) -> CompFor v a -> a # toList :: CompFor v a -> [a] # length :: CompFor v a -> Int # elem :: Eq a => a -> CompFor v a -> Bool # maximum :: Ord a => CompFor v a -> a # minimum :: Ord a => CompFor v a -> a # | |
Traversable (CompFor v) Source # | |
Defined in Language.Python.Syntax.Expr | |
ForSyntax (Raw CompFor) In Source # |
|
Eq a => Eq (CompFor v a) Source # | |
Show a => Show (CompFor v a) Source # | |
HasTrailingWhitespace (CompFor v a) Source # | |
Defined in Language.Python.Syntax.Expr trailingWhitespace :: Lens' (CompFor v a) [Whitespace] Source # | |
HasNewlines (CompFor v a) Source # | |
Collection items
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
DictItem | |
| |
DictUnpack | |
|
Instances
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
ListItem | |
| |
ListUnpack | |
|
Instances
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
SetItem | |
| |
SetUnpack | |
|
Instances
data TupleItem (v :: [*]) a Source #
a
or *a
Used to construct tuples, e.g. (1,
x
, **c)
TupleItem | |
| |
TupleUnpack | |
|
Instances
Subscripts
data Subscript (v :: [*]) a Source #
Syntax for things that can be used as subscripts (inside the square brackets)
e.g.
a[b]
a[:]
a[b:]
a[:b]
a[b:c]
a[b:c:d]
https://docs.python.org/3/reference/expressions.html#subscriptions
SubscriptExpr (Expr v a) | |
SubscriptSlice (Maybe (Expr v a)) Colon (Maybe (Expr v a)) (Maybe (Colon, Maybe (Expr v a))) |