blob: cd0832da8d0b3f2526494a5f2f40b9ccab79ac8a [file] [log] [blame]
Benjamin Peterson442f2092012-12-06 17:41:04 -05001-- ASDL's six builtin types are identifier, int, string, bytes, object, singleton
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002
Benjamin Peterson6cb2b922011-03-12 18:28:16 -06003module Python
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004{
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -05005 mod = Module(stmt* body)
6 | Interactive(stmt* body)
7 | Expression(expr body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00008
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -05009 -- not really an actual node but useful in Jython's typesystem.
10 | Suite(stmt* body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000011
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030012 stmt = FunctionDef(identifier name, arguments args,
Yury Selivanov75445082015-05-11 22:57:16 -040013 stmt* body, expr* decorator_list, expr? returns)
14 | AsyncFunctionDef(identifier name, arguments args,
15 stmt* body, expr* decorator_list, expr? returns)
16
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030017 | ClassDef(identifier name,
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050018 expr* bases,
19 keyword* keywords,
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050020 stmt* body,
21 expr* decorator_list)
22 | Return(expr? value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000023
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050024 | Delete(expr* targets)
25 | Assign(expr* targets, expr value)
26 | AugAssign(expr target, operator op, expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000027
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050028 -- use 'orelse' because else is a keyword in target languages
29 | For(expr target, expr iter, stmt* body, stmt* orelse)
Yury Selivanov75445082015-05-11 22:57:16 -040030 | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050031 | While(expr test, stmt* body, stmt* orelse)
32 | If(expr test, stmt* body, stmt* orelse)
33 | With(withitem* items, stmt* body)
Yury Selivanov75445082015-05-11 22:57:16 -040034 | AsyncWith(withitem* items, stmt* body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000035
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050036 | Raise(expr? exc, expr? cause)
37 | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
38 | Assert(expr test, expr? msg)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000039
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050040 | Import(alias* names)
41 | ImportFrom(identifier? module, alias* names, int? level)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000042
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050043 | Global(identifier* names)
44 | Nonlocal(identifier* names)
45 | Expr(expr value)
46 | Pass | Break | Continue
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000047
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050048 -- XXX Jython will be different
49 -- col_offset is the byte offset in the utf8 string the parser uses
50 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000051
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050052 -- BoolOp() can use left & right?
53 expr = BoolOp(boolop op, expr* values)
54 | BinOp(expr left, operator op, expr right)
55 | UnaryOp(unaryop op, expr operand)
56 | Lambda(arguments args, expr body)
57 | IfExp(expr test, expr body, expr orelse)
58 | Dict(expr* keys, expr* values)
59 | Set(expr* elts)
60 | ListComp(expr elt, comprehension* generators)
61 | SetComp(expr elt, comprehension* generators)
62 | DictComp(expr key, expr value, comprehension* generators)
63 | GeneratorExp(expr elt, comprehension* generators)
64 -- the grammar constrains where yield expressions can occur
Yury Selivanov75445082015-05-11 22:57:16 -040065 | Await(expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050066 | Yield(expr? value)
Mark Dickinsonded35ae2012-11-25 14:36:26 +000067 | YieldFrom(expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050068 -- need sequences for compare to distinguish between
69 -- x < 4 < 3 and (x < 4) < 3
70 | Compare(expr left, cmpop* ops, expr* comparators)
Benjamin Peterson025e9eb2015-05-05 20:16:41 -040071 | Call(expr func, expr* args, keyword* keywords)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050072 | Num(object n) -- a number as a PyObject.
73 | Str(string s) -- need to specify raw, unicode, etc?
74 | Bytes(bytes s)
Benjamin Peterson442f2092012-12-06 17:41:04 -050075 | NameConstant(singleton value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050076 | Ellipsis
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000077
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050078 -- the following expression can appear in assignment context
79 | Attribute(expr value, identifier attr, expr_context ctx)
80 | Subscript(expr value, slice slice, expr_context ctx)
81 | Starred(expr value, expr_context ctx)
82 | Name(identifier id, expr_context ctx)
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030083 | List(expr* elts, expr_context ctx)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050084 | Tuple(expr* elts, expr_context ctx)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000085
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050086 -- col_offset is the byte offset in the utf8 string the parser uses
87 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000088
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050089 expr_context = Load | Store | Del | AugLoad | AugStore | Param
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000090
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030091 slice = Slice(expr? lower, expr? upper, expr? step)
92 | ExtSlice(slice* dims)
93 | Index(expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000094
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030095 boolop = And | Or
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000096
Serhiy Storchaka45ec3282015-04-03 19:42:32 +030097 operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000098 | RShift | BitOr | BitXor | BitAnd | FloorDiv
99
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500100 unaryop = Invert | Not | UAdd | USub
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000101
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500102 cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000103
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500104 comprehension = (expr target, expr iter, expr* ifs)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000105
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500106 excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
107 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000108
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700109 arguments = (arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults,
110 arg? kwarg, expr* defaults)
111
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500112 arg = (identifier arg, expr? annotation)
Benjamin Petersoncda75be2013-03-18 10:48:58 -0700113 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000114
Benjamin Peterson025e9eb2015-05-05 20:16:41 -0400115 -- keyword arguments supplied to call (NULL identifier for **kwargs)
116 keyword = (identifier? arg, expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000117
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500118 -- import name with optional 'as' alias.
119 alias = (identifier name, identifier? asname)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -0500120
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500121 withitem = (expr context_expr, expr? optional_vars)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000122}
Thomas Wouters8b4a3e82007-02-23 20:00:10 +0000123