Debian Codegraph @

pypy/interpreter/astcompiler/tools/Python.asdl

raw
1 -- ASDL's 4 builtin types are:
2 -- identifier, int, string, constant
3
4 module 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 | TryStar(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 -- col_offset is the byte offset in the utf8 string the parser uses
55 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
56
57 -- BoolOp() can use left & right?
58 expr = BoolOp(boolop op, expr* values)
59 | NamedExpr(expr target, expr value)
60 | BinOp(expr left, operator op, expr right)
61 | UnaryOp(unaryop op, expr operand)
62 | Lambda(arguments args, expr body)
63 | IfExp(expr test, expr body, expr orelse)
64 | Dict(expr* keys, expr* values)
65 | Set(expr* elts)
66 | ListComp(expr elt, comprehension* generators)
67 | SetComp(expr elt, comprehension* generators)
68 | DictComp(expr key, expr value, comprehension* generators)
69 | GeneratorExp(expr elt, comprehension* generators)
70 -- the grammar constrains where yield expressions can occur
71 | Await(expr value)
72 | Yield(expr? value)
73 | YieldFrom(expr value)
74 -- need sequences for compare to distinguish between
75 -- x < 4 < 3 and (x < 4) < 3
76 | Compare(expr left, cmpop* ops, expr* comparators)
77 | Call(expr func, expr* args, keyword* keywords)
78 | RevDBMetaVar(int metavar)
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, expr 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 -- can appear only in Subscript
92 | Slice(expr? lower, expr? upper, expr? step)
93
94 -- col_offset is the byte offset in the utf8 string the parser uses
95 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
96
97 expr_context = Load | Store | Del
98
99 boolop = And | Or
100
101 operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift
102 | RShift | BitOr | BitXor | BitAnd | FloorDiv
103
104 unaryop = Invert | Not | UAdd | USub
105
106 cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn
107
108 comprehension = (expr target, expr iter, expr* ifs, int is_async)
109
110 excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
111 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
112
113 arguments = (arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs,
114 expr* kw_defaults, arg? kwarg, expr* defaults)
115
116 arg = (identifier arg, expr? annotation, string? type_comment)
117 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
118
119 -- keyword arguments supplied to call (NULL identifier for **kwargs)
120 keyword = (identifier? arg, expr value)
121 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
122
123 -- import name with optional 'as' alias.
124 alias = (identifier name, identifier? asname)
125 attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
126
127 withitem = (expr context_expr, expr? optional_vars)
128
129 match_case = (pattern pattern, expr? guard, stmt* body)
130
131 pattern = MatchValue(expr value)
132 | MatchSingleton(constant value)
133 | MatchSequence(pattern* patterns)
134 | MatchMapping(expr* keys, pattern* patterns, identifier? rest)
135 | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)
136
137 | MatchStar(identifier? name)
138 -- The optional "rest" MatchMapping parameter handles capturing extra mapping keys
139
140 | MatchAs(pattern? pattern, identifier? name)
141 | MatchOr(pattern* patterns)
142
143 attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)
144
145 type_ignore = TypeIgnore(int lineno, string tag)
146 }