Module Ast_builder.Default

Helpers taking a ~loc argument. This module is meant to be opened or aliased.

module Located : sig ... end

Value description

val value_description : loc:Location.t -> name:string Astlib.Location.loc -> type_:Astlib.Ast_500.Parsetree.core_type -> prim:string list -> Astlib.Ast_500.Parsetree.value_description

value_description constructs an Ast.value_description

Example OCaml

Values of type value_description represents:

  • val x: T, when pval_prim is []
  • external x: T = "s1" ... "sn" when pval_prim is ["s1";..."sn"]

Value binding

value_binding constructs an Ast.value_binding

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

type_exception constructs an Ast.type_exception

Example OCaml

Definition of a new exception (exception E).

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 when type_kind is Ptype_abstract, and manifest is None,
  • type t = T0 when type_kind is Ptype_abstract, and manifest is Some T0,
  • type t = C of T | ... when type_kind is Ptype_variant, and manifest is None,
  • type t = T0 = C of T | ... when type_kind is Ptype_variant, and manifest is Some T0,
  • type t = {l: T; ...} when type_kind is Ptype_record, and manifest is None,
  • type t = T0 = {l : T; ...} when type_kind is Ptype_record, and manifest is Some T0,
  • type t = .. when type_kind is Ptype_open, and manifest is None.

Toplevel directive

toplevel_directive constructs an Ast.toplevel_directive

Structure item

pstr_extension constructs an Ast.structure_item_desc.Pstr_extension

Example OCaml

[%%id]

pstr_attribute constructs an Ast.structure_item_desc.Pstr_attribute

Example OCaml

[@@@id]

pstr_include constructs an Ast.structure_item_desc.Pstr_include

Example OCaml

include ME

pstr_class_type constructs an Ast.structure_item_desc.Pstr_class_type

Example OCaml

class type ct1 = ... and ... and ctn = ...

pstr_class constructs an Ast.structure_item_desc.Pstr_class

Example OCaml

class c1 = ... and ... and cn = ...

pstr_open constructs an Ast.structure_item_desc.Pstr_open

Example OCaml

open X

pstr_modtype constructs an Ast.structure_item_desc.Pstr_modtype

Example OCaml

module type S = MT

pstr_recmodule constructs an Ast.structure_item_desc.Pstr_recmodule

Example OCaml

module rec X1 = ME1 and ... and Xn = MEn

pstr_module constructs an Ast.structure_item_desc.Pstr_module

Example OCaml

module X = ME

pstr_exception constructs an Ast.structure_item_desc.Pstr_exception

Example OCaml

  • exception C of T
  • exception C = M.X

pstr_typext constructs an Ast.structure_item_desc.Pstr_typext

Example OCaml

type t1 += ...

pstr_type constructs an Ast.structure_item_desc.Pstr_type

Example OCaml

type t1 = ... and ... and tn = ...

pstr_primitive constructs an Ast.structure_item_desc.Pstr_primitive

Example OCaml

  • val x: T
  • external x: T = "s1" ... "sn"

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 when rec is Nonrecursive,
  • let rec P1 = E1 and ... and Pn = EN when rec is Recursive.

pstr_eval constructs an Ast.structure_item_desc.Pstr_eval

Example OCaml

E

Signature item

psig_extension constructs an Ast.signature_item_desc.Psig_extension

Example OCaml

[%%id]

psig_attribute constructs an Ast.signature_item_desc.Psig_attribute

Example OCaml

[@@@id]

psig_class_type constructs an Ast.signature_item_desc.Psig_class_type

Example OCaml

class type ct1 = ... and ... and ctn = ...

psig_class constructs an Ast.signature_item_desc.Psig_class

Example OCaml

class c1 : ... and ... and cn : ...

psig_include constructs an Ast.signature_item_desc.Psig_include

Example OCaml

include MT

psig_open constructs an Ast.signature_item_desc.Psig_open

Example OCaml

open X

psig_modtypesubst constructs an Ast.signature_item_desc.Psig_modtypesubst

Example OCaml

module type S := ...

psig_modtype constructs an Ast.signature_item_desc.Psig_modtype

Example OCaml

module type S = MT and module type S

psig_recmodule constructs an Ast.signature_item_desc.Psig_recmodule

Example OCaml

module rec X1 : MT1 and ... and Xn : MTn

psig_modsubst constructs an Ast.signature_item_desc.Psig_modsubst

Example OCaml

module X := M

psig_module constructs an Ast.signature_item_desc.Psig_module

Example OCaml

module X = M and module X : MT

psig_exception constructs an Ast.signature_item_desc.Psig_exception

Example OCaml

exception C of T

psig_typext constructs an Ast.signature_item_desc.Psig_typext

Example OCaml

type t1 += ...

psig_typesubst constructs an Ast.signature_item_desc.Psig_typesubst

Example OCaml

type t1 := ... and ... and tn := ...

psig_type constructs an Ast.signature_item_desc.Psig_type

Example OCaml

type t1 = ... and ... and tn = ...

psig_value constructs an Ast.signature_item_desc.Psig_value

Example OCaml

  • val x: T
  • external x: T = "s1" ... "sn"

Row field

rinherit constructs an Ast.row_field_desc.Rinherit

Example OCaml

[ | t ]

rtag constructs an Ast.row_field_desc.Rtag

Example OCaml

Rtag(`A, b, l) represents:

  • `A when b is true and l is [],
  • `A of T when b is false and l is [T],
  • `A of T1 & .. & Tn when b is false and l is [T1;...Tn],
  • `A of & 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)

Position

val position : fname:string -> lnum:int -> bol:int -> cnum:int -> Lexing.position

position constructs an Ast.position

Pattern

ppat_open constructs an Ast.pattern_desc.Ppat_open

Example OCaml

Pattern M.(P)

ppat_extension constructs an Ast.pattern_desc.Ppat_extension

Example OCaml

Pattern [%id]

ppat_exception constructs an Ast.pattern_desc.Ppat_exception

Example OCaml

Pattern exception P

val ppat_unpack : loc:Location.t -> string option Astlib.Location.loc -> Astlib.Ast_500.Parsetree.pattern

ppat_unpack constructs an Ast.pattern_desc.Ppat_unpack

Example OCaml

Ppat_unpack(s) represents:

  • (module P) when s is Some "P"
  • (module _) when s is None

Note: (module P : S) is represented as Ppat_constraint(Ppat_unpack(Some "P"), Ptyp_package S)

ppat_lazy constructs an Ast.pattern_desc.Ppat_lazy

Example OCaml

Pattern lazy P

ppat_type constructs an Ast.pattern_desc.Ppat_type

Example OCaml

Pattern #tconst

ppat_constraint constructs an Ast.pattern_desc.Ppat_constraint

Example OCaml

Pattern (P : T)

ppat_or constructs an Ast.pattern_desc.Ppat_or

Example OCaml

Pattern P1 | P2

ppat_array constructs an Ast.pattern_desc.Ppat_array

Example OCaml

Pattern [| P1; ...; Pn |]

ppat_record constructs an Ast.pattern_desc.Ppat_record

Example OCaml

Ppat_record([(l1, P1) ; ... ; (ln, Pn)], flag) represents:

  • { l1=P1; ...; ln=Pn } when flag is Closed
  • { l1=P1; ...; ln=Pn; _} when flag is Open

Invariant: n > 0

ppat_variant constructs an Ast.pattern_desc.Ppat_variant

Example OCaml

Ppat_variant(`A, pat) represents:

  • `A when pat is None,
  • `A P when pat is Some P

ppat_tuple constructs an Ast.pattern_desc.Ppat_tuple

Example OCaml

Patterns (P1, ..., Pn).

Invariant: n >= 2

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

ppat_alias constructs an Ast.pattern_desc.Ppat_alias

Example OCaml

An alias pattern such as P as 'a

ppat_var constructs an Ast.pattern_desc.Ppat_var

Example OCaml

A variable pattern such as x

ppat_any constructs an Ast.pattern_desc.Ppat_any

Example OCaml

The pattern _.

Object field

oinherit constructs an Ast.object_field_desc.Oinherit

otag constructs an Ast.object_field_desc.Otag

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, when pmtd_type is None.

Module type

pmty_alias constructs an Ast.module_type_desc.Pmty_alias

Example OCaml

(module M)

pmty_extension constructs an Ast.module_type_desc.Pmty_extension

Example OCaml

[%id]

pmty_typeof constructs an Ast.module_type_desc.Pmty_typeof

Example OCaml

module type of ME

pmty_with constructs an Ast.module_type_desc.Pmty_with

Example OCaml

MT with ...

pmty_functor constructs an Ast.module_type_desc.Pmty_functor

Example OCaml

functor(X : MT1) -> MT2

pmty_signature constructs an Ast.module_type_desc.Pmty_signature

Example OCaml

sig ... end

pmty_ident constructs an Ast.module_type_desc.Pmty_ident

Example OCaml

Pmty_ident(S) represents S

Module substitution

module_substitution constructs an Ast.module_substitution

Example OCaml

Values of type module_substitution represents S := M

Module expr

pmod_extension constructs an Ast.module_expr_desc.Pmod_extension

Example OCaml

[%id]

pmod_unpack constructs an Ast.module_expr_desc.Pmod_unpack

Example OCaml

(val E)

pmod_constraint constructs an Ast.module_expr_desc.Pmod_constraint

Example OCaml

(ME : MT)

pmod_apply constructs an Ast.module_expr_desc.Pmod_apply

Example OCaml

ME1(ME2)

pmod_functor constructs an Ast.module_expr_desc.Pmod_functor

Example OCaml

functor(X : MT1) -> ME

pmod_structure constructs an Ast.module_expr_desc.Pmod_structure

Example OCaml

struct ... end

pmod_ident constructs an Ast.module_expr_desc.Pmod_ident

Example OCaml

X

Module declaration

module_declaration constructs an Ast.module_declaration

Example OCaml

Values of type module_declaration represents S : MT

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

letop constructs an Ast.letop

Label declaration

label_declaration constructs an Ast.label_declaration

Example OCaml

Note: T can be a Ptyp_poly.

Extension constructor

extension_constructor constructs an Ast.extension_constructor

Expression

val pexp_unreachable : loc:Location.t -> Astlib.Ast_500.Parsetree.expression

pexp_unreachable constructs an Ast.expression_desc.Pexp_unreachable

Example OCaml

.

pexp_extension constructs an Ast.expression_desc.Pexp_extension

Example OCaml

[%id]

pexp_letop constructs an Ast.expression_desc.Pexp_letop

Example OCaml

  • let* P = E0 in E1
  • let* P0 = E00 and* P1 = E01 in E1

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)

pexp_newtype constructs an Ast.expression_desc.Pexp_newtype

Example OCaml

fun (type t) -> E

pexp_object constructs an Ast.expression_desc.Pexp_object

Example OCaml

object ... end

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_lazy constructs an Ast.expression_desc.Pexp_lazy

Example OCaml

lazy E

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.

pexp_letexception constructs an Ast.expression_desc.Pexp_letexception

Example OCaml

let exception C in E

pexp_letmodule constructs an Ast.expression_desc.Pexp_letmodule

Example OCaml

let module M = ME in E

pexp_override constructs an Ast.expression_desc.Pexp_override

Example OCaml

{< x1 = E1; ...; xn = En >}

pexp_setinstvar constructs an Ast.expression_desc.Pexp_setinstvar

Example OCaml

x <- 2

pexp_new constructs an Ast.expression_desc.Pexp_new

Example OCaml

new M.c

pexp_send constructs an Ast.expression_desc.Pexp_send

Example OCaml

E # m

pexp_coerce constructs an Ast.expression_desc.Pexp_coerce

Example OCaml

Pexp_coerce(E, from, T) represents

  • (E :> T) when from is None,
  • (E : T0 :> T) when from is Some T0.

pexp_constraint constructs an Ast.expression_desc.Pexp_constraint

Example OCaml

(E : T)

pexp_for constructs an Ast.expression_desc.Pexp_for

Example OCaml

Pexp_for(i, E1, E2, direction, E3) represents:

  • for i = E1 to E2 do E3 done when direction is Upto
  • for i = E1 downto E2 do E3 done when direction is Downto

pexp_while constructs an Ast.expression_desc.Pexp_while

Example OCaml

while E1 do E2 done

pexp_sequence constructs an Ast.expression_desc.Pexp_sequence

Example OCaml

E1; E2

pexp_ifthenelse constructs an Ast.expression_desc.Pexp_ifthenelse

Example OCaml

if E1 then E2 else E3

pexp_array constructs an Ast.expression_desc.Pexp_array

Example OCaml

[| E1; ...; En |]

pexp_setfield constructs an Ast.expression_desc.Pexp_setfield

Example OCaml

E1.l <- E2

pexp_field constructs an Ast.expression_desc.Pexp_field

Example OCaml

E.l

pexp_record constructs an Ast.expression_desc.Pexp_record

Example OCaml

Pexp_record([(l1,P1) ; ... ; (ln,Pn)], exp0) represents

  • { l1=P1; ...; ln=Pn } when exp0 is None
  • { E0 with l1=P1; ...; ln=Pn } when exp0 is Some E0

Invariant: n > 0

pexp_variant constructs an Ast.expression_desc.Pexp_variant

Example OCaml

Pexp_variant(`A, exp) represents

  • `A when exp is None
  • `A E when exp is Some E

pexp_construct constructs an Ast.expression_desc.Pexp_construct

Example OCaml

Pexp_construct(C, exp) represents:

  • C when exp is None,
  • C E when exp is Some E,
  • C (E1, ..., En) when exp is Some (Pexp_tuple[E1;...;En])

pexp_tuple constructs an Ast.expression_desc.Pexp_tuple

Example OCaml

Expressions (E1, ..., En)

Invariant: n >= 2

pexp_try constructs an Ast.expression_desc.Pexp_try

Example OCaml

try E0 with P1 -> E1 | ... | Pn -> En

pexp_match constructs an Ast.expression_desc.Pexp_match

Example OCaml

match E0 with P1 -> E1 | ... | Pn -> En

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

pexp_fun constructs an Ast.expression_desc.Pexp_fun

Example OCaml

Pexp_fun(lbl, exp0, P, E1) represents:

  • fun P -> E1 when lbl is Nolabel and exp0 is None
  • fun ~l:P -> E1 when lbl is Labelled l and exp0 is None
  • fun ?l:P -> E1 when lbl is Optional l and exp0 is None
  • fun ?l:(P = E0) -> E1 when lbl is Optional l and exp0 is Some E0

Notes:

  • If E0 is provided, only Optional is allowed.
  • fun P1 P2 .. Pn -> E1 is represented as nested Pexp_fun.
  • let f P = E is represented using Pexp_fun.

pexp_function constructs an Ast.expression_desc.Pexp_function

Example OCaml

function P1 -> E1 | ... | Pn -> En

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 when flag is Nonrecursive,
  • let rec P1 = E1 and ... and Pn = EN in E when flag is Recursive.

pexp_constant constructs an Ast.expression_desc.Pexp_constant

Example OCaml

Expressions constant such as 1, 'a', "true", 1.0, 1l, 1L, 1n

pexp_ident constructs an Ast.expression_desc.Pexp_ident

Example OCaml

Identifiers such as x and M.x

Directive argument

val pdir_int : loc:Location.t -> string -> char option -> Astlib.Ast_500.Parsetree.directive_argument
val pdir_string : loc:Location.t -> string -> Astlib.Ast_500.Parsetree.directive_argument

pdir_string constructs an Ast.directive_argument_desc.Pdir_string

Core type

ptyp_extension constructs an Ast.core_type_desc.Ptyp_extension

Example OCaml

[%id].

ptyp_package constructs an Ast.core_type_desc.Ptyp_package

Example OCaml

(module S).

ptyp_poly constructs an Ast.core_type_desc.Ptyp_poly

Example OCaml

'a1 ... 'an. T

Can only appear in the following context:

let x : 'a1 ... 'an. T = e ...

ptyp_variant constructs an Ast.core_type_desc.Ptyp_variant

Example OCaml

Ptyp_variant([`A;`B], flag, labels) represents:

  • [ `A|`B ] when flag is Closed, and labels is None,
  • [> `A|`B ] when flag is Open, and labels is None,
  • [< `A|`B ] when flag is Closed, and labels is Some [],
  • [< `A|`B > `X `Y ] when flag is Closed, and labels is Some ["X";"Y"].

ptyp_alias constructs an Ast.core_type_desc.Ptyp_alias

Example OCaml

T as 'a.

ptyp_class constructs an Ast.core_type_desc.Ptyp_class

Example OCaml

Ptyp_class(tconstr, l) represents:

  • #tconstr when l=[],
  • T #tconstr when l=[T],
  • (T1, ..., Tn) #tconstr when l=[T1 ; ... ; Tn].

ptyp_object constructs an Ast.core_type_desc.Ptyp_object

Example OCaml

Ptyp_object([ l1:T1; ...; ln:Tn ], flag) represents:

  • < l1:T1; ...; ln:Tn > when flag is Closed,
  • < l1:T1; ...; ln:Tn; .. > when flag is Open.

ptyp_constr constructs an Ast.core_type_desc.Ptyp_constr

Example OCaml

Ptyp_constr(lident, l) represents:

  • tconstr when l=[],
  • T tconstr when l=[T],
  • (T1, ..., Tn) tconstr when l=[T1 ; ... ; Tn].

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.

ptyp_arrow constructs an Ast.core_type_desc.Ptyp_arrow

Example OCaml

Ptyp_arrow(lbl, T1, T2) represents:

val ptyp_var : loc:Location.t -> string -> Astlib.Ast_500.Parsetree.core_type

ptyp_var constructs an Ast.core_type_desc.Ptyp_var

Example OCaml

A type variable such as 'a

ptyp_any constructs an Ast.core_type_desc.Ptyp_any

Example OCaml

_

Constructor declaration

Class type field

pctf_extension constructs an Ast.class_type_field_desc.Pctf_extension

Example OCaml

[%%id]

pctf_attribute constructs an Ast.class_type_field_desc.Pctf_attribute

Example OCaml

[@@@id]

pctf_constraint constructs an Ast.class_type_field_desc.Pctf_constraint

Example OCaml

constraint T1 = T2

pctf_method constructs an Ast.class_type_field_desc.Pctf_method

Example OCaml

method x: T

Note: T can be a Ptyp_poly.

pctf_val constructs an Ast.class_type_field_desc.Pctf_val

Example OCaml

val x: T

pctf_inherit constructs an Ast.class_type_field_desc.Pctf_inherit

Example OCaml

inherit CT

Class type

pcty_open constructs an Ast.class_type_desc.Pcty_open

Example OCaml

let open M in CT

pcty_extension constructs an Ast.class_type_desc.Pcty_extension

Example OCaml

%id

pcty_arrow constructs an Ast.class_type_desc.Pcty_arrow

Example OCaml

Pcty_arrow(lbl, T, CT) represents:

pcty_signature constructs an Ast.class_type_desc.Pcty_signature

Example OCaml

object ... end

pcty_constr constructs an Ast.class_type_desc.Pcty_constr

Example OCaml

  • c
  • ['a1, ..., 'an] c

Class structure

class_structure constructs an Ast.class_structure

Example OCaml

Values of type class_structure represents:

Class signature

class_signature constructs an Ast.class_signature

Example OCaml

Values of type class_signature represents:

Class field

pcf_extension constructs an Ast.class_field_desc.Pcf_extension

Example OCaml

[%%id]

pcf_attribute constructs an Ast.class_field_desc.Pcf_attribute

Example OCaml

[@@@id]

pcf_initializer constructs an Ast.class_field_desc.Pcf_initializer

Example OCaml

initializer E

pcf_constraint constructs an Ast.class_field_desc.Pcf_constraint

Example OCaml

constraint T1 = T2

pcf_method constructs an Ast.class_field_desc.Pcf_method

Example OCaml

pcf_val constructs an Ast.class_field_desc.Pcf_val

Example OCaml

Pcf_val(x,flag, kind) represents:

pcf_inherit constructs an Ast.class_field_desc.Pcf_inherit

Example OCaml

Pcf_inherit(flag, CE, s) represents:

  • inherit CE when flag is Fresh and s is None,
  • inherit CE as x when flag is Fresh and s is Some x,
  • inherit! CE when flag is Override and s is None,
  • inherit! CE as x when flag is Override and s is Some x

Class expr

pcl_open constructs an Ast.class_expr_desc.Pcl_open

Example OCaml

let open M in CE

pcl_extension constructs an Ast.class_expr_desc.Pcl_extension

Example OCaml

[%id]

pcl_constraint constructs an Ast.class_expr_desc.Pcl_constraint

Example OCaml

(CE : CT)

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 when rec is Nonrecursive,
  • let rec P1 = E1 and ... and Pn = EN in CE when rec is Recursive.

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

pcl_fun constructs an Ast.class_expr_desc.Pcl_fun

Example OCaml

Pcl_fun(lbl, exp0, P, CE) represents:

  • fun P -> CE when lbl is Nolabel and exp0 is None,
  • fun ~l:P -> CE when lbl is Labelled l and exp0 is None,
  • fun ?l:P -> CE when lbl is Optional l and exp0 is None,
  • fun ?l:(P = E0) -> CE when lbl is Optional l and exp0 is Some E0.

pcl_structure constructs an Ast.class_expr_desc.Pcl_structure

Example OCaml

object ... end

pcl_constr constructs an Ast.class_expr_desc.Pcl_constr

Example OCaml

c and ['a1, ..., 'an] c

Case

case constructs an Ast.case

Example OCaml

Values of type case represents (P -> E) or (P when E0 -> E)

Binding op

binding_op constructs an Ast.binding_op

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

open_infos constructs an Ast.'aopen_infos

Example OCaml

Values of type 'a open_infos represents:

'a include infos

val include_infos : loc:Location.t -> 'a -> 'a Astlib.Ast_500.Parsetree.include_infos

include_infos constructs an Ast.'ainclude_infos

'a 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.

module Latest : sig ... end

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 estring : loc:Location.t -> string -> Astlib.Ast_500.Parsetree.expression
val efloat : loc:Location.t -> string -> Astlib.Ast_500.Parsetree.expression
val eint32 : loc:Location.t -> int32 -> Astlib.Ast_500.Parsetree.expression
val eint64 : loc:Location.t -> int64 -> Astlib.Ast_500.Parsetree.expression
val enativeint : loc:Location.t -> nativeint -> Astlib.Ast_500.Parsetree.expression
val pchar : loc:Location.t -> char -> Astlib.Ast_500.Parsetree.pattern
val pstring : loc:Location.t -> string -> Astlib.Ast_500.Parsetree.pattern
val pfloat : loc:Location.t -> string -> Astlib.Ast_500.Parsetree.pattern
val pint32 : loc:Location.t -> int32 -> Astlib.Ast_500.Parsetree.pattern
val pint64 : loc:Location.t -> int64 -> Astlib.Ast_500.Parsetree.pattern
val pnativeint : loc:Location.t -> nativeint -> Astlib.Ast_500.Parsetree.pattern
val pbool : loc:Location.t -> bool -> Astlib.Ast_500.Parsetree.pattern

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 pvar : loc:Location.t -> string -> Astlib.Ast_500.Parsetree.pattern

Same as pexp_apply but without labels

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].

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].

pstr_value_list ~loc rf vbs = pstr_value ~loc rf vbs if vbs <> [], [] otherwise.

  • deprecated [since 2016-10] use Nonrecursive on the P(str|sig)_type instead
val unapplied_type_constr_conv : loc:Location.t -> Longident.t Loc.t -> f:(string -> string) -> Astlib.Ast_500.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 : loc:Location.t -> Longident.t Loc.t -> f:(string -> string) -> Astlib.Ast_500.Parsetree.expression list -> Astlib.Ast_500.Parsetree.expression

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-expanding f 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.