| 1 |
-- ASDL's 4 builtin types are: |
| 2 |
-- identifier, int, string, constant |
| 3 |
|
| 4 |
module Python |
| 5 |
{ |
| 6 |
mod = Module(stmt* body, type_ignore* type_ignores) |
| 7 |
| Interactive(stmt* body) |
| 8 |
| Expression(expr body) |
| 9 |
| FunctionType(expr* argtypes, expr returns) |
| 10 |
|
| 11 |
stmt = FunctionDef(identifier name, arguments args, |
| 12 |
stmt* body, expr* decorator_list, expr? returns, |
| 13 |
string? type_comment, type_param* type_params) |
| 14 |
| AsyncFunctionDef(identifier name, arguments args, |
| 15 |
stmt* body, expr* decorator_list, expr? returns, |
| 16 |
string? type_comment, type_param* type_params) |
| 17 |
|
| 18 |
| ClassDef(identifier name, |
| 19 |
expr* bases, |
| 20 |
keyword* keywords, |
| 21 |
stmt* body, |
| 22 |
expr* decorator_list, |
| 23 |
type_param* type_params) |
| 24 |
| Return(expr? value) |
| 25 |
|
| 26 |
| Delete(expr* targets) |
| 27 |
| Assign(expr* targets, expr value, string? type_comment) |
| 28 |
| TypeAlias(expr name, type_param* type_params, expr value) |
| 29 |
| AugAssign(expr target, operator op, expr value) |
| 30 |
-- 'simple' indicates that we annotate simple name without parens |
| 31 |
| AnnAssign(expr target, expr annotation, expr? value, int simple) |
| 32 |
|
| 33 |
-- use 'orelse' because else is a keyword in target languages |
| 34 |
| For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment) |
| 35 |
| AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment) |
| 36 |
| While(expr test, stmt* body, stmt* orelse) |
| 37 |
| If(expr test, stmt* body, stmt* orelse) |
| 38 |
| With(withitem* items, stmt* body, string? type_comment) |
| 39 |
| AsyncWith(withitem* items, stmt* body, string? type_comment) |
| 40 |
|
| 41 |
| Match(expr subject, match_case* cases) |
| 42 |
|
| 43 |
| Raise(expr? exc, expr? cause) |
| 44 |
| Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody) |
| 45 |
| TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody) |
| 46 |
| Assert(expr test, expr? msg) |
| 47 |
|
| 48 |
| Import(alias* names) |
| 49 |
| ImportFrom(identifier? module, alias* names, int? level) |
| 50 |
|
| 51 |
| Global(identifier* names) |
| 52 |
| Nonlocal(identifier* names) |
| 53 |
| Expr(expr value) |
| 54 |
| Pass | Break | Continue |
| 55 |
|
| 56 |
-- col_offset is the byte offset in the utf8 string the parser uses |
| 57 |
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) |
| 58 |
|
| 59 |
-- BoolOp() can use left & right? |
| 60 |
expr = BoolOp(boolop op, expr* values) |
| 61 |
| NamedExpr(expr target, expr value) |
| 62 |
| BinOp(expr left, operator op, expr right) |
| 63 |
| UnaryOp(unaryop op, expr operand) |
| 64 |
| Lambda(arguments args, expr body) |
| 65 |
| IfExp(expr test, expr body, expr orelse) |
| 66 |
| Dict(expr* keys, expr* values) |
| 67 |
| Set(expr* elts) |
| 68 |
| ListComp(expr elt, comprehension* generators) |
| 69 |
| SetComp(expr elt, comprehension* generators) |
| 70 |
| DictComp(expr key, expr value, comprehension* generators) |
| 71 |
| GeneratorExp(expr elt, comprehension* generators) |
| 72 |
-- the grammar constrains where yield expressions can occur |
| 73 |
| Await(expr value) |
| 74 |
| Yield(expr? value) |
| 75 |
| YieldFrom(expr value) |
| 76 |
-- need sequences for compare to distinguish between |
| 77 |
-- x < 4 < 3 and (x < 4) < 3 |
| 78 |
| Compare(expr left, cmpop* ops, expr* comparators) |
| 79 |
| Call(expr func, expr* args, keyword* keywords) |
| 80 |
| FormattedValue(expr value, int conversion, expr? format_spec) |
| 81 |
| JoinedStr(expr* values) |
| 82 |
| Constant(constant value, string? kind) |
| 83 |
|
| 84 |
-- the following expression can appear in assignment context |
| 85 |
| Attribute(expr value, identifier attr, expr_context ctx) |
| 86 |
| Subscript(expr value, expr slice, expr_context ctx) |
| 87 |
| Starred(expr value, expr_context ctx) |
| 88 |
| Name(identifier id, expr_context ctx) |
| 89 |
| List(expr* elts, expr_context ctx) |
| 90 |
| Tuple(expr* elts, expr_context ctx) |
| 91 |
|
| 92 |
-- can appear only in Subscript |
| 93 |
| Slice(expr? lower, expr? upper, expr? step) |
| 94 |
|
| 95 |
-- col_offset is the byte offset in the utf8 string the parser uses |
| 96 |
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) |
| 97 |
|
| 98 |
expr_context = Load | Store | Del |
| 99 |
|
| 100 |
boolop = And | Or |
| 101 |
|
| 102 |
operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift |
| 103 |
| RShift | BitOr | BitXor | BitAnd | FloorDiv |
| 104 |
|
| 105 |
unaryop = Invert | Not | UAdd | USub |
| 106 |
|
| 107 |
cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn |
| 108 |
|
| 109 |
comprehension = (expr target, expr iter, expr* ifs, int is_async) |
| 110 |
|
| 111 |
excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body) |
| 112 |
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) |
| 113 |
|
| 114 |
arguments = (arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, |
| 115 |
expr* kw_defaults, arg? kwarg, expr* defaults) |
| 116 |
|
| 117 |
arg = (identifier arg, expr? annotation, string? type_comment) |
| 118 |
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) |
| 119 |
|
| 120 |
-- keyword arguments supplied to call (NULL identifier for **kwargs) |
| 121 |
keyword = (identifier? arg, expr value) |
| 122 |
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) |
| 123 |
|
| 124 |
-- import name with optional 'as' alias. |
| 125 |
alias = (identifier name, identifier? asname) |
| 126 |
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) |
| 127 |
|
| 128 |
withitem = (expr context_expr, expr? optional_vars) |
| 129 |
|
| 130 |
match_case = (pattern pattern, expr? guard, stmt* body) |
| 131 |
|
| 132 |
pattern = MatchValue(expr value) |
| 133 |
| MatchSingleton(constant value) |
| 134 |
| MatchSequence(pattern* patterns) |
| 135 |
| MatchMapping(expr* keys, pattern* patterns, identifier? rest) |
| 136 |
| MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns) |
| 137 |
|
| 138 |
| MatchStar(identifier? name) |
| 139 |
-- The optional "rest" MatchMapping parameter handles capturing extra mapping keys |
| 140 |
|
| 141 |
| MatchAs(pattern? pattern, identifier? name) |
| 142 |
| MatchOr(pattern* patterns) |
| 143 |
|
| 144 |
attributes (int lineno, int col_offset, int end_lineno, int end_col_offset) |
| 145 |
|
| 146 |
type_ignore = TypeIgnore(int lineno, string tag) |
| 147 |
|
| 148 |
type_param = TypeVar(identifier name, expr? bound, expr? default_value) |
| 149 |
| ParamSpec(identifier name, expr? default_value) |
| 150 |
| TypeVarTuple(identifier name, expr? default_value) |
| 151 |
attributes (int lineno, int col_offset, int end_lineno, int end_col_offset) |
| 152 |
} |