blob: 789e07bd3f9323d226effe97c9e181ad1b6a8d38 [file] [log] [blame]
Benjamin Petersone84f03f2008-12-06 18:32:13 +00001-- ASDL's four builtin types are identifier, int, string, object
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002
Martin v. Löwiseae93b72006-02-28 00:12:47 +00003module Python version "$Revision$"
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,
20 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)
Guido van Rossumc2e20742006-02-27 22:32:47 +000031 | With(expr context_expr, expr? optional_vars, stmt* body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000032
Collin Winter828f04a2007-08-31 00:04:24 +000033 | Raise(expr? exc, expr? cause)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000034 | TryExcept(stmt* body, excepthandler* handlers, stmt* orelse)
35 | TryFinally(stmt* body, stmt* finalbody)
36 | Assert(expr test, expr? msg)
37
38 | Import(alias* names)
Thomas Woutersf7f438b2006-02-28 16:09:29 +000039 | ImportFrom(identifier module, alias* names, int? level)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000040
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000041 | Global(identifier* names)
Jeremy Hylton81e95022007-02-27 06:50:52 +000042 | Nonlocal(identifier* names)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000043 | Expr(expr value)
44 | Pass | Break | Continue
45
46 -- XXX Jython will be different
Martin v. Löwis49c5da12006-03-01 22:49:05 +000047 -- col_offset is the byte offset in the utf8 string the parser uses
48 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000049
50 -- BoolOp() can use left & right?
51 expr = BoolOp(boolop op, expr* values)
52 | BinOp(expr left, operator op, expr right)
53 | UnaryOp(unaryop op, expr operand)
54 | Lambda(arguments args, expr body)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +000055 | IfExp(expr test, expr body, expr orelse)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000056 | Dict(expr* keys, expr* values)
Guido van Rossum86e58e22006-08-28 15:27:34 +000057 | Set(expr* elts)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000058 | ListComp(expr elt, comprehension* generators)
Guido van Rossum992d4a32007-07-11 13:09:30 +000059 | SetComp(expr elt, comprehension* generators)
60 | DictComp(expr key, expr value, comprehension* generators)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000061 | GeneratorExp(expr elt, comprehension* generators)
Jeremy Hyltonc960f262006-01-27 15:18:39 +000062 -- the grammar constrains where yield expressions can occur
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000063 | Yield(expr? value)
64 -- need sequences for compare to distinguish between
65 -- x < 4 < 3 and (x < 4) < 3
66 | Compare(expr left, cmpop* ops, expr* comparators)
67 | Call(expr func, expr* args, keyword* keywords,
68 expr? starargs, expr? kwargs)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000069 | Num(object n) -- a number as a PyObject.
70 | Str(string s) -- need to specify raw, unicode, etc?
Thomas Wouters00e41de2007-02-23 19:56:57 +000071 | Bytes(string s)
Georg Brandl52318d62006-09-06 07:06:08 +000072 | Ellipsis
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000073 -- other literals? bools?
74
75 -- the following expression can appear in assignment context
76 | Attribute(expr value, identifier attr, expr_context ctx)
77 | Subscript(expr value, slice slice, expr_context ctx)
Guido van Rossum0368b722007-05-11 16:50:42 +000078 | Starred(expr value, expr_context ctx)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000079 | Name(identifier id, expr_context ctx)
80 | List(expr* elts, expr_context ctx)
Thomas Wouterscf297e42007-02-23 15:07:44 +000081 | Tuple(expr* elts, expr_context ctx)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000082
Martin v. Löwis49c5da12006-03-01 22:49:05 +000083 -- col_offset is the byte offset in the utf8 string the parser uses
84 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000085
86 expr_context = Load | Store | Del | AugLoad | AugStore | Param
87
Georg Brandl52318d62006-09-06 07:06:08 +000088 slice = Slice(expr? lower, expr? upper, expr? step)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000089 | ExtSlice(slice* dims)
90 | Index(expr value)
91
92 boolop = And | Or
93
94 operator = Add | Sub | Mult | Div | Mod | Pow | LShift
95 | RShift | BitOr | BitXor | BitAnd | FloorDiv
96
97 unaryop = Invert | Not | UAdd | USub
98
99 cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
100
101 comprehension = (expr target, expr iter, expr* ifs)
102
103 -- not sure what to call the first argument for raise and except
Neal Norwitzad74aa82008-03-31 05:14:30 +0000104 excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
105 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000106
Neal Norwitzc1505362006-12-28 06:47:50 +0000107 arguments = (arg* args, identifier? vararg, expr? varargannotation,
108 arg* kwonlyargs, identifier? kwarg,
109 expr? kwargannotation, expr* defaults,
110 expr* kw_defaults)
Guido van Rossum1bc535d2007-05-15 18:46:22 +0000111 arg = (identifier arg, expr? annotation)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000112
113 -- keyword arguments supplied to call
114 keyword = (identifier arg, expr value)
115
116 -- import name with optional 'as' alias.
117 alias = (identifier name, identifier? asname)
118}
Thomas Wouters8b4a3e82007-02-23 20:00:10 +0000119