blob: 32fdc01a7e0e6ea7b1a4628f82e1e6a55c1b401e [file] [log] [blame]
Batuhan Taskaya091951a2020-05-06 17:29:32 +03001-- ASDL's 4 builtin types are:
2-- identifier, int, string, constant
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003
Benjamin Peterson6cb2b922011-03-12 18:28:16 -06004module Python
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005{
Batuhan Taşkayad82e4692020-03-04 19:16:47 +03006 mod = Module(stmt* body, type_ignore* type_ignores)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -05007 | Interactive(stmt* body)
8 | Expression(expr body)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009 | FunctionType(expr* argtypes, expr returns)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030011 stmt = FunctionDef(identifier name, arguments args,
Guido van Rossumdcfcd142019-01-31 03:40:27 -080012 stmt* body, expr* decorator_list, expr? returns,
13 string? type_comment)
Yury Selivanov75445082015-05-11 22:57:16 -040014 | AsyncFunctionDef(identifier name, arguments args,
Guido van Rossumdcfcd142019-01-31 03:40:27 -080015 stmt* body, expr* decorator_list, expr? returns,
16 string? type_comment)
Yury Selivanov75445082015-05-11 22:57:16 -040017
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030018 | ClassDef(identifier name,
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050019 expr* bases,
20 keyword* keywords,
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050021 stmt* body,
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +030022 expr* decorator_list)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050023 | Return(expr? value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000024
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050025 | Delete(expr* targets)
Guido van Rossumdcfcd142019-01-31 03:40:27 -080026 | Assign(expr* targets, expr value, string? type_comment)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050027 | AugAssign(expr target, operator op, expr value)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -070028 -- 'simple' indicates that we annotate simple name without parens
29 | AnnAssign(expr target, expr annotation, expr? value, int simple)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000030
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050031 -- use 'orelse' because else is a keyword in target languages
Guido van Rossumdcfcd142019-01-31 03:40:27 -080032 | 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 Peterson8d5a62d2012-01-16 09:54:28 -050034 | While(expr test, stmt* body, stmt* orelse)
35 | If(expr test, stmt* body, stmt* orelse)
Guido van Rossumdcfcd142019-01-31 03:40:27 -080036 | With(withitem* items, stmt* body, string? type_comment)
37 | AsyncWith(withitem* items, stmt* body, string? type_comment)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000038
Brandt Bucher145bf262021-02-26 14:51:55 -080039 | Match(expr subject, match_case* cases)
40
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050041 | Raise(expr? exc, expr? cause)
42 | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
43 | Assert(expr test, expr? msg)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000044
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050045 | Import(alias* names)
46 | ImportFrom(identifier? module, alias* names, int? level)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000047
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050048 | Global(identifier* names)
49 | Nonlocal(identifier* names)
50 | Expr(expr value)
51 | Pass | Break | Continue
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000052
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050053 -- col_offset is the byte offset in the utf8 string the parser uses
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000054 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000055
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050056 -- BoolOp() can use left & right?
57 expr = BoolOp(boolop op, expr* values)
Emily Morehouse8f59ee02019-01-24 16:49:56 -070058 | NamedExpr(expr target, expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050059 | BinOp(expr left, operator op, expr right)
60 | UnaryOp(unaryop op, expr operand)
61 | Lambda(arguments args, expr body)
62 | IfExp(expr test, expr body, expr orelse)
63 | Dict(expr* keys, expr* values)
64 | Set(expr* elts)
65 | ListComp(expr elt, comprehension* generators)
66 | SetComp(expr elt, comprehension* generators)
67 | DictComp(expr key, expr value, comprehension* generators)
68 | GeneratorExp(expr elt, comprehension* generators)
69 -- the grammar constrains where yield expressions can occur
Yury Selivanov75445082015-05-11 22:57:16 -040070 | Await(expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050071 | Yield(expr? value)
Mark Dickinsonded35ae2012-11-25 14:36:26 +000072 | YieldFrom(expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050073 -- need sequences for compare to distinguish between
74 -- x < 4 < 3 and (x < 4) < 3
75 | Compare(expr left, cmpop* ops, expr* comparators)
Benjamin Peterson025e9eb2015-05-05 20:16:41 -040076 | Call(expr func, expr* args, keyword* keywords)
Miss Islington (bot)bea3f422022-01-07 14:30:18 -080077 | FormattedValue(expr value, int conversion, expr? format_spec)
Eric V. Smith235a6f02015-09-19 14:51:32 -040078 | JoinedStr(expr* values)
Guido van Rossum10f8ce62019-03-13 13:00:46 -070079 | Constant(constant value, string? kind)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000080
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050081 -- the following expression can appear in assignment context
82 | Attribute(expr value, identifier attr, expr_context ctx)
Serhiy Storchaka13d52c22020-03-10 18:52:34 +020083 | Subscript(expr value, expr slice, expr_context ctx)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050084 | Starred(expr value, expr_context ctx)
85 | Name(identifier id, expr_context ctx)
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030086 | List(expr* elts, expr_context ctx)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050087 | Tuple(expr* elts, expr_context ctx)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000088
Serhiy Storchaka13d52c22020-03-10 18:52:34 +020089 -- can appear only in Subscript
90 | Slice(expr? lower, expr? upper, expr? step)
91
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050092 -- col_offset is the byte offset in the utf8 string the parser uses
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000093 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000094
Serhiy Storchaka6b975982020-03-17 23:41:08 +020095 expr_context = Load | Store | Del
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000096
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030097 boolop = And | Or
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000098
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030099 operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000100 | RShift | BitOr | BitXor | BitAnd | FloorDiv
101
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500102 unaryop = Invert | Not | UAdd | USub
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000103
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500104 cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000105
Yury Selivanov52c4e7c2016-09-09 10:36:01 -0700106 comprehension = (expr target, expr iter, expr* ifs, int is_async)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000107
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500108 excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000109 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000110
Pablo Galindocd6e83b2019-07-15 01:32:18 +0200111 arguments = (arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs,
Pablo Galindo8c77b8c2019-04-29 13:36:57 +0100112 expr* kw_defaults, arg? kwarg, expr* defaults)
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700113
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800114 arg = (identifier arg, expr? annotation, string? type_comment)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000115 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000116
Benjamin Peterson025e9eb2015-05-05 20:16:41 -0400117 -- keyword arguments supplied to call (NULL identifier for **kwargs)
118 keyword = (identifier? arg, expr value)
Pablo Galindo168660b2020-04-02 00:47:39 +0100119 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000120
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500121 -- import name with optional 'as' alias.
122 alias = (identifier name, identifier? asname)
Matthew Suozzo75a06f02021-04-10 16:56:28 -0400123 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -0500124
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500125 withitem = (expr context_expr, expr? optional_vars)
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800126
Nick Coghlan1e7b8582021-04-29 15:58:44 +1000127 match_case = (pattern pattern, expr? guard, stmt* body)
128
129 pattern = MatchValue(expr value)
130 | MatchSingleton(constant value)
131 | MatchSequence(pattern* patterns)
132 | MatchMapping(expr* keys, pattern* patterns, identifier? rest)
133 | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)
134
135 | MatchStar(identifier? name)
136 -- The optional "rest" MatchMapping parameter handles capturing extra mapping keys
137
138 | MatchAs(pattern? pattern, identifier? name)
139 | MatchOr(pattern* patterns)
140
141 attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)
Brandt Bucher145bf262021-02-26 14:51:55 -0800142
Michael J. Sullivan933e1502019-05-22 07:54:20 -0700143 type_ignore = TypeIgnore(int lineno, string tag)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000144}