blob: bcb5ecb69367795774d9b65d1b24b2b565951176 [file] [log] [blame]
Neal Norwitz19b0f402005-11-15 04:52:16 +00001-- ASDL's five builtin types are identifier, int, string, object, bool
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002
Martin v. Löwiseae93b72006-02-28 00:12:47 +00003module Python version "$Revision$"
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004{
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)
Guido van Rossumc2e20742006-02-27 22:32:47 +000028 | With(expr context_expr, expr? optional_vars, stmt* body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000029
30 -- 'type' is a bad name
31 | Raise(expr? type, expr? inst, expr? tback)
32 | TryExcept(stmt* body, excepthandler* handlers, stmt* orelse)
33 | TryFinally(stmt* body, stmt* finalbody)
34 | Assert(expr test, expr? msg)
35
36 | Import(alias* names)
Thomas Woutersf7f438b2006-02-28 16:09:29 +000037 | ImportFrom(identifier module, alias* names, int? level)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000038
39 -- Doesn't capture requirement that locals must be
40 -- defined if globals is
41 -- still supports use as a function!
42 | Exec(expr body, expr? globals, expr? locals)
43
44 | Global(identifier* names)
45 | Expr(expr value)
46 | Pass | Break | Continue
47
48 -- XXX Jython will be different
49 attributes (int lineno)
50
51 -- BoolOp() can use left & right?
52 expr = BoolOp(boolop op, expr* values)
53 | BinOp(expr left, operator op, expr right)
54 | UnaryOp(unaryop op, expr operand)
55 | Lambda(arguments args, expr body)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +000056 | IfExp(expr test, expr body, expr orelse)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000057 | Dict(expr* keys, expr* values)
58 | ListComp(expr elt, comprehension* generators)
59 | GeneratorExp(expr elt, comprehension* generators)
Jeremy Hyltonc960f262006-01-27 15:18:39 +000060 -- the grammar constrains where yield expressions can occur
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000061 | Yield(expr? value)
62 -- need sequences for compare to distinguish between
63 -- x < 4 < 3 and (x < 4) < 3
64 | Compare(expr left, cmpop* ops, expr* comparators)
65 | Call(expr func, expr* args, keyword* keywords,
66 expr? starargs, expr? kwargs)
67 | Repr(expr value)
68 | Num(object n) -- a number as a PyObject.
69 | Str(string s) -- need to specify raw, unicode, etc?
70 -- other literals? bools?
71
72 -- the following expression can appear in assignment context
73 | Attribute(expr value, identifier attr, expr_context ctx)
74 | Subscript(expr value, slice slice, expr_context ctx)
75 | Name(identifier id, expr_context ctx)
76 | List(expr* elts, expr_context ctx)
77 | Tuple(expr *elts, expr_context ctx)
78
79 attributes (int lineno)
80
81 expr_context = Load | Store | Del | AugLoad | AugStore | Param
82
83 slice = Ellipsis | Slice(expr? lower, expr? upper, expr? step)
84 | ExtSlice(slice* dims)
85 | Index(expr value)
86
87 boolop = And | Or
88
89 operator = Add | Sub | Mult | Div | Mod | Pow | LShift
90 | RShift | BitOr | BitXor | BitAnd | FloorDiv
91
92 unaryop = Invert | Not | UAdd | USub
93
94 cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
95
96 comprehension = (expr target, expr iter, expr* ifs)
97
98 -- not sure what to call the first argument for raise and except
99
100 excepthandler = (expr? type, expr? name, stmt* body)
101
102 arguments = (expr* args, identifier? vararg,
103 identifier? kwarg, expr* defaults)
104
105 -- keyword arguments supplied to call
106 keyword = (identifier arg, expr value)
107
108 -- import name with optional 'as' alias.
109 alias = (identifier name, identifier? asname)
110}