• 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          | Match(expr subject, match_case* cases)
40
41          | Raise(expr? exc, expr? cause)
42          | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
43          | Assert(expr test, expr? msg)
44
45          | Import(alias* names)
46          | ImportFrom(identifier? module, alias* names, int? level)
47
48          | Global(identifier* names)
49          | Nonlocal(identifier* names)
50          | Expr(expr value)
51          | Pass | Break | Continue
52
53          -- col_offset is the byte offset in the utf8 string the parser uses
54          attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
55
56          -- BoolOp() can use left & right?
57    expr = BoolOp(boolop op, expr* values)
58         | NamedExpr(expr target, expr value)
59         | BinOp(expr left, operator op, expr right)
60         | UnaryOp(unaryop op, expr operand)
61         | Lambda(arguments args, expr body)
62         | IfExp(expr test, expr body, expr orelse)
63         | Dict(expr* keys, expr* values)
64         | Set(expr* elts)
65         | ListComp(expr elt, comprehension* generators)
66         | SetComp(expr elt, comprehension* generators)
67         | DictComp(expr key, expr value, comprehension* generators)
68         | GeneratorExp(expr elt, comprehension* generators)
69         -- the grammar constrains where yield expressions can occur
70         | Await(expr value)
71         | Yield(expr? value)
72         | YieldFrom(expr value)
73         -- need sequences for compare to distinguish between
74         -- x < 4 < 3 and (x < 4) < 3
75         | Compare(expr left, cmpop* ops, expr* comparators)
76         | Call(expr func, expr* args, keyword* keywords)
77         | FormattedValue(expr value, int conversion, expr? format_spec)
78         | JoinedStr(expr* values)
79         | Constant(constant value, string? kind)
80
81         -- the following expression can appear in assignment context
82         | Attribute(expr value, identifier attr, expr_context ctx)
83         | Subscript(expr value, expr slice, expr_context ctx)
84         | Starred(expr value, expr_context ctx)
85         | Name(identifier id, expr_context ctx)
86         | List(expr* elts, expr_context ctx)
87         | Tuple(expr* elts, expr_context ctx)
88
89         -- can appear only in Subscript
90         | Slice(expr? lower, expr? upper, expr? step)
91
92          -- col_offset is the byte offset in the utf8 string the parser uses
93          attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
94
95    expr_context = Load | Store | Del
96
97    boolop = And | Or
98
99    operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift
100                 | RShift | BitOr | BitXor | BitAnd | FloorDiv
101
102    unaryop = Invert | Not | UAdd | USub
103
104    cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
105
106    comprehension = (expr target, expr iter, expr* ifs, int is_async)
107
108    excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
109                    attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
110
111    arguments = (arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs,
112                 expr* kw_defaults, arg? kwarg, expr* defaults)
113
114    arg = (identifier arg, expr? annotation, string? type_comment)
115           attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
116
117    -- keyword arguments supplied to call (NULL identifier for **kwargs)
118    keyword = (identifier? arg, expr value)
119               attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
120
121    -- import name with optional 'as' alias.
122    alias = (identifier name, identifier? asname)
123             attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
124
125    withitem = (expr context_expr, expr? optional_vars)
126
127    match_case = (pattern pattern, expr? guard, stmt* body)
128
129    pattern = MatchValue(expr value)
130            | MatchSingleton(constant value)
131            | MatchSequence(pattern* patterns)
132            | MatchMapping(expr* keys, pattern* patterns, identifier? rest)
133            | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)
134
135            | MatchStar(identifier? name)
136            -- The optional "rest" MatchMapping parameter handles capturing extra mapping keys
137
138            | MatchAs(pattern? pattern, identifier? name)
139            | MatchOr(pattern* patterns)
140
141             attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)
142
143    type_ignore = TypeIgnore(int lineno, string tag)
144}
145