Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 1 | -- ASDL's 7 builtin types are: |
| 2 | -- identifier, int, string, bytes, object, singleton, constant |
| 3 | -- |
| 4 | -- singleton: None, True or False |
| 5 | -- constant can be None, whereas None means "no value" for object. |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6 | |
Benjamin Peterson | 6cb2b92 | 2011-03-12 18:28:16 -0600 | [diff] [blame] | 7 | module Python |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 8 | { |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 9 | mod = Module(stmt* body, string? docstring) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 10 | | Interactive(stmt* body) |
| 11 | | Expression(expr body) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 12 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 13 | -- not really an actual node but useful in Jython's typesystem. |
| 14 | | Suite(stmt* body) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 15 | |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 16 | stmt = FunctionDef(identifier name, arguments args, |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 17 | stmt* body, expr* decorator_list, expr? returns, |
| 18 | string? docstring) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 19 | | AsyncFunctionDef(identifier name, arguments args, |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 20 | stmt* body, expr* decorator_list, expr? returns, |
| 21 | string? docstring) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 22 | |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 23 | | ClassDef(identifier name, |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 24 | expr* bases, |
| 25 | keyword* keywords, |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 26 | stmt* body, |
INADA Naoki | cb41b27 | 2017-02-23 00:31:59 +0900 | [diff] [blame] | 27 | expr* decorator_list, |
| 28 | string? docstring) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 29 | | Return(expr? value) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 30 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 31 | | Delete(expr* targets) |
| 32 | | Assign(expr* targets, expr value) |
| 33 | | AugAssign(expr target, operator op, expr value) |
Yury Selivanov | f8cb8a1 | 2016-09-08 20:50:03 -0700 | [diff] [blame] | 34 | -- 'simple' indicates that we annotate simple name without parens |
| 35 | | AnnAssign(expr target, expr annotation, expr? value, int simple) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 36 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 37 | -- use 'orelse' because else is a keyword in target languages |
| 38 | | For(expr target, expr iter, stmt* body, stmt* orelse) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 39 | | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 40 | | While(expr test, stmt* body, stmt* orelse) |
| 41 | | If(expr test, stmt* body, stmt* orelse) |
| 42 | | With(withitem* items, stmt* body) |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 43 | | AsyncWith(withitem* items, stmt* body) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 44 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 45 | | Raise(expr? exc, expr? cause) |
| 46 | | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody) |
| 47 | | Assert(expr test, expr? msg) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 48 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 49 | | Import(alias* names) |
| 50 | | ImportFrom(identifier? module, alias* names, int? level) |
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 | | Global(identifier* names) |
| 53 | | Nonlocal(identifier* names) |
| 54 | | Expr(expr value) |
| 55 | | Pass | Break | Continue |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 56 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 57 | -- XXX Jython will be different |
| 58 | -- col_offset is the byte offset in the utf8 string the parser uses |
| 59 | attributes (int lineno, int col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 60 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 61 | -- BoolOp() can use left & right? |
| 62 | expr = BoolOp(boolop op, expr* values) |
| 63 | | BinOp(expr left, operator op, expr right) |
| 64 | | UnaryOp(unaryop op, expr operand) |
| 65 | | Lambda(arguments args, expr body) |
| 66 | | IfExp(expr test, expr body, expr orelse) |
| 67 | | Dict(expr* keys, expr* values) |
| 68 | | Set(expr* elts) |
| 69 | | ListComp(expr elt, comprehension* generators) |
| 70 | | SetComp(expr elt, comprehension* generators) |
| 71 | | DictComp(expr key, expr value, comprehension* generators) |
| 72 | | GeneratorExp(expr elt, comprehension* generators) |
| 73 | -- the grammar constrains where yield expressions can occur |
Yury Selivanov | 7544508 | 2015-05-11 22:57:16 -0400 | [diff] [blame] | 74 | | Await(expr value) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 75 | | Yield(expr? value) |
Mark Dickinson | ded35ae | 2012-11-25 14:36:26 +0000 | [diff] [blame] | 76 | | YieldFrom(expr value) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 77 | -- need sequences for compare to distinguish between |
| 78 | -- x < 4 < 3 and (x < 4) < 3 |
| 79 | | Compare(expr left, cmpop* ops, expr* comparators) |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 80 | | Call(expr func, expr* args, keyword* keywords) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 81 | | Num(object n) -- a number as a PyObject. |
| 82 | | Str(string s) -- need to specify raw, unicode, etc? |
Eric V. Smith | 235a6f0 | 2015-09-19 14:51:32 -0400 | [diff] [blame] | 83 | | FormattedValue(expr value, int? conversion, expr? format_spec) |
| 84 | | JoinedStr(expr* values) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 85 | | Bytes(bytes s) |
Benjamin Peterson | 442f209 | 2012-12-06 17:41:04 -0500 | [diff] [blame] | 86 | | NameConstant(singleton value) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 87 | | Ellipsis |
Victor Stinner | f2c1aa1 | 2016-01-26 00:40:57 +0100 | [diff] [blame] | 88 | | Constant(constant value) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 89 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 90 | -- the following expression can appear in assignment context |
| 91 | | Attribute(expr value, identifier attr, expr_context ctx) |
| 92 | | Subscript(expr value, slice slice, expr_context ctx) |
| 93 | | Starred(expr value, expr_context ctx) |
| 94 | | Name(identifier id, expr_context ctx) |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 95 | | List(expr* elts, expr_context ctx) |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 96 | | Tuple(expr* elts, expr_context ctx) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 97 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 98 | -- col_offset is the byte offset in the utf8 string the parser uses |
| 99 | attributes (int lineno, int col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 100 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 101 | expr_context = Load | Store | Del | AugLoad | AugStore | Param |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 102 | |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 103 | slice = Slice(expr? lower, expr? upper, expr? step) |
| 104 | | ExtSlice(slice* dims) |
| 105 | | Index(expr value) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 106 | |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 107 | boolop = And | Or |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 108 | |
Serhiy Storchaka | 45ec328 | 2015-04-03 19:42:32 +0300 | [diff] [blame] | 109 | operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 110 | | RShift | BitOr | BitXor | BitAnd | FloorDiv |
| 111 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 112 | unaryop = Invert | Not | UAdd | USub |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 113 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 114 | cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 115 | |
Yury Selivanov | 52c4e7c | 2016-09-09 10:36:01 -0700 | [diff] [blame] | 116 | comprehension = (expr target, expr iter, expr* ifs, int is_async) |
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 | excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body) |
| 119 | attributes (int lineno, int col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 120 | |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 121 | arguments = (arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, |
| 122 | arg? kwarg, expr* defaults) |
| 123 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 124 | arg = (identifier arg, expr? annotation) |
Benjamin Peterson | cda75be | 2013-03-18 10:48:58 -0700 | [diff] [blame] | 125 | attributes (int lineno, int col_offset) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 126 | |
Benjamin Peterson | 025e9eb | 2015-05-05 20:16:41 -0400 | [diff] [blame] | 127 | -- keyword arguments supplied to call (NULL identifier for **kwargs) |
| 128 | keyword = (identifier? arg, expr value) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 129 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 130 | -- import name with optional 'as' alias. |
| 131 | alias = (identifier name, identifier? asname) |
Benjamin Peterson | bf1bbc1 | 2011-05-27 13:58:08 -0500 | [diff] [blame] | 132 | |
Benjamin Peterson | 8d5a62d | 2012-01-16 09:54:28 -0500 | [diff] [blame] | 133 | withitem = (expr context_expr, expr? optional_vars) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 134 | } |
Thomas Wouters | 8b4a3e8 | 2007-02-23 20:00:10 +0000 | [diff] [blame] | 135 | |