• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1-- ASDL's 5 builtin types are:
2-- identifier, int, string, object, constant
3
4module Python
5{
6    mod = Module(stmt* body, type_ignore *type_ignores)
7        | Interactive(stmt* body)
8        | Expression(expr body)
9        | FunctionType(expr* argtypes, expr returns)
10
11        -- not really an actual node but useful in Jython's typesystem.
12        | Suite(stmt* body)
13
14    stmt = FunctionDef(identifier name, arguments args,
15                       stmt* body, expr* decorator_list, expr? returns,
16                       string? type_comment)
17          | AsyncFunctionDef(identifier name, arguments args,
18                             stmt* body, expr* decorator_list, expr? returns,
19                             string? type_comment)
20
21          | ClassDef(identifier name,
22             expr* bases,
23             keyword* keywords,
24             stmt* body,
25             expr* decorator_list)
26          | Return(expr? value)
27
28          | Delete(expr* targets)
29          | Assign(expr* targets, expr value, string? type_comment)
30          | AugAssign(expr target, operator op, expr value)
31          -- 'simple' indicates that we annotate simple name without parens
32          | AnnAssign(expr target, expr annotation, expr? value, int simple)
33
34          -- use 'orelse' because else is a keyword in target languages
35          | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)
36          | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)
37          | While(expr test, stmt* body, stmt* orelse)
38          | If(expr test, stmt* body, stmt* orelse)
39          | With(withitem* items, stmt* body, string? type_comment)
40          | AsyncWith(withitem* items, stmt* body, string? type_comment)
41
42          | Raise(expr? exc, expr? cause)
43          | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
44          | Assert(expr test, expr? msg)
45
46          | Import(alias* names)
47          | ImportFrom(identifier? module, alias* names, int? level)
48
49          | Global(identifier* names)
50          | Nonlocal(identifier* names)
51          | Expr(expr value)
52          | Pass | Break | Continue
53
54          -- XXX Jython will be different
55          -- col_offset is the byte offset in the utf8 string the parser uses
56          attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
57
58          -- BoolOp() can use left & right?
59    expr = BoolOp(boolop op, expr* values)
60         | NamedExpr(expr target, expr value)
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         | FormattedValue(expr value, int? conversion, expr? format_spec)
80         | JoinedStr(expr* values)
81         | Constant(constant value, string? kind)
82
83         -- the following expression can appear in assignment context
84         | Attribute(expr value, identifier attr, expr_context ctx)
85         | Subscript(expr value, slice slice, expr_context ctx)
86         | Starred(expr value, expr_context ctx)
87         | Name(identifier id, expr_context ctx)
88         | List(expr* elts, expr_context ctx)
89         | Tuple(expr* elts, expr_context ctx)
90
91          -- col_offset is the byte offset in the utf8 string the parser uses
92          attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
93
94    expr_context = Load | Store | Del | AugLoad | AugStore | Param
95
96    slice = Slice(expr? lower, expr? upper, expr? step)
97          | ExtSlice(slice* dims)
98          | Index(expr value)
99
100    boolop = And | Or
101
102    operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift
103                 | RShift | BitOr | BitXor | BitAnd | FloorDiv
104
105    unaryop = Invert | Not | UAdd | USub
106
107    cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
108
109    comprehension = (expr target, expr iter, expr* ifs, int is_async)
110
111    excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
112                    attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
113
114    arguments = (arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs,
115                 expr* kw_defaults, arg? kwarg, expr* defaults)
116
117    arg = (identifier arg, expr? annotation, string? type_comment)
118           attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
119
120    -- keyword arguments supplied to call (NULL identifier for **kwargs)
121    keyword = (identifier? arg, expr value)
122
123    -- import name with optional 'as' alias.
124    alias = (identifier name, identifier? asname)
125
126    withitem = (expr context_expr, expr? optional_vars)
127
128    type_ignore = TypeIgnore(int lineno, string tag)
129}
130