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