blob: 526cffbce028f8515f48492f624ba4c360b2c8c4 [file] [log] [blame]
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001-- ASDL's 7 builtin types are:
2-- identifier, int, string, bytes, object, singleton, constant
3--
4-- singleton: None, True or False
5-- constant can be None, whereas None means "no value" for object.
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00006
Benjamin Peterson6cb2b922011-03-12 18:28:16 -06007module Python
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00008{
INADA Naokicb41b272017-02-23 00:31:59 +09009 mod = Module(stmt* body, string? docstring)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050010 | Interactive(stmt* body)
11 | Expression(expr body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000012
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050013 -- not really an actual node but useful in Jython's typesystem.
14 | Suite(stmt* body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000015
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030016 stmt = FunctionDef(identifier name, arguments args,
INADA Naokicb41b272017-02-23 00:31:59 +090017 stmt* body, expr* decorator_list, expr? returns,
18 string? docstring)
Yury Selivanov75445082015-05-11 22:57:16 -040019 | AsyncFunctionDef(identifier name, arguments args,
INADA Naokicb41b272017-02-23 00:31:59 +090020 stmt* body, expr* decorator_list, expr? returns,
21 string? docstring)
Yury Selivanov75445082015-05-11 22:57:16 -040022
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030023 | ClassDef(identifier name,
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050024 expr* bases,
25 keyword* keywords,
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050026 stmt* body,
INADA Naokicb41b272017-02-23 00:31:59 +090027 expr* decorator_list,
28 string? docstring)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050029 | Return(expr? value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000030
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050031 | Delete(expr* targets)
32 | Assign(expr* targets, expr value)
33 | AugAssign(expr target, operator op, expr value)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -070034 -- 'simple' indicates that we annotate simple name without parens
35 | AnnAssign(expr target, expr annotation, expr? value, int simple)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000036
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050037 -- use 'orelse' because else is a keyword in target languages
38 | For(expr target, expr iter, stmt* body, stmt* orelse)
Yury Selivanov75445082015-05-11 22:57:16 -040039 | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050040 | While(expr test, stmt* body, stmt* orelse)
41 | If(expr test, stmt* body, stmt* orelse)
42 | With(withitem* items, stmt* body)
Yury Selivanov75445082015-05-11 22:57:16 -040043 | AsyncWith(withitem* items, stmt* body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000044
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050045 | Raise(expr? exc, expr? cause)
46 | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
47 | Assert(expr test, expr? msg)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000048
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050049 | Import(alias* names)
50 | ImportFrom(identifier? module, alias* names, int? level)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000051
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050052 | Global(identifier* names)
53 | Nonlocal(identifier* names)
54 | Expr(expr value)
55 | Pass | Break | Continue
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000056
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050057 -- XXX Jython will be different
58 -- col_offset is the byte offset in the utf8 string the parser uses
59 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000060
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050061 -- BoolOp() can use left & right?
62 expr = BoolOp(boolop op, expr* values)
63 | BinOp(expr left, operator op, expr right)
64 | UnaryOp(unaryop op, expr operand)
65 | Lambda(arguments args, expr body)
66 | IfExp(expr test, expr body, expr orelse)
67 | Dict(expr* keys, expr* values)
68 | Set(expr* elts)
69 | ListComp(expr elt, comprehension* generators)
70 | SetComp(expr elt, comprehension* generators)
71 | DictComp(expr key, expr value, comprehension* generators)
72 | GeneratorExp(expr elt, comprehension* generators)
73 -- the grammar constrains where yield expressions can occur
Yury Selivanov75445082015-05-11 22:57:16 -040074 | Await(expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050075 | Yield(expr? value)
Mark Dickinsonded35ae2012-11-25 14:36:26 +000076 | YieldFrom(expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050077 -- need sequences for compare to distinguish between
78 -- x < 4 < 3 and (x < 4) < 3
79 | Compare(expr left, cmpop* ops, expr* comparators)
Benjamin Peterson025e9eb2015-05-05 20:16:41 -040080 | Call(expr func, expr* args, keyword* keywords)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050081 | Num(object n) -- a number as a PyObject.
82 | Str(string s) -- need to specify raw, unicode, etc?
Eric V. Smith235a6f02015-09-19 14:51:32 -040083 | FormattedValue(expr value, int? conversion, expr? format_spec)
84 | JoinedStr(expr* values)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050085 | Bytes(bytes s)
Benjamin Peterson442f2092012-12-06 17:41:04 -050086 | NameConstant(singleton value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050087 | Ellipsis
Victor Stinnerf2c1aa12016-01-26 00:40:57 +010088 | Constant(constant value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000089
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050090 -- the following expression can appear in assignment context
91 | Attribute(expr value, identifier attr, expr_context ctx)
92 | Subscript(expr value, slice slice, expr_context ctx)
93 | Starred(expr value, expr_context ctx)
94 | Name(identifier id, expr_context ctx)
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030095 | List(expr* elts, expr_context ctx)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050096 | Tuple(expr* elts, expr_context ctx)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000097
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050098 -- col_offset is the byte offset in the utf8 string the parser uses
99 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000100
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500101 expr_context = Load | Store | Del | AugLoad | AugStore | Param
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000102
Serhiy Storchaka45ec3282015-04-03 19:42:32 +0300103 slice = Slice(expr? lower, expr? upper, expr? step)
104 | ExtSlice(slice* dims)
105 | Index(expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000106
Serhiy Storchaka45ec3282015-04-03 19:42:32 +0300107 boolop = And | Or
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000108
Serhiy Storchaka45ec3282015-04-03 19:42:32 +0300109 operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000110 | RShift | BitOr | BitXor | BitAnd | FloorDiv
111
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500112 unaryop = Invert | Not | UAdd | USub
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000113
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500114 cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000115
Yury Selivanov52c4e7c2016-09-09 10:36:01 -0700116 comprehension = (expr target, expr iter, expr* ifs, int is_async)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000117
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500118 excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
119 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000120
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700121 arguments = (arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults,
122 arg? kwarg, expr* defaults)
123
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500124 arg = (identifier arg, expr? annotation)
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700125 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000126
Benjamin Peterson025e9eb2015-05-05 20:16:41 -0400127 -- keyword arguments supplied to call (NULL identifier for **kwargs)
128 keyword = (identifier? arg, expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000129
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500130 -- import name with optional 'as' alias.
131 alias = (identifier name, identifier? asname)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -0500132
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500133 withitem = (expr context_expr, expr? optional_vars)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000134}
Thomas Wouters8b4a3e82007-02-23 20:00:10 +0000135