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