blob: aaddf619e7c7c25fdff76b4dab7f9d4752903c61 [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)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000031
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050032 -- use 'orelse' because else is a keyword in target languages
33 | For(expr target, expr iter, stmt* body, stmt* orelse)
Yury Selivanov75445082015-05-11 22:57:16 -040034 | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050035 | While(expr test, stmt* body, stmt* orelse)
36 | If(expr test, stmt* body, stmt* orelse)
37 | With(withitem* items, stmt* body)
Yury Selivanov75445082015-05-11 22:57:16 -040038 | AsyncWith(withitem* items, stmt* body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000039
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050040 | Raise(expr? exc, expr? cause)
41 | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
42 | Assert(expr test, expr? msg)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000043
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050044 | Import(alias* names)
45 | ImportFrom(identifier? module, alias* names, int? level)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000046
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050047 | Global(identifier* names)
48 | Nonlocal(identifier* names)
49 | Expr(expr value)
50 | Pass | Break | Continue
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000051
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050052 -- XXX Jython will be different
53 -- col_offset is the byte offset in the utf8 string the parser uses
54 attributes (int lineno, int 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)
58 | BinOp(expr left, operator op, expr right)
59 | UnaryOp(unaryop op, expr operand)
60 | Lambda(arguments args, expr body)
61 | IfExp(expr test, expr body, expr orelse)
62 | Dict(expr* keys, expr* values)
63 | Set(expr* elts)
64 | ListComp(expr elt, comprehension* generators)
65 | SetComp(expr elt, comprehension* generators)
66 | DictComp(expr key, expr value, comprehension* generators)
67 | GeneratorExp(expr elt, comprehension* generators)
68 -- the grammar constrains where yield expressions can occur
Yury Selivanov75445082015-05-11 22:57:16 -040069 | Await(expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050070 | Yield(expr? value)
Mark Dickinsonded35ae2012-11-25 14:36:26 +000071 | YieldFrom(expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050072 -- need sequences for compare to distinguish between
73 -- x < 4 < 3 and (x < 4) < 3
74 | Compare(expr left, cmpop* ops, expr* comparators)
Benjamin Peterson025e9eb2015-05-05 20:16:41 -040075 | Call(expr func, expr* args, keyword* keywords)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050076 | Num(object n) -- a number as a PyObject.
77 | Str(string s) -- need to specify raw, unicode, etc?
Eric V. Smith235a6f02015-09-19 14:51:32 -040078 | FormattedValue(expr value, int? conversion, expr? format_spec)
79 | JoinedStr(expr* values)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050080 | Bytes(bytes s)
Benjamin Peterson442f2092012-12-06 17:41:04 -050081 | NameConstant(singleton value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050082 | Ellipsis
Victor Stinnerf2c1aa12016-01-26 00:40:57 +010083 | Constant(constant value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000084
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050085 -- the following expression can appear in assignment context
86 | Attribute(expr value, identifier attr, expr_context ctx)
87 | Subscript(expr value, slice slice, expr_context ctx)
88 | Starred(expr value, expr_context ctx)
89 | Name(identifier id, expr_context ctx)
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030090 | List(expr* elts, expr_context ctx)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050091 | Tuple(expr* elts, expr_context ctx)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000092
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050093 -- col_offset is the byte offset in the utf8 string the parser uses
94 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000095
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050096 expr_context = Load | Store | Del | AugLoad | AugStore | Param
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000097
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030098 slice = Slice(expr? lower, expr? upper, expr? step)
99 | ExtSlice(slice* dims)
100 | Index(expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000101
Serhiy Storchaka45ec3282015-04-03 19:42:32 +0300102 boolop = And | Or
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000103
Serhiy Storchaka45ec3282015-04-03 19:42:32 +0300104 operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000105 | RShift | BitOr | BitXor | BitAnd | FloorDiv
106
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500107 unaryop = Invert | Not | UAdd | USub
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000108
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500109 cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000110
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500111 comprehension = (expr target, expr iter, expr* ifs)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000112
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500113 excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
114 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000115
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700116 arguments = (arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults,
117 arg? kwarg, expr* defaults)
118
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500119 arg = (identifier arg, expr? annotation)
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700120 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000121
Benjamin Peterson025e9eb2015-05-05 20:16:41 -0400122 -- keyword arguments supplied to call (NULL identifier for **kwargs)
123 keyword = (identifier? arg, expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000124
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500125 -- import name with optional 'as' alias.
126 alias = (identifier name, identifier? asname)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -0500127
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500128 withitem = (expr context_expr, expr? optional_vars)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000129}
Thomas Wouters8b4a3e82007-02-23 20:00:10 +0000130