Module Parsetree
: sigend
Abstract syntax tree produced by parsing
Warning: this module is unstable and part of Compiler_libs .
typeconstant = {
pconst_desc : constant_desc ;
pconst_loc : Location.t ;
}
typeconstant_desc =
| Pconst_integer ofstring*charoption
(* Integer constants such as 33l3L3n .
Suffixes [g-z][G-Z] are accepted by the parser. Suffixes except 'l' , 'L' and 'n' are rejected by the
typechecker
*)
| Pconst_char ofchar
(* Character such as 'c' .
*)
| Pconst_string ofstring*Location.t*stringoption
(* Constant string such as "constant" or {delim|otherconstant|delim} .
The location span the content of the string, without the delimiters.
*)
| Pconst_float ofstring*charoption
(* Float constant such as 3.4 , 2e5 or 1.4e-4 .
Suffixes g-zG-Z are accepted by the parser. Suffixes are rejected by the typechecker.
*)
typelocation_stack = Location.tlistExtensionpointstypeattribute = {
attr_name : stringAsttypes.loc ;
attr_payload : payload ;
attr_loc : Location.t ;
}
Attributes such as [@idARG] and [@@idARG] .
Metadata containers passed around within the AST. The compiler ignores unknown attributes.
typeextension = stringAsttypes.loc*payload
Extension points such as [%idARG]and[%%idARG] .
Sub-language placeholder -- rejected by the typechecker.
typeattributes = attributelisttypepayload =
| PStr ofstructure
| PSig ofsignature
(* :SIG in an attribute or an extension point
*)
| PTyp ofcore_type
(* :T in an attribute or an extension point
*)
| PPat ofpattern*expressionoption
(* ?P or ?PwhenE , in an attribute or an extension point
*)
CorelanguageTypeexpressionstypecore_type = {
ptyp_desc : core_type_desc ;
ptyp_loc : Location.t ;
ptyp_loc_stack : location_stack ;
ptyp_attributes : attributes ; (* ...[@id1][@id2]
*)
}
typecore_type_desc =
| Ptyp_any (* _
*)
| Ptyp_var ofstring
(* A type variable such as 'a
*)
| Ptyp_arrow ofAsttypes.arg_label*core_type*core_type
(* Ptyp_arrow(lbl,T1,T2) represents:
- T1->T2 when lbl is Asttypes.arg_label.Nolabel ,
- ~l:T1->T2 when lbl is Asttypes.arg_label.Labelled ,
- ?l:T1->T2 when lbl is Asttypes.arg_label.Optional .
*)
| Ptyp_tuple ofcore_typelist
(* Ptyp_tuple([T1;...;Tn]) represents a product type T1*...*Tn .
Invariant: n>=2 .
*)
| Ptyp_constr ofLongident.tAsttypes.loc*core_typelist
(* Ptyp_constr(lident,l) represents:
- tconstr when l=[] ,
- Ttconstr when l=[T] ,
- (T1,...,Tn)tconstr when l=[T1;...;Tn] .
*)
| Ptyp_object ofobject_fieldlist*Asttypes.closed_flag
(* Ptyp_object([l1:T1;...;ln:Tn],flag) represents:
- <l1:T1;...;ln:Tn> when flag is Asttypes.closed_flag.Closed ,
- <l1:T1;...;ln:Tn;..> when flag is Asttypes.closed_flag.Open .
*)
| Ptyp_class ofLongident.tAsttypes.loc*core_typelist
(* Ptyp_class(tconstr,l) represents:
- #tconstr when l=[] ,
- T#tconstr when l=[T] ,
- (T1,...,Tn)#tconstr when l=[T1;...;Tn] .
*)
| Ptyp_alias ofcore_type*stringAsttypes.loc
(* Tas'a .
*)
| Ptyp_variant ofrow_fieldlist*Asttypes.closed_flag*Asttypes.labellistoption
(* Ptyp_variant([`A;`B],flag,labels) represents:
- [`A|`B] when flag is Asttypes.closed_flag.Closed , and labels is None ,
- [>`A|`B] when flag is Asttypes.closed_flag.Open , and labels is None ,
- [<`A|`B] when flag is Asttypes.closed_flag.Closed , and labels is Some[] ,
- [<`A|`B>`X`Y] when flag is Asttypes.closed_flag.Closed , and labels is Some["X";"Y"] .
*)
| Ptyp_poly ofstringAsttypes.loclist*core_type
(* 'a1...'an.T
Can only appear in the following context:
-As the Parsetree.core_type of a Parsetree.pattern_desc.Ppat_constraint node corresponding to a
constraint on a let-binding:
letx:'a1...'an.T=e...
-Under Parsetree.class_field_kind.Cfk_virtual for methods (not values).
-As the Parsetree.core_type of a Parsetree.class_type_field_desc.Pctf_method node.
-As the Parsetree.core_type of a Parsetree.expression_desc.Pexp_poly node.
-As the Parsetree.label_declaration.pld_type field of a Parsetree.label_declaration .
-As a Parsetree.core_type of a Parsetree.core_type_desc.Ptyp_object node.
-As the Parsetree.value_description.pval_type field of a Parsetree.value_description .
*)
| Ptyp_package ofpackage_type
(* (moduleS) .
*)
| Ptyp_open ofLongident.tAsttypes.loc*core_type
(* M.(T)
*)
| Ptyp_extension ofextension
(* [%id] .
*)
typepackage_type = Longident.tAsttypes.loc*(Longident.tAsttypes.loc*core_type)list
As Parsetree.package_type typed values:
- (S,[]) represents (moduleS) ,
- (S,[(t1,T1);...;(tn,Tn)]) represents (moduleSwithtypet1=T1and...andtn=Tn) .
typerow_field = {
prf_desc : row_field_desc ;
prf_loc : Location.t ;
prf_attributes : attributes ;
}
typerow_field_desc =
| Rtag ofAsttypes.labelAsttypes.loc*bool*core_typelist
(* Rtag(`A,b,l) represents:
- `A when b is true and l is [] ,
- `AofT when b is false and l is [T] ,
- `AofT1&..&Tn when b is false and l is [T1;...Tn] ,
- `Aof&T1&..&Tn when b is true and l is [T1;...Tn] .
-The bool field is true if the tag contains a constant (empty) constructor.
- & occurs when several types are used for the same constructor (see 4.2 in the manual)
*)
| Rinherit ofcore_type
(* [|t]
*)
typeobject_field = {
pof_desc : object_field_desc ;
pof_loc : Location.t ;
pof_attributes : attributes ;
}
typeobject_field_desc =
| Otag ofAsttypes.labelAsttypes.loc*core_type
| Oinherit ofcore_typePatternstypepattern = {
ppat_desc : pattern_desc ;
ppat_loc : Location.t ;
ppat_loc_stack : location_stack ;
ppat_attributes : attributes ; (* ...[@id1][@id2]
*)
}
typepattern_desc =
| Ppat_any (* The pattern _ .
*)
| Ppat_var ofstringAsttypes.loc
(* A variable pattern such as x
*)
| Ppat_alias ofpattern*stringAsttypes.loc
(* An alias pattern such as Pas'a
*)
| Ppat_constant ofconstant
(* Patterns such as 1 , 'a' , "true" , 1.0 , 1l , 1L , 1n
*)
| Ppat_interval ofconstant*constant
(* Patterns such as 'a'..'z' .
Other forms of interval are recognized by the parser but rejected by the type-checker.
*)
| Ppat_tuple ofpatternlist
(* Patterns (P1,...,Pn) .
Invariant: n>=2
*)
| Ppat_construct ofLongident.tAsttypes.loc*(stringAsttypes.loclist*pattern)option
(* Ppat_construct(C,args) represents:
- C when args is None ,
- CP when args is Some([],P)
- C(P1,...,Pn) when args is Some([],Ppat_tuple[P1;...;Pn])
- C(typeab)P when args is Some([a;b],P)
*)
| Ppat_variant ofAsttypes.label*patternoption
(* Ppat_variant(`A,pat) represents:
- `A when pat is None ,
- `AP when pat is SomeP
*)
| Ppat_record of(Longident.tAsttypes.loc*pattern)list*Asttypes.closed_flag
(* Ppat_record([(l1,P1);...;(ln,Pn)],flag) represents:
- {l1=P1;...;ln=Pn} when flag is Asttypes.closed_flag.Closed
- {l1=P1;...;ln=Pn;_} when flag is Asttypes.closed_flag.Open
Invariant: n>0
*)
| Ppat_array ofpatternlist
(* Pattern [|P1;...;Pn|]
*)
| Ppat_or ofpattern*pattern
(* Pattern P1|P2
*)
| Ppat_constraint ofpattern*core_type
(* Pattern (P:T)
*)
| Ppat_type ofLongident.tAsttypes.loc
(* Pattern #tconst
*)
| Ppat_lazy ofpattern
(* Pattern lazyP
*)
| Ppat_unpack ofstringoptionAsttypes.loc
(* Ppat_unpack(s) represents:
- (moduleP) when s is Some"P"
- (module_) when s is None
Note: (moduleP:S) is represented as Ppat_constraint(Ppat_unpack(Some"P"),Ptyp_packageS)
*)
| Ppat_exception ofpattern
(* Pattern exceptionP
*)
| Ppat_effect ofpattern*pattern
| Ppat_extension ofextension
(* Pattern [%id]
*)
| Ppat_open ofLongident.tAsttypes.loc*pattern
(* Pattern M.(P)
*)
Valueexpressionstypeexpression = {
pexp_desc : expression_desc ;
pexp_loc : Location.t ;
pexp_loc_stack : location_stack ;
pexp_attributes : attributes ; (* ...[@id1][@id2]
*)
}
typeexpression_desc =
| Pexp_ident ofLongident.tAsttypes.loc
(* Identifiers such as x and M.x
*)
| Pexp_constant ofconstant
(* Expressions constant such as 1 , 'a' , "true" , 1.0 , 1l , 1L , 1n
*)
| Pexp_let ofAsttypes.rec_flag*value_bindinglist*expression
(* Pexp_let(flag,[(P1,E1);...;(Pn,En)],E) represents:
- letP1=E1and...andPn=ENinE when flag is Asttypes.rec_flag.Nonrecursive ,
- letrecP1=E1and...andPn=ENinE when flag is Asttypes.rec_flag.Recursive .
*)
| Pexp_function offunction_paramlist*type_constraintoption*function_body
(* Pexp_function([P1;...;Pn],C,body) represents any construct involving fun or function ,
including:
- funP1...Pn->E when body=Pfunction_bodyE
- funP1...Pn->functionp1->e1|...|pm->em when body=Pfunction_cases[p1->e1;...;pm->em]C represents a type constraint or coercion placed immediately before the arrow, e.g. funP1...Pn:ty->... when C=Some(Pconstraintty) .
A function must have parameters. Pexp_function(params,_,body) must have non-empty params or a
Pfunction_cases_ body.
*)
| Pexp_apply ofexpression*(Asttypes.arg_label*expression)list
(* Pexp_apply(E0,[(l1,E1);...;(ln,En)]) represents E0~l1:E1...~ln:Enli can be Asttypes.arg_label.Nolabel (non labeled argument), Asttypes.arg_label.Labelled (labelled
arguments) or Asttypes.arg_label.Optional (optional argument).
Invariant: n>0
*)
| Pexp_match ofexpression*caselist
(* matchE0withP1->E1|...|Pn->En
*)
| Pexp_try ofexpression*caselist
(* tryE0withP1->E1|...|Pn->En
*)
| Pexp_tuple ofexpressionlist
(* Expressions (E1,...,En)
Invariant: n>=2
*)
| Pexp_construct ofLongident.tAsttypes.loc*expressionoption
(* Pexp_construct(C,exp) represents:
- C when exp is None ,
- CE when exp is SomeE ,
- C(E1,...,En) when exp is Some(Pexp_tuple[E1;...;En])
*)
| Pexp_variant ofAsttypes.label*expressionoption
(* Pexp_variant(`A,exp) represents
- `A when exp is None
- `AE when exp is SomeE
*)
| Pexp_record of(Longident.tAsttypes.loc*expression)list*expressionoption
(* Pexp_record([(l1,P1);...;(ln,Pn)],exp0) represents
- {l1=P1;...;ln=Pn} when exp0 is None
- {E0withl1=P1;...;ln=Pn} when exp0 is SomeE0
Invariant: n>0
*)
| Pexp_field ofexpression*Longident.tAsttypes.loc
(* E.l
*)
| Pexp_setfield ofexpression*Longident.tAsttypes.loc*expression
(* E1.l<-E2
*)
| Pexp_array ofexpressionlist
(* [|E1;...;En|]
*)
| Pexp_ifthenelse ofexpression*expression*expressionoption
(* ifE1thenE2elseE3
*)
| Pexp_sequence ofexpression*expression
(* E1;E2
*)
| Pexp_while ofexpression*expression
(* whileE1doE2done
*)
| Pexp_for ofpattern*expression*expression*Asttypes.direction_flag*expression
(* Pexp_for(i,E1,E2,direction,E3) represents:
- fori=E1toE2doE3done when direction is Asttypes.direction_flag.Upto
- fori=E1downtoE2doE3done when direction is Asttypes.direction_flag.Downto
*)
| Pexp_constraint ofexpression*core_type
(* (E:T)
*)
| Pexp_coerce ofexpression*core_typeoption*core_type
(* Pexp_coerce(E,from,T) represents
- (E:>T) when from is None ,
- (E:T0:>T) when from is SomeT0 .
*)
| Pexp_send ofexpression*Asttypes.labelAsttypes.loc
(* E#m
*)
| Pexp_new ofLongident.tAsttypes.loc
(* newM.c
*)
| Pexp_setinstvar ofAsttypes.labelAsttypes.loc*expression
(* x<-2
*)
| Pexp_override of(Asttypes.labelAsttypes.loc*expression)list
(* {<x1=E1;...;xn=En>}
*)
| Pexp_letmodule ofstringoptionAsttypes.loc*module_expr*expression
(* letmoduleM=MEinE
*)
| Pexp_letexception ofextension_constructor*expression
(* letexceptionCinE
*)
| Pexp_assert ofexpression
(* assertE .
Note: assertfalse is treated in a special way by the type-checker.
*)
| Pexp_lazy ofexpression
(* lazyE
*)
| Pexp_poly ofexpression*core_typeoption
(* Used for method bodies.
Can only be used as the expression under Parsetree.class_field_kind.Cfk_concrete for methods (not
values).
*)
| Pexp_object ofclass_structure
(* object...end
*)
| Pexp_newtype ofstringAsttypes.loc*expression
(* fun(typet)->E
*)
| Pexp_pack ofmodule_expr
(* (moduleME) .
(moduleME:S) is represented as Pexp_constraint(Pexp_packME,Ptyp_packageS)
*)
| Pexp_open ofopen_declaration*expression
(* - M.(E)
- letopenMinE
- letopen!MinE
*)
| Pexp_letop ofletop
(* - let*P=E0inE1
- let*P0=E00and*P1=E01inE1
*)
| Pexp_extension ofextension
(* [%id]
*)
| Pexp_unreachable (* .
*)
typecase = {
pc_lhs : pattern ;
pc_guard : expressionoption ;
pc_rhs : expression ;
}
Values of type Parsetree.case represents (P->E) or (PwhenE0->E)typeletop = {
let_ : binding_op ;
ands : binding_oplist ;
body : expression ;
}
typebinding_op = {
pbop_op : stringAsttypes.loc ;
pbop_pat : pattern ;
pbop_exp : expression ;
pbop_loc : Location.t ;
}
typefunction_param_desc =
| Pparam_val ofAsttypes.arg_label*expressionoption*pattern
(* Pparam_val(lbl,exp0,P) represents the parameter:
- P when lbl is Asttypes.arg_label.Nolabel and exp0 is None
- ~l:P when lbl is Asttypes.arg_label.Labelled and exp0 is None
- ?l:P when lbl is Asttypes.arg_label.Optional and exp0 is None
- ?l:(P=E0) when lbl is Asttypes.arg_label.Optional and exp0 is SomeE0
Note: If E0 is provided, only Asttypes.arg_label.Optional is allowed.
*)
| Pparam_newtype ofstringAsttypes.loc
(* Pparam_newtypex represents the parameter (typex) . x carries the location of the identifier,
whereas the pparam_loc on the enclosing function_param node is the location of the (typex) as a whole.
Multiple parameters (typeabc) are represented as multiple Pparam_newtype nodes, let's say:
[{pparam_kind=Pparam_newtypea;pparam_loc=loc1};{pparam_kind=Pparam_newtypeb;pparam_loc=loc2};{pparam_kind=Pparam_newtypec;pparam_loc=loc3};]
Here, the first loc loc1 is the location of (typeabc) , and the subsequent locs loc2 and loc3 are the
same as loc1 , except marked as ghost locations. The locations on a , b , c , correspond to the variables
a , b , and c in the source code.
*)
typefunction_param = {
pparam_loc : Location.t ;
pparam_desc : function_param_desc ;
}
typefunction_body =
| Pfunction_body ofexpression
| Pfunction_cases ofcaselist*Location.t*attributes
(* In Pfunction_cases(_,loc,attrs) , the location extends from the start of the function keyword to
the end of the last case. The compiler will only use typechecking-related attributes from attrs , e.g.
enabling or disabling a warning.
*)
See the comment on Parsetree.expression_desc.Pexp_function .
typetype_constraint =
| Pconstraint ofcore_type
| Pcoerce ofcore_typeoption*core_type
(* See the comment on Parsetree.expression_desc.Pexp_function .
*)
Valuedescriptionstypevalue_description = {
pval_name : stringAsttypes.loc ;
pval_type : core_type ;
pval_prim : stringlist ;
pval_attributes : attributes ; (* ...[@@id1][@@id2]
*)
pval_loc : Location.t ;
}
Values of type Parsetree.value_description represents:
- valx:T , when Parsetree.value_description.pval_prim is []
- externalx:T="s1"..."sn" when Parsetree.value_description.pval_prim is ["s1";..."sn"]Typedeclarationstypetype_declaration = {
ptype_name : stringAsttypes.loc ;
ptype_params : (core_type*(Asttypes.variance*Asttypes.injectivity))list ; (* ('a1,...'an)t
*)
ptype_cstrs : (core_type*core_type*Location.t)list ; (* ...constraintT1=T1'...constraintTn=Tn'
*)
ptype_kind : type_kind ;
ptype_private : Asttypes.private_flag ; (* for =private...
*)
ptype_manifest : core_typeoption ; (* represents =T
*)
ptype_attributes : attributes ; (* ...[@@id1][@@id2]
*)
ptype_loc : Location.t ;
}
Here are type declarations and their representation, for various Parsetree.type_declaration.ptype_kind
and Parsetree.type_declaration.ptype_manifest values:
- typet when type_kind is Parsetree.type_kind.Ptype_abstract , and manifest is None ,
- typet=T0 when type_kind is Parsetree.type_kind.Ptype_abstract , and manifest is SomeT0 ,
- typet=CofT|... when type_kind is Parsetree.type_kind.Ptype_variant , and manifest is None ,
- typet=T0=CofT|... when type_kind is Parsetree.type_kind.Ptype_variant , and manifest is SomeT0 ,
- typet={l:T;...} when type_kind is Parsetree.type_kind.Ptype_record , and manifest is None ,
- typet=T0={l:T;...} when type_kind is Parsetree.type_kind.Ptype_record , and manifest is SomeT0
,
- typet=.. when type_kind is Parsetree.type_kind.Ptype_open , and manifest is None .
typetype_kind =
| Ptype_abstract
| Ptype_variant ofconstructor_declarationlist
| Ptype_record oflabel_declarationlist
(* Invariant: non-empty list
*)
| Ptype_open
typelabel_declaration = {
pld_name : stringAsttypes.loc ;
pld_mutable : Asttypes.mutable_flag ;
pld_type : core_type ;
pld_loc : Location.t ;
pld_attributes : attributes ; (* l:T[@id1][@id2]
*)
}
- {...;l:T;...} when Parsetree.label_declaration.pld_mutable is Asttypes.mutable_flag.Immutable ,
- {...;mutablel:T;...} when Parsetree.label_declaration.pld_mutable is
Asttypes.mutable_flag.Mutable .
Note: T can be a Parsetree.core_type_desc.Ptyp_poly .
typeconstructor_declaration = {
pcd_name : stringAsttypes.loc ;
pcd_vars : stringAsttypes.loclist ;
pcd_args : constructor_arguments ;
pcd_res : core_typeoption ;
pcd_loc : Location.t ;
pcd_attributes : attributes ; (* Cof...[@id1][@id2]
*)
}
typeconstructor_arguments =
| Pcstr_tuple ofcore_typelist
| Pcstr_record oflabel_declarationlist
(* Values of type Parsetree.constructor_declaration represents the constructor arguments of:
- CofT1*...*Tn when res=None , and args=Pcstr_tuple[T1;...;Tn] ,
- C:T0 when res=SomeT0 , and args=Pcstr_tuple[] ,
- C:T1*...*Tn->T0 when res=SomeT0 , and args=Pcstr_tuple[T1;...;Tn] ,
- Cof{...} when res=None , and args=Pcstr_record[...] ,
- C:{...}->T0 when res=SomeT0 , and args=Pcstr_record[...] .
*)
typetype_extension = {
ptyext_path : Longident.tAsttypes.loc ;
ptyext_params : (core_type*(Asttypes.variance*Asttypes.injectivity))list ;
ptyext_constructors : extension_constructorlist ;
ptyext_private : Asttypes.private_flag ;
ptyext_loc : Location.t ;
ptyext_attributes : attributes ; (* ... @@id1@@id2
*)
}
Definition of new extensions constructors for the extensive sum type t ( typet+=... ).
typeextension_constructor = {
pext_name : stringAsttypes.loc ;
pext_kind : extension_constructor_kind ;
pext_loc : Location.t ;
pext_attributes : attributes ; (* Cof...[@id1][@id2]
*)
}
typetype_exception = {
ptyexn_constructor : extension_constructor ;
ptyexn_loc : Location.t ;
ptyexn_attributes : attributes ; (* ...[@@id1][@@id2]
*)
}
Definition of a new exception ( exceptionE ).
typeextension_constructor_kind =
| Pext_decl ofstringAsttypes.loclist*constructor_arguments*core_typeoption
(* Pext_decl(existentials,c_args,t_opt) describes a new extension constructor. It can be:
- CofT1*...*Tn when:
- existentials is [] ,
- c_args is [T1;...;Tn] ,
- t_opt is None
- C:T0 when
- existentials is [] ,
- c_args is [] ,
- t_opt is SomeT0 .
- C:T1*...*Tn->T0 when
- existentials is [] ,
- c_args is [T1;...;Tn] ,
- t_opt is SomeT0 .
- C:'a....T1*...*Tn->T0 when
- existentials is ['a;...] ,
- c_args is [T1;...;Tn] ,
- t_opt is SomeT0 .
*)
| Pext_rebind ofLongident.tAsttypes.loc
(* Pext_rebind(D) re-export the constructor D with the new name C
*)
ClasslanguageTypeexpressionsfortheclasslanguagetypeclass_type = {
pcty_desc : class_type_desc ;
pcty_loc : Location.t ;
pcty_attributes : attributes ; (* ...[@id1][@id2]
*)
}
typeclass_type_desc =
| Pcty_constr ofLongident.tAsttypes.loc*core_typelist
(* - c
- ['a1,...,'an]c
*)
| Pcty_signature ofclass_signature
(* object...end
*)
| Pcty_arrow ofAsttypes.arg_label*core_type*class_type
(* Pcty_arrow(lbl,T,CT) represents:
- T->CT when lbl is Asttypes.arg_label.Nolabel ,
- ~l:T->CT when lbl is Asttypes.arg_label.Labelled ,
- ?l:T->CT when lbl is Asttypes.arg_label.Optional .
*)
| Pcty_extension ofextension
(* %id
*)
| Pcty_open ofopen_description*class_type
(* letopenMinCT
*)
typeclass_signature = {
pcsig_self : core_type ;
pcsig_fields : class_type_fieldlist ;
}
Values of type class_signature represents:
- object('selfpat)...end
- object...end when Parsetree.class_signature.pcsig_self is Parsetree.core_type_desc.Ptyp_anytypeclass_type_field = {
pctf_desc : class_type_field_desc ;
pctf_loc : Location.t ;
pctf_attributes : attributes ; (* ...[@@id1][@@id2]
*)
}
typeclass_type_field_desc =
| Pctf_inherit ofclass_type
(* inheritCT
*)
| Pctf_val of(Asttypes.labelAsttypes.loc*Asttypes.mutable_flag*Asttypes.virtual_flag*core_type)
(* valx:T
*)
| Pctf_method of(Asttypes.labelAsttypes.loc*Asttypes.private_flag*Asttypes.virtual_flag*core_type)
(* methodx:T
Note: T can be a Parsetree.core_type_desc.Ptyp_poly .
*)
| Pctf_constraint of(core_type*core_type)
(* constraintT1=T2
*)
| Pctf_attribute ofattribute
(* [@@@id]
*)
| Pctf_extension ofextension
(* [%%id]
*)
type'aclass_infos = {
pci_virt : Asttypes.virtual_flag ;
pci_params : (core_type*(Asttypes.variance*Asttypes.injectivity))list ;
pci_name : stringAsttypes.loc ;
pci_expr : 'a ;
pci_loc : Location.t ;
pci_attributes : attributes ; (* ...[@@id1][@@id2]
*)
}
Values of type class_exprclass_infos represents:
- classc=...
- class['a1,...,'an]c=...
- classvirtualc=...
They are also used for "class type" declaration.
typeclass_description = class_typeclass_infostypeclass_type_declaration = class_typeclass_infosValueexpressionsfortheclasslanguagetypeclass_expr = {
pcl_desc : class_expr_desc ;
pcl_loc : Location.t ;
pcl_attributes : attributes ; (* ...[@id1][@id2]
*)
}
typeclass_expr_desc =
| Pcl_constr ofLongident.tAsttypes.loc*core_typelist
(* c and ['a1,...,'an]c
*)
| Pcl_structure ofclass_structure
(* object...end
*)
| Pcl_fun ofAsttypes.arg_label*expressionoption*pattern*class_expr
(* Pcl_fun(lbl,exp0,P,CE) represents:
- funP->CE when lbl is Asttypes.arg_label.Nolabel and exp0 is None ,
- fun~l:P->CE when lbl is Asttypes.arg_label.Labelled and exp0 is None ,
- fun?l:P->CE when lbl is Asttypes.arg_label.Optional and exp0 is None ,
- fun?l:(P=E0)->CE when lbl is Asttypes.arg_label.Optional and exp0 is SomeE0 .
*)
| Pcl_apply ofclass_expr*(Asttypes.arg_label*expression)list
(* Pcl_apply(CE,[(l1,E1);...;(ln,En)]) represents CE~l1:E1...~ln:En . li can be empty (non
labeled argument) or start with ? (optional argument).
Invariant: n>0
*)
| Pcl_let ofAsttypes.rec_flag*value_bindinglist*class_expr
(* Pcl_let(rec,[(P1,E1);...;(Pn,En)],CE) represents:
- letP1=E1and...andPn=ENinCE when rec is Asttypes.rec_flag.Nonrecursive ,
- letrecP1=E1and...andPn=ENinCE when rec is Asttypes.rec_flag.Recursive .
*)
| Pcl_constraint ofclass_expr*class_type
(* (CE:CT)
*)
| Pcl_extension ofextension
(* [%id]
*)
| Pcl_open ofopen_description*class_expr
(* letopenMinCE
*)
typeclass_structure = {
pcstr_self : pattern ;
pcstr_fields : class_fieldlist ;
}
Values of type Parsetree.class_structure represents:
- object(selfpat)...end
- object...end when Parsetree.class_structure.pcstr_self is Parsetree.pattern_desc.Ppat_anytypeclass_field = {
pcf_desc : class_field_desc ;
pcf_loc : Location.t ;
pcf_attributes : attributes ; (* ...[@@id1][@@id2]
*)
}
typeclass_field_desc =
| Pcf_inherit ofAsttypes.override_flag*class_expr*stringAsttypes.locoption
(* Pcf_inherit(flag,CE,s) represents:
- inheritCE when flag is Asttypes.override_flag.Fresh and s is None ,
- inheritCEasx when flag is Asttypes.override_flag.Fresh and s is Somex ,
- inherit!CE when flag is Asttypes.override_flag.Override and s is None ,
- inherit!CEasx when flag is Asttypes.override_flag.Override and s is Somex
*)
| Pcf_val of(Asttypes.labelAsttypes.loc*Asttypes.mutable_flag*class_field_kind)
(* Pcf_val(x,flag,kind) represents:
- valx=E when flag is Asttypes.mutable_flag.Immutable and kind is
Parsetree.class_field_kind.Cfk_concrete
- valvirtualx:T when flag is Asttypes.mutable_flag.Immutable and kind is
Parsetree.class_field_kind.Cfk_virtual
- valmutablex=E when flag is Asttypes.mutable_flag.Mutable and kind is
Parsetree.class_field_kind.Cfk_concrete
- valmutablevirtualx:T when flag is Asttypes.mutable_flag.Mutable and kind is
Parsetree.class_field_kind.Cfk_virtual
*)
| Pcf_method of(Asttypes.labelAsttypes.loc*Asttypes.private_flag*class_field_kind)
(* - methodx=E ( E can be a Parsetree.expression_desc.Pexp_poly )
- methodvirtualx:T ( T can be a Parsetree.core_type_desc.Ptyp_poly )
*)
| Pcf_constraint of(core_type*core_type)
(* constraintT1=T2
*)
| Pcf_initializer ofexpression
(* initializerE
*)
| Pcf_attribute ofattribute
(* [@@@id]
*)
| Pcf_extension ofextension
(* [%%id]
*)
typeclass_field_kind =
| Cfk_virtual ofcore_type
| Cfk_concrete ofAsttypes.override_flag*expressiontypeclass_declaration = class_exprclass_infosModulelanguageTypeexpressionsforthemodulelanguagetypemodule_type = {
pmty_desc : module_type_desc ;
pmty_loc : Location.t ;
pmty_attributes : attributes ; (* ...[@id1][@id2]
*)
}
typemodule_type_desc =
| Pmty_ident ofLongident.tAsttypes.loc
(* Pmty_ident(S) represents S
*)
| Pmty_signature ofsignature
(* sig...end
*)
| Pmty_functor offunctor_parameter*module_type
(* functor(X:MT1)->MT2
*)
| Pmty_with ofmodule_type*with_constraintlist
(* MTwith...
*)
| Pmty_typeof ofmodule_expr
(* moduletypeofME
*)
| Pmty_extension ofextension
(* [%id]
*)
| Pmty_alias ofLongident.tAsttypes.loc
(* (moduleM)
*)
typefunctor_parameter =
| Unit (* ()
*)
| Named ofstringoptionAsttypes.loc*module_type
(* Named(name,MT) represents:
- (X:MT) when name is SomeX ,
- (_:MT) when name is None
*)
typesignature = signature_itemlisttypesignature_item = {
psig_desc : signature_item_desc ;
psig_loc : Location.t ;
}
typesignature_item_desc =
| Psig_value ofvalue_description
(* - valx:T
- externalx:T="s1"..."sn"
*)
| Psig_type ofAsttypes.rec_flag*type_declarationlist
(* typet1=...and...andtn=...
*)
| Psig_typesubst oftype_declarationlist
(* typet1:=...and...andtn:=...
*)
| Psig_typext oftype_extension
(* typet1+=...
*)
| Psig_exception oftype_exception
(* exceptionCofT
*)
| Psig_module ofmodule_declaration
(* moduleX=M and moduleX:MT
*)
| Psig_modsubst ofmodule_substitution
(* moduleX:=M
*)
| Psig_recmodule ofmodule_declarationlist
(* modulerecX1:MT1and...andXn:MTn
*)
| Psig_modtype ofmodule_type_declaration
(* moduletypeS=MT and moduletypeS
*)
| Psig_modtypesubst ofmodule_type_declaration
(* moduletypeS:=...
*)
| Psig_open ofopen_description
(* openX
*)
| Psig_include ofinclude_description
(* includeMT
*)
| Psig_class ofclass_descriptionlist
(* classc1:...and...andcn:...
*)
| Psig_class_type ofclass_type_declarationlist
(* classtypect1=...and...andctn=...
*)
| Psig_attribute ofattribute
(* [@@@id]
*)
| Psig_extension ofextension*attributes
(* [%%id]
*)
typemodule_declaration = {
pmd_name : stringoptionAsttypes.loc ;
pmd_type : module_type ;
pmd_attributes : attributes ; (* ...[@@id1][@@id2]
*)
pmd_loc : Location.t ;
}
Values of type module_declaration represents S:MTtypemodule_substitution = {
pms_name : stringAsttypes.loc ;
pms_manifest : Longident.tAsttypes.loc ;
pms_attributes : attributes ; (* ...[@@id1][@@id2]
*)
pms_loc : Location.t ;
}
Values of type module_substitution represents S:=Mtypemodule_type_declaration = {
pmtd_name : stringAsttypes.loc ;
pmtd_type : module_typeoption ;
pmtd_attributes : attributes ; (* ...[@@id1][@@id2]
*)
pmtd_loc : Location.t ;
}
Values of type module_type_declaration represents:
- S=MT ,
- S for abstract module type declaration, when Parsetree.module_type_declaration.pmtd_type is None .
type'aopen_infos = {
popen_expr : 'a ;
popen_override : Asttypes.override_flag ;
popen_loc : Location.t ;
popen_attributes : attributes ;
}
Values of type 'aopen_infos represents:
- open!X when Parsetree.open_infos.popen_override is Asttypes.override_flag.Override (silences the "used
identifier shadowing" warning)
- openX when Parsetree.open_infos.popen_override is Asttypes.override_flag.Freshtypeopen_description = Longident.tAsttypes.locopen_infos
Values of type open_description represents:
- openM.N
- openM(N).Otypeopen_declaration = module_expropen_infos
Values of type open_declaration represents:
- openM.N
- openM(N).O
- openstruct...endtype'ainclude_infos = {
pincl_mod : 'a ;
pincl_loc : Location.t ;
pincl_attributes : attributes ;
}
typeinclude_description = module_typeinclude_infos
Values of type include_description represents includeMTtypeinclude_declaration = module_exprinclude_infos
Values of type include_declaration represents includeMEtypewith_constraint =
| Pwith_type ofLongident.tAsttypes.loc*type_declaration
(* withtypeX.t=...
Note: the last component of the longident must match the name of the type_declaration.
*)
| Pwith_module ofLongident.tAsttypes.loc*Longident.tAsttypes.loc
(* withmoduleX.Y=Z
*)
| Pwith_modtype ofLongident.tAsttypes.loc*module_type
(* withmoduletypeX.Y=Z
*)
| Pwith_modtypesubst ofLongident.tAsttypes.loc*module_type
(* withmoduletypeX.Y:=sigend
*)
| Pwith_typesubst ofLongident.tAsttypes.loc*type_declaration
(* withtypeX.t:=...,sameformatas[Pwith_type]
*)
| Pwith_modsubst ofLongident.tAsttypes.loc*Longident.tAsttypes.loc
(* withmoduleX.Y:=Z
*)
Valueexpressionsforthemodulelanguagetypemodule_expr = {
pmod_desc : module_expr_desc ;
pmod_loc : Location.t ;
pmod_attributes : attributes ; (* ...[@id1][@id2]
*)
}
typemodule_expr_desc =
| Pmod_ident ofLongident.tAsttypes.loc
(* X
*)
| Pmod_structure ofstructure
(* struct...end
*)
| Pmod_functor offunctor_parameter*module_expr
(* functor(X:MT1)->ME
*)
| Pmod_apply ofmodule_expr*module_expr
(* ME1(ME2)
*)
| Pmod_apply_unit ofmodule_expr
(* ME1()
*)
| Pmod_constraint ofmodule_expr*module_type
(* (ME:MT)
*)
| Pmod_unpack ofexpression
(* (valE)
*)
| Pmod_extension ofextension
(* [%id]
*)
typestructure = structure_itemlisttypestructure_item = {
pstr_desc : structure_item_desc ;
pstr_loc : Location.t ;
}
typestructure_item_desc =
| Pstr_eval ofexpression*attributes
(* E
*)
| Pstr_value ofAsttypes.rec_flag*value_bindinglist
(* Pstr_value(rec,[(P1,E1;...;(Pn,En))]) represents:
- letP1=E1and...andPn=EN when rec is Asttypes.rec_flag.Nonrecursive ,
- letrecP1=E1and...andPn=EN when rec is Asttypes.rec_flag.Recursive .
*)
| Pstr_primitive ofvalue_description
(* - valx:T
- externalx:T="s1"..."sn"
*)
| Pstr_type ofAsttypes.rec_flag*type_declarationlist
(* typet1=...and...andtn=...
*)
| Pstr_typext oftype_extension
(* typet1+=...
*)
| Pstr_exception oftype_exception
(* - exceptionCofT
- exceptionC=M.X
*)
| Pstr_module ofmodule_binding
(* moduleX=ME
*)
| Pstr_recmodule ofmodule_bindinglist
(* modulerecX1=ME1and...andXn=MEn
*)
| Pstr_modtype ofmodule_type_declaration
(* moduletypeS=MT
*)
| Pstr_open ofopen_declaration
(* openX
*)
| Pstr_class ofclass_declarationlist
(* classc1=...and...andcn=...
*)
| Pstr_class_type ofclass_type_declarationlist
(* classtypect1=...and...andctn=...
*)
| Pstr_include ofinclude_declaration
(* includeME
*)
| Pstr_attribute ofattribute
(* [@@@id]
*)
| Pstr_extension ofextension*attributes
(* [%%id]
*)
typevalue_constraint =
| Pvc_constraint of{
locally_abstract_univars : stringAsttypes.loclist ;
typ : core_type ;
}
| Pvc_coercion of{
ground : core_typeoption ;
coercion : core_type ;
}
(* - Pvc_constraint{locally_abstract_univars=[];typ} is a simple type constraint on a value binding:
letx:typ
-More generally, in Pvc_constraint{locally_abstract_univars;typ}locally_abstract_univars is the list of locally abstract type variables in letx:typea....typ
- Pvc_coercion{ground=None;coercion} represents letx:>typ
- Pvc_coercion{ground=Someg;coercion} represents letx:g:>typ
*)
typevalue_binding = {
pvb_pat : pattern ;
pvb_expr : expression ;
pvb_constraint : value_constraintoption ;
pvb_attributes : attributes ;
pvb_loc : Location.t ;
}
letpat:type_constraint=exptypemodule_binding = {
pmb_name : stringoptionAsttypes.loc ;
pmb_expr : module_expr ;
pmb_attributes : attributes ;
pmb_loc : Location.t ;
}
Values of type module_binding represents moduleX=METoplevelToplevelphrasestypetoplevel_phrase =
| Ptop_def ofstructure
| Ptop_dir oftoplevel_directive
(* #use , #load ...
*)
typetoplevel_directive = {
pdir_name : stringAsttypes.loc ;
pdir_arg : directive_argumentoption ;
pdir_loc : Location.t ;
}
typedirective_argument = {
pdira_desc : directive_argument_desc ;
pdira_loc : Location.t ;
}
typedirective_argument_desc =
| Pdir_string ofstring
| Pdir_int ofstring*charoption
| Pdir_ident ofLongident.t
| Pdir_bool ofbool
OCamldoc 2025-06-12 Parsetree(3o)