1Parsetree(3) OCaml library Parsetree(3)
2
3
4
6 Parsetree - Abstract syntax tree produced by parsing
7
9 Module Parsetree
10
12 Module Parsetree
13 : sig end
14
15
16 Abstract syntax tree produced by parsing
17
18 Warning: this module is unstable and part of Compiler_libs .
19
20
21
22
23
24 type constant =
25 | Pconst_integer of string * char option
26 | Pconst_char of char
27 | Pconst_string of string * string option
28 | Pconst_float of string * char option
29
30
31
32
33
34
35 Extension points
36 type attribute = {
37 attr_name : string Asttypes.loc ;
38 attr_payload : payload ;
39 attr_loc : Location.t ;
40 }
41
42
43
44
45 type extension = string Asttypes.loc * payload
46
47
48
49
50 type attributes = attribute list
51
52
53
54
55 type payload =
56 | PStr of structure
57 | PSig of signature
58 | PTyp of core_type
59 | PPat of pattern * expression option
60
61
62
63
64
65
66 Core language
67 type core_type = {
68 ptyp_desc : core_type_desc ;
69 ptyp_loc : Location.t ;
70 ptyp_loc_stack : Location.t list ;
71 ptyp_attributes : attributes ;
72 }
73
74
75
76
77 type core_type_desc =
78 | Ptyp_any
79 | Ptyp_var of string
80 | Ptyp_arrow of Asttypes.arg_label * core_type * core_type
81 | Ptyp_tuple of core_type list
82 | Ptyp_constr of Longident.t Asttypes.loc * core_type list
83 | Ptyp_object of object_field list * Asttypes.closed_flag
84 | Ptyp_class of Longident.t Asttypes.loc * core_type list
85 | Ptyp_alias of core_type * string
86 | Ptyp_variant of row_field list * Asttypes.closed_flag * Ast‐
87 types.label list option
88 | Ptyp_poly of string Asttypes.loc list * core_type
89 | Ptyp_package of package_type
90 | Ptyp_extension of extension
91
92
93
94
95 type package_type = Longident.t Asttypes.loc * (Longident.t Ast‐
96 types.loc * core_type) list
97
98
99
100
101 type row_field = {
102 prf_desc : row_field_desc ;
103 prf_loc : Location.t ;
104 prf_attributes : attributes ;
105 }
106
107
108
109
110 type row_field_desc =
111 | Rtag of Asttypes.label Asttypes.loc * bool * core_type list
112 | Rinherit of core_type
113
114
115
116
117 type object_field = {
118 pof_desc : object_field_desc ;
119 pof_loc : Location.t ;
120 pof_attributes : attributes ;
121 }
122
123
124
125
126 type object_field_desc =
127 | Otag of Asttypes.label Asttypes.loc * core_type
128 | Oinherit of core_type
129
130
131
132
133 type pattern = {
134 ppat_desc : pattern_desc ;
135 ppat_loc : Location.t ;
136 ppat_loc_stack : Location.t list ;
137 ppat_attributes : attributes ;
138 }
139
140
141
142
143 type pattern_desc =
144 | Ppat_any
145 | Ppat_var of string Asttypes.loc
146 | Ppat_alias of pattern * string Asttypes.loc
147 | Ppat_constant of constant
148 | Ppat_interval of constant * constant
149 | Ppat_tuple of pattern list
150 | Ppat_construct of Longident.t Asttypes.loc * pattern option
151 | Ppat_variant of Asttypes.label * pattern option
152 | Ppat_record of (Longident.t Asttypes.loc * pattern) list * Ast‐
153 types.closed_flag
154 | Ppat_array of pattern list
155 | Ppat_or of pattern * pattern
156 | Ppat_constraint of pattern * core_type
157 | Ppat_type of Longident.t Asttypes.loc
158 | Ppat_lazy of pattern
159 | Ppat_unpack of string Asttypes.loc
160 | Ppat_exception of pattern
161 | Ppat_extension of extension
162 | Ppat_open of Longident.t Asttypes.loc * pattern
163
164
165
166
167 type expression = {
168 pexp_desc : expression_desc ;
169 pexp_loc : Location.t ;
170 pexp_loc_stack : Location.t list ;
171 pexp_attributes : attributes ;
172 }
173
174
175
176
177 type expression_desc =
178 | Pexp_ident of Longident.t Asttypes.loc
179 | Pexp_constant of constant
180 | Pexp_let of Asttypes.rec_flag * value_binding list * expression
181 | Pexp_function of case list
182 | Pexp_fun of Asttypes.arg_label * expression option * pattern *
183 expression
184 | Pexp_apply of expression * (Asttypes.arg_label * expression) list
185 | Pexp_match of expression * case list
186 | Pexp_try of expression * case list
187 | Pexp_tuple of expression list
188 | Pexp_construct of Longident.t Asttypes.loc * expression option
189 | Pexp_variant of Asttypes.label * expression option
190 | Pexp_record of (Longident.t Asttypes.loc * expression) list *
191 expression option
192 | Pexp_field of expression * Longident.t Asttypes.loc
193 | Pexp_setfield of expression * Longident.t Asttypes.loc * expression
194 | Pexp_array of expression list
195 | Pexp_ifthenelse of expression * expression * expression option
196 | Pexp_sequence of expression * expression
197 | Pexp_while of expression * expression
198 | Pexp_for of pattern * expression * expression * Asttypes.direc‐
199 tion_flag * expression
200 | Pexp_constraint of expression * core_type
201 | Pexp_coerce of expression * core_type option * core_type
202 | Pexp_send of expression * Asttypes.label Asttypes.loc
203 | Pexp_new of Longident.t Asttypes.loc
204 | Pexp_setinstvar of Asttypes.label Asttypes.loc * expression
205 | Pexp_override of (Asttypes.label Asttypes.loc * expression) list
206 | Pexp_letmodule of string Asttypes.loc * module_expr * expression
207 | Pexp_letexception of extension_constructor * expression
208 | Pexp_assert of expression
209 | Pexp_lazy of expression
210 | Pexp_poly of expression * core_type option
211 | Pexp_object of class_structure
212 | Pexp_newtype of string Asttypes.loc * expression
213 | Pexp_pack of module_expr
214 | Pexp_open of open_declaration * expression
215 | Pexp_letop of letop
216 | Pexp_extension of extension
217 | Pexp_unreachable
218
219
220
221
222 type case = {
223 pc_lhs : pattern ;
224 pc_guard : expression option ;
225 pc_rhs : expression ;
226 }
227
228
229
230
231 type letop = {
232 let_ : binding_op ;
233 ands : binding_op list ;
234 body : expression ;
235 }
236
237
238
239
240 type binding_op = {
241 pbop_op : string Asttypes.loc ;
242 pbop_pat : pattern ;
243 pbop_exp : expression ;
244 pbop_loc : Location.t ;
245 }
246
247
248
249
250 type value_description = {
251 pval_name : string Asttypes.loc ;
252 pval_type : core_type ;
253 pval_prim : string list ;
254 pval_attributes : attributes ;
255 pval_loc : Location.t ;
256 }
257
258
259
260
261 type type_declaration = {
262 ptype_name : string Asttypes.loc ;
263 ptype_params : (core_type * Asttypes.variance) list ;
264 ptype_cstrs : (core_type * core_type * Location.t) list ;
265 ptype_kind : type_kind ;
266 ptype_private : Asttypes.private_flag ;
267 ptype_manifest : core_type option ;
268 ptype_attributes : attributes ;
269 ptype_loc : Location.t ;
270 }
271
272
273
274
275 type type_kind =
276 | Ptype_abstract
277 | Ptype_variant of constructor_declaration list
278 | Ptype_record of label_declaration list
279 | Ptype_open
280
281
282
283
284 type label_declaration = {
285 pld_name : string Asttypes.loc ;
286 pld_mutable : Asttypes.mutable_flag ;
287 pld_type : core_type ;
288 pld_loc : Location.t ;
289 pld_attributes : attributes ;
290 }
291
292
293
294
295 type constructor_declaration = {
296 pcd_name : string Asttypes.loc ;
297 pcd_args : constructor_arguments ;
298 pcd_res : core_type option ;
299 pcd_loc : Location.t ;
300 pcd_attributes : attributes ;
301 }
302
303
304
305
306 type constructor_arguments =
307 | Pcstr_tuple of core_type list
308 | Pcstr_record of label_declaration list
309
310
311
312
313 type type_extension = {
314 ptyext_path : Longident.t Asttypes.loc ;
315 ptyext_params : (core_type * Asttypes.variance) list ;
316 ptyext_constructors : extension_constructor list ;
317 ptyext_private : Asttypes.private_flag ;
318 ptyext_loc : Location.t ;
319 ptyext_attributes : attributes ;
320 }
321
322
323
324
325 type extension_constructor = {
326 pext_name : string Asttypes.loc ;
327 pext_kind : extension_constructor_kind ;
328 pext_loc : Location.t ;
329 pext_attributes : attributes ;
330 }
331
332
333
334
335 type type_exception = {
336 ptyexn_constructor : extension_constructor ;
337 ptyexn_loc : Location.t ;
338 ptyexn_attributes : attributes ;
339 }
340
341
342
343
344 type extension_constructor_kind =
345 | Pext_decl of constructor_arguments * core_type option
346 | Pext_rebind of Longident.t Asttypes.loc
347
348
349
350
351
352
353 Class language
354 type class_type = {
355 pcty_desc : class_type_desc ;
356 pcty_loc : Location.t ;
357 pcty_attributes : attributes ;
358 }
359
360
361
362
363 type class_type_desc =
364 | Pcty_constr of Longident.t Asttypes.loc * core_type list
365 | Pcty_signature of class_signature
366 | Pcty_arrow of Asttypes.arg_label * core_type * class_type
367 | Pcty_extension of extension
368 | Pcty_open of open_description * class_type
369
370
371
372
373 type class_signature = {
374 pcsig_self : core_type ;
375 pcsig_fields : class_type_field list ;
376 }
377
378
379
380
381 type class_type_field = {
382 pctf_desc : class_type_field_desc ;
383 pctf_loc : Location.t ;
384 pctf_attributes : attributes ;
385 }
386
387
388
389
390 type class_type_field_desc =
391 | Pctf_inherit of class_type
392 | Pctf_val of (Asttypes.label Asttypes.loc * Asttypes.mutable_flag *
393 Asttypes.virtual_flag * core_type)
394 | Pctf_method of (Asttypes.label Asttypes.loc * Asttypes.private_flag
395 * Asttypes.virtual_flag * core_type)
396 | Pctf_constraint of (core_type * core_type)
397 | Pctf_attribute of attribute
398 | Pctf_extension of extension
399
400
401
402
403 type 'a class_infos = {
404 pci_virt : Asttypes.virtual_flag ;
405 pci_params : (core_type * Asttypes.variance) list ;
406 pci_name : string Asttypes.loc ;
407 pci_expr : 'a ;
408 pci_loc : Location.t ;
409 pci_attributes : attributes ;
410 }
411
412
413
414
415 type class_description = class_type class_infos
416
417
418
419
420 type class_type_declaration = class_type class_infos
421
422
423
424
425 type class_expr = {
426 pcl_desc : class_expr_desc ;
427 pcl_loc : Location.t ;
428 pcl_attributes : attributes ;
429 }
430
431
432
433
434 type class_expr_desc =
435 | Pcl_constr of Longident.t Asttypes.loc * core_type list
436 | Pcl_structure of class_structure
437 | Pcl_fun of Asttypes.arg_label * expression option * pattern *
438 class_expr
439 | Pcl_apply of class_expr * (Asttypes.arg_label * expression) list
440 | Pcl_let of Asttypes.rec_flag * value_binding list * class_expr
441 | Pcl_constraint of class_expr * class_type
442 | Pcl_extension of extension
443 | Pcl_open of open_description * class_expr
444
445
446
447
448 type class_structure = {
449 pcstr_self : pattern ;
450 pcstr_fields : class_field list ;
451 }
452
453
454
455
456 type class_field = {
457 pcf_desc : class_field_desc ;
458 pcf_loc : Location.t ;
459 pcf_attributes : attributes ;
460 }
461
462
463
464
465 type class_field_desc =
466 | Pcf_inherit of Asttypes.override_flag * class_expr * string Ast‐
467 types.loc option
468 | Pcf_val of (Asttypes.label Asttypes.loc * Asttypes.mutable_flag *
469 class_field_kind)
470 | Pcf_method of (Asttypes.label Asttypes.loc * Asttypes.private_flag *
471 class_field_kind)
472 | Pcf_constraint of (core_type * core_type)
473 | Pcf_initializer of expression
474 | Pcf_attribute of attribute
475 | Pcf_extension of extension
476
477
478
479
480 type class_field_kind =
481 | Cfk_virtual of core_type
482 | Cfk_concrete of Asttypes.override_flag * expression
483
484
485
486
487 type class_declaration = class_expr class_infos
488
489
490
491
492
493
494 Module language
495 type module_type = {
496 pmty_desc : module_type_desc ;
497 pmty_loc : Location.t ;
498 pmty_attributes : attributes ;
499 }
500
501
502
503
504 type module_type_desc =
505 | Pmty_ident of Longident.t Asttypes.loc
506 | Pmty_signature of signature
507 | Pmty_functor of string Asttypes.loc * module_type option * mod‐
508 ule_type
509 | Pmty_with of module_type * with_constraint list
510 | Pmty_typeof of module_expr
511 | Pmty_extension of extension
512 | Pmty_alias of Longident.t Asttypes.loc
513
514
515
516
517 type signature = signature_item list
518
519
520
521
522 type signature_item = {
523 psig_desc : signature_item_desc ;
524 psig_loc : Location.t ;
525 }
526
527
528
529
530 type signature_item_desc =
531 | Psig_value of value_description
532 | Psig_type of Asttypes.rec_flag * type_declaration list
533 | Psig_typesubst of type_declaration list
534 | Psig_typext of type_extension
535 | Psig_exception of type_exception
536 | Psig_module of module_declaration
537 | Psig_modsubst of module_substitution
538 | Psig_recmodule of module_declaration list
539 | Psig_modtype of module_type_declaration
540 | Psig_open of open_description
541 | Psig_include of include_description
542 | Psig_class of class_description list
543 | Psig_class_type of class_type_declaration list
544 | Psig_attribute of attribute
545 | Psig_extension of extension * attributes
546
547
548
549
550 type module_declaration = {
551 pmd_name : string Asttypes.loc ;
552 pmd_type : module_type ;
553 pmd_attributes : attributes ;
554 pmd_loc : Location.t ;
555 }
556
557
558
559
560 type module_substitution = {
561 pms_name : string Asttypes.loc ;
562 pms_manifest : Longident.t Asttypes.loc ;
563 pms_attributes : attributes ;
564 pms_loc : Location.t ;
565 }
566
567
568
569
570 type module_type_declaration = {
571 pmtd_name : string Asttypes.loc ;
572 pmtd_type : module_type option ;
573 pmtd_attributes : attributes ;
574 pmtd_loc : Location.t ;
575 }
576
577
578
579
580 type 'a open_infos = {
581 popen_expr : 'a ;
582 popen_override : Asttypes.override_flag ;
583 popen_loc : Location.t ;
584 popen_attributes : attributes ;
585 }
586
587
588
589
590 type open_description = Longident.t Asttypes.loc open_infos
591
592
593
594
595 type open_declaration = module_expr open_infos
596
597
598
599
600 type 'a include_infos = {
601 pincl_mod : 'a ;
602 pincl_loc : Location.t ;
603 pincl_attributes : attributes ;
604 }
605
606
607
608
609 type include_description = module_type include_infos
610
611
612
613
614 type include_declaration = module_expr include_infos
615
616
617
618
619 type with_constraint =
620 | Pwith_type of Longident.t Asttypes.loc * type_declaration
621 | Pwith_module of Longident.t Asttypes.loc * Longident.t Asttypes.loc
622 | Pwith_typesubst of Longident.t Asttypes.loc * type_declaration
623 | Pwith_modsubst of Longident.t Asttypes.loc * Longident.t Ast‐
624 types.loc
625
626
627
628
629 type module_expr = {
630 pmod_desc : module_expr_desc ;
631 pmod_loc : Location.t ;
632 pmod_attributes : attributes ;
633 }
634
635
636
637
638 type module_expr_desc =
639 | Pmod_ident of Longident.t Asttypes.loc
640 | Pmod_structure of structure
641 | Pmod_functor of string Asttypes.loc * module_type option * mod‐
642 ule_expr
643 | Pmod_apply of module_expr * module_expr
644 | Pmod_constraint of module_expr * module_type
645 | Pmod_unpack of expression
646 | Pmod_extension of extension
647
648
649
650
651 type structure = structure_item list
652
653
654
655
656 type structure_item = {
657 pstr_desc : structure_item_desc ;
658 pstr_loc : Location.t ;
659 }
660
661
662
663
664 type structure_item_desc =
665 | Pstr_eval of expression * attributes
666 | Pstr_value of Asttypes.rec_flag * value_binding list
667 | Pstr_primitive of value_description
668 | Pstr_type of Asttypes.rec_flag * type_declaration list
669 | Pstr_typext of type_extension
670 | Pstr_exception of type_exception
671 | Pstr_module of module_binding
672 | Pstr_recmodule of module_binding list
673 | Pstr_modtype of module_type_declaration
674 | Pstr_open of open_declaration
675 | Pstr_class of class_declaration list
676 | Pstr_class_type of class_type_declaration list
677 | Pstr_include of include_declaration
678 | Pstr_attribute of attribute
679 | Pstr_extension of extension * attributes
680
681
682
683
684 type value_binding = {
685 pvb_pat : pattern ;
686 pvb_expr : expression ;
687 pvb_attributes : attributes ;
688 pvb_loc : Location.t ;
689 }
690
691
692
693
694 type module_binding = {
695 pmb_name : string Asttypes.loc ;
696 pmb_expr : module_expr ;
697 pmb_attributes : attributes ;
698 pmb_loc : Location.t ;
699 }
700
701
702
703
704
705
706 Toplevel
707 type toplevel_phrase =
708 | Ptop_def of structure
709 | Ptop_dir of toplevel_directive
710
711
712
713
714 type toplevel_directive = {
715 pdir_name : string Asttypes.loc ;
716 pdir_arg : directive_argument option ;
717 pdir_loc : Location.t ;
718 }
719
720
721
722
723 type directive_argument = {
724 pdira_desc : directive_argument_desc ;
725 pdira_loc : Location.t ;
726 }
727
728
729
730
731 type directive_argument_desc =
732 | Pdir_string of string
733 | Pdir_int of string * char option
734 | Pdir_ident of Longident.t
735 | Pdir_bool of bool
736
737
738
739
740
741
742
743OCamldoc 2019-07-30 Parsetree(3)