Copyright | (C) CSIRO 2017-2018 |
---|---|
License | BSD3 |
Maintainer | Isaac Elliott <isaace71295@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- (&) :: a -> (a -> b) -> b
- type Raw f = f '[] ()
- data Module v a
- data Statement (v :: [*]) a
- data Expr (v :: [*]) a
- module_ :: [Raw Line] -> Raw Module
- blank_ :: Raw Line
- class AsLine s where
- newtype Line v a = Line {}
- id_ :: String -> Raw Ident
- data Ident (v :: [*]) a = MkIdent {
- _identAnn :: a
- _identValue :: String
- _identWhitespace :: [Whitespace]
- identAnn :: Lens (Ident v a) (Ident v a) a a
- identValue :: Lens (Ident v a) (Ident '[] a) String String
- identWhitespace :: Lens (Ident v a) (Ident v a) [Whitespace] [Whitespace]
- class StarSyntax s t | t -> s where
- star_ :: Raw Param
- class DoubleStarSyntax s t | t -> s where
- class As s t u | s t -> u, u -> s t where
- class IfSyntax a where
- class ForSyntax a x | a -> x where
- class InSyntax a x | a -> x, x -> a where
- data In v a = MkIn (Expr v a) (Expr v a)
- data InList v a = MkInList (Expr v a) [Expr v a]
- class ColonSyntax s t | s -> t, t -> s where
- comp_ :: Raw e -> Raw CompFor -> [Raw Guard] -> Raw (Comprehension e)
- newtype Guard v a = MkGuard {}
- 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 {
- class ParametersSyntax s where
- 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
- class ArgumentsSyntax s where
- setArguments :: [Raw Arg] -> Raw s -> Raw s
- getArguments :: Raw s -> [Raw Arg]
- class PositionalSyntax p v | p -> v, v -> p where
- data PositionalParam v a = MkPositionalParam {}
- _PositionalParam :: Prism (Param v a) (Param '[] a) (PositionalParam v a) (PositionalParam '[] a)
- ppAnn :: forall v a. Lens' (PositionalParam v a) a
- ppName :: forall v a. Lens' (PositionalParam v a) (Ident v a)
- ppType :: forall v a. Lens' (PositionalParam v a) (Maybe (Colon, Expr v a))
- class KeywordSyntax p where
- data KeywordParam v a = MkKeywordParam {}
- _KeywordParam :: Prism (Param v a) (Param '[] a) (KeywordParam v a) (KeywordParam '[] a)
- kpAnn :: forall v a. Lens' (KeywordParam v a) a
- kpName :: forall v a. Lens' (KeywordParam v a) (Ident v a)
- kpType :: forall v a. Lens' (KeywordParam v a) (Maybe (Colon, Expr v a))
- kpEquals :: forall v a. Lens' (KeywordParam v a) [Whitespace]
- kpExpr :: forall v a. Lens' (KeywordParam v a) (Expr v a)
- decorated_ :: DecoratorsSyntax s => [Raw Expr] -> Raw s -> Raw s
- class DecoratorsSyntax s where
- setDecorators :: [Raw Expr] -> Raw s -> Raw s
- getDecorators :: Raw s -> [Raw Expr]
- decorators :: Lens' (Raw s) [Raw Decorator]
- class AsyncSyntax s where
- class BodySyntax s where
- def_ :: Raw Ident -> [Raw Param] -> [Raw Line] -> Raw Fundef
- data Fundef v a = MkFundef {
- _fdAnn :: a
- _fdDecorators :: [Decorator v a]
- _fdIndents :: Indents a
- _fdAsync :: Maybe (NonEmpty Whitespace)
- _fdDefSpaces :: NonEmpty Whitespace
- _fdName :: Ident v a
- _fdLeftParenSpaces :: [Whitespace]
- _fdParameters :: CommaSep (Param v a)
- _fdRightParenSpaces :: [Whitespace]
- _fdReturnType :: Maybe ([Whitespace], Expr v a)
- _fdBody :: Suite v a
- mkFundef :: Raw Ident -> [Raw Line] -> Raw Fundef
- fdAnn :: forall v a. Lens' (Fundef v a) a
- fdDecorators :: forall v a. Lens' (Fundef v a) [Decorator v a]
- fdIndents :: forall v a. Lens' (Fundef v a) (Indents a)
- fdAsync :: forall v a. Lens' (Fundef v a) (Maybe (NonEmpty Whitespace))
- fdDefSpaces :: forall v a. Lens' (Fundef v a) (NonEmpty Whitespace)
- fdName :: forall v a. Lens' (Fundef v a) (Ident v a)
- fdLeftParenSpaces :: forall v a. Lens' (Fundef v a) [Whitespace]
- fdParameters :: forall v a. Lens' (Fundef v a) (CommaSep (Param v a))
- fdRightParenSpaces :: forall v a. Lens' (Fundef v a) [Whitespace]
- fdReturnType :: forall v a. Lens' (Fundef v a) (Maybe ([Whitespace], Expr v a))
- fdBody :: forall v a. Lens' (Fundef v a) (Suite v a)
- class_ :: Raw Ident -> [Raw Arg] -> [Raw Line] -> Raw ClassDef
- data ClassDef v a = MkClassDef {
- _cdAnn :: a
- _cdDecorators :: [Decorator v a]
- _cdIndents :: Indents a
- _cdClass :: NonEmpty Whitespace
- _cdName :: Ident v a
- _cdArguments :: Maybe ([Whitespace], Maybe (CommaSep1' (Arg v a)), [Whitespace])
- _cdBody :: Suite v a
- mkClassDef :: Raw Ident -> [Raw Line] -> Raw ClassDef
- cdAnn :: forall v a. Lens' (ClassDef v a) a
- cdDecorators :: forall v a. Lens' (ClassDef v a) [Decorator v a]
- cdIndents :: forall v a. Lens' (ClassDef v a) (Indents a)
- cdClass :: forall v a. Lens' (ClassDef v a) (NonEmpty Whitespace)
- cdName :: forall v a. Lens' (ClassDef v a) (Ident v a)
- cdArguments :: forall v a. Lens' (ClassDef v a) (Maybe ([Whitespace], Maybe (CommaSep1' (Arg v a)), [Whitespace]))
- cdBody :: forall v a. Lens' (ClassDef v a) (Suite v a)
- chainEq :: Raw Expr -> [Raw Expr] -> Raw Statement
- (.=) :: Raw Expr -> Raw Expr -> Raw Statement
- (.+=) :: Raw Expr -> Raw Expr -> Raw Statement
- (.-=) :: Raw Expr -> Raw Expr -> Raw Statement
- (.*=) :: Raw Expr -> Raw Expr -> Raw Statement
- (.@=) :: Raw Expr -> Raw Expr -> Raw Statement
- (./=) :: Raw Expr -> Raw Expr -> Raw Statement
- (.%=) :: Raw Expr -> Raw Expr -> Raw Statement
- (.&=) :: Raw Expr -> Raw Expr -> Raw Statement
- (.|=) :: Raw Expr -> Raw Expr -> Raw Statement
- (.^=) :: Raw Expr -> Raw Expr -> Raw Statement
- (.<<=) :: Raw Expr -> Raw Expr -> Raw Statement
- (.>>=) :: Raw Expr -> Raw Expr -> Raw Statement
- (.**=) :: Raw Expr -> Raw Expr -> Raw Statement
- (.//=) :: Raw Expr -> Raw Expr -> Raw Statement
- tryE_ :: [Raw Line] -> Raw Except -> Raw TryExcept
- tryF_ :: [Raw Line] -> [Raw Line] -> Raw TryFinally
- class ExceptSyntax s where
- class FinallySyntax s t | s -> t where
- data TryExcept v a = MkTryExcept {
- _teAnn :: a
- _teIndents :: Indents a
- _teTry :: [Whitespace]
- _teBody :: Suite v a
- _teExcepts :: NonEmpty (Except v a)
- _teElse :: Maybe (Else v a)
- _teFinally :: Maybe (Finally v a)
- mkTryExcept :: [Raw Line] -> Raw Except -> Raw TryExcept
- data TryFinally v a = MkTryFinally {
- _tfAnn :: a
- _tfIndents :: Indents a
- _tfTry :: [Whitespace]
- _tfBody :: Suite v a
- _tfFinally :: Finally v a
- mkTryFinally :: [Raw Line] -> [Raw Line] -> Raw TryFinally
- data ExceptAs (v :: [*]) a = ExceptAs {
- _exceptAsAnn :: a
- _exceptAsExpr :: Expr v a
- _exceptAsName :: Maybe ([Whitespace], Ident v a)
- class AsExceptAs s where
- toExceptAs :: Raw s -> Raw ExceptAs
- data Except v a = MkExcept {
- _exceptIndents :: Indents a
- _exceptExcept :: [Whitespace]
- _exceptExceptAs :: Maybe (ExceptAs v a)
- _exceptBody :: Suite v a
- mkExcept :: [Raw Line] -> Raw Except
- data Finally v a = MkFinally {
- _finallyIndents :: Indents a
- _finallyFinally :: [Whitespace]
- _finallyBody :: Suite v a
- mkFinally :: [Raw Line] -> Raw Finally
- teAnn :: forall v a. Lens' (TryExcept v a) a
- teIndents :: forall v a. Lens' (TryExcept v a) (Indents a)
- teTry :: forall v a. Lens' (TryExcept v a) [Whitespace]
- teBody :: forall v a. Lens' (TryExcept v a) (Suite v a)
- teExcepts :: forall v a. Lens' (TryExcept v a) (NonEmpty (Except v a))
- teElse :: forall v a. Lens' (TryExcept v a) (Maybe (Else v a))
- teFinally :: forall v a. Lens' (TryExcept v a) (Maybe (Finally v a))
- exceptIndents :: forall v a. Lens' (Except v a) (Indents a)
- exceptExcept :: forall v a. Lens' (Except v a) [Whitespace]
- exceptExceptAs :: forall v a. Lens' (Except v a) (Maybe (ExceptAs v a))
- exceptBody :: forall v a. Lens' (Except v a) (Suite v a)
- finallyIndents :: forall v a. Lens' (Finally v a) (Indents a)
- finallyFinally :: forall v a. Lens' (Finally v a) [Whitespace]
- finallyBody :: forall v a v. Lens (Finally v a) (Finally v a) (Suite v a) (Suite v a)
- with_ :: AsWithItem e => NonEmpty (Raw e) -> [Raw Line] -> Raw With
- withItem_ :: Raw Expr -> Maybe (Raw Expr) -> Raw WithItem
- data With v a = MkWith {
- _withAnn :: a
- _withIndents :: Indents a
- _withAsync :: Maybe (NonEmpty Whitespace)
- _withWith :: [Whitespace]
- _withItems :: CommaSep1 (WithItem v a)
- _withBody :: Suite v a
- mkWith :: NonEmpty (Raw WithItem) -> [Raw Line] -> Raw With
- class AsWithItem s where
- toWithItem :: Raw s -> Raw WithItem
- data WithItem (v :: [*]) a = WithItem {
- _withItemAnn :: a
- _withItemValue :: Expr v a
- _withItemBinder :: Maybe ([Whitespace], Expr v a)
- withAnn :: forall v a. Lens' (With v a) a
- withIndents :: forall v a. Lens' (With v a) (Indents a)
- withAsync :: forall v a. Lens' (With v a) (Maybe (NonEmpty Whitespace))
- withWith :: forall v a. Lens' (With v a) [Whitespace]
- withItems :: forall v a. Lens' (With v a) (CommaSep1 (WithItem v a))
- withBody :: forall v a. Lens' (With v a) (Suite v a)
- else_ :: ElseSyntax s => [Raw Line] -> Raw s -> Raw s
- class ElseSyntax s where
- break_ :: Raw Statement
- forSt_ :: Raw Expr -> [Raw Expr] -> [Raw Line] -> Raw For
- data For v a = MkFor {
- _forAnn :: a
- _forIndents :: Indents a
- _forAsync :: Maybe (NonEmpty Whitespace)
- _forFor :: [Whitespace]
- _forBinder :: Expr v a
- _forIn :: [Whitespace]
- _forCollection :: CommaSep1' (Expr v a)
- _forBody :: Suite v a
- _forElse :: Maybe (Else v a)
- _For :: HasFor s => Prism (s v a) (s '[] a) (For v a) (For '[] a)
- mkFor :: Raw Expr -> [Raw Expr] -> [Raw Line] -> Raw For
- ifThen_ :: Raw Expr -> [Raw Line] -> Raw If
- elif_ :: Raw Expr -> [Raw Line] -> Raw If -> Raw If
- data If v a = MkIf {}
- mkIf :: Raw Expr -> [Raw Line] -> Raw If
- data Elif v a = MkElif {
- _elifIndents :: Indents a
- _elifElif :: [Whitespace]
- _elifCond :: Expr v a
- _elifBody :: Suite v a
- mkElif :: Raw Expr -> [Raw Line] -> Raw Elif
- data Else v a = MkElse {
- _elseIndents :: Indents a
- _elseElse :: [Whitespace]
- _elseBody :: Suite v a
- mkElse :: [Raw Line] -> Raw Else
- ifAnn :: forall v a. Lens' (If v a) a
- ifIndents :: forall v a. Lens' (If v a) (Indents a)
- ifIf :: forall v a. Lens' (If v a) [Whitespace]
- ifCond :: forall v a. Lens' (If v a) (Expr v a)
- ifBody :: forall v a. Lens' (If v a) (Suite v a)
- ifElifs :: forall v a. Lens' (If v a) [Elif v a]
- ifElse :: forall v a. Lens' (If v a) (Maybe (Else v a))
- elifIndents :: forall v a. Lens' (Elif v a) (Indents a)
- elifElif :: forall v a. Lens' (Elif v a) [Whitespace]
- elifCond :: forall v a. Lens' (Elif v a) (Expr v a)
- elifBody :: forall v a. Lens' (Elif v a) (Suite v a)
- elseIndents :: forall v a. Lens' (Else v a) (Indents a)
- elseElse :: forall v a. Lens' (Else v a) [Whitespace]
- elseBody :: forall v a v. Lens (Else v a) (Else v a) (Suite v a) (Suite v a)
- pass_ :: Raw Statement
- return_ :: Raw Expr -> Raw Statement
- while_ :: Raw Expr -> [Raw Line] -> Raw While
- data While v a = MkWhile {
- _whileAnn :: a
- _whileIndents :: Indents a
- _whileWhile :: [Whitespace]
- _whileCond :: Expr v a
- _whileBody :: Suite v a
- _whileElse :: Maybe (Else v a)
- mkWhile :: Raw Expr -> [Raw Line] -> Raw While
- whileAnn :: forall v a. Lens' (While v a) a
- whileIndents :: forall v a. Lens' (While v a) (Indents a)
- whileWhile :: forall v a. Lens' (While v a) [Whitespace]
- whileCond :: forall v a. Lens' (While v a) (Expr v a)
- whileBody :: forall v a. Lens' (While v a) (Suite v a)
- expr_ :: Raw Expr -> Raw Statement
- var_ :: String -> Raw Expr
- await_ :: Raw Expr -> Raw Expr
- ifThenElse_ :: Raw Expr -> Raw Expr -> Raw Expr -> Raw Expr
- gen_ :: Raw (Comprehension Expr) -> Raw Expr
- yield_ :: [Raw Expr] -> Raw Expr
- yieldFrom_ :: Raw Expr -> Raw Expr
- tuple_ :: [Raw TupleItem] -> Raw Expr
- data Tuple v a = MkTuple {
- _tupleAnn :: a
- _tupleHead :: TupleItem v a
- _tupleComma :: Comma
- _tupleTail :: Maybe (CommaSep1' (TupleItem v a))
- class AsTupleItem e where
- data TupleItem (v :: [*]) a
- call_ :: Raw Expr -> [Raw Arg] -> Raw Expr
- data Call v a = MkCall {
- _callAnn :: a
- _callFunction :: Expr v a
- _callLeftParen :: [Whitespace]
- _callArguments :: Maybe (CommaSep1' (Arg v a))
- _callRightParen :: [Whitespace]
- mkCall :: Raw Expr -> Raw Call
- callAnn :: forall v a. Lens' (Call v a) a
- callFunction :: forall v a. Lens' (Call v a) (Expr v a)
- callLeftParen :: forall v a. Lens' (Call v a) [Whitespace]
- callArguments :: forall v a. Lens' (Call v a) (Maybe (CommaSep1' (Arg v a)))
- callRightParen :: forall v a. Lens' (Call v a) [Whitespace]
- none_ :: Raw Expr
- data None (v :: [*]) a = MkNone {
- _noneAnn :: a
- _noneWhitespace :: [Whitespace]
- _None :: Prism (Expr v a) (Expr '[] a) (None v a) (None '[] a)
- noneAnn :: forall v a v a. Lens (None v a) (None v a) a a
- noneWhitespace :: forall v a v. Lens (None v a) (None v a) [Whitespace] [Whitespace]
- str_ :: String -> Raw Expr
- str'_ :: String -> Raw Expr
- longStr_ :: String -> Raw Expr
- longStr'_ :: String -> Raw Expr
- int_ :: Integer -> Raw Expr
- true_ :: Raw Expr
- false_ :: Raw Expr
- ellipsis_ :: Raw Expr
- class AsList s where
- class AsListItem s where
- data ListItem (v :: [*]) a
- class AsDict s where
- data DictItem (v :: [*]) a
- class AsSet s where
- class AsSetItem s where
- data SetItem (v :: [*]) a
- lambda_ :: [Raw Param] -> Raw Expr -> Raw Expr
- subs_ :: Raw Expr -> Raw Expr -> Raw Expr
- sliceF_ :: Raw Expr -> Raw Expr
- sliceFS_ :: Raw Expr -> Raw Expr -> Raw Expr
- sliceT_ :: Raw Expr -> Raw Expr
- sliceTS_ :: Raw Expr -> Raw Expr -> Raw Expr
- sliceFT_ :: Raw Expr -> Raw Expr -> Raw Expr
- sliceFTS_ :: Raw Expr -> Raw Expr -> Raw Expr -> Raw Expr
- sliceS_ :: Raw Expr -> Raw Expr
- fullSlice_ :: Raw Expr
- slice_ :: Maybe (Raw Expr) -> Maybe (Raw Expr) -> Maybe (Raw Expr) -> Raw Expr
- (/>) :: Raw Expr -> Raw Ident -> Raw Expr
- not_ :: Raw Expr -> Raw Expr
- neg_ :: Raw Expr -> Raw Expr
- pos_ :: Raw Expr -> Raw Expr
- compl_ :: Raw Expr -> Raw Expr
- or_ :: Raw Expr -> Raw Expr -> Raw Expr
- and_ :: Raw Expr -> Raw Expr -> Raw Expr
- is_ :: Raw Expr -> Raw Expr -> Raw Expr
- isNot_ :: Raw Expr -> Raw Expr -> Raw Expr
- notIn_ :: Raw Expr -> Raw Expr -> Raw Expr
- (.==) :: Raw Expr -> Raw Expr -> Raw Expr
- (.>) :: Raw Expr -> Raw Expr -> Raw Expr
- (.>=) :: Raw Expr -> Raw Expr -> Raw Expr
- (.<) :: Raw Expr -> Raw Expr -> Raw Expr
- (.<=) :: Raw Expr -> Raw Expr -> Raw Expr
- (.!=) :: Raw Expr -> Raw Expr -> Raw Expr
- (.|) :: Raw Expr -> Raw Expr -> Raw Expr
- (.^) :: Raw Expr -> Raw Expr -> Raw Expr
- (.&) :: Raw Expr -> Raw Expr -> Raw Expr
- (.<<) :: Raw Expr -> Raw Expr -> Raw Expr
- (.>>) :: Raw Expr -> Raw Expr -> Raw Expr
- (.-) :: Raw Expr -> Raw Expr -> Raw Expr
- (.+) :: Raw Expr -> Raw Expr -> Raw Expr
- (.*) :: Raw Expr -> Raw Expr -> Raw Expr
- (.@) :: Raw Expr -> Raw Expr -> Raw Expr
- (./) :: Raw Expr -> Raw Expr -> Raw Expr
- (.//) :: Raw Expr -> Raw Expr -> Raw Expr
- (.%) :: Raw Expr -> Raw Expr -> Raw Expr
- (.**) :: Raw Expr -> Raw Expr -> Raw Expr
- linesToBlock :: [Raw Line] -> Raw Block
- blockToLines :: Raw Block -> [Raw Line]
Documentation
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 # | |
Defined in Language.Python.Syntax.Module | |
Functor (Module v) Source # | |
Foldable (Module v) Source # | |
Defined in Language.Python.Syntax.Module 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 # elem :: Eq a => a -> Module v a -> Bool # maximum :: Ord a => Module v a -> a # minimum :: Ord a => Module v a -> a # | |
Traversable (Module v) Source # | |
Eq a => Eq (Module v a) Source # | |
Show a => Show (Module v a) Source # | |
HasNewlines (Module v a) Source # | |
data Statement (v :: [*]) a Source #
A Statement
is either a SmallStatement
or a Statement
https://docs.python.org/3.5/reference/compound_stmts.html#compound-statements
Instances
data Expr (v :: [*]) a Source #
This large sum type covers all valid Python expressions
Instances
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
Convert some data to a Line
Instances
AsLine Expr Source # | |
AsLine CompoundStatement Source # | |
Defined in Language.Python.DSL | |
AsLine SimpleStatement Source # | |
Defined in Language.Python.DSL | |
AsLine Statement Source # | |
AsLine SmallStatement Source # | |
Defined in Language.Python.DSL | |
AsLine Fundef Source # | |
AsLine While Source # | |
AsLine If Source # | |
AsLine For Source # | |
AsLine TryExcept Source # | |
AsLine TryFinally Source # | |
Defined in Language.Python.DSL | |
AsLine ClassDef Source # | |
AsLine With Source # | |
One or more lines of Python code
Instances
HasExprs Line Source # | |
HasStatements Line Source # | |
Defined in Language.Python.DSL | |
Eq a => Eq (Line v a) Source # | |
Show a => Show (Line v a) Source # | |
Wrapped (Line v a) Source # | |
Line v1 a1 ~ t => Rewrapped (Line v2 a2) t Source # | |
Defined in Language.Python.DSL | |
type Unwrapped (Line v a) Source # | |
Identifiers
data Ident (v :: [*]) a Source #
An identifier. Like many types in hpython, it has an optional annotation and tracks its trailing whitespace.
Raw
Ident
s have an IsString
instance.
See https://docs.python.org/3.5/reference/lexical_analysis.html#identifiers
MkIdent | |
|
Instances
Lenses
identWhitespace :: Lens (Ident v a) (Ident v a) [Whitespace] [Whitespace] Source #
Starred values
class StarSyntax s t | t -> s where 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 #
as
syntax
if
syntax
class IfSyntax a where Source #
Instances
IfSyntax (Raw Guard) Source # |
|
(l ~ Raw Line, s ~ Raw If) => IfSyntax ([l] -> s) Source # |
|
for
syntax
class ForSyntax a x | a -> x where Source #
Instances
ForSyntax (Raw CompFor) In Source # |
|
ForSyntax (Raw Guard) In Source # |
|
(l ~ [Raw Line], s ~ Raw For) => ForSyntax (l -> s) InList Source # |
|
in
syntax
>>>
var_ "a" `in_` var_ "b"
a in b
Instances
ForSyntax (Raw CompFor) In Source # |
|
ForSyntax (Raw Guard) In Source # |
|
>>>
var_ "a" `in_` [var_ "b", var_ "c"]
a in b, c
:
syntax
class ColonSyntax s t | s -> t, t -> s where Source #
Instances
ColonSyntax Expr DictItem Source # | Constructing dictionary items ( |
ColonSyntax Param Param Source # | Function parameter type annotations (
See |
Comprehensions
Instances
IfSyntax (Raw Guard) Source # |
|
ForSyntax (Raw Guard) In Source # |
|
Parameters and arguments
Parameters
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
class ParametersSyntax s where Source #
parameters_ :: Functor f => ([Raw Param] -> f [Raw Param]) -> Raw s -> f (Raw s) Source #
A faux-Lens that allows targeting Param
s 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 set
s 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
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)
PositionalArg | |
KeywordArg | |
| |
StarArg | |
| |
DoubleStarArg | |
|
Instances
class ArgumentsSyntax s where Source #
Instances
ArgumentsSyntax Call Source # | |
ArgumentsSyntax ClassDef Source # | |
Positional
class PositionalSyntax p v | p -> v, v -> p where Source #
data PositionalParam v a Source #
Instances
Eq a => Eq (PositionalParam v a) Source # | |
Defined in Language.Python.Syntax.Types (==) :: PositionalParam v a -> PositionalParam v a -> Bool # (/=) :: PositionalParam v a -> PositionalParam v a -> Bool # | |
Show a => Show (PositionalParam v a) Source # | |
Defined in Language.Python.Syntax.Types showsPrec :: Int -> PositionalParam v a -> ShowS # show :: PositionalParam v a -> String # showList :: [PositionalParam v a] -> ShowS # |
_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 #
Keyword
class KeywordSyntax p where Source #
Keyword parameters/arguments
p_ ::Raw
SimpleStatement
->Raw
SimpleStatement
->Raw
Arg
p_ ::Raw
Expr
->Raw
SimpleStatement
->Raw
Param
data KeywordParam v a Source #
Instances
Eq a => Eq (KeywordParam v a) Source # | |
Defined in Language.Python.Syntax.Types (==) :: KeywordParam v a -> KeywordParam v a -> Bool # (/=) :: KeywordParam v a -> KeywordParam v a -> Bool # | |
Show a => Show (KeywordParam v a) Source # | |
Defined in Language.Python.Syntax.Types showsPrec :: Int -> KeywordParam v a -> ShowS # show :: KeywordParam v a -> String # showList :: [KeywordParam v a] -> ShowS # |
_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 #
kpEquals :: forall v a. Lens' (KeywordParam v a) [Whitespace] Source #
kpExpr :: forall v a. Lens' (KeywordParam v a) (Expr v a) Source #
Decorators
decorated_ :: DecoratorsSyntax s => [Raw Expr] -> Raw s -> Raw s Source #
class DecoratorsSyntax s where Source #
Instances
DecoratorsSyntax Fundef Source # | |
DecoratorsSyntax ClassDef Source # | |
Statements
async
class AsyncSyntax s where Source #
Instances
AsyncSyntax Fundef Source # | |
AsyncSyntax For Source # | |
AsyncSyntax With Source # | |
Block bodies
class BodySyntax s where Source #
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)
Instances
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
MkFundef | |
|
mkFundef :: Raw Ident -> [Raw Line] -> Raw Fundef Source #
Create a minimal valid function definition
Lenses
fdDecorators :: forall v a. Lens' (Fundef v a) [Decorator v a] Source #
fdDefSpaces :: forall v a. Lens' (Fundef v a) (NonEmpty Whitespace) Source #
fdLeftParenSpaces :: forall v a. Lens' (Fundef v a) [Whitespace] 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 #
Class definitions
class_ :: Raw Ident -> [Raw Arg] -> [Raw Line] -> Raw ClassDef Source #
>>>
class_ "A" [] [line_ pass_]
class A: pass
MkClassDef | |
|
Lenses
cdDecorators :: forall v a. Lens' (ClassDef v a) [Decorator v a] Source #
cdArguments :: forall v a. Lens' (ClassDef v a) (Maybe ([Whitespace], Maybe (CommaSep1' (Arg v a)), [Whitespace])) 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
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 #
except_ :: [Raw Line] -> s -> Raw TryExcept Source #
exceptAs_ :: AsExceptAs e => Raw e -> [Raw Line] -> s -> Raw TryExcept Source #
Instances
ExceptSyntax (Raw TryExcept) Source # |
(someTryStatement :: (someTryStatement :: |
ExceptSyntax (Raw TryFinally) Source # |
(someTryStatement :: (someTryStatement :: |
(e ~ Raw Except, s ~ Raw TryExcept) => ExceptSyntax (e -> s) Source # |
|
class FinallySyntax s t | s -> t where Source #
Instances
FinallySyntax (Raw TryExcept) TryExcept Source # |
|
FinallySyntax (Raw TryFinally) TryFinally Source # | |
Defined in Language.Python.DSL finally_ :: [Raw Line] -> Raw TryFinally -> Raw TryFinally Source # | |
(a ~ [Raw Line], b ~ Raw TryFinally) => FinallySyntax (a -> b) TryFinally Source # | |
Defined in Language.Python.DSL |
MkTryExcept | |
|
Instances
HasTryExcept TryExcept Source # | |
Defined in Language.Python.Optics | |
ElseSyntax TryExcept Source # | |
BodySyntax TryExcept Source # | |
AsLine TryExcept Source # | |
ExceptSyntax (Raw TryExcept) Source # |
(someTryStatement :: (someTryStatement :: |
FinallySyntax (Raw TryExcept) TryExcept Source # |
|
Eq a => Eq (TryExcept v a) Source # | |
Show a => Show (TryExcept v a) Source # | |
HasIndents (TryExcept ([] :: [Type]) a) a Source # | |
data TryFinally v a Source #
MkTryFinally | |
|
Instances
mkTryFinally :: [Raw Line] -> [Raw Line] -> Raw TryFinally Source #
Create a minimal valid TryFinally
data ExceptAs (v :: [*]) a Source #
ExceptAs | |
|
Instances
class AsExceptAs s where Source #
Instances
AsExceptAs Expr Source # | |
Defined in Language.Python.DSL | |
AsExceptAs ExceptAs Source # | |
Defined in Language.Python.DSL |
MkExcept | |
|
MkFinally | |
|
Lenses
teTry :: forall v a. Lens' (TryExcept v a) [Whitespace] Source #
exceptIndents :: forall v a. Lens' (Except v a) (Indents a) Source #
exceptExcept :: forall v a. Lens' (Except v a) [Whitespace] 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 #
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
MkWith | |
|
class AsWithItem s where Source #
Instances
AsWithItem Expr Source # | |
Defined in Language.Python.DSL | |
AsWithItem WithItem Source # | |
Defined in Language.Python.DSL |
data WithItem (v :: [*]) a Source #
WithItem | |
|
Instances
Lenses
withIndents :: forall v a. Lens' (With v a) (Indents a) Source #
withWith :: forall v a. Lens' (With v a) [Whitespace] 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_ false_ [line_ pass_] & else_ [line_ pass_]
if False: pass else: pass
---
>>>
while_ false_ [line_ pass_] & else_ [line_ pass_]
while False: pass else: pass
---
>>>
for_ (var_ "a" `in_` [var_ b]) [line_ pass_] & else_ [line_ pass_]
for a in b: pass else: pass
---
>>>
tryE_ [line_ pass_] & except_ [line_ pass_] & else_ [line_ pass_]
try: pass except: pass else: pass
class ElseSyntax s where Source #
getElse :: Raw s -> Maybe (Raw Else) Source #
setElse :: [Whitespace] -> Maybe (Raw Else) -> Raw s -> Raw s Source #
Instances
ElseSyntax While Source # | |
ElseSyntax If Source # | |
ElseSyntax For Source # | |
ElseSyntax TryExcept Source # | |
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
MkFor | |
|
If statements
MkElif | |
|
MkElse | |
|
Lenses
ifIf :: forall v a. Lens' (If v a) [Whitespace] Source #
elifIndents :: forall v a. Lens' (Elif v a) (Indents a) Source #
elifElif :: forall v a. Lens' (Elif v a) [Whitespace] Source #
elseIndents :: forall v a. Lens' (Else v a) (Indents a) Source #
elseElse :: forall v a. Lens' (Else v a) [Whitespace] Source #
Pass
Return
While loops
MkWhile | |
|
Lenses
whileIndents :: forall v a. Lens' (While v a) (Indents a) Source #
whileWhile :: forall v a. Lens' (While v a) [Whitespace] Source #
Expressions
expr_ :: Raw Expr -> Raw Statement Source #
Turns an SimpleStatement
into a Statement
>>>
expr_ (int_ 3)
3
await
... 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 ...
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
MkTuple | |
|
class AsTupleItem e where Source #
data TupleItem (v :: [*]) a Source #
a
or *a
Used to construct tuples, e.g. (1,
x
, **c)
Instances
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)
MkCall | |
|
Lenses
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
data None (v :: [*]) a Source #
MkNone | |
|
Lenses
noneWhitespace :: forall v a v. Lens (None v a) (None v a) [Whitespace] [Whitespace] Source #
Strings
Integers
int_ :: Integer -> Raw Expr Source #
has a Raw
SimpleStatement
Num
instance, but sometimes we need to name integers
explicitly
>>>
int_ 10
10
Booleans
Ellipses
Lists
>>>
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]
class AsListItem s where Source #
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
Dictionaries
>>>
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}
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
Sets
>>>
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}
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
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)
Dereferencing
Unary operators
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)