Neal Norwitz | 3591bbe | 2007-02-26 19:04:49 +0000 | [diff] [blame] | 1 | -- ASDL's five builtin types are identifier, int, string, object |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 2 | |
Martin v. Löwis | eae93b7 | 2006-02-28 00:12:47 +0000 | [diff] [blame] | 3 | module Python version "$Revision$" |
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, |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 13 | stmt* body, expr* decorators, 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, |
| 19 | stmt* body) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 20 | | Return(expr? value) |
| 21 | |
| 22 | | Delete(expr* targets) |
| 23 | | Assign(expr* targets, expr value) |
| 24 | | AugAssign(expr target, operator op, expr value) |
| 25 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 26 | -- use 'orelse' because else is a keyword in target languages |
| 27 | | For(expr target, expr iter, stmt* body, stmt* orelse) |
| 28 | | While(expr test, stmt* body, stmt* orelse) |
| 29 | | If(expr test, stmt* body, stmt* orelse) |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 30 | | With(expr context_expr, expr? optional_vars, stmt* body) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 31 | |
| 32 | -- 'type' is a bad name |
| 33 | | Raise(expr? type, expr? inst, expr? tback) |
| 34 | | 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 Wouters | f7f438b | 2006-02-28 16:09:29 +0000 | [diff] [blame] | 39 | | ImportFrom(identifier module, alias* names, int? level) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 40 | |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 41 | | Global(identifier* names) |
Jeremy Hylton | 81e9502 | 2007-02-27 06:50:52 +0000 | [diff] [blame] | 42 | | Nonlocal(identifier* names) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 43 | | Expr(expr value) |
| 44 | | Pass | Break | Continue |
| 45 | |
| 46 | -- XXX Jython will be different |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 47 | -- col_offset is the byte offset in the utf8 string the parser uses |
| 48 | attributes (int lineno, int col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 49 | |
| 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 Wouters | dca3b9c | 2006-02-27 00:24:13 +0000 | [diff] [blame] | 55 | | IfExp(expr test, expr body, expr orelse) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 56 | | Dict(expr* keys, expr* values) |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame] | 57 | | Set(expr* elts) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 58 | | ListComp(expr elt, comprehension* generators) |
Nick Coghlan | 650f0d0 | 2007-04-15 12:05:43 +0000 | [diff] [blame^] | 59 | | SetComp(expr elt, 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? |
Thomas Wouters | 00e41de | 2007-02-23 19:56:57 +0000 | [diff] [blame] | 70 | | Bytes(string 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) |
| 77 | | Name(identifier id, expr_context ctx) |
| 78 | | List(expr* elts, expr_context ctx) |
Thomas Wouters | cf297e4 | 2007-02-23 15:07:44 +0000 | [diff] [blame] | 79 | | Tuple(expr* elts, expr_context ctx) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 80 | |
Martin v. Löwis | 49c5da1 | 2006-03-01 22:49:05 +0000 | [diff] [blame] | 81 | -- col_offset is the byte offset in the utf8 string the parser uses |
| 82 | attributes (int lineno, int col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 83 | |
| 84 | expr_context = Load | Store | Del | AugLoad | AugStore | Param |
| 85 | |
Georg Brandl | 52318d6 | 2006-09-06 07:06:08 +0000 | [diff] [blame] | 86 | slice = Slice(expr? lower, expr? upper, expr? step) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 87 | | ExtSlice(slice* dims) |
| 88 | | Index(expr value) |
| 89 | |
| 90 | boolop = And | Or |
| 91 | |
| 92 | operator = Add | Sub | Mult | Div | Mod | Pow | LShift |
| 93 | | RShift | BitOr | BitXor | BitAnd | FloorDiv |
| 94 | |
| 95 | unaryop = Invert | Not | UAdd | USub |
| 96 | |
| 97 | cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn |
| 98 | |
| 99 | comprehension = (expr target, expr iter, expr* ifs) |
| 100 | |
| 101 | -- not sure what to call the first argument for raise and except |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 102 | -- TODO(jhylton): Figure out if there is a better way to handle |
| 103 | -- lineno and col_offset fields, particularly when |
| 104 | -- ast is exposed to Python. |
Guido van Rossum | 16be03e | 2007-01-10 18:51:35 +0000 | [diff] [blame] | 105 | excepthandler = (expr? type, identifier? name, stmt* body, int lineno, |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 106 | int col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 107 | |
Neal Norwitz | c150536 | 2006-12-28 06:47:50 +0000 | [diff] [blame] | 108 | arguments = (arg* args, identifier? vararg, expr? varargannotation, |
| 109 | arg* kwonlyargs, identifier? kwarg, |
| 110 | expr? kwargannotation, expr* defaults, |
| 111 | expr* kw_defaults) |
| 112 | arg = SimpleArg(identifier arg, expr? annotation) |
| 113 | | NestedArgs(arg* args) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 114 | |
| 115 | -- keyword arguments supplied to call |
| 116 | keyword = (identifier arg, expr value) |
| 117 | |
| 118 | -- import name with optional 'as' alias. |
| 119 | alias = (identifier name, identifier? asname) |
| 120 | } |
Thomas Wouters | 8b4a3e8 | 2007-02-23 20:00:10 +0000 | [diff] [blame] | 121 | |