-
bigarray
-
dynlink
-
ocamlbytecomp
-
ocamlcommon
-
ocamlmiddleend
-
ocamloptcomp
-
odoc_info
-
stdlib
-
str
-
unix
Library
Module
Module type
Parameter
Class
Class type
Abstract syntax tree produced by parsing
Warning: this module is unstable and part of compiler-libs.
type constant =
| Pconst_integer of string * char option
(*Integer constants such as
3
3l
3L
3n
.Suffixes
*)[g-z][G-Z]
are accepted by the parser. Suffixes except'l'
,'L'
and'n'
are rejected by the typechecker| Pconst_char of char
(*Character such as
*)'c'
.| Pconst_string of string * Location.t * string option
(*Constant string such as
"constant"
or{delim|other constant|delim}
.The location span the content of the string, without the delimiters.
*)| Pconst_float of string * char option
(*Float constant such as
3.4
,2e5
or1.4e-4
.Suffixes
*)g-z
G-Z
are accepted by the parser. Suffixes are rejected by the typechecker.
type location_stack = Location.t list
Extension points
Attributes such as [\@id ARG]
and [\@\@id ARG]
.
Metadata containers passed around within the AST. The compiler ignores unknown attributes.
and extension = string Asttypes.loc * payload
Extension points such as [%id ARG] and [%%id ARG]
.
Sub-language placeholder -- rejected by the typechecker.
and attributes = attribute list
and payload =
| PStr of structure
| PSig of signature
(*
*): SIG
in an attribute or an extension point| PTyp of core_type
(*
*): T
in an attribute or an extension point| PPat of pattern * expression option
(*
*)? P
or? P when E
, in an attribute or an extension point
Core language
Type expressions
and core_type = {
ptyp_desc : core_type_desc;
ptyp_loc : Location.t;
ptyp_loc_stack : location_stack;
ptyp_attributes : attributes;
(*
*)... [\@id1] [\@id2]
}
and core_type_desc =
| Ptyp_any
(*
*)_
| Ptyp_var of string
(*A type variable such as
*)'a
| Ptyp_arrow of Asttypes.arg_label * core_type * core_type
| Ptyp_tuple of core_type list
(*Ptyp_tuple([T1 ; ... ; Tn])
represents a product typeT1 * ... * Tn
.Invariant:
*)n >= 2
.| Ptyp_constr of Longident.t Asttypes.loc * core_type list
(*Ptyp_constr(lident, l)
represents:tconstr
whenl=[]
,T tconstr
whenl=[T]
,(T1, ..., Tn) tconstr
whenl=[T1 ; ... ; Tn]
.
| Ptyp_object of object_field list * Asttypes.closed_flag
| Ptyp_class of Longident.t Asttypes.loc * core_type list
(*Ptyp_class(tconstr, l)
represents:#tconstr
whenl=[]
,T #tconstr
whenl=[T]
,(T1, ..., Tn) #tconstr
whenl=[T1 ; ... ; Tn]
.
| Ptyp_alias of core_type * string
(*
*)T as 'a
.| Ptyp_variant of row_field list * Asttypes.closed_flag * Asttypes.label list option
| Ptyp_poly of string Asttypes.loc list * core_type
(*'a1 ... 'an. T
Can only appear in the following context:
As the
core_type
of aPpat_constraint
node corresponding to a constraint on a let-binding:let x : 'a1 ... 'an. T = e ...
- Under
Cfk_virtual
for methods (not values).
- As the
core_type
of aPctf_method
node.
- As the
pld_type
field of alabel_declaration
.
- As a
core_type
of aPtyp_object
node.
- As the
pval_type
field of avalue_description
.
| Ptyp_package of package_type
(*
*)(module S)
.| Ptyp_extension of extension
(*
*)[%id]
.
and package_type =
Longident.t Asttypes.loc * (Longident.t Asttypes.loc * core_type) list
As package_type
typed values:
(S, [])
represents(module S)
,(S, [(t1, T1) ; ... ; (tn, Tn)])
represents(module S with type t1 = T1 and ... and tn = Tn)
.
and row_field_desc =
| Rtag of Asttypes.label Asttypes.loc * bool * core_type list
(*Rtag(`A, b, l)
represents:`A
whenb
istrue
andl
is[]
,`A of T
whenb
isfalse
andl
is[T]
,`A of T1 & .. & Tn
whenb
isfalse
andl
is[T1;...Tn]
,`A of & T1 & .. & Tn
whenb
istrue
andl
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 of core_type
(*
*)[ | t ]
Patterns
and pattern = {
ppat_desc : pattern_desc;
ppat_loc : Location.t;
ppat_loc_stack : location_stack;
ppat_attributes : attributes;
(*
*)... [\@id1] [\@id2]
}
and pattern_desc =
| Ppat_any
(*The pattern
*)_
.| Ppat_var of string Asttypes.loc
(*A variable pattern such as
*)x
| Ppat_alias of pattern * string Asttypes.loc
(*An alias pattern such as
*)P as 'a
| Ppat_constant of constant
(*Patterns such as
*)1
,'a'
,"true"
,1.0
,1l
,1L
,1n
| Ppat_interval of constant * constant
(*Patterns such as
'a'..'z'
.Other forms of interval are recognized by the parser but rejected by the type-checker.
*)| Ppat_tuple of pattern list
(*Patterns
(P1, ..., Pn)
.Invariant:
*)n >= 2
| Ppat_construct of Longident.t Asttypes.loc * (string Asttypes.loc list * pattern) option
(*Ppat_construct(C, args)
represents:C
whenargs
isNone
,C P
whenargs
isSome ([], P)
C (P1, ..., Pn)
whenargs
isSome ([], Ppat_tuple [P1; ...; Pn])
C (type a b) P
whenargs
isSome ([a; b], P)
| Ppat_variant of Asttypes.label * pattern option
(*Ppat_variant(`A, pat)
represents:`A
whenpat
isNone
,`A P
whenpat
isSome P
| Ppat_record of (Longident.t Asttypes.loc * pattern) list * Asttypes.closed_flag
| Ppat_array of pattern list
(*Pattern
[| P1; ...; Pn |]