package ppxlib
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=89a98c95ddd0bfbac17b5a936f6811af7097be3258c482d5859b73e9de9b4552
sha512=b19306473d867252d382e58e9b697531c5edccdc9283b5eaf72f524803c2fca2a58a5e8f25bee198b00de82cf8ef805b43f7488791c3ac5beb0ffba938ded826
doc/ppxlib/Ppxlib/Ast_builder/Make/index.html
Module Ast_builder.Make
Source
Build Ast helpers with the location argument factorized.
Parameters
Signature
Value description
val value_description :
name:string Astlib.Location.loc ->
type_:Astlib.Ast_502.Parsetree.core_type ->
prim:string list ->
Astlib.Ast_502.Parsetree.value_description
value_description
constructs an Ast.value_description
Example OCaml
Values of type value_description
represents:
Value binding
Type extension
val type_extension :
path:Astlib.Longident.t Astlib.Location.loc ->
params:
(Astlib.Ast_502.Parsetree.core_type
* (Astlib.Ast_502.Asttypes.variance * Astlib.Ast_502.Asttypes.injectivity))
list ->
constructors:Astlib.Ast_502.Parsetree.extension_constructor list ->
private_:Astlib.Ast_502.Asttypes.private_flag ->
Astlib.Ast_502.Parsetree.type_extension
type_extension
constructs an Ast.type_extension
Example OCaml
Definition of new extensions constructors for the extensive sum type t
(type t += ...
).
Type exception
val type_exception :
Astlib.Ast_502.Parsetree.extension_constructor ->
Astlib.Ast_502.Parsetree.type_exception
type_exception
constructs an Ast.type_exception
Example OCaml
Definition of a new exception (exception E
).
Type declaration
val type_declaration :
name:string Astlib.Location.loc ->
params:
(Astlib.Ast_502.Parsetree.core_type
* (Astlib.Ast_502.Asttypes.variance * Astlib.Ast_502.Asttypes.injectivity))
list ->
cstrs:
(Astlib.Ast_502.Parsetree.core_type
* Astlib.Ast_502.Parsetree.core_type
* Astlib.Location.t)
list ->
kind:Astlib.Ast_502.Parsetree.type_kind ->
private_:Astlib.Ast_502.Asttypes.private_flag ->
manifest:Astlib.Ast_502.Parsetree.core_type option ->
Astlib.Ast_502.Parsetree.type_declaration
type_declaration
constructs an Ast.type_declaration
Example OCaml
Here are type declarations and their representation, for various ptype_kind
and ptype_manifest
values:
type t
whentype_kind
isPtype_abstract
, andmanifest
isNone
,type t = T0
whentype_kind
isPtype_abstract
, andmanifest
isSome T0
,type t = C of T | ...
whentype_kind
isPtype_variant
, andmanifest
isNone
,type t = T0 = C of T | ...
whentype_kind
isPtype_variant
, andmanifest
isSome T0
,type t = {l: T; ...}
whentype_kind
isPtype_record
, andmanifest
isNone
,type t = T0 = {l : T; ...}
whentype_kind
isPtype_record
, andmanifest
isSome T0
,type t = ..
whentype_kind
isPtype_open
, andmanifest
isNone
.
Toplevel directive
val toplevel_directive :
name:string Astlib.Location.loc ->
arg:Astlib.Ast_502.Parsetree.directive_argument option ->
Astlib.Ast_502.Parsetree.toplevel_directive
toplevel_directive
constructs an Ast.toplevel_directive
Structure item
val pstr_extension :
(string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) ->
Astlib.Ast_502.Parsetree.attribute list ->
Astlib.Ast_502.Parsetree.structure_item
val pstr_attribute :
Astlib.Ast_502.Parsetree.attribute ->
Astlib.Ast_502.Parsetree.structure_item
val pstr_class_type :
Astlib.Ast_502.Parsetree.class_type Astlib.Ast_502.Parsetree.class_infos list ->
Astlib.Ast_502.Parsetree.structure_item
pstr_class_type
constructs an Ast.structure_item_desc.Pstr_class_type
Example OCaml
class type ct1 = ... and ... and ctn = ...
val pstr_class :
Astlib.Ast_502.Parsetree.class_expr Astlib.Ast_502.Parsetree.class_infos list ->
Astlib.Ast_502.Parsetree.structure_item
pstr_class
constructs an Ast.structure_item_desc.Pstr_class
Example OCaml
class c1 = ... and ... and cn = ...
val pstr_recmodule :
Astlib.Ast_502.Parsetree.module_binding list ->
Astlib.Ast_502.Parsetree.structure_item
pstr_recmodule
constructs an Ast.structure_item_desc.Pstr_recmodule
Example OCaml
module rec X1 = ME1 and ... and Xn = MEn
val pstr_module :
Astlib.Ast_502.Parsetree.module_binding ->
Astlib.Ast_502.Parsetree.structure_item
val pstr_exception :
Astlib.Ast_502.Parsetree.type_exception ->
Astlib.Ast_502.Parsetree.structure_item
pstr_exception
constructs an Ast.structure_item_desc.Pstr_exception
Example OCaml
exception C of T
exception C = M.X
val pstr_typext :
Astlib.Ast_502.Parsetree.type_extension ->
Astlib.Ast_502.Parsetree.structure_item
val pstr_type :
Astlib.Ast_502.Asttypes.rec_flag ->
Astlib.Ast_502.Parsetree.type_declaration list ->
Astlib.Ast_502.Parsetree.structure_item
pstr_type
constructs an Ast.structure_item_desc.Pstr_type
Example OCaml
type t1 = ... and ... and tn = ...
val pstr_primitive :
Astlib.Ast_502.Parsetree.value_description ->
Astlib.Ast_502.Parsetree.structure_item
pstr_primitive
constructs an Ast.structure_item_desc.Pstr_primitive
Example OCaml
val x: T
external x: T = "s1" ... "sn"
val pstr_value :
Astlib.Ast_502.Asttypes.rec_flag ->
Astlib.Ast_502.Parsetree.value_binding list ->
Astlib.Ast_502.Parsetree.structure_item
pstr_value
constructs an Ast.structure_item_desc.Pstr_value
Example OCaml
Pstr_value(rec, [(P1, E1 ; ... ; (Pn, En))])
represents:
let P1 = E1 and ... and Pn = EN
whenrec
isNonrecursive
,let rec P1 = E1 and ... and Pn = EN
whenrec
isRecursive
.
val pstr_eval :
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.attribute list ->
Astlib.Ast_502.Parsetree.structure_item
Signature item
val psig_extension :
(string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) ->
Astlib.Ast_502.Parsetree.attribute list ->
Astlib.Ast_502.Parsetree.signature_item
val psig_attribute :
Astlib.Ast_502.Parsetree.attribute ->
Astlib.Ast_502.Parsetree.signature_item
val psig_class_type :
Astlib.Ast_502.Parsetree.class_type Astlib.Ast_502.Parsetree.class_infos list ->
Astlib.Ast_502.Parsetree.signature_item
psig_class_type
constructs an Ast.signature_item_desc.Psig_class_type
Example OCaml
class type ct1 = ... and ... and ctn = ...
val psig_class :
Astlib.Ast_502.Parsetree.class_type Astlib.Ast_502.Parsetree.class_infos list ->
Astlib.Ast_502.Parsetree.signature_item
psig_class
constructs an Ast.signature_item_desc.Psig_class
Example OCaml
class c1 : ... and ... and cn : ...
val psig_modtypesubst :
Astlib.Ast_502.Parsetree.module_type_declaration ->
Astlib.Ast_502.Parsetree.signature_item
psig_modtypesubst
constructs an Ast.signature_item_desc.Psig_modtypesubst
Example OCaml
module type S := ...
val psig_modtype :
Astlib.Ast_502.Parsetree.module_type_declaration ->
Astlib.Ast_502.Parsetree.signature_item
psig_modtype
constructs an Ast.signature_item_desc.Psig_modtype
Example OCaml
module type S = MT
and module type S
val psig_recmodule :
Astlib.Ast_502.Parsetree.module_declaration list ->
Astlib.Ast_502.Parsetree.signature_item
psig_recmodule
constructs an Ast.signature_item_desc.Psig_recmodule
Example OCaml
module rec X1 : MT1 and ... and Xn : MTn
val psig_modsubst :
Astlib.Ast_502.Parsetree.module_substitution ->
Astlib.Ast_502.Parsetree.signature_item
val psig_module :
Astlib.Ast_502.Parsetree.module_declaration ->
Astlib.Ast_502.Parsetree.signature_item
psig_module
constructs an Ast.signature_item_desc.Psig_module
Example OCaml
module X = M
and module X : MT
val psig_exception :
Astlib.Ast_502.Parsetree.type_exception ->
Astlib.Ast_502.Parsetree.signature_item
val psig_typext :
Astlib.Ast_502.Parsetree.type_extension ->
Astlib.Ast_502.Parsetree.signature_item
val psig_typesubst :
Astlib.Ast_502.Parsetree.type_declaration list ->
Astlib.Ast_502.Parsetree.signature_item
psig_typesubst
constructs an Ast.signature_item_desc.Psig_typesubst
Example OCaml
type t1 := ... and ... and tn := ...
val psig_type :
Astlib.Ast_502.Asttypes.rec_flag ->
Astlib.Ast_502.Parsetree.type_declaration list ->
Astlib.Ast_502.Parsetree.signature_item
psig_type
constructs an Ast.signature_item_desc.Psig_type
Example OCaml
type t1 = ... and ... and tn = ...
val psig_value :
Astlib.Ast_502.Parsetree.value_description ->
Astlib.Ast_502.Parsetree.signature_item
psig_value
constructs an Ast.signature_item_desc.Psig_value
Example OCaml
val x: T
external x: T = "s1" ... "sn"
Row field
val rtag :
string Astlib.Location.loc ->
bool ->
Astlib.Ast_502.Parsetree.core_type list ->
Astlib.Ast_502.Parsetree.row_field
rtag
constructs an Ast.row_field_desc.Rtag
Example OCaml
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)
Position
position
constructs an Ast.position
Pattern
val ppat_extension :
(string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) ->
Astlib.Ast_502.Parsetree.pattern
ppat_unpack
constructs an Ast.pattern_desc.Ppat_unpack
Example OCaml
Ppat_unpack(s)
represents:
(module P)
whens
isSome "P"
(module _)
whens
isNone
Note: (module P : S)
is represented as Ppat_constraint(Ppat_unpack(Some "P"), Ptyp_package S)
val ppat_constraint :
Astlib.Ast_502.Parsetree.pattern ->
Astlib.Ast_502.Parsetree.core_type ->
Astlib.Ast_502.Parsetree.pattern
val ppat_record :
(Astlib.Longident.t Astlib.Location.loc * Astlib.Ast_502.Parsetree.pattern)
list ->
Astlib.Ast_502.Asttypes.closed_flag ->
Astlib.Ast_502.Parsetree.pattern
ppat_record
constructs an Ast.pattern_desc.Ppat_record
Example OCaml
Ppat_record([(l1, P1) ; ... ; (ln, Pn)], flag)
represents:
Invariant: n > 0
val ppat_variant :
string ->
Astlib.Ast_502.Parsetree.pattern option ->
Astlib.Ast_502.Parsetree.pattern
ppat_variant
constructs an Ast.pattern_desc.Ppat_variant
Example OCaml
Ppat_variant(`A, pat)
represents:
`A
whenpat
isNone
,`A P
whenpat
isSome P
ppat_tuple
constructs an Ast.pattern_desc.Ppat_tuple
Example OCaml
Patterns (P1, ..., Pn)
.
Invariant: n >= 2
val ppat_interval :
Astlib.Ast_502.Parsetree.constant ->
Astlib.Ast_502.Parsetree.constant ->
Astlib.Ast_502.Parsetree.pattern
ppat_interval
constructs an Ast.pattern_desc.Ppat_interval
Example OCaml
Patterns such as 'a'..'z'
.
Other forms of interval are recognized by the parser but rejected by the type-checker.
ppat_constant
constructs an Ast.pattern_desc.Ppat_constant
Example OCaml
Patterns such as 1
, 'a'
, "true"
, 1.0
, 1l
, 1L
, 1n
val ppat_alias :
Astlib.Ast_502.Parsetree.pattern ->
string Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.pattern
Object field
oinherit
constructs an Ast.object_field_desc.Oinherit
val otag :
string Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.core_type ->
Astlib.Ast_502.Parsetree.object_field
otag
constructs an Ast.object_field_desc.Otag
Module type declaration
val module_type_declaration :
name:string Astlib.Location.loc ->
type_:Astlib.Ast_502.Parsetree.module_type option ->
Astlib.Ast_502.Parsetree.module_type_declaration
module_type_declaration
constructs an Ast.module_type_declaration
Example OCaml
Values of type module_type_declaration
represents:
S = MT
,S
for abstract module type declaration, whenpmtd_type
isNone
.
Module type
val pmty_alias :
Astlib.Longident.t Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.module_type
val pmty_extension :
(string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) ->
Astlib.Ast_502.Parsetree.module_type
val pmty_typeof :
Astlib.Ast_502.Parsetree.module_expr ->
Astlib.Ast_502.Parsetree.module_type
val pmty_signature :
Astlib.Ast_502.Parsetree.signature_item list ->
Astlib.Ast_502.Parsetree.module_type
val pmty_ident :
Astlib.Longident.t Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.module_type
Module substitution
val module_substitution :
name:string Astlib.Location.loc ->
manifest:Astlib.Longident.t Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.module_substitution
module_substitution
constructs an Ast.module_substitution
Example OCaml
Values of type module_substitution
represents S := M
Module expr
val pmod_extension :
(string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) ->
Astlib.Ast_502.Parsetree.module_expr
val pmod_constraint :
Astlib.Ast_502.Parsetree.module_expr ->
Astlib.Ast_502.Parsetree.module_type ->
Astlib.Ast_502.Parsetree.module_expr
val pmod_apply_unit :
Astlib.Ast_502.Parsetree.module_expr ->
Astlib.Ast_502.Parsetree.module_expr
val pmod_structure :
Astlib.Ast_502.Parsetree.structure_item list ->
Astlib.Ast_502.Parsetree.module_expr
val pmod_ident :
Astlib.Longident.t Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.module_expr
Module declaration
val module_declaration :
name:string option Astlib.Location.loc ->
type_:Astlib.Ast_502.Parsetree.module_type ->
Astlib.Ast_502.Parsetree.module_declaration
module_declaration
constructs an Ast.module_declaration
Example OCaml
Values of type module_declaration
represents S : MT
Module binding
val module_binding :
name:string option Astlib.Location.loc ->
expr:Astlib.Ast_502.Parsetree.module_expr ->
Astlib.Ast_502.Parsetree.module_binding
module_binding
constructs an Ast.module_binding
Example OCaml
Values of type module_binding
represents module X = ME
Location
val location :
start:Lexing.position ->
end_:Lexing.position ->
ghost:bool ->
Astlib.Location.t
location
constructs an Ast.location
Letop
val letop :
let_:Astlib.Ast_502.Parsetree.binding_op ->
ands:Astlib.Ast_502.Parsetree.binding_op list ->
body:Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.letop
letop
constructs an Ast.letop
Label declaration
val label_declaration :
name:string Astlib.Location.loc ->
mutable_:Astlib.Ast_502.Asttypes.mutable_flag ->
type_:Astlib.Ast_502.Parsetree.core_type ->
Astlib.Ast_502.Parsetree.label_declaration
label_declaration
constructs an Ast.label_declaration
Example OCaml
{ ...; l: T; ... }
whenpld_mutable
isImmutable
,{ ...; mutable l: T; ... }
whenpld_mutable
isMutable
.
Note: T
can be a Ptyp_poly
.
Function param
pparam_newtype
constructs an Ast.function_param_desc.Pparam_newtype
Example OCaml
Pparam_newtype x
represents the parameter (type x)
. x
carries the location of the identifier, whereas the pparam_loc
on the enclosing function_param
node is the location of the (type x)
as a whole.
Multiple parameters (type a b c)
are represented as multiple Pparam_newtype
nodes, let's say:
[
{ pparam_kind = Pparam_newtype a; pparam_loc = loc1 };
{ pparam_kind = Pparam_newtype b; pparam_loc = loc2 };
{ pparam_kind = Pparam_newtype c; pparam_loc = loc3 };
]
Here, the first loc loc1
is the location of (type a b c)
, 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.
val pparam_val :
Astlib.Ast_502.Asttypes.arg_label ->
Astlib.Ast_502.Parsetree.expression option ->
Astlib.Ast_502.Parsetree.pattern ->
Astlib.Ast_502.Parsetree.function_param
pparam_val
constructs an Ast.function_param_desc.Pparam_val
Example OCaml
Pparam_val (lbl, exp0, P)
represents the parameter:
P
whenlbl
isNolabel
andexp0
isNone
~l:P
whenlbl
isLabelled l
andexp0
isNone
?l:P
whenlbl
isOptional l
andexp0
isNone
?l:(P = E0)
whenlbl
isOptional l
andexp0
isSome E0
Note: If E0
is provided, only Optional
is allowed.
Extension constructor
val extension_constructor :
name:string Astlib.Location.loc ->
kind:Astlib.Ast_502.Parsetree.extension_constructor_kind ->
Astlib.Ast_502.Parsetree.extension_constructor
extension_constructor
constructs an Ast.extension_constructor
Expression
val pexp_extension :
(string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) ->
Astlib.Ast_502.Parsetree.expression
pexp_letop
constructs an Ast.expression_desc.Pexp_letop
Example OCaml
let* P = E0 in E1
let* P0 = E00 and* P1 = E01 in E1
val pexp_open :
Astlib.Ast_502.Parsetree.module_expr Astlib.Ast_502.Parsetree.open_infos ->
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression
pexp_open
constructs an Ast.expression_desc.Pexp_open
Example OCaml
M.(E)
let open M in E
let open! M in E
pexp_pack
constructs an Ast.expression_desc.Pexp_pack
Example OCaml
(module ME)
.
(module ME : S)
is represented as Pexp_constraint(Pexp_pack ME, Ptyp_package S)
val pexp_newtype :
string Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression
val pexp_object :
Astlib.Ast_502.Parsetree.class_structure ->
Astlib.Ast_502.Parsetree.expression
val pexp_poly :
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.core_type option ->
Astlib.Ast_502.Parsetree.expression
pexp_poly
constructs an Ast.expression_desc.Pexp_poly
Example OCaml
Used for method bodies.
Can only be used as the expression under Cfk_concrete
for methods (not values).
pexp_assert
constructs an Ast.expression_desc.Pexp_assert
Example OCaml
assert E
.
Note: assert false
is treated in a special way by the type-checker.
val pexp_letexception :
Astlib.Ast_502.Parsetree.extension_constructor ->
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression
pexp_letexception
constructs an Ast.expression_desc.Pexp_letexception
Example OCaml
let exception C in E
val pexp_letmodule :
string option Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.module_expr ->
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression
val pexp_override :
(string Astlib.Location.loc * Astlib.Ast_502.Parsetree.expression) list ->
Astlib.Ast_502.Parsetree.expression
pexp_override
constructs an Ast.expression_desc.Pexp_override
Example OCaml
{< x1 = E1; ...; xn = En >}
val pexp_setinstvar :
string Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression
val pexp_send :
Astlib.Ast_502.Parsetree.expression ->
string Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.expression
val pexp_coerce :
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.core_type option ->
Astlib.Ast_502.Parsetree.core_type ->
Astlib.Ast_502.Parsetree.expression
pexp_coerce
constructs an Ast.expression_desc.Pexp_coerce
Example OCaml
Pexp_coerce(E, from, T)
represents
(E :> T)
whenfrom
isNone
,(E : T0 :> T)
whenfrom
isSome T0
.
val pexp_constraint :
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.core_type ->
Astlib.Ast_502.Parsetree.expression
val pexp_for :
Astlib.Ast_502.Parsetree.pattern ->
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Asttypes.direction_flag ->
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression
pexp_for
constructs an Ast.expression_desc.Pexp_for
Example OCaml
Pexp_for(i, E1, E2, direction, E3)
represents:
val pexp_sequence :
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression
val pexp_ifthenelse :
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression option ->
Astlib.Ast_502.Parsetree.expression
val pexp_array :
Astlib.Ast_502.Parsetree.expression list ->
Astlib.Ast_502.Parsetree.expression
val pexp_record :
(Astlib.Longident.t Astlib.Location.loc * Astlib.Ast_502.Parsetree.expression)
list ->
Astlib.Ast_502.Parsetree.expression option ->
Astlib.Ast_502.Parsetree.expression
pexp_record
constructs an Ast.expression_desc.Pexp_record
Example OCaml
Pexp_record([(l1,P1) ; ... ; (ln,Pn)], exp0)
represents
{ l1=P1; ...; ln=Pn }
whenexp0
isNone
{ E0 with l1=P1; ...; ln=Pn }
whenexp0
isSome E0
Invariant: n > 0
val pexp_variant :
string ->
Astlib.Ast_502.Parsetree.expression option ->
Astlib.Ast_502.Parsetree.expression
pexp_variant
constructs an Ast.expression_desc.Pexp_variant
Example OCaml
Pexp_variant(`A, exp)
represents
`A
whenexp
isNone
`A E
whenexp
isSome E
val pexp_construct :
Astlib.Longident.t Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.expression option ->
Astlib.Ast_502.Parsetree.expression
pexp_construct
constructs an Ast.expression_desc.Pexp_construct
Example OCaml
Pexp_construct(C, exp)
represents:
C
whenexp
isNone
,C E
whenexp
isSome E
,C (E1, ..., En)
whenexp
isSome (Pexp_tuple[E1;...;En])
val pexp_tuple :
Astlib.Ast_502.Parsetree.expression list ->
Astlib.Ast_502.Parsetree.expression
pexp_tuple
constructs an Ast.expression_desc.Pexp_tuple
Example OCaml
Expressions (E1, ..., En)
Invariant: n >= 2
val pexp_try :
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.case list ->
Astlib.Ast_502.Parsetree.expression
pexp_try
constructs an Ast.expression_desc.Pexp_try
Example OCaml
try E0 with P1 -> E1 | ... | Pn -> En
val pexp_match :
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.case list ->
Astlib.Ast_502.Parsetree.expression
pexp_match
constructs an Ast.expression_desc.Pexp_match
Example OCaml
match E0 with P1 -> E1 | ... | Pn -> En
val pexp_apply :
Astlib.Ast_502.Parsetree.expression ->
(Astlib.Ast_502.Asttypes.arg_label * Astlib.Ast_502.Parsetree.expression)
list ->
Astlib.Ast_502.Parsetree.expression
pexp_apply
constructs an Ast.expression_desc.Pexp_apply
Example OCaml
Pexp_apply(E0, [(l1, E1) ; ... ; (ln, En)])
represents E0 ~l1:E1 ... ~ln:En
li
can be Nolabel
(non labeled argument), Labelled
(labelled arguments) or Optional
(optional argument).
Invariant: n > 0
val pexp_let :
Astlib.Ast_502.Asttypes.rec_flag ->
Astlib.Ast_502.Parsetree.value_binding list ->
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression
pexp_let
constructs an Ast.expression_desc.Pexp_let
Example OCaml
Pexp_let(flag, [(P1,E1) ; ... ; (Pn,En)], E)
represents:
let P1 = E1 and ... and Pn = EN in E
whenflag
isNonrecursive
,let rec P1 = E1 and ... and Pn = EN in E
whenflag
isRecursive
.
pexp_constant
constructs an Ast.expression_desc.Pexp_constant
Example OCaml
Expressions constant such as 1
, 'a'
, "true"
, 1.0
, 1l
, 1L
, 1n
val pexp_ident :
Astlib.Longident.t Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.expression
Directive argument
pdir_bool
constructs an Ast.directive_argument_desc.Pdir_bool
pdir_ident
constructs an Ast.directive_argument_desc.Pdir_ident
pdir_int
constructs an Ast.directive_argument_desc.Pdir_int
pdir_string
constructs an Ast.directive_argument_desc.Pdir_string
Core type
val ptyp_extension :
(string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) ->
Astlib.Ast_502.Parsetree.core_type
val ptyp_package :
(Astlib.Longident.t Astlib.Location.loc
* (Astlib.Longident.t Astlib.Location.loc
* Astlib.Ast_502.Parsetree.core_type)
list) ->
Astlib.Ast_502.Parsetree.core_type
val ptyp_poly :
string Astlib.Location.loc list ->
Astlib.Ast_502.Parsetree.core_type ->
Astlib.Ast_502.Parsetree.core_type
ptyp_poly
constructs an Ast.core_type_desc.Ptyp_poly
Example OCaml
'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
.
val ptyp_variant :
Astlib.Ast_502.Parsetree.row_field list ->
Astlib.Ast_502.Asttypes.closed_flag ->
string list option ->
Astlib.Ast_502.Parsetree.core_type
ptyp_variant
constructs an Ast.core_type_desc.Ptyp_variant
Example OCaml
Ptyp_variant([`A;`B], flag, labels)
represents:
val ptyp_alias :
Astlib.Ast_502.Parsetree.core_type ->
string Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.core_type
val ptyp_class :
Astlib.Longident.t Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.core_type list ->
Astlib.Ast_502.Parsetree.core_type
ptyp_class
constructs an Ast.core_type_desc.Ptyp_class
Example OCaml
Ptyp_class(tconstr, l)
represents:
#tconstr
whenl=[]
,T #tconstr
whenl=[T]
,(T1, ..., Tn) #tconstr
whenl=[T1 ; ... ; Tn]
.
val ptyp_object :
Astlib.Ast_502.Parsetree.object_field list ->
Astlib.Ast_502.Asttypes.closed_flag ->
Astlib.Ast_502.Parsetree.core_type
ptyp_object
constructs an Ast.core_type_desc.Ptyp_object
Example OCaml
Ptyp_object([ l1:T1; ...; ln:Tn ], flag)
represents:
val ptyp_constr :
Astlib.Longident.t Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.core_type list ->
Astlib.Ast_502.Parsetree.core_type
ptyp_constr
constructs an Ast.core_type_desc.Ptyp_constr
Example OCaml
Ptyp_constr(lident, l)
represents:
tconstr
whenl=[]
,T tconstr
whenl=[T]
,(T1, ..., Tn) tconstr
whenl=[T1 ; ... ; Tn]
.
val ptyp_tuple :
Astlib.Ast_502.Parsetree.core_type list ->
Astlib.Ast_502.Parsetree.core_type
ptyp_tuple
constructs an Ast.core_type_desc.Ptyp_tuple
Example OCaml
Ptyp_tuple([T1 ; ... ; Tn])
represents a product type T1 * ... * Tn
.
Invariant: n >= 2
.
val ptyp_arrow :
Astlib.Ast_502.Asttypes.arg_label ->
Astlib.Ast_502.Parsetree.core_type ->
Astlib.Ast_502.Parsetree.core_type ->
Astlib.Ast_502.Parsetree.core_type
ptyp_arrow
constructs an Ast.core_type_desc.Ptyp_arrow
Example OCaml
Ptyp_arrow(lbl, T1, T2)
represents:
Constructor declaration
Class type field
val pctf_extension :
(string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) ->
Astlib.Ast_502.Parsetree.class_type_field
val pctf_attribute :
Astlib.Ast_502.Parsetree.attribute ->
Astlib.Ast_502.Parsetree.class_type_field
val pctf_constraint :
(Astlib.Ast_502.Parsetree.core_type * Astlib.Ast_502.Parsetree.core_type) ->
Astlib.Ast_502.Parsetree.class_type_field
pctf_constraint
constructs an Ast.class_type_field_desc.Pctf_constraint
Example OCaml
constraint T1 = T2
val pctf_method :
(string Astlib.Location.loc
* Astlib.Ast_502.Asttypes.private_flag
* Astlib.Ast_502.Asttypes.virtual_flag
* Astlib.Ast_502.Parsetree.core_type) ->
Astlib.Ast_502.Parsetree.class_type_field
pctf_method
constructs an Ast.class_type_field_desc.Pctf_method
Example OCaml
method x: T
Note: T
can be a Ptyp_poly
.
val pctf_inherit :
Astlib.Ast_502.Parsetree.class_type ->
Astlib.Ast_502.Parsetree.class_type_field
Class type
val pcty_extension :
(string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) ->
Astlib.Ast_502.Parsetree.class_type
val pcty_arrow :
Astlib.Ast_502.Asttypes.arg_label ->
Astlib.Ast_502.Parsetree.core_type ->
Astlib.Ast_502.Parsetree.class_type ->
Astlib.Ast_502.Parsetree.class_type
pcty_arrow
constructs an Ast.class_type_desc.Pcty_arrow
Example OCaml
Pcty_arrow(lbl, T, CT)
represents:
T -> CT
whenlbl
isNolabel
,~l:T -> CT
whenlbl
isLabelled l
,?l:T -> CT
whenlbl
isOptional l
.
val pcty_signature :
Astlib.Ast_502.Parsetree.class_signature ->
Astlib.Ast_502.Parsetree.class_type
val pcty_constr :
Astlib.Longident.t Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.core_type list ->
Astlib.Ast_502.Parsetree.class_type
Class structure
val class_structure :
self:Astlib.Ast_502.Parsetree.pattern ->
fields:Astlib.Ast_502.Parsetree.class_field list ->
Astlib.Ast_502.Parsetree.class_structure
class_structure
constructs an Ast.class_structure
Example OCaml
Values of type class_structure
represents:
object(selfpat) ... end
object ... end
whenpcstr_self
isPpat_any
Class signature
val class_signature :
self:Astlib.Ast_502.Parsetree.core_type ->
fields:Astlib.Ast_502.Parsetree.class_type_field list ->
Astlib.Ast_502.Parsetree.class_signature
class_signature
constructs an Ast.class_signature
Example OCaml
Values of type class_signature
represents:
object('selfpat) ... end
object ... end
whenpcsig_self
isPtyp_any
Class field
val pcf_extension :
(string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) ->
Astlib.Ast_502.Parsetree.class_field
val pcf_attribute :
Astlib.Ast_502.Parsetree.attribute ->
Astlib.Ast_502.Parsetree.class_field
val pcf_initializer :
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.class_field
val pcf_constraint :
(Astlib.Ast_502.Parsetree.core_type * Astlib.Ast_502.Parsetree.core_type) ->
Astlib.Ast_502.Parsetree.class_field
val pcf_method :
(string Astlib.Location.loc
* Astlib.Ast_502.Asttypes.private_flag
* Astlib.Ast_502.Parsetree.class_field_kind) ->
Astlib.Ast_502.Parsetree.class_field
pcf_method
constructs an Ast.class_field_desc.Pcf_method
Example OCaml
val pcf_val :
(string Astlib.Location.loc
* Astlib.Ast_502.Asttypes.mutable_flag
* Astlib.Ast_502.Parsetree.class_field_kind) ->
Astlib.Ast_502.Parsetree.class_field
pcf_val
constructs an Ast.class_field_desc.Pcf_val
Example OCaml
Pcf_val(x,flag, kind)
represents:
val x = E
whenflag
isImmutable
andkind
isCfk_concrete(Fresh, E)
val virtual x: T
whenflag
isImmutable
andkind
isCfk_virtual(T)
val mutable x = E
whenflag
isMutable
andkind
isCfk_concrete(Fresh, E)
val mutable virtual x: T
whenflag
isMutable
andkind
isCfk_virtual(T)
val pcf_inherit :
Astlib.Ast_502.Asttypes.override_flag ->
Astlib.Ast_502.Parsetree.class_expr ->
string Astlib.Location.loc option ->
Astlib.Ast_502.Parsetree.class_field
pcf_inherit
constructs an Ast.class_field_desc.Pcf_inherit
Example OCaml
Pcf_inherit(flag, CE, s)
represents:
Class expr
val pcl_extension :
(string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) ->
Astlib.Ast_502.Parsetree.class_expr
val pcl_constraint :
Astlib.Ast_502.Parsetree.class_expr ->
Astlib.Ast_502.Parsetree.class_type ->
Astlib.Ast_502.Parsetree.class_expr
val pcl_let :
Astlib.Ast_502.Asttypes.rec_flag ->
Astlib.Ast_502.Parsetree.value_binding list ->
Astlib.Ast_502.Parsetree.class_expr ->
Astlib.Ast_502.Parsetree.class_expr
pcl_let
constructs an Ast.class_expr_desc.Pcl_let
Example OCaml
Pcl_let(rec, [(P1, E1); ... ; (Pn, En)], CE)
represents:
let P1 = E1 and ... and Pn = EN in CE
whenrec
isNonrecursive
,let rec P1 = E1 and ... and Pn = EN in CE
whenrec
isRecursive
.
val pcl_apply :
Astlib.Ast_502.Parsetree.class_expr ->
(Astlib.Ast_502.Asttypes.arg_label * Astlib.Ast_502.Parsetree.expression)
list ->
Astlib.Ast_502.Parsetree.class_expr
pcl_apply
constructs an Ast.class_expr_desc.Pcl_apply
Example OCaml
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
val pcl_fun :
Astlib.Ast_502.Asttypes.arg_label ->
Astlib.Ast_502.Parsetree.expression option ->
Astlib.Ast_502.Parsetree.pattern ->
Astlib.Ast_502.Parsetree.class_expr ->
Astlib.Ast_502.Parsetree.class_expr
pcl_fun
constructs an Ast.class_expr_desc.Pcl_fun
Example OCaml
Pcl_fun(lbl, exp0, P, CE)
represents:
fun P -> CE
whenlbl
isNolabel
andexp0
isNone
,fun ~l:P -> CE
whenlbl
isLabelled l
andexp0
isNone
,fun ?l:P -> CE
whenlbl
isOptional l
andexp0
isNone
,fun ?l:(P = E0) -> CE
whenlbl
isOptional l
andexp0
isSome E0
.
val pcl_structure :
Astlib.Ast_502.Parsetree.class_structure ->
Astlib.Ast_502.Parsetree.class_expr
val pcl_constr :
Astlib.Longident.t Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.core_type list ->
Astlib.Ast_502.Parsetree.class_expr
Case
val case :
lhs:Astlib.Ast_502.Parsetree.pattern ->
guard:Astlib.Ast_502.Parsetree.expression option ->
rhs:Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.case
Binding op
val binding_op :
op:string Astlib.Location.loc ->
pat:Astlib.Ast_502.Parsetree.pattern ->
exp:Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.binding_op
binding_op
constructs an Ast.binding_op
Attribute
val attribute :
name:string Astlib.Location.loc ->
payload:Astlib.Ast_502.Parsetree.payload ->
Astlib.Ast_502.Parsetree.attribute
attribute
constructs an Ast.attribute
Example OCaml
Attributes such as [\@id ARG]
and [\@\@id ARG]
.
Metadata containers passed around within the AST. The compiler ignores unknown attributes.
'a open infos
val open_infos :
expr:'a ->
override:Astlib.Ast_502.Asttypes.override_flag ->
'a Astlib.Ast_502.Parsetree.open_infos
open_infos
constructs an Ast.'aopen_infos
Example OCaml
Values of type 'a open_infos
represents:
open! X
whenpopen_override
isOverride
(silences the "used identifier shadowing" warning)open X
whenpopen_override
isFresh
'a include infos
include_infos
constructs an Ast.'ainclude_infos
'a class infos
val class_infos :
virt:Astlib.Ast_502.Asttypes.virtual_flag ->
params:
(Astlib.Ast_502.Parsetree.core_type
* (Astlib.Ast_502.Asttypes.variance * Astlib.Ast_502.Asttypes.injectivity))
list ->
name:string Astlib.Location.loc ->
expr:'a ->
'a Astlib.Ast_502.Parsetree.class_infos
class_infos
constructs an Ast.'aclass_infos
Example OCaml
Values of type class_expr class_infos
represents:
class c = ...
class ['a1,...,'an] c = ...
class virtual c = ...
They are also used for "class type" declaration.
evar id
produces a Pexp_ident _
expression, it parses its input so you can pass any dot-separated identifier, for instance: evar ~loc "Foo.bar"
.
val eapply :
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression list ->
Astlib.Ast_502.Parsetree.expression
Same as pexp_apply but without labels
val eabstract :
Astlib.Ast_502.Parsetree.pattern list ->
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression
val esequence :
Astlib.Ast_502.Parsetree.expression list ->
Astlib.Ast_502.Parsetree.expression
val ppat_tuple_opt :
Astlib.Ast_502.Parsetree.pattern list ->
Astlib.Ast_502.Parsetree.pattern option
val pexp_tuple_opt :
Astlib.Ast_502.Parsetree.expression list ->
Astlib.Ast_502.Parsetree.expression option
val pexp_fun :
Astlib.Ast_502.Asttypes.arg_label ->
Astlib.Ast_502.Parsetree.expression option ->
Astlib.Ast_502.Parsetree.pattern ->
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression
pexp_fun
can be used to create function expressions. It will check if the function's body is itself a function expression and if so it will coalesce the arguments.
For example, if we have pexp_fun Nolabel None (var "x") f
and f
is fun y -> x + y
then the function expression returned will be fun x y -> x + y
and not fun x -> y -> x + y
. However, it will be more efficient to create maximum arity functions directly with pexp_function
.
val pexp_function :
Astlib.Ast_502.Parsetree.function_param list ->
Astlib.Ast_502.Parsetree.type_constraint option ->
Astlib.Ast_502.Parsetree.function_body ->
Astlib.Ast_502.Parsetree.expression
val pexp_function_cases :
Astlib.Ast_502.Parsetree.case list ->
Astlib.Ast_502.Parsetree.expression
pexp_function_cases
builds an expression in the shape function C1 -> E1 | ...
.
val pconstruct :
Astlib.Ast_502.Parsetree.constructor_declaration ->
Astlib.Ast_502.Parsetree.pattern option ->
Astlib.Ast_502.Parsetree.pattern
val econstruct :
Astlib.Ast_502.Parsetree.constructor_declaration ->
Astlib.Ast_502.Parsetree.expression option ->
Astlib.Ast_502.Parsetree.expression
val elist_tail :
Astlib.Ast_502.Parsetree.expression list ->
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression
elist_tail ~loc [expr1; expr2; expr3] expr_tail
produces the expression expr1::expr2::expr3::expr_tail
.
elist ~loc [expr1; expr2; expr3]
produces the list litteral expression [expr1; expr2; expr3]
.
val plist_tail :
Astlib.Ast_502.Parsetree.pattern list ->
Astlib.Ast_502.Parsetree.pattern ->
Astlib.Ast_502.Parsetree.pattern
plist_tail ~loc [pat1; pat2; pat3] pat_tail
produces the pattern pat1::pat2::pat3::pat_tail
.
plist ~loc [pat1; pat2; pat3]
produces the list pattern [pat1; pat2; pat3]
.
val value_binding :
pat:Astlib.Ast_502.Parsetree.pattern ->
expr:Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.value_binding
val pstr_value_list :
loc:Location.t ->
Ppxlib_ast.Asttypes.rec_flag ->
Astlib.Ast_502.Parsetree.value_binding list ->
Astlib.Ast_502.Parsetree.structure_item list
pstr_value_list ~loc rf vbs
= pstr_value ~loc rf vbs
if vbs <> []
, []
otherwise.
val nonrec_type_declaration :
name:string Loc.t ->
params:
(Astlib.Ast_502.Parsetree.core_type * Ppxlib_ast.Asttypes.variance) list ->
cstrs:
(Astlib.Ast_502.Parsetree.core_type
* Astlib.Ast_502.Parsetree.core_type
* Location.t)
list ->
kind:Astlib.Ast_502.Parsetree.type_kind ->
private_:Ppxlib_ast.Asttypes.private_flag ->
manifest:Astlib.Ast_502.Parsetree.core_type option ->
Astlib.Ast_502.Parsetree.type_declaration
val unapplied_type_constr_conv :
Longident.t Loc.t ->
f:(string -> string) ->
Astlib.Ast_502.Parsetree.expression
unapplied_type_constr_conv
is the standard way to map identifiers to conversion fonctions, for preprocessor that creates values that follow the structure of types. More precisely, path_conv path (sprintf "sexp_of_%s")
is:
- sexp_of_t if path is "t"
- A.B.sexp_of_foo if path is "A.B.foo"
- A.B.sexp_of_f__foo (module A1) (module A2) if path is "A.B.F(A1)(A2).foo"
type_constr_conv
also applies it to a list of expression, which both prevents the compiler from allocating useless closures, and almost always what is needed, since type constructors are always applied.
val type_constr_conv :
Longident.t Loc.t ->
f:(string -> string) ->
Astlib.Ast_502.Parsetree.expression list ->
Astlib.Ast_502.Parsetree.expression
val eta_reduce :
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression option
Tries to simplify fun v1 v2 .. -> f v1 v2 ..
into f
. Only works when f
is a path, not an arbitrary expression as that would change the meaning of the code. This can be used either for cleaning up the generated code, or to reduce allocation if f
is a local variable (the compiler won't optimize the allocation of the closure).
Eta-reduction can change the types/behavior in some corner cases that are unlikely to show up in generated code:
- if
f
has optional arguments, eta-expandingf
can drop them - because labels commute, it can change the type of an expression: $ let f ~x y = x + y let f2 = fun x -> add x;; val f : x:int -> int -> int = <fun> val f2 : int -> x:int -> int = <fun> In fact, if
f
does side effects before receiving all its arguments, and if the eta-expansion is partially applied, eta-reducing could change behavior.
eta_reduce_if_possible_and_nonrec
is meant for the case where the resulting expression is going to be bound in a potentially recursive let-binding, where we have to keep the eta-expansion when rec_flag
is Recursive
to avoid a compile error.
val eta_reduce_if_possible :
Astlib.Ast_502.Parsetree.expression ->
Astlib.Ast_502.Parsetree.expression
val eta_reduce_if_possible_and_nonrec :
Astlib.Ast_502.Parsetree.expression ->
rec_flag:Astlib.Ast_502.Asttypes.rec_flag ->
Astlib.Ast_502.Parsetree.expression
This module contains updated versions of node constructors that were kept stable when the node changed. For every function in this module, there's an equally-named function outside this module. The function outside this module will stay stable, whereas the function inside this module will adapt potential upcoming new compiler features. Only use a function in this module, if the equally-named one outside this module is missing a feature you need.
val ppat_construct :
Astlib.Longident.t Astlib.Location.loc ->
Astlib.Ast_502.Parsetree.pattern option ->
Astlib.Ast_502.Parsetree.pattern
val constructor_declaration :
name:string Astlib.Location.loc ->
args:Astlib.Ast_502.Parsetree.constructor_arguments ->
res:Astlib.Ast_502.Parsetree.core_type option ->
Astlib.Ast_502.Parsetree.constructor_declaration
- Parameters
-
Signature
- Value description
- Value binding
- Type extension
- Type exception
- Type declaration
- Toplevel directive
- Structure item
- Signature item
- Row field
- Position
- Pattern
- Object field
- Module type declaration
- Module type
- Module substitution
- Module expr
- Module declaration
- Module binding
- Location
- Letop
- Label declaration
- Function param
- Extension constructor
- Expression
- Directive argument
- Core type
- Constructor declaration
- Class type field
- Class type
- Class structure
- Class signature
- Class field
- Class expr
- Case
- Binding op
- Attribute
- 'a open infos
- 'a include infos
- 'a class infos