blob: c5b64a992321353ce73b9d5f6ffd74addf5ce1f0 [file] [log] [blame]
Neal Norwitz3591bbe2007-02-26 19:04:49 +00001-- ASDL's five builtin types are identifier, int, string, object
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,
Neal Norwitzc1505362006-12-28 06:47:50 +000013 stmt* body, expr* decorators, expr? returns)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000014 | 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
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000021 -- use 'orelse' because else is a keyword in target languages
22 | For(expr target, expr iter, stmt* body, stmt* orelse)
23 | While(expr test, stmt* body, stmt* orelse)
24 | If(expr test, stmt* body, stmt* orelse)
Guido van Rossumc2e20742006-02-27 22:32:47 +000025 | With(expr context_expr, expr? optional_vars, stmt* body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000026
27 -- 'type' is a bad name
28 | Raise(expr? type, expr? inst, expr? tback)
29 | TryExcept(stmt* body, excepthandler* handlers, stmt* orelse)
30 | TryFinally(stmt* body, stmt* finalbody)
31 | Assert(expr test, expr? msg)
32
33 | Import(alias* names)
Thomas Woutersf7f438b2006-02-28 16:09:29 +000034 | ImportFrom(identifier module, alias* names, int? level)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000035
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000036 | Global(identifier* names)
37 | Expr(expr value)
38 | Pass | Break | Continue
39
40 -- XXX Jython will be different
Martin v. Löwis49c5da12006-03-01 22:49:05 +000041 -- col_offset is the byte offset in the utf8 string the parser uses
42 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000043
44 -- BoolOp() can use left & right?
45 expr = BoolOp(boolop op, expr* values)
46 | BinOp(expr left, operator op, expr right)
47 | UnaryOp(unaryop op, expr operand)
48 | Lambda(arguments args, expr body)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +000049 | IfExp(expr test, expr body, expr orelse)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000050 | Dict(expr* keys, expr* values)
Guido van Rossum86e58e22006-08-28 15:27:34 +000051 | Set(expr* elts)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000052 | ListComp(expr elt, comprehension* generators)
53 | GeneratorExp(expr elt, comprehension* generators)
Jeremy Hyltonc960f262006-01-27 15:18:39 +000054 -- the grammar constrains where yield expressions can occur
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000055 | Yield(expr? value)
56 -- need sequences for compare to distinguish between
57 -- x < 4 < 3 and (x < 4) < 3
58 | Compare(expr left, cmpop* ops, expr* comparators)
59 | Call(expr func, expr* args, keyword* keywords,
60 expr? starargs, expr? kwargs)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000061 | Num(object n) -- a number as a PyObject.
62 | Str(string s) -- need to specify raw, unicode, etc?
Thomas Wouters00e41de2007-02-23 19:56:57 +000063 | Bytes(string s)
Georg Brandl52318d62006-09-06 07:06:08 +000064 | Ellipsis
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000065 -- other literals? bools?
66
67 -- the following expression can appear in assignment context
68 | Attribute(expr value, identifier attr, expr_context ctx)
69 | Subscript(expr value, slice slice, expr_context ctx)
70 | Name(identifier id, expr_context ctx)
71 | List(expr* elts, expr_context ctx)
Thomas Wouterscf297e42007-02-23 15:07:44 +000072 | Tuple(expr* elts, expr_context ctx)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000073
Martin v. Löwis49c5da12006-03-01 22:49:05 +000074 -- col_offset is the byte offset in the utf8 string the parser uses
75 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000076
77 expr_context = Load | Store | Del | AugLoad | AugStore | Param
78
Georg Brandl52318d62006-09-06 07:06:08 +000079 slice = Slice(expr? lower, expr? upper, expr? step)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000080 | ExtSlice(slice* dims)
81 | Index(expr value)
82
83 boolop = And | Or
84
85 operator = Add | Sub | Mult | Div | Mod | Pow | LShift
86 | RShift | BitOr | BitXor | BitAnd | FloorDiv
87
88 unaryop = Invert | Not | UAdd | USub
89
90 cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
91
92 comprehension = (expr target, expr iter, expr* ifs)
93
94 -- not sure what to call the first argument for raise and except
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000095 -- TODO(jhylton): Figure out if there is a better way to handle
96 -- lineno and col_offset fields, particularly when
97 -- ast is exposed to Python.
Guido van Rossum16be03e2007-01-10 18:51:35 +000098 excepthandler = (expr? type, identifier? name, stmt* body, int lineno,
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000099 int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000100
Neal Norwitzc1505362006-12-28 06:47:50 +0000101 arguments = (arg* args, identifier? vararg, expr? varargannotation,
102 arg* kwonlyargs, identifier? kwarg,
103 expr? kwargannotation, expr* defaults,
104 expr* kw_defaults)
105 arg = SimpleArg(identifier arg, expr? annotation)
106 | NestedArgs(arg* args)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000107
108 -- keyword arguments supplied to call
109 keyword = (identifier arg, expr value)
110
111 -- import name with optional 'as' alias.
112 alias = (identifier name, identifier? asname)
113}
Thomas Wouters8b4a3e82007-02-23 20:00:10 +0000114