Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 1 | -- ASDL's six builtin types are identifier, int, string, bytes, object, singleton |
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 | { |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 5 | mod = Module(stmt* body) |
| 6 | | Interactive(stmt* body) |
| 7 | | Expression(expr body) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 9 | -- not really an actual node but useful in Jython's typesystem. |
| 10 | | Suite(stmt* body) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 11 | |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 12 | stmt = FunctionDef(identifier name, arguments args, |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 13 | stmt* body, expr* decorator_list, expr? returns) |
| 14 | | AsyncFunctionDef(identifier name, arguments args, |
| 15 | stmt* body, expr* decorator_list, expr? returns) |
| 16 | |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 17 | | ClassDef(identifier name, |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 18 | expr* bases, |
| 19 | keyword* keywords, |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 20 | stmt* body, |
| 21 | expr* decorator_list) |
| 22 | | Return(expr? value) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 23 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 24 | | Delete(expr* targets) |
| 25 | | Assign(expr* targets, expr value) |
| 26 | | AugAssign(expr target, operator op, expr value) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 27 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 28 | -- use 'orelse' because else is a keyword in target languages |
| 29 | | For(expr target, expr iter, stmt* body, stmt* orelse) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 30 | | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 31 | | While(expr test, stmt* body, stmt* orelse) |
| 32 | | If(expr test, stmt* body, stmt* orelse) |
| 33 | | With(withitem* items, stmt* body) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 34 | | AsyncWith(withitem* items, stmt* body) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 35 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 36 | | Raise(expr? exc, expr? cause) |
| 37 | | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody) |
| 38 | | Assert(expr test, expr? msg) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 39 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 40 | | Import(alias* names) |
| 41 | | ImportFrom(identifier? module, alias* names, int? level) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 42 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 43 | | Global(identifier* names) |
| 44 | | Nonlocal(identifier* names) |
| 45 | | Expr(expr value) |
| 46 | | Pass | Break | Continue |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 47 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 48 | -- 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 Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 51 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 52 | -- 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 Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 65 | | Await(expr value) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 66 | | Yield(expr? value) |
Mark Dickinson | ded35ae | 2012-11-25 14:36:26 +0000 | [diff] [blame] | 67 | | YieldFrom(expr value) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 68 | -- need sequences for compare to distinguish between |
| 69 | -- x < 4 < 3 and (x < 4) < 3 |
| 70 | | Compare(expr left, cmpop* ops, expr* comparators) |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 71 | | Call(expr func, expr* args, keyword* keywords) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 72 | | Num(object n) -- a number as a PyObject. |
| 73 | | Str(string s) -- need to specify raw, unicode, etc? |
| 74 | | Bytes(bytes s) |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 75 | | NameConstant(singleton value) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 76 | | Ellipsis |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 77 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 78 | -- 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 Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 83 | | List(expr* elts, expr_context ctx) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 84 | | Tuple(expr* elts, expr_context ctx) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 85 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 86 | -- col_offset is the byte offset in the utf8 string the parser uses |
| 87 | attributes (int lineno, int col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 88 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 89 | expr_context = Load | Store | Del | AugLoad | AugStore | Param |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 90 | |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 91 | slice = Slice(expr? lower, expr? upper, expr? step) |
| 92 | | ExtSlice(slice* dims) |
| 93 | | Index(expr value) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 94 | |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 95 | boolop = And | Or |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 96 | |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 97 | operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 98 | | RShift | BitOr | BitXor | BitAnd | FloorDiv |
| 99 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 100 | unaryop = Invert | Not | UAdd | USub |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 101 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 102 | cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 103 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 104 | comprehension = (expr target, expr iter, expr* ifs) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 105 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 106 | excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body) |
| 107 | attributes (int lineno, int col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 108 | |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 109 | arguments = (arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, |
| 110 | arg? kwarg, expr* defaults) |
| 111 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 112 | arg = (identifier arg, expr? annotation) |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 113 | attributes (int lineno, int col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 114 | |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 115 | -- keyword arguments supplied to call (NULL identifier for **kwargs) |
| 116 | keyword = (identifier? arg, expr value) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 117 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 118 | -- import name with optional 'as' alias. |
| 119 | alias = (identifier name, identifier? asname) |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 120 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 121 | withitem = (expr context_expr, expr? optional_vars) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 122 | } |
Thomas Wouters | 8b4a3e8 | 2007-02-23 20:00:10 +0000 | [diff] [blame] | 123 | |