blob: eee982be1c9545321b6724dfbeae089304c97ba9 [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{
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +03006 mod = Module(stmt* body)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -05007 | Interactive(stmt* body)
8 | Expression(expr body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00009
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050010 -- not really an actual node but useful in Jython's typesystem.
11 | Suite(stmt* body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000012
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030013 stmt = FunctionDef(identifier name, arguments args,
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +030014 stmt* body, expr* decorator_list, expr? returns)
Yury Selivanov75445082015-05-11 22:57:16 -040015 | AsyncFunctionDef(identifier name, arguments args,
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +030016 stmt* body, expr* decorator_list, expr? returns)
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)
26 | Assign(expr* targets, expr value)
27 | 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
32 | For(expr target, expr iter, stmt* body, stmt* orelse)
Yury Selivanov75445082015-05-11 22:57:16 -040033 | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050034 | While(expr test, stmt* body, stmt* orelse)
35 | If(expr test, stmt* body, stmt* orelse)
36 | With(withitem* items, stmt* body)
Yury Selivanov75445082015-05-11 22:57:16 -040037 | AsyncWith(withitem* items, stmt* body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000038
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050039 | Raise(expr? exc, expr? cause)
40 | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
41 | Assert(expr test, expr? msg)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000042
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050043 | Import(alias* names)
44 | ImportFrom(identifier? module, alias* names, int? level)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000045
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050046 | Global(identifier* names)
47 | Nonlocal(identifier* names)
48 | Expr(expr value)
49 | Pass | Break | Continue
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000050
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050051 -- XXX Jython will be different
52 -- col_offset is the byte offset in the utf8 string the parser uses
53 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000054
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050055 -- BoolOp() can use left & right?
56 expr = BoolOp(boolop op, expr* values)
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 Selivanov75445082015-05-11 22:57:16 -040068 | Await(expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050069 | Yield(expr? value)
Mark Dickinsonded35ae2012-11-25 14:36:26 +000070 | YieldFrom(expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050071 -- need sequences for compare to distinguish between
72 -- x < 4 < 3 and (x < 4) < 3
73 | Compare(expr left, cmpop* ops, expr* comparators)
Benjamin Peterson025e9eb2015-05-05 20:16:41 -040074 | Call(expr func, expr* args, keyword* keywords)
Eric V. Smith235a6f02015-09-19 14:51:32 -040075 | FormattedValue(expr value, int? conversion, expr? format_spec)
76 | JoinedStr(expr* values)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +010077 | Constant(constant value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000078
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050079 -- the following expression can appear in assignment context
80 | Attribute(expr value, identifier attr, expr_context ctx)
81 | Subscript(expr value, slice slice, expr_context ctx)
82 | Starred(expr value, expr_context ctx)
83 | Name(identifier id, expr_context ctx)
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030084 | List(expr* elts, expr_context ctx)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050085 | Tuple(expr* elts, expr_context ctx)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000086
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050087 -- col_offset is the byte offset in the utf8 string the parser uses
88 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000089
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050090 expr_context = Load | Store | Del | AugLoad | AugStore | Param
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000091
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030092 slice = Slice(expr? lower, expr? upper, expr? step)
93 | ExtSlice(slice* dims)
94 | Index(expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000095
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030096 boolop = And | Or
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000097
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030098 operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000099 | RShift | BitOr | BitXor | BitAnd | FloorDiv
100
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500101 unaryop = Invert | Not | UAdd | USub
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000102
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500103 cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000104
Yury Selivanov52c4e7c2016-09-09 10:36:01 -0700105 comprehension = (expr target, expr iter, expr* ifs, int is_async)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000106
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500107 excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
108 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000109
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700110 arguments = (arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults,
111 arg? kwarg, expr* defaults)
112
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500113 arg = (identifier arg, expr? annotation)
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700114 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000115
Benjamin Peterson025e9eb2015-05-05 20:16:41 -0400116 -- keyword arguments supplied to call (NULL identifier for **kwargs)
117 keyword = (identifier? arg, expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000118
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500119 -- import name with optional 'as' alias.
120 alias = (identifier name, identifier? asname)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -0500121
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500122 withitem = (expr context_expr, expr? optional_vars)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000123}
Thomas Wouters8b4a3e82007-02-23 20:00:10 +0000124