|
| 1 | +-- Python 2.7 AST |
| 2 | +-- ASDL's five builtin types are identifier, int, string, object, bool |
| 3 | + |
| 4 | +module Python version "2.7" |
| 5 | +{ |
| 6 | + mod = Module(stmt* body) |
| 7 | + | Interactive(stmt* body) |
| 8 | + | Expression(expr body) |
| 9 | + |
| 10 | + -- not really an actual node but useful in Jython's typesystem. |
| 11 | + | Suite(stmt* body) |
| 12 | + |
| 13 | + stmt = FunctionDef(identifier name, |
| 14 | + arguments args, |
| 15 | + stmt* body, |
| 16 | + expr* decorator_list) |
| 17 | + | ClassDef(identifier name, expr* bases, stmt* body, expr* decorator_list) |
| 18 | + | Return(expr? value) |
| 19 | + |
| 20 | + | Delete(expr* targets) |
| 21 | + | Assign(expr* targets, expr value) |
| 22 | + | AugAssign(expr target, operator op, expr value) |
| 23 | + |
| 24 | + -- not sure if bool is allowed, can always use int |
| 25 | + | Print(expr? dest, expr* values, bool nl) |
| 26 | + |
| 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) |
| 31 | + | With(expr context_expr, expr? optional_vars, stmt* body) |
| 32 | + |
| 33 | + -- 'type' is a bad name |
| 34 | + | Raise(expr? type, expr? inst, expr? tback) |
| 35 | + | TryExcept(stmt* body, excepthandler* handlers, stmt* orelse) |
| 36 | + | TryFinally(stmt* body, stmt* finalbody) |
| 37 | + | Assert(expr test, expr? msg) |
| 38 | + |
| 39 | + | Import(alias* names) |
| 40 | + | ImportFrom(identifier? module, alias* names, int? level) |
| 41 | + |
| 42 | + -- Doesn't capture requirement that locals must be |
| 43 | + -- defined if globals is |
| 44 | + -- still supports use as a function! |
| 45 | + | Exec(expr body, expr? globals, expr? locals) |
| 46 | + |
| 47 | + | Global(identifier* names) |
| 48 | + | Expr(expr value) |
| 49 | + | Pass | Break | Continue |
| 50 | + |
| 51 | + -- XXX Jython will be different |
| 52 | + -- col_offset is the byte offset in the utf8 string the parser uses |
| 53 | + attributes (int lineno, int col_offset) |
| 54 | + |
| 55 | + -- BoolOp() can use left & right? |
| 56 | + expr = BoolOp(boolop op, expr* values) |
| 57 | + | BinOp(expr left, operator op, expr right) |
| 58 | + | UnaryOp(unaryop op, expr operand) |
| 59 | + | Lambda(arguments args, expr body) |
| 60 | + | IfExp(expr test, expr body, expr orelse) |
| 61 | + | Dict(expr* keys, expr* values) |
| 62 | + | Set(expr* elts) |
| 63 | + | ListComp(expr elt, comprehension* generators) |
| 64 | + | SetComp(expr elt, comprehension* generators) |
| 65 | + | DictComp(expr key, expr value, comprehension* generators) |
| 66 | + | GeneratorExp(expr elt, comprehension* generators) |
| 67 | + -- the grammar constrains where yield expressions can occur |
| 68 | + | Yield(expr? value) |
| 69 | + -- need sequences for compare to distinguish between |
| 70 | + -- x < 4 < 3 and (x < 4) < 3 |
| 71 | + | Compare(expr left, cmpop* ops, expr* comparators) |
| 72 | + | Call(expr func, expr* args, keyword* keywords, expr? starargs, expr? kwargs) |
| 73 | + | Repr(expr value) |
| 74 | + | Num(object n) -- a number as a PyObject. |
| 75 | + | Str(string s) -- need to specify raw, unicode, etc? |
| 76 | + -- other literals? bools? |
| 77 | + |
| 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 | + | Name(identifier id, expr_context ctx) |
| 82 | + | List(expr* elts, expr_context ctx) |
| 83 | + | Tuple(expr* elts, expr_context ctx) |
| 84 | + |
| 85 | + -- col_offset is the byte offset in the utf8 string the parser uses |
| 86 | + attributes (int lineno, int col_offset) |
| 87 | + |
| 88 | + expr_context = Load |
| 89 | + | Store |
| 90 | + | Del |
| 91 | + | AugLoad |
| 92 | + | AugStore |
| 93 | + | Param |
| 94 | + |
| 95 | + slice = Ellipsis |
| 96 | + | Slice(expr? lower, expr? upper, expr? step) |
| 97 | + | ExtSlice(slice* dims) |
| 98 | + | Index(expr value) |
| 99 | + |
| 100 | + boolop = And |
| 101 | + | Or |
| 102 | + |
| 103 | + operator = Add |
| 104 | + | Sub |
| 105 | + | Mult |
| 106 | + | Div |
| 107 | + | Mod |
| 108 | + | Pow |
| 109 | + | LShift |
| 110 | + | RShift |
| 111 | + | BitOr |
| 112 | + | BitXor |
| 113 | + | BitAnd |
| 114 | + | FloorDiv |
| 115 | + |
| 116 | + unaryop = Invert |
| 117 | + | Not |
| 118 | + | UAdd |
| 119 | + | USub |
| 120 | + |
| 121 | + cmpop = Eq |
| 122 | + | NotEq |
| 123 | + | Lt |
| 124 | + | LtE |
| 125 | + | Gt |
| 126 | + | GtE |
| 127 | + | Is |
| 128 | + | IsNot |
| 129 | + | In |
| 130 | + | NotIn |
| 131 | + |
| 132 | + comprehension = (expr target, expr iter, expr* ifs) |
| 133 | + |
| 134 | + -- not sure what to call the first argument for raise and except |
| 135 | + excepthandler = ExceptHandler(expr? type, expr? name, stmt* body) |
| 136 | + attributes (int lineno, int col_offset) |
| 137 | + |
| 138 | + arguments = (expr* args, identifier? vararg, |
| 139 | + identifier? kwarg, expr* defaults) |
| 140 | + |
| 141 | + -- keyword arguments supplied to call |
| 142 | + keyword = (identifier arg, expr value) |
| 143 | + |
| 144 | + -- import name with optional 'as' alias. |
| 145 | + alias = (identifier name, identifier? asname) |
| 146 | +} |
0 commit comments