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