-
Notifications
You must be signed in to change notification settings - Fork 6
/
ast.ml
476 lines (439 loc) · 8.47 KB
/
ast.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
(*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
type num =
| Int of int
| Float of float
| Complex of float
| Big_int of string
(** pyast uses Py.Object.t for Big_int, but this is presumably not what we want (if it's an
opaque wrapper for a CPython object). Just have the source text representing the integer
digits for now instead. *)
[@@deriving show]
type object_ = num [@@deriving show]
type constant_desc =
| Ellipsis
| Bool of bool
| Num of num
| Str of string
| ByteStr of string
[@@deriving show]
type constant = constant_desc option [@@deriving show]
type singleton = bool option [@@deriving show]
type withitem = {
context_expr: expr;
optional_vars: expr option;
}
and recoverableerrorwithlocation = {
error: string;
lineno: int;
col_offset: int;
end_lineno: int;
end_col_offset: int;
}
and unaryop =
| Invert
| Not
| UAdd
| USub
and type_ignore =
| TypeIgnore of {
lineno: int;
tag: string;
}
and stmt = {
desc: stmt_desc;
lineno: int;
col_offset: int;
end_lineno: int option;
end_col_offset: int option;
}
and stmt_desc =
| FunctionDef of {
name: string;
args: arguments;
body: stmt list;
decorator_list: expr list;
type_params: expr list;
returns: expr option;
type_comment: string option;
}
| AsyncFunctionDef of {
name: string;
args: arguments;
body: stmt list;
decorator_list: expr list;
type_params: expr list;
returns: expr option;
type_comment: string option;
}
| ClassDef of {
name: string;
bases: expr list;
keywords: keyword list;
body: stmt list;
decorator_list: expr list;
type_params: expr list;
}
| Return of expr option
| Delete of expr list
| Assign of {
targets: expr list;
value: expr;
type_comment: string option;
}
| AugAssign of {
target: expr;
op: operator;
value: expr;
}
| AnnAssign of {
target: expr;
annotation: expr;
value: expr option;
simple: int;
}
| For of {
target: expr;
iter: expr;
body: stmt list;
orelse: stmt list;
type_comment: string option;
}
| AsyncFor of {
target: expr;
iter: expr;
body: stmt list;
orelse: stmt list;
type_comment: string option;
}
| While of {
test: expr;
body: stmt list;
orelse: stmt list;
}
| If of {
test: expr;
body: stmt list;
orelse: stmt list;
}
| With of {
items: withitem list;
body: stmt list;
type_comment: string option;
}
| AsyncWith of {
items: withitem list;
body: stmt list;
type_comment: string option;
}
| Match of {
subject: expr;
cases: match_case list;
}
| Raise of {
exc: expr option;
cause: expr option;
}
| Try of {
body: stmt list;
handlers: excepthandler list;
orelse: stmt list;
finalbody: stmt list;
}
| Assert of {
test: expr;
msg: expr option;
}
| Import of alias list
| ImportFrom of {
module_: string option;
names: alias list;
level: int option;
}
| Global of string list
| Nonlocal of string list
| Expr of expr
| Pass
| Break
| Continue
and slice = expr
and pattern = {
desc: pattern_desc;
lineno: int;
col_offset: int;
end_lineno: int;
end_col_offset: int;
}
and pattern_desc =
| MatchValue of expr
| MatchSingleton of constant
| MatchSequence of pattern list
| MatchMapping of {
keys: expr list;
patterns: pattern list;
rest: string option;
}
| MatchClass of {
cls: expr;
patterns: pattern list;
kwd_attrs: string list;
kwd_patterns: pattern list;
}
| MatchStar of string option
| MatchAs of {
pattern: pattern option;
name: string option;
}
| MatchOr of pattern list
and operator =
| Add
| Sub
| Mult
| MatMult
| Div
| Mod
| Pow
| LShift
| RShift
| BitOr
| BitXor
| BitAnd
| FloorDiv
and mod_ =
| Module of {
body: stmt list;
type_ignores: type_ignore list;
}
| Interactive of stmt list
| Expression of expr
| FunctionType of {
argtypes: expr list;
returns: expr;
}
and match_case = {
pattern: pattern;
guard: expr option;
body: stmt list;
}
and keyword = {
arg: string option;
value: expr;
lineno: int;
col_offset: int;
end_lineno: int option;
end_col_offset: int option;
}
and expr_context =
| Load
| Store
| Del
and expr = {
desc: expr_desc;
lineno: int;
col_offset: int;
end_lineno: int option;
end_col_offset: int option;
}
and expr_desc =
| BoolOp of {
op: boolop;
values: expr list;
}
| NamedExpr of {
target: expr;
value: expr;
}
| BinOp of {
left: expr;
op: operator;
right: expr;
}
| UnaryOp of {
op: unaryop;
operand: expr;
}
| Lambda of {
args: arguments;
body: expr;
}
| IfExp of {
test: expr;
body: expr;
orelse: expr;
}
| Dict of {
keys: expr option list;
values: expr list;
}
| Set of expr list
| ListComp of {
elt: expr;
generators: comprehension list;
}
| SetComp of {
elt: expr;
generators: comprehension list;
}
| DictComp of {
key: expr;
value: expr;
generators: comprehension list;
}
| GeneratorExp of {
elt: expr;
generators: comprehension list;
}
| Await of expr
| Yield of expr option
| YieldFrom of expr
| Compare of {
left: expr;
ops: cmpop list;
comparators: expr list;
}
| Call of {
func: expr;
args: expr list;
keywords: keyword list;
}
| FormattedValue of {
value: expr;
conversion: int option;
format_spec: expr option;
}
| JoinedStr of expr list
| Constant of {
value: constant;
kind: string option;
}
| Attribute of {
value: expr;
attr: string;
ctx: expr_context;
}
| Subscript of {
value: expr;
slice: expr;
ctx: expr_context;
}
| Starred of {
value: expr;
ctx: expr_context;
}
| Name of {
id: string;
ctx: expr_context;
}
| List of {
elts: expr list;
ctx: expr_context;
}
| Tuple of {
elts: expr list;
ctx: expr_context;
}
| Slice of {
lower: expr option;
upper: expr option;
step: expr option;
}
and excepthandler = {
desc: excepthandler_desc;
lineno: int;
col_offset: int;
end_lineno: int option;
end_col_offset: int option;
}
and excepthandler_desc =
| ExceptHandler of {
type_: expr option;
name: string option;
body: stmt list;
}
and comprehension = {
target: expr;
iter: expr;
ifs: expr list;
is_async: bool;
}
and cmpop =
| Eq
| NotEq
| Lt
| LtE
| Gt
| GtE
| Is
| IsNot
| In
| NotIn
and boolop =
| And
| Or
and arguments = {
posonlyargs: arg list;
args: arg list;
vararg: arg option;
kwonlyargs: arg list;
kw_defaults: expr option list;
kwarg: arg option;
defaults: expr list;
}
and arg = {
arg: string;
annotation: expr option;
type_comment: string option;
lineno: int;
col_offset: int;
end_lineno: int option;
end_col_offset: int option;
}
and alias = {
name: string;
asname: string option;
lineno: int;
col_offset: int;
end_lineno: int option;
end_col_offset: int option;
}
[@@deriving show]
type arguments_args =
| Expr_list of expr list
| Arg_list of arg list
[@@deriving show]
type arguments_kwarg =
| Identifier_opt of string option
| Arg_opt of arg option
[@@deriving show]
type arguments_vararg =
| Identifier_opt of string option
| Arg_opt of arg option
[@@deriving show]
type excepthandler_excepthandler_name =
| Identifier_opt of string option
| Expr_opt of expr option
[@@deriving show]
type expr_bytes_s =
| String of string
| Bytes of string
[@@deriving show]
type expr_subscript_slice =
| Slice of slice
| Expr of expr
[@@deriving show]
type expr_yieldfrom_value =
| Expr_opt of expr option
| Expr of expr
[@@deriving show]
type keyword_arg =
| Identifier_opt of string option
| Identifier of string
[@@deriving show]
type stmt_importfrom_module =
| Identifier_opt of string option
| Identifier of string
[@@deriving show]