blob: f470ad13b6551e2277064b146589173cb0b7931c [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{
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -05009 mod = Module(stmt* body)
10 | 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,
Yury Selivanov75445082015-05-11 22:57:16 -040017 stmt* body, expr* decorator_list, expr? returns)
18 | AsyncFunctionDef(identifier name, arguments args,
19 stmt* body, expr* decorator_list, expr? returns)
20
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,
25 expr* decorator_list)
26 | Return(expr? value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000027
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050028 | Delete(expr* targets)
29 | Assign(expr* targets, expr value)
30 | 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
35 | For(expr target, expr iter, stmt* body, stmt* orelse)
Yury Selivanov75445082015-05-11 22:57:16 -040036 | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050037 | While(expr test, stmt* body, stmt* orelse)
38 | If(expr test, stmt* body, stmt* orelse)
39 | With(withitem* items, stmt* body)
Yury Selivanov75445082015-05-11 22:57:16 -040040 | AsyncWith(withitem* items, stmt* body)
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
56 attributes (int lineno, int 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)
60 | BinOp(expr left, operator op, expr right)
61 | UnaryOp(unaryop op, expr operand)
62 | Lambda(arguments args, expr body)
63 | IfExp(expr test, expr body, expr orelse)
64 | Dict(expr* keys, expr* values)
65 | Set(expr* elts)
66 | ListComp(expr elt, comprehension* generators)
67 | SetComp(expr elt, comprehension* generators)
68 | DictComp(expr key, expr value, comprehension* generators)
69 | GeneratorExp(expr elt, comprehension* generators)
70 -- the grammar constrains where yield expressions can occur
Yury Selivanov75445082015-05-11 22:57:16 -040071 | Await(expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050072 | Yield(expr? value)
Mark Dickinsonded35ae2012-11-25 14:36:26 +000073 | YieldFrom(expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050074 -- need sequences for compare to distinguish between
75 -- x < 4 < 3 and (x < 4) < 3
76 | Compare(expr left, cmpop* ops, expr* comparators)
Benjamin Peterson025e9eb2015-05-05 20:16:41 -040077 | Call(expr func, expr* args, keyword* keywords)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050078 | Num(object n) -- a number as a PyObject.
79 | Str(string s) -- need to specify raw, unicode, etc?
Eric V. Smith235a6f02015-09-19 14:51:32 -040080 | FormattedValue(expr value, int? conversion, expr? format_spec)
81 | JoinedStr(expr* values)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050082 | Bytes(bytes s)
Benjamin Peterson442f2092012-12-06 17:41:04 -050083 | NameConstant(singleton value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050084 | Ellipsis
Victor Stinnerf2c1aa12016-01-26 00:40:57 +010085 | Constant(constant value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000086
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050087 -- the following expression can appear in assignment context
88 | Attribute(expr value, identifier attr, expr_context ctx)
89 | Subscript(expr value, slice slice, expr_context ctx)
90 | Starred(expr value, expr_context ctx)
91 | Name(identifier id, expr_context ctx)
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030092 | List(expr* elts, expr_context ctx)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050093 | Tuple(expr* elts, expr_context ctx)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000094
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050095 -- col_offset is the byte offset in the utf8 string the parser uses
96 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000097
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050098 expr_context = Load | Store | Del | AugLoad | AugStore | Param
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000099
Serhiy Storchaka45ec3282015-04-03 19:42:32 +0300100 slice = Slice(expr? lower, expr? upper, expr? step)
101 | ExtSlice(slice* dims)
102 | Index(expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000103
Serhiy Storchaka45ec3282015-04-03 19:42:32 +0300104 boolop = And | Or
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000105
Serhiy Storchaka45ec3282015-04-03 19:42:32 +0300106 operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000107 | RShift | BitOr | BitXor | BitAnd | FloorDiv
108
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500109 unaryop = Invert | Not | UAdd | USub
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000110
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500111 cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000112
Yury Selivanov52c4e7c2016-09-09 10:36:01 -0700113 comprehension = (expr target, expr iter, expr* ifs, int is_async)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000114
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500115 excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
116 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000117
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700118 arguments = (arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults,
119 arg? kwarg, expr* defaults)
120
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500121 arg = (identifier arg, expr? annotation)
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700122 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000123
Benjamin Peterson025e9eb2015-05-05 20:16:41 -0400124 -- keyword arguments supplied to call (NULL identifier for **kwargs)
125 keyword = (identifier? arg, expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000126
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500127 -- import name with optional 'as' alias.
128 alias = (identifier name, identifier? asname)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -0500129
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500130 withitem = (expr context_expr, expr? optional_vars)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000131}
Thomas Wouters8b4a3e82007-02-23 20:00:10 +0000132