1-- ASDL's 7 builtin types are:
2-- identifier, int, string, bytes, object, singleton, constant
3--
4-- singleton: None, True or False
5-- constant can be None, whereas None means "no value" for object.
6
7module Python
8{
9    mod = Module(stmt* body, type_ignore *type_ignores)
10        | Interactive(stmt* body)
11        | Expression(expr body)
12        | FunctionType(expr* argtypes, expr returns)
13
14        -- not really an actual node but useful in Jython's typesystem.
15        | Suite(stmt* body)
16
17    stmt = FunctionDef(identifier name, arguments args,
18                       stmt* body, expr* decorator_list, expr? returns, string? type_comment)
19          | AsyncFunctionDef(identifier name, arguments args,
20                             stmt* body, expr* decorator_list, expr? returns, string? type_comment)
21
22          | ClassDef(identifier name,
23             expr* bases,
24             keyword* keywords,
25             stmt* body,
26             expr* decorator_list)
27          | Return(expr? value)
28
29          | Delete(expr* targets)
30          | Assign(expr* targets, expr value, string? type_comment)
31          | AugAssign(expr target, operator op, expr value)
32          -- 'simple' indicates that we annotate simple name without parens
33          | AnnAssign(expr target, expr annotation, expr? value, int simple)
34
35          -- use 'orelse' because else is a keyword in target languages
36          | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)
37          | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)
38          | While(expr test, stmt* body, stmt* orelse)
39          | If(expr test, stmt* body, stmt* orelse)
40          | With(withitem* items, stmt* body, string? type_comment)
41          | AsyncWith(withitem* items, stmt* body, string? type_comment)
42
43          | Raise(expr? exc, expr? cause)
44          | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
45          | Assert(expr test, expr? msg)
46
47          | Import(alias* names)
48          | ImportFrom(identifier? module, alias* names, int? level)
49
50          | Global(identifier* names)
51          | Nonlocal(identifier* names)
52          | Expr(expr value)
53          | Pass | Break | Continue
54
55          -- XXX Jython will be different
56          -- col_offset is the byte offset in the utf8 string the parser uses
57          attributes (int lineno, int col_offset)
58
59          -- BoolOp() can use left & right?
60    expr = BoolOp(boolop op, expr* values)
61         | BinOp(expr left, operator op, expr right)
62         | UnaryOp(unaryop op, expr operand)
63         | Lambda(arguments args, expr body)
64         | IfExp(expr test, expr body, expr orelse)
65         | Dict(expr* keys, expr* values)
66         | Set(expr* elts)
67         | ListComp(expr elt, comprehension* generators)
68         | SetComp(expr elt, comprehension* generators)
69         | DictComp(expr key, expr value, comprehension* generators)
70         | GeneratorExp(expr elt, comprehension* generators)
71         -- the grammar constrains where yield expressions can occur
72         | Await(expr value)
73         | Yield(expr? value)
74         | YieldFrom(expr value)
75         -- need sequences for compare to distinguish between
76         -- x < 4 < 3 and (x < 4) < 3
77         | Compare(expr left, cmpop* ops, expr* comparators)
78         | Call(expr func, expr* args, keyword* keywords)
79         | Num(object n) -- a number as a PyObject.
80         | Str(string s, string kind)
81         | FormattedValue(expr value, int? conversion, expr? format_spec)
82         | JoinedStr(expr* values)
83         | Bytes(bytes s, string kind)
84         | NameConstant(singleton value)
85         | Ellipsis
86         | Constant(constant value)
87
88         -- the following expression can appear in assignment context
89         | Attribute(expr value, identifier attr, expr_context ctx)
90         | Subscript(expr value, slice slice, expr_context ctx)
91         | Starred(expr value, expr_context ctx)
92         | Name(identifier id, expr_context ctx)
93         | List(expr* elts, expr_context ctx)
94         | Tuple(expr* elts, expr_context ctx)
95
96          -- col_offset is the byte offset in the utf8 string the parser uses
97          attributes (int lineno, int col_offset)
98
99    expr_context = Load | Store | Del | AugLoad | AugStore | Param
100
101    slice = Slice(expr? lower, expr? upper, expr? step)
102          | ExtSlice(slice* dims)
103          | Index(expr value)
104
105    boolop = And | Or
106
107    operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift
108                 | RShift | BitOr | BitXor | BitAnd | FloorDiv
109
110    unaryop = Invert | Not | UAdd | USub
111
112    cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
113
114    comprehension = (expr target, expr iter, expr* ifs, int is_async)
115
116    excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
117                    attributes (int lineno, int col_offset)
118
119    arguments = (arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults,
120                 arg? kwarg, expr* defaults)
121
122    arg = (identifier arg, expr? annotation, string? type_comment)
123           attributes (int lineno, int col_offset)
124
125    -- keyword arguments supplied to call (NULL identifier for **kwargs)
126    keyword = (identifier? arg, expr value)
127
128    -- import name with optional 'as' alias.
129    alias = (identifier name, identifier? asname)
130
131    withitem = (expr context_expr, expr? optional_vars)
132
133    type_ignore = TypeIgnore(int lineno, string tag)
134}
135