blob: 0d373b09d3237babbfe7c9c4a1b25c8e2bbb0793 [file] [log] [blame]
Benjamin Peterson442f2092012-12-06 17:41:04 -05001-- ASDL's six builtin types are identifier, int, string, bytes, object, singleton
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002
Benjamin Peterson6cb2b922011-03-12 18:28:16 -06003module Python
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004{
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -05005 mod = Module(stmt* body)
6 | Interactive(stmt* body)
7 | Expression(expr body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00008
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -05009 -- not really an actual node but useful in Jython's typesystem.
10 | Suite(stmt* body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000011
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050012 stmt = FunctionDef(identifier name, arguments args,
Guido van Rossumd59da4b2007-05-22 18:11:13 +000013 stmt* body, expr* decorator_list, expr? returns)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050014 | ClassDef(identifier name,
15 expr* bases,
16 keyword* keywords,
17 expr? starargs,
18 expr? kwargs,
19 stmt* body,
20 expr* decorator_list)
21 | Return(expr? value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000022
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050023 | Delete(expr* targets)
24 | Assign(expr* targets, expr value)
25 | AugAssign(expr target, operator op, expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000026
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050027 -- 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(withitem* items, stmt* body)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000032
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050033 | Raise(expr? exc, expr? cause)
34 | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
35 | Assert(expr test, expr? msg)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000036
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050037 | Import(alias* names)
38 | ImportFrom(identifier? module, alias* names, int? level)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000039
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050040 | Global(identifier* names)
41 | Nonlocal(identifier* names)
42 | Expr(expr value)
43 | Pass | Break | Continue
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000044
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050045 -- XXX Jython will be different
46 -- col_offset is the byte offset in the utf8 string the parser uses
47 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000048
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050049 -- BoolOp() can use left & right?
50 expr = BoolOp(boolop op, expr* values)
51 | BinOp(expr left, operator op, expr right)
52 | UnaryOp(unaryop op, expr operand)
53 | Lambda(arguments args, expr body)
54 | IfExp(expr test, expr body, expr orelse)
55 | Dict(expr* keys, expr* values)
56 | Set(expr* elts)
57 | ListComp(expr elt, comprehension* generators)
58 | SetComp(expr elt, comprehension* generators)
59 | DictComp(expr key, expr value, comprehension* generators)
60 | GeneratorExp(expr elt, comprehension* generators)
61 -- the grammar constrains where yield expressions can occur
62 | Yield(expr? value)
Mark Dickinsonded35ae2012-11-25 14:36:26 +000063 | YieldFrom(expr value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050064 -- need sequences for compare to distinguish between
65 -- x < 4 < 3 and (x < 4) < 3
66 | Compare(expr left, cmpop* ops, expr* comparators)
67 | Call(expr func, expr* args, keyword* keywords,
68 expr? starargs, expr? kwargs)
69 | Num(object n) -- a number as a PyObject.
70 | Str(string s) -- need to specify raw, unicode, etc?
71 | Bytes(bytes s)
Benjamin Peterson442f2092012-12-06 17:41:04 -050072 | NameConstant(singleton value)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050073 | Ellipsis
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000074
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050075 -- the following expression can appear in assignment context
76 | Attribute(expr value, identifier attr, expr_context ctx)
77 | Subscript(expr value, slice slice, expr_context ctx)
78 | Starred(expr value, expr_context ctx)
79 | Name(identifier id, expr_context ctx)
80 | List(expr* elts, expr_context ctx)
81 | Tuple(expr* elts, expr_context ctx)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000082
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050083 -- col_offset is the byte offset in the utf8 string the parser uses
84 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000085
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050086 expr_context = Load | Store | Del | AugLoad | AugStore | Param
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000087
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050088 slice = Slice(expr? lower, expr? upper, expr? step)
89 | ExtSlice(slice* dims)
90 | Index(expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000091
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050092 boolop = And | Or
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000093
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050094 operator = Add | Sub | Mult | Div | Mod | Pow | LShift
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000095 | RShift | BitOr | BitXor | BitAnd | FloorDiv
96
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050097 unaryop = Invert | Not | UAdd | USub
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000098
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -050099 cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000100
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500101 comprehension = (expr target, expr iter, expr* ifs)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000102
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500103 excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
104 attributes (int lineno, int col_offset)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000105
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500106 arguments = (arg* args, identifier? vararg, expr? varargannotation,
Neal Norwitzc1505362006-12-28 06:47:50 +0000107 arg* kwonlyargs, identifier? kwarg,
108 expr? kwargannotation, expr* defaults,
109 expr* kw_defaults)
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500110 arg = (identifier arg, expr? annotation)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000111
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500112 -- keyword arguments supplied to call
113 keyword = (identifier arg, expr value)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000114
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500115 -- import name with optional 'as' alias.
116 alias = (identifier name, identifier? asname)
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -0500117
Benjamin Peterson8d5a62d2012-01-16 09:54:28 -0500118 withitem = (expr context_expr, expr? optional_vars)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +0000119}
Thomas Wouters8b4a3e82007-02-23 20:00:10 +0000120