1Parsetree(3)                       OCamldoc                       Parsetree(3)
2
3
4

NAME

6       Parsetree - Abstract syntax tree produced by parsing
7

Module

9       Module   Parsetree
10

Documentation

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