blob: 126d478975bbbb449e600fcecff5072a7239bd94 [file] [log] [blame]
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001-- ASDL's 5 builtin types are:
2-- identifier, int, string, object, 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{
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006 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
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050011 -- not really an actual node but useful in Jython's typesystem.
12 | Suite(stmt* body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000013
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030014 stmt = FunctionDef(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 | AsyncFunctionDef(identifier name, arguments args,
Guido van Rossumdcfcd142019-01-31 03:40:27 -080018 stmt* body, expr* decorator_list, expr? returns,
19 string? type_comment)
Yury Selivanov75445082015-05-11 22:57:16 -040020
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030021 | ClassDef(identifier name,
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050022 expr* bases,
23 keyword* keywords,
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050024 stmt* body,
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +030025 expr* decorator_list)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050026 | Return(expr? value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000027
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050028 | Delete(expr* targets)
Guido van Rossumdcfcd142019-01-31 03:40:27 -080029 | Assign(expr* targets, expr value, string? type_comment)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050030 | AugAssign(expr target, operator op, expr value)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -070031 -- 'simple' indicates that we annotate simple name without parens
32 | AnnAssign(expr target, expr annotation, expr? value, int simple)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000033
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050034 -- use 'orelse' because else is a keyword in target languages
Guido van Rossumdcfcd142019-01-31 03:40:27 -080035 | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)
36 | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050037 | While(expr test, stmt* body, stmt* orelse)
38 | If(expr test, stmt* body, stmt* orelse)
Guido van Rossumdcfcd142019-01-31 03:40:27 -080039 | With(withitem* items, stmt* body, string? type_comment)
40 | AsyncWith(withitem* items, stmt* body, string? type_comment)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000041
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050042 | Raise(expr? exc, expr? cause)
43 | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
44 | Assert(expr test, expr? msg)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000045
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050046 | Import(alias* names)
47 | ImportFrom(identifier? module, alias* names, int? level)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000048
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050049 | Global(identifier* names)
50 | Nonlocal(identifier* names)
51 | Expr(expr value)
52 | Pass | Break | Continue
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000053
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050054 -- XXX Jython will be different
55 -- col_offset is the byte offset in the utf8 string the parser uses
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000056 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000057
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050058 -- BoolOp() can use left & right?
59 expr = BoolOp(boolop op, expr* values)
Emily Morehouse8f59ee02019-01-24 16:49:56 -070060 | NamedExpr(expr target, expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050061 | BinOp(expr left, operator op, expr right)
62 | UnaryOp(unaryop op, expr operand)
63 | Lambda(arguments args, expr body)
64 | IfExp(expr test, expr body, expr orelse)
65 | Dict(expr* keys, expr* values)
66 | Set(expr* elts)
67 | ListComp(expr elt, comprehension* generators)
68 | SetComp(expr elt, comprehension* generators)
69 | DictComp(expr key, expr value, comprehension* generators)
70 | GeneratorExp(expr elt, comprehension* generators)
71 -- the grammar constrains where yield expressions can occur
Yury Selivanov75445082015-05-11 22:57:16 -040072 | Await(expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050073 | Yield(expr? value)
Mark Dickinsonded35ae2012-11-25 14:36:26 +000074 | YieldFrom(expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050075 -- need sequences for compare to distinguish between
76 -- x < 4 < 3 and (x < 4) < 3
77 | Compare(expr left, cmpop* ops, expr* comparators)
Benjamin Peterson025e9eb2015-05-05 20:16:41 -040078 | Call(expr func, expr* args, keyword* keywords)
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -040079 | FormattedValue(expr value, int? conversion, expr? format_spec)
Eric V. Smith235a6f02015-09-19 14:51:32 -040080 | JoinedStr(expr* values)
Guido van Rossum10f8ce62019-03-13 13:00:46 -070081 | Constant(constant value, string? kind)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000082
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050083 -- the following expression can appear in assignment context
84 | Attribute(expr value, identifier attr, expr_context ctx)
85 | Subscript(expr value, slice slice, expr_context ctx)
86 | Starred(expr value, expr_context ctx)
87 | Name(identifier id, expr_context ctx)
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030088 | List(expr* elts, expr_context ctx)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050089 | Tuple(expr* elts, expr_context ctx)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000090
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050091 -- col_offset is the byte offset in the utf8 string the parser uses
Ivan Levkivskyi9932a222019-01-22 11:18:22 +000092 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000093
Serhiy Storchakad8b3a982019-03-05 20:42:06 +020094 expr_context = Load | Store | Del | AugLoad | AugStore | Param
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000095
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030096 slice = Slice(expr? lower, expr? upper, expr? step)
97 | ExtSlice(slice* dims)
98 | Index(expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000099
Serhiy Storchaka45ec3282015-04-03 19:42:32 +0300100 boolop = And | Or
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000101
Serhiy Storchaka45ec3282015-04-03 19:42:32 +0300102 operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000103 | RShift | BitOr | BitXor | BitAnd | FloorDiv
104
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500105 unaryop = Invert | Not | UAdd | USub
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000106
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500107 cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000108
Yury Selivanov52c4e7c2016-09-09 10:36:01 -0700109 comprehension = (expr target, expr iter, expr* ifs, int is_async)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000110
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500111 excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000112 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000113
Miss Islington (bot)cf9a63c2019-07-14 16:49:52 -0700114 arguments = (arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs,
Pablo Galindo8c77b8c2019-04-29 13:36:57 +0100115 expr* kw_defaults, arg? kwarg, expr* defaults)
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700116
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800117 arg = (identifier arg, expr? annotation, string? type_comment)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000118 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000119
Benjamin Peterson025e9eb2015-05-05 20:16:41 -0400120 -- keyword arguments supplied to call (NULL identifier for **kwargs)
121 keyword = (identifier? arg, expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000122
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500123 -- import name with optional 'as' alias.
124 alias = (identifier name, identifier? asname)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -0500125
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500126 withitem = (expr context_expr, expr? optional_vars)
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800127
Michael J. Sullivan933e1502019-05-22 07:54:20 -0700128 type_ignore = TypeIgnore(int lineno, string tag)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000129}