Portability | ghc |
---|---|
Stability | experimental |
Maintainer | bjpop@csse.unimelb.edu.au |
Representation of the Python version 3 abstract syntax.
See:
- http://docs.python.org/dev/3.0/reference/index.html for an overview of the language.
- http://docs.python.org/dev/3.0/reference/grammar.html for the full grammar.
Note: there are cases where the AST is more liberal than the formal grammar of the language. Therefore some care must be taken when constructing Python programs using the raw AST. XXX At some point we should provide smart constructors which ensure syntactic correctness of the AST.
- newtype Module = Module [Statement]
- newtype Ident = Ident String
- type DottedName = [Ident]
- data Statement
- = Import {
- import_items :: [ImportItem]
- | FromImport { }
- | While {
- while_cond :: Expr
- while_body :: Suite
- while_else :: Suite
- | For {
- for_targets :: [Expr]
- for_generator :: Expr
- for_body :: Suite
- for_else :: Suite
- | Fun { }
- | Class {
- class_name :: Ident
- class_args :: [Argument]
- class_body :: Suite
- | Conditional {
- cond_guards :: [(Expr, Suite)]
- cond_else :: Suite
- | Assign {
- assign_to :: [Expr]
- assign_expr :: Expr
- | AugmentedAssign { }
- | Decorated { }
- | Return {
- return_expr :: Maybe Expr
- | Try {
- try_body :: Suite
- try_excepts :: [Handler]
- try_else :: Suite
- try_finally :: Suite
- | Raise {
- raise_expr :: Maybe (Expr, Maybe Expr)
- | With { }
- | Pass
- | Break
- | Continue
- | Delete { }
- | StmtExpr { }
- | Global {
- global_vars :: [Ident]
- | NonLocal {
- nonLocal_vars :: [Ident]
- | Assert {
- assert_exprs :: [Expr]
- = Import {
- type Suite = [Statement]
- data Parameter
- = Param { }
- | VarArgsPos { }
- | VarArgsKeyword { }
- | EndPositional
- data Decorator = Decorator {}
- data AssignOp
- = PlusAssign
- | MinusAssign
- | MultAssign
- | DivAssign
- | ModAssign
- | PowAssign
- | BinAndAssign
- | BinOrAssign
- | BinXorAssign
- | LeftShiftAssign
- | RightShiftAssign
- | FloorDivAssign
- data Expr
- = Var Ident
- | Int Integer
- | Float Double
- | Imaginary { }
- | Bool Bool
- | None
- | Ellipsis
- | ByteStrings [ByteString]
- | Strings [String]
- | Call { }
- | Subscript {
- subscriptee :: Expr
- subscript_exprs :: [Expr]
- | SlicedExpr { }
- | CondExpr { }
- | BinaryOp {
- operator :: Op
- left_op_arg :: Expr
- right_op_arg :: Expr
- | UnaryOp { }
- | Lambda {
- lambda_args :: [Parameter]
- lambda_body :: Expr
- | Tuple {
- tuple_exprs :: [Expr]
- | Yield {
- yield_expr :: Maybe Expr
- | Generator { }
- | ListComp { }
- | List {
- list_exprs :: [Expr]
- | Dictionary {
- dict_mappings :: [(Expr, Expr)]
- | DictComp { }
- | Set { }
- | SetComp { }
- | Starred {
- starred_expr :: Expr
- data Op
- data Argument
- = ArgExpr { }
- | ArgVarArgsPos { }
- | ArgVarArgsKeyword { }
- | ArgKeyword {
- arg_keyword :: Ident
- arg_expr :: Expr
- data Slice
- = SliceProper {
- slice_lower :: Maybe Expr
- slice_upper :: Maybe Expr
- slice_stride :: Maybe (Maybe Expr)
- | SliceExpr {
- slice_expr :: Expr
- = SliceProper {
- data ImportItem = ImportItem {}
- data FromItem = FromItem {}
- data FromItems
- data ImportModule
- type Handler = (ExceptClause, Suite)
- type ExceptClause = Maybe (Expr, Maybe Ident)
- data Comprehension e = Comprehension {}
- data CompFor = CompFor {
- comp_for_exprs :: [Expr]
- comp_in_expr :: Expr
- comp_for_iter :: Maybe CompIter
- data CompIf = CompIf {
- comp_if :: Expr
- comp_if_iter :: Maybe CompIter
- data CompIter
Modules
A module (Python source file). See http://docs.python.org/dev/3.0/reference/toplevel_components.html.
Identifiers and dotted names
type DottedName = [Ident]Source
A compound name constructed with the dot operator.
Statements, suites, parameters, decorators and assignment operators
Statements.
See:
type Suite = [Statement]Source
A block of statements. A suite is a group of statements controlled by a clause, for example, the body of a loop. See http://docs.python.org/dev/3.0/reference/compound_stmts.html.
Formal parameter of function definitions and lambda expressions.
See:
Param | Ordinary named parameter. |
| |
VarArgsPos | Excess positional parameter (single asterisk before its name in the concrete syntax). |
| |
VarArgsKeyword | Excess keyword parameter (double asterisk before its name in the concrete syntax). |
| |
EndPositional | Marker for the end of positional parameters (not a parameter itself). |
Decorator.
Decorator | |
|
Augmented assignment operators.
PlusAssign | '+=' |
MinusAssign | '-=' |
MultAssign | '*=' |
DivAssign | '/=' |
ModAssign | '%=' |
PowAssign | '*=' |
BinAndAssign | '&=' |
BinOrAssign | '|=' |
BinXorAssign | '^=' |
LeftShiftAssign | '<<=' |
RightShiftAssign | '>>=' |
FloorDivAssign | '//=' |
Expressions, operators, arguments and slices
Expression.
See: http://docs.python.org/dev/3.0/reference/expressions.html.
Operators.
And | 'and' |
Or | 'or' |
Not | 'not' |
Exponent | '**' |
LessThan | '<' |
GreaterThan | '>' |
Equality | '==' |
GreaterThanEquals | '>=' |
LessThanEquals | '<=' |
NotEquals | '!=' |
In | 'in' |
Is | 'is' |
IsNot | 'is not' |
NotIn | 'not in' |
BinaryOr | '|' |
Xor | '^' |
BinaryAnd | '&' |
ShiftLeft | '<<' |
ShiftRight | '>>' |
Multiply | '*' |
Plus | '+' |
Minus | '-' |
Divide | '/' |
FloorDivide | '//' |
Invert | '~' (bitwise inversion of its integer argument) |
Modulo | '%' |
Dot | '.' |
Arguments to function calls, class declarations and decorators.
ArgExpr | Ordinary argument expression. |
ArgVarArgsPos | Excess positional argument. |
ArgVarArgsKeyword | Excess keyword argument. |
ArgKeyword | Keyword argument. |
|
SliceProper | |
| |
SliceExpr | |
|
Imports
data ImportItem Source
An entity imported using the 'import' keyword. See http://docs.python.org/dev/3.0/reference/simple_stmts.html#the-import-statement.
ImportItem | |
|
An entity imported using the 'from ... import' construct. See http://docs.python.org/dev/3.0/reference/simple_stmts.html#the-import-statement
FromItem | |
|
Items imported using the 'from ... import' construct.
ImportEverything | Import everything exported from the module. |
FromItems [FromItem] | Import a specific list of items from the module. |
data ImportModule Source
A reference to the module to import from using the 'from ... import' construct.
ImportRelative ImportModule | Relative import. A dot followed by something. |
ImportDot | Relative import. Dot on its own. |
ImportName DottedName | The name of the module to import from. |
Exceptions
type Handler = (ExceptClause, Suite)Source
Exception handler. See: http://docs.python.org/dev/3.0/reference/compound_stmts.html#the-try-statement.
type ExceptClause = Maybe (Expr, Maybe Ident)Source
Exception clause. See: http://docs.python.org/dev/3.0/reference/compound_stmts.html#the-try-statement.
Comprehensions
data Comprehension e Source
Comprehension. See: http://docs.python.org/dev/3.0/reference/expressions.html#displays-for-lists-sets-and-dictionaries
Show e => Show (Comprehension e) | |
Pretty a => Pretty (Comprehension a) |
Comprehension 'for' component. See: http://docs.python.org/dev/3.0/reference/expressions.html#displays-for-lists-sets-and-dictionaries
CompFor | |
|
Comprehension guard. See: http://docs.python.org/dev/3.0/reference/expressions.html#displays-for-lists-sets-and-dictionaries.