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