Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1 | -- ASDL's three builtin types are identifier, int, string |
| 2 | |
| 3 | module Python |
| 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, |
| 13 | stmt* body, expr* decorators) |
| 14 | | ClassDef(identifier name, expr* bases, stmt* body) |
| 15 | | Return(expr? value) |
| 16 | |
| 17 | | Delete(expr* targets) |
| 18 | | Assign(expr* targets, expr value) |
| 19 | | AugAssign(expr target, operator op, expr value) |
| 20 | |
| 21 | -- not sure if bool is allowed, can always use int |
| 22 | | Print(expr? dest, expr* values, bool nl) |
| 23 | |
| 24 | -- use 'orelse' because else is a keyword in target languages |
| 25 | | For(expr target, expr iter, stmt* body, stmt* orelse) |
| 26 | | While(expr test, stmt* body, stmt* orelse) |
| 27 | | If(expr test, stmt* body, stmt* orelse) |
| 28 | |
| 29 | -- 'type' is a bad name |
| 30 | | Raise(expr? type, expr? inst, expr? tback) |
| 31 | | TryExcept(stmt* body, excepthandler* handlers, stmt* orelse) |
| 32 | | TryFinally(stmt* body, stmt* finalbody) |
| 33 | | Assert(expr test, expr? msg) |
| 34 | |
| 35 | | Import(alias* names) |
| 36 | | ImportFrom(identifier module, alias* names) |
| 37 | |
| 38 | -- Doesn't capture requirement that locals must be |
| 39 | -- defined if globals is |
| 40 | -- still supports use as a function! |
| 41 | | Exec(expr body, expr? globals, expr? locals) |
| 42 | |
| 43 | | Global(identifier* names) |
| 44 | | Expr(expr value) |
| 45 | | Pass | Break | Continue |
| 46 | |
| 47 | -- XXX Jython will be different |
| 48 | attributes (int lineno) |
| 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) |
| 55 | | Dict(expr* keys, expr* values) |
| 56 | | ListComp(expr elt, comprehension* generators) |
| 57 | | GeneratorExp(expr elt, comprehension* generators) |
| 58 | | Yield(expr? value) |
| 59 | -- need sequences for compare to distinguish between |
| 60 | -- x < 4 < 3 and (x < 4) < 3 |
| 61 | | Compare(expr left, cmpop* ops, expr* comparators) |
| 62 | | Call(expr func, expr* args, keyword* keywords, |
| 63 | expr? starargs, expr? kwargs) |
| 64 | | Repr(expr value) |
| 65 | | Num(object n) -- a number as a PyObject. |
| 66 | | Str(string s) -- need to specify raw, unicode, etc? |
| 67 | -- other literals? bools? |
| 68 | |
| 69 | -- the following expression can appear in assignment context |
| 70 | | Attribute(expr value, identifier attr, expr_context ctx) |
| 71 | | Subscript(expr value, slice slice, expr_context ctx) |
| 72 | | Name(identifier id, expr_context ctx) |
| 73 | | List(expr* elts, expr_context ctx) |
| 74 | | Tuple(expr *elts, expr_context ctx) |
| 75 | |
| 76 | attributes (int lineno) |
| 77 | |
| 78 | expr_context = Load | Store | Del | AugLoad | AugStore | Param |
| 79 | |
| 80 | slice = Ellipsis | Slice(expr? lower, expr? upper, expr? step) |
| 81 | | ExtSlice(slice* dims) |
| 82 | | Index(expr value) |
| 83 | |
| 84 | boolop = And | Or |
| 85 | |
| 86 | operator = Add | Sub | Mult | Div | Mod | Pow | LShift |
| 87 | | RShift | BitOr | BitXor | BitAnd | FloorDiv |
| 88 | |
| 89 | unaryop = Invert | Not | UAdd | USub |
| 90 | |
| 91 | cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn |
| 92 | |
| 93 | comprehension = (expr target, expr iter, expr* ifs) |
| 94 | |
| 95 | -- not sure what to call the first argument for raise and except |
| 96 | |
| 97 | excepthandler = (expr? type, expr? name, stmt* body) |
| 98 | |
| 99 | arguments = (expr* args, identifier? vararg, |
| 100 | identifier? kwarg, expr* defaults) |
| 101 | |
| 102 | -- keyword arguments supplied to call |
| 103 | keyword = (identifier arg, expr value) |
| 104 | |
| 105 | -- import name with optional 'as' alias. |
| 106 | alias = (identifier name, identifier? asname) |
| 107 | } |