Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 1 | -- ASDL's five builtin types are identifier, int, string, bytes, object |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2 | |
Benjamin Peterson | 6cb2b92 | 2011-03-12 18:28:16 -0600 | [diff] [blame] | 3 | module Python |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 4 | { |
| 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 Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 13 | stmt* body, expr* decorator_list, expr? returns) |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 14 | | ClassDef(identifier name, |
| 15 | expr* bases, |
| 16 | keyword* keywords, |
| 17 | expr? starargs, |
| 18 | expr? kwargs, |
Guido van Rossum | d59da4b | 2007-05-22 18:11:13 +0000 | [diff] [blame] | 19 | stmt* body, |
Benjamin Peterson | 60995fb | 2010-06-22 20:02:39 +0000 | [diff] [blame] | 20 | expr* decorator_list) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 21 | | Return(expr? value) |
| 22 | |
| 23 | | Delete(expr* targets) |
| 24 | | Assign(expr* targets, expr value) |
| 25 | | AugAssign(expr target, operator op, expr value) |
| 26 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 27 | -- 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 Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 31 | | With(withitem* items, stmt* body) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 32 | |
Collin Winter | 828f04a | 2007-08-31 00:04:24 +0000 | [diff] [blame] | 33 | | Raise(expr? exc, expr? cause) |
Benjamin Peterson | 43af12b | 2011-05-29 11:43:10 -0500 | [diff] [blame] | 34 | | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 35 | | Assert(expr test, expr? msg) |
| 36 | |
| 37 | | Import(alias* names) |
Benjamin Peterson | 78565b2 | 2009-06-28 19:19:51 +0000 | [diff] [blame] | 38 | | ImportFrom(identifier? module, alias* names, int? level) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 39 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 40 | | Global(identifier* names) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 41 | | Nonlocal(identifier* names) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 42 | | Expr(expr value) |
| 43 | | Pass | Break | Continue |
| 44 | |
| 45 | -- XXX Jython will be different |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 46 | -- col_offset is the byte offset in the utf8 string the parser uses |
| 47 | attributes (int lineno, int col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 48 | |
| 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 Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 54 | | IfExp(expr test, expr body, expr orelse) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 55 | | Dict(expr* keys, expr* values) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 56 | | Set(expr* elts) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 57 | | ListComp(expr elt, comprehension* generators) |
Guido van Rossum | 992d4a3 | 2007-07-11 13:09:30 +0000 | [diff] [blame] | 58 | | SetComp(expr elt, comprehension* generators) |
| 59 | | DictComp(expr key, expr value, comprehension* generators) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 60 | | GeneratorExp(expr elt, comprehension* generators) |
Jeremy Hylton | c960f26 | 2006-01-27 15:18:39 +0000 | [diff] [blame] | 61 | -- the grammar constrains where yield expressions can occur |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 62 | | 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 Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 68 | | Num(object n) -- a number as a PyObject. |
| 69 | | Str(string s) -- need to specify raw, unicode, etc? |
Benjamin Peterson | e249841 | 2011-08-09 16:08:39 -0500 | [diff] [blame] | 70 | | Bytes(bytes s) |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 71 | | Ellipsis |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 72 | -- 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 Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 77 | | Starred(expr value, expr_context ctx) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 78 | | Name(identifier id, expr_context ctx) |
| 79 | | List(expr* elts, expr_context ctx) |
Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 80 | | Tuple(expr* elts, expr_context ctx) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 81 | |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 82 | -- col_offset is the byte offset in the utf8 string the parser uses |
| 83 | attributes (int lineno, int col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 84 | |
| 85 | expr_context = Load | Store | Del | AugLoad | AugStore | Param |
| 86 | |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 87 | slice = Slice(expr? lower, expr? upper, expr? step) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 88 | | 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 Norwitz | ad74aa8 | 2008-03-31 05:14:30 +0000 | [diff] [blame] | 102 | excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body) |
| 103 | attributes (int lineno, int col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 104 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 105 | arguments = (arg* args, identifier? vararg, expr? varargannotation, |
| 106 | arg* kwonlyargs, identifier? kwarg, |
| 107 | expr? kwargannotation, expr* defaults, |
| 108 | expr* kw_defaults) |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 109 | arg = (identifier arg, expr? annotation) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 110 | |
| 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 Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 116 | |
| 117 | withitem = (expr context_expr, expr? optional_vars) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 118 | } |
Thomas Wouters | 8b4a3e8 | 2007-02-23 20:00:10 +0000 | [diff] [blame] | 119 | |