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