blob: 6955199280ca7615f2ac879691dbb05e1659dc6c [file] [log] [blame]
Benjamin Petersone2498412011-08-09 16:08:39 -05001-- ASDL's five builtin types are identifier, int, string, bytes, object
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{
5 mod = Module(stmt* body)
6 | Interactive(stmt* body)
7 | Expression(expr body)
8
9 -- not really an actual node but useful in Jython's typesystem.
10 | Suite(stmt* body)
11
12 stmt = FunctionDef(identifier name, arguments args,
Guido van Rossumd59da4b2007-05-22 18:11:13 +000013 stmt* body, expr* decorator_list, expr? returns)
Guido van Rossum52cc1d82007-03-18 15:41:51 +000014 | ClassDef(identifier name,
15 expr* bases,
16 keyword* keywords,
17 expr? starargs,
18 expr? kwargs,
Guido van Rossumd59da4b2007-05-22 18:11:13 +000019 stmt* body,
Benjamin Peterson60995fb2010-06-22 20:02:39 +000020 expr* decorator_list)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000021 | Return(expr? value)
22
23 | Delete(expr* targets)
24 | Assign(expr* targets, expr value)
25 | AugAssign(expr target, operator op, expr value)
26
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000027 -- use 'orelse' because else is a keyword in target languages
28 | For(expr target, expr iter, stmt* body, stmt* orelse)
29 | While(expr test, stmt* body, stmt* orelse)
30 | If(expr test, stmt* body, stmt* orelse)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -050031 | With(withitem* items, stmt* body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000032
Collin Winter828f04a2007-08-31 00:04:24 +000033 | Raise(expr? exc, expr? cause)
Benjamin Peterson43af12b2011-05-29 11:43:10 -050034 | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000035 | Assert(expr test, expr? msg)
36
37 | Import(alias* names)
Benjamin Peterson78565b22009-06-28 19:19:51 +000038 | ImportFrom(identifier? module, alias* names, int? level)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000039
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000040 | Global(identifier* names)
Jeremy Hylton81e95022007-02-27 06:50:52 +000041 | Nonlocal(identifier* names)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000042 | Expr(expr value)
43 | Pass | Break | Continue
44
45 -- XXX Jython will be different
Martin v. Löwis49c5da12006-03-01 22:49:05 +000046 -- col_offset is the byte offset in the utf8 string the parser uses
47 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000048
49 -- BoolOp() can use left & right?
50 expr = BoolOp(boolop op, expr* values)
51 | BinOp(expr left, operator op, expr right)
52 | UnaryOp(unaryop op, expr operand)
53 | Lambda(arguments args, expr body)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +000054 | IfExp(expr test, expr body, expr orelse)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000055 | Dict(expr* keys, expr* values)
Guido van Rossum86e58e22006-08-28 15:27:34 +000056 | Set(expr* elts)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000057 | ListComp(expr elt, comprehension* generators)
Guido van Rossum992d4a32007-07-11 13:09:30 +000058 | SetComp(expr elt, comprehension* generators)
59 | DictComp(expr key, expr value, comprehension* generators)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000060 | GeneratorExp(expr elt, comprehension* generators)
Jeremy Hyltonc960f262006-01-27 15:18:39 +000061 -- the grammar constrains where yield expressions can occur
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000062 | Yield(expr? value)
63 -- need sequences for compare to distinguish between
64 -- x < 4 < 3 and (x < 4) < 3
65 | Compare(expr left, cmpop* ops, expr* comparators)
66 | Call(expr func, expr* args, keyword* keywords,
67 expr? starargs, expr? kwargs)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000068 | Num(object n) -- a number as a PyObject.
69 | Str(string s) -- need to specify raw, unicode, etc?
Benjamin Petersone2498412011-08-09 16:08:39 -050070 | Bytes(bytes s)
Georg Brandl52318d62006-09-06 07:06:08 +000071 | Ellipsis
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000072 -- other literals? bools?
73
74 -- the following expression can appear in assignment context
75 | Attribute(expr value, identifier attr, expr_context ctx)
76 | Subscript(expr value, slice slice, expr_context ctx)
Guido van Rossum0368b722007-05-11 16:50:42 +000077 | Starred(expr value, expr_context ctx)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000078 | Name(identifier id, expr_context ctx)
79 | List(expr* elts, expr_context ctx)
Thomas Wouterscf297e42007-02-23 15:07:44 +000080 | Tuple(expr* elts, expr_context ctx)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000081
Martin v. Löwis49c5da12006-03-01 22:49:05 +000082 -- col_offset is the byte offset in the utf8 string the parser uses
83 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000084
85 expr_context = Load | Store | Del | AugLoad | AugStore | Param
86
Georg Brandl52318d62006-09-06 07:06:08 +000087 slice = Slice(expr? lower, expr? upper, expr? step)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000088 | ExtSlice(slice* dims)
89 | Index(expr value)
90
91 boolop = And | Or
92
93 operator = Add | Sub | Mult | Div | Mod | Pow | LShift
94 | RShift | BitOr | BitXor | BitAnd | FloorDiv
95
96 unaryop = Invert | Not | UAdd | USub
97
98 cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
99
100 comprehension = (expr target, expr iter, expr* ifs)
101
Neal Norwitzad74aa82008-03-31 05:14:30 +0000102 excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
103 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000104
Neal Norwitzc1505362006-12-28 06:47:50 +0000105 arguments = (arg* args, identifier? vararg, expr? varargannotation,
106 arg* kwonlyargs, identifier? kwarg,
107 expr? kwargannotation, expr* defaults,
108 expr* kw_defaults)
Guido van Rossum1bc535d2007-05-15 18:46:22 +0000109 arg = (identifier arg, expr? annotation)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000110
111 -- keyword arguments supplied to call
112 keyword = (identifier arg, expr value)
113
114 -- import name with optional 'as' alias.
115 alias = (identifier name, identifier? asname)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -0500116
117 withitem = (expr context_expr, expr? optional_vars)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000118}
Thomas Wouters8b4a3e82007-02-23 20:00:10 +0000119