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