Batuhan Taskaya | 091951a | 2020-05-06 17:29:32 +0300 | [diff] [blame] | 1 | -- ASDL's 4 builtin types are: |
| 2 | -- identifier, int, string, constant |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 3 | |
Benjamin Peterson | 6cb2b92 | 2011-03-12 18:28:16 -0600 | [diff] [blame] | 4 | module Python |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 5 | { |
Batuhan Taşkaya | d82e469 | 2020-03-04 19:16:47 +0300 | [diff] [blame] | 6 | mod = Module(stmt* body, type_ignore* type_ignores) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 7 | | Interactive(stmt* body) |
| 8 | | Expression(expr body) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 9 | | FunctionType(expr* argtypes, expr returns) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 10 | |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 11 | stmt = FunctionDef(identifier name, arguments args, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 12 | stmt* body, expr* decorator_list, expr? returns, |
| 13 | string? type_comment) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 14 | | AsyncFunctionDef(identifier name, arguments args, |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 15 | stmt* body, expr* decorator_list, expr? returns, |
| 16 | string? type_comment) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 17 | |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 18 | | ClassDef(identifier name, |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 19 | expr* bases, |
| 20 | keyword* keywords, |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 21 | stmt* body, |
Serhiy Storchaka | 73cbe7a | 2018-05-29 12:04:55 +0300 | [diff] [blame] | 22 | expr* decorator_list) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 23 | | Return(expr? value) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 24 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 25 | | Delete(expr* targets) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 26 | | Assign(expr* targets, expr value, string? type_comment) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 27 | | AugAssign(expr target, operator op, expr value) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 28 | -- 'simple' indicates that we annotate simple name without parens |
| 29 | | AnnAssign(expr target, expr annotation, expr? value, int simple) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 30 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 31 | -- use 'orelse' because else is a keyword in target languages |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 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) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 34 | | While(expr test, stmt* body, stmt* orelse) |
| 35 | | If(expr test, stmt* body, stmt* orelse) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 36 | | With(withitem* items, stmt* body, string? type_comment) |
| 37 | | AsyncWith(withitem* items, stmt* body, string? type_comment) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 38 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 39 | | Raise(expr? exc, expr? cause) |
| 40 | | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody) |
| 41 | | Assert(expr test, expr? msg) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 42 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 43 | | Import(alias* names) |
| 44 | | ImportFrom(identifier? module, alias* names, int? level) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 45 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 46 | | Global(identifier* names) |
| 47 | | Nonlocal(identifier* names) |
| 48 | | Expr(expr value) |
| 49 | | Pass | Break | Continue |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 50 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 51 | -- col_offset is the byte offset in the utf8 string the parser uses |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 52 | attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 53 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 54 | -- BoolOp() can use left & right? |
| 55 | expr = BoolOp(boolop op, expr* values) |
Emily Morehouse | 8f59ee0 | 2019-01-24 16:49:56 -0700 | [diff] [blame] | 56 | | NamedExpr(expr target, expr value) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 57 | | BinOp(expr left, operator op, expr right) |
| 58 | | UnaryOp(unaryop op, expr operand) |
| 59 | | Lambda(arguments args, expr body) |
| 60 | | IfExp(expr test, expr body, expr orelse) |
| 61 | | Dict(expr* keys, expr* values) |
| 62 | | Set(expr* elts) |
| 63 | | ListComp(expr elt, comprehension* generators) |
| 64 | | SetComp(expr elt, comprehension* generators) |
| 65 | | DictComp(expr key, expr value, comprehension* generators) |
| 66 | | GeneratorExp(expr elt, comprehension* generators) |
| 67 | -- the grammar constrains where yield expressions can occur |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 68 | | Await(expr value) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 69 | | Yield(expr? value) |
Mark Dickinson | ded35ae | 2012-11-25 14:36:26 +0000 | [diff] [blame] | 70 | | YieldFrom(expr value) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 71 | -- need sequences for compare to distinguish between |
| 72 | -- x < 4 < 3 and (x < 4) < 3 |
| 73 | | Compare(expr left, cmpop* ops, expr* comparators) |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 74 | | Call(expr func, expr* args, keyword* keywords) |
Eric V. Smith | 6f6ff8a | 2019-05-27 15:31:52 -0400 | [diff] [blame] | 75 | | FormattedValue(expr value, int? conversion, expr? format_spec) |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 76 | | JoinedStr(expr* values) |
Guido van Rossum | 10f8ce6 | 2019-03-13 13:00:46 -0700 | [diff] [blame] | 77 | | Constant(constant value, string? kind) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 78 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 79 | -- the following expression can appear in assignment context |
| 80 | | Attribute(expr value, identifier attr, expr_context ctx) |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 81 | | Subscript(expr value, expr slice, expr_context ctx) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 82 | | Starred(expr value, expr_context ctx) |
| 83 | | Name(identifier id, expr_context ctx) |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 84 | | List(expr* elts, expr_context ctx) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 85 | | Tuple(expr* elts, expr_context ctx) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 86 | |
Serhiy Storchaka | 13d52c2 | 2020-03-10 18:52:34 +0200 | [diff] [blame] | 87 | -- can appear only in Subscript |
| 88 | | Slice(expr? lower, expr? upper, expr? step) |
| 89 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 90 | -- col_offset is the byte offset in the utf8 string the parser uses |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 91 | attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 92 | |
Serhiy Storchaka | 6b97598 | 2020-03-17 23:41:08 +0200 | [diff] [blame] | 93 | expr_context = Load | Store | Del |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 94 | |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 95 | boolop = And | Or |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 96 | |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 97 | operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 98 | | RShift | BitOr | BitXor | BitAnd | FloorDiv |
| 99 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 100 | unaryop = Invert | Not | UAdd | USub |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 101 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 102 | cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 103 | |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 104 | comprehension = (expr target, expr iter, expr* ifs, int is_async) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 105 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 106 | excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 107 | attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 108 | |
Pablo Galindo | cd6e83b | 2019-07-15 01:32:18 +0200 | [diff] [blame] | 109 | arguments = (arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, |
Pablo Galindo | 8c77b8c | 2019-04-29 13:36:57 +0100 | [diff] [blame] | 110 | expr* kw_defaults, arg? kwarg, expr* defaults) |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 111 | |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 112 | arg = (identifier arg, expr? annotation, string? type_comment) |
Ivan Levkivskyi | 9932a22 | 2019-01-22 11:18:22 +0000 | [diff] [blame] | 113 | attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 114 | |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 115 | -- keyword arguments supplied to call (NULL identifier for **kwargs) |
| 116 | keyword = (identifier? arg, expr value) |
Pablo Galindo | 168660b | 2020-04-02 00:47:39 +0100 | [diff] [blame] | 117 | attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 118 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 119 | -- import name with optional 'as' alias. |
| 120 | alias = (identifier name, identifier? asname) |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 121 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 122 | withitem = (expr context_expr, expr? optional_vars) |
Guido van Rossum | dcfcd14 | 2019-01-31 03:40:27 -0800 | [diff] [blame] | 123 | |
Michael J. Sullivan | 933e150 | 2019-05-22 07:54:20 -0700 | [diff] [blame] | 124 | type_ignore = TypeIgnore(int lineno, string tag) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 125 | } |