Copyright | (C) CSIRO 2017-2019 |
---|---|
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 :: Ann a
- _unsafeLambdaWhitespace :: [Whitespace]
- _unsafeLambdaArgs :: CommaSep (Param v a)
- _unsafeLambdaColon :: Colon
- _unsafeLambdaBody :: Expr v a
- | Yield {
- _unsafeExprAnn :: Ann a
- _unsafeYieldWhitespace :: [Whitespace]
- _unsafeYieldValue :: CommaSep (Expr v a)
- | YieldFrom { }
- | Ternary {
- _unsafeExprAnn :: Ann a
- _unsafeTernaryValue :: Expr v a
- _unsafeTernaryWhitespaceIf :: [Whitespace]
- _unsafeTernaryCond :: Expr v a
- _unsafeTernaryWhitespaceElse :: [Whitespace]
- _unsafeTernaryElse :: Expr v a
- | ListComp { }
- | List {
- _unsafeExprAnn :: Ann a
- _unsafeListWhitespaceLeft :: [Whitespace]
- _unsafeListValues :: Maybe (CommaSep1' (ListItem v a))
- _unsafeListWhitespaceRight :: [Whitespace]
- | DictComp { }
- | Dict {
- _unsafeExprAnn :: Ann a
- _unsafeDictWhitespaceLeft :: [Whitespace]
- _unsafeDictValues :: Maybe (CommaSep1' (DictItem v a))
- _unsafeDictWhitespaceRight :: [Whitespace]
- | SetComp { }
- | Set { }
- | Deref {
- _unsafeExprAnn :: Ann a
- _unsafeDerefValueLeft :: Expr v a
- _unsafeDerefWhitespaceLeft :: [Whitespace]
- _unsafeDerefValueRight :: Ident v a
- | Subscript { }
- | Call {
- _unsafeExprAnn :: Ann a
- _unsafeCallFunction :: Expr v a
- _unsafeCallWhitespaceLeft :: [Whitespace]
- _unsafeCallArguments :: Maybe (CommaSep1' (Arg v a))
- _unsafeCallWhitespaceRight :: [Whitespace]
- | None {
- _unsafeExprAnn :: Ann a
- _unsafeNoneWhitespace :: [Whitespace]
- | Ellipsis { }
- | BinOp {
- _unsafeExprAnn :: Ann a
- _unsafeBinOpExprLeft :: Expr v a
- _unsafeBinOpOp :: BinOp a
- _unsafeBinOpExprRight :: Expr v a
- | UnOp {
- _exprAnn :: Ann a
- _unsafeUnOpOp :: UnOp a
- _unsafeUnOpValue :: Expr v a
- | Parens { }
- | Ident {
- _exprAnn :: Ann a
- _unsafeIdentValue :: Ident v a
- | Int {
- _exprAnn :: Ann a
- _unsafeIntValue :: IntLiteral a
- _unsafeIntWhitespace :: [Whitespace]
- | Float {
- _exprAnn :: Ann a
- _unsafeFloatValue :: FloatLiteral a
- _unsafeFloatWhitespace :: [Whitespace]
- | Imag {
- _exprAnn :: Ann a
- _unsafeImagValue :: ImagLiteral a
- _unsafeImagWhitespace :: [Whitespace]
- | Bool {
- _exprAnn :: Ann a
- _unsafeBoolValue :: Bool
- _unsafeBoolWhitespace :: [Whitespace]
- | String {
- _exprAnn :: Ann a
- _unsafeStringValue :: NonEmpty (StringLiteral a)
- | Tuple {
- _exprAnn :: Ann a
- _unsafeTupleHead :: TupleItem v a
- _unsafeTupleWhitespace :: Comma
- _unsafeTupleTail :: Maybe (CommaSep1' (TupleItem v a))
- | Not {
- _exprAnn :: Ann a
- _unsafeNotWhitespace :: [Whitespace]
- _unsafeNotValue :: Expr v a
- | Generator {
- _exprAnn :: Ann a
- _generatorValue :: Comprehension Expr v a
- | Await {
- _exprAnn :: Ann a
- _unsafeAwaitWhitespace :: [Whitespace]
- _unsafeAwaitValue :: Expr v a
- class HasExprs s where
- shouldGroupLeft :: BinOp a -> Expr v a -> Bool
- shouldGroupRight :: BinOp a -> Expr v a -> Bool
- data Param (v :: [*]) a
- = PositionalParam {
- _paramAnn :: Ann a
- _paramName :: Ident v a
- _paramType :: Maybe (Colon, Expr v a)
- | KeywordParam {
- _paramAnn :: Ann a
- _paramName :: Ident v a
- _paramType :: Maybe (Colon, Expr v a)
- _unsafeKeywordParamWhitespaceRight :: [Whitespace]
- _unsafeKeywordParamExpr :: Expr v a
- | StarParam {
- _paramAnn :: Ann a
- _unsafeStarParamWhitespace :: [Whitespace]
- _unsafeStarParamName :: Ident v a
- _paramType :: Maybe (Colon, Expr v a)
- | UnnamedStarParam { }
- | DoubleStarParam {
- _paramAnn :: Ann 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 :: Ann a
- _unsafeKeywordArgName :: Ident v a
- _unsafeKeywordArgWhitespaceRight :: [Whitespace]
- _argExpr :: Expr v a
- | StarArg {
- _argAnn :: Ann a
- _unsafeStarArgWhitespace :: [Whitespace]
- _argExpr :: Expr v a
- | DoubleStarArg {
- _argAnn :: Ann 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 (Ann a) (e v a) (CompFor v a) [Either (CompFor v a) (CompIf v a)]
- data CompIf (v :: [*]) a = CompIf (Ann a) [Whitespace] (Expr v a)
- data CompFor (v :: [*]) a = CompFor (Ann a) [Whitespace] (Expr v a) [Whitespace] (Expr v a)
- data DictItem (v :: [*]) a
- = DictItem {
- _dictItemAnn :: Ann a
- _unsafeDictItemKey :: Expr v a
- _unsafeDictItemColon :: Colon
- _unsafeDictItemValue :: Expr v a
- | DictUnpack { }
- = DictItem {
- data ListItem (v :: [*]) a
- = ListItem {
- _listItemAnn :: Ann a
- _unsafeListItemValue :: Expr v a
- | ListUnpack {
- _listItemAnn :: Ann a
- _unsafeListUnpackParens :: [([Whitespace], [Whitespace])]
- _unsafeListUnpackWhitespace :: [Whitespace]
- _unsafeListUnpackValue :: Expr v a
- = ListItem {
- data SetItem (v :: [*]) a
- = SetItem {
- _setItemAnn :: Ann a
- _unsafeSetItemValue :: Expr v a
- | SetUnpack {
- _setItemAnn :: Ann a
- _unsafeSetUnpackParens :: [([Whitespace], [Whitespace])]
- _unsafeSetUnpackWhitespace :: [Whitespace]
- _unsafeSetUnpackValue :: Expr v a
- = SetItem {
- data TupleItem (v :: [*]) a
- = TupleItem {
- _tupleItemAnn :: Ann a
- _unsafeTupleItemValue :: Expr v a
- | TupleUnpack {
- _tupleItemAnn :: Ann 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 Module 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
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
Instances
data CompIf (v :: [*]) a Source #
A condition inside a comprehension, e.g. [x for x in xs if even(x)]
CompIf (Ann a) [Whitespace] (Expr v a) |
Instances
data CompFor (v :: [*]) a Source #
A nested comprehesion, e.g. [(x, y) for x in xs for y in ys]
CompFor (Ann a) [Whitespace] (Expr v a) [Whitespace] (Expr v a) |
Instances
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))) |