package ppx_repr

  1. Overview
  2. Docs

doc/ppx_repr.lib/Ppx_repr_lib/Engine/Located/argument-2-_/index.html

Parameter Located._

module Located : sig ... end

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:

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

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

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

pstr_extension constructs an Ast.Pstr_extension

Example OCaml

[%%id]

val pstr_attribute : Astlib.Ast_502.Parsetree.attribute -> Astlib.Ast_502.Parsetree.structure_item

pstr_attribute constructs an Ast.Pstr_attribute

Example OCaml

[\@\@\@id]

val pstr_include : Astlib.Ast_502.Parsetree.module_expr Astlib.Ast_502.Parsetree.include_infos -> Astlib.Ast_502.Parsetree.structure_item

pstr_include constructs an Ast.Pstr_include

Example OCaml

include ME

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

Example OCaml

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

val pstr_open : Astlib.Ast_502.Parsetree.module_expr Astlib.Ast_502.Parsetree.open_infos -> Astlib.Ast_502.Parsetree.structure_item

pstr_open constructs an Ast.Pstr_open

Example OCaml

open X

val pstr_modtype : Astlib.Ast_502.Parsetree.module_type_declaration -> Astlib.Ast_502.Parsetree.structure_item

pstr_modtype constructs an Ast.Pstr_modtype

Example OCaml

module type S = MT

val pstr_recmodule : Astlib.Ast_502.Parsetree.module_binding list -> Astlib.Ast_502.Parsetree.structure_item

pstr_recmodule constructs an Ast.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

pstr_module constructs an Ast.Pstr_module

Example OCaml

module X = ME

val pstr_exception : Astlib.Ast_502.Parsetree.type_exception -> Astlib.Ast_502.Parsetree.structure_item

pstr_exception constructs an Ast.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

pstr_typext constructs an Ast.Pstr_typext

Example OCaml

type t1 += ...

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.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.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.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.
val pstr_eval : Astlib.Ast_502.Parsetree.expression -> Astlib.Ast_502.Parsetree.attribute list -> Astlib.Ast_502.Parsetree.structure_item

pstr_eval constructs an Ast.Pstr_eval

Example OCaml

E

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

psig_extension constructs an Ast.Psig_extension

Example OCaml

[%%id]

val psig_attribute : Astlib.Ast_502.Parsetree.attribute -> Astlib.Ast_502.Parsetree.signature_item

psig_attribute constructs an Ast.Psig_attribute

Example OCaml

[\@\@\@id]

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

Example OCaml

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

val psig_include : Astlib.Ast_502.Parsetree.module_type Astlib.Ast_502.Parsetree.include_infos -> Astlib.Ast_502.Parsetree.signature_item

psig_include constructs an Ast.Psig_include

Example OCaml

include MT

val psig_open : Astlib.Longident.t Astlib.Location.loc Astlib.Ast_502.Parsetree.open_infos -> Astlib.Ast_502.Parsetree.signature_item

psig_open constructs an Ast.Psig_open

Example OCaml

open X

val psig_modtypesubst : Astlib.Ast_502.Parsetree.module_type_declaration -> Astlib.Ast_502.Parsetree.signature_item

psig_modtypesubst constructs an Ast.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.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.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

psig_modsubst constructs an Ast.Psig_modsubst

Example OCaml

module X := M

val psig_module : Astlib.Ast_502.Parsetree.module_declaration -> Astlib.Ast_502.Parsetree.signature_item

psig_module constructs an Ast.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

psig_exception constructs an Ast.Psig_exception

Example OCaml

exception C of T

val psig_typext : Astlib.Ast_502.Parsetree.type_extension -> Astlib.Ast_502.Parsetree.signature_item

psig_typext constructs an Ast.Psig_typext

Example OCaml

type t1 += ...

val psig_typesubst : Astlib.Ast_502.Parsetree.type_declaration list -> Astlib.Ast_502.Parsetree.signature_item

psig_typesubst constructs an Ast.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.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.Psig_value

Example OCaml

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

Row field

val rinherit : Astlib.Ast_502.Parsetree.core_type -> Astlib.Ast_502.Parsetree.row_field

rinherit constructs an Ast.Rinherit

Example OCaml

[ | t ]

val rtag : string Astlib.Location.loc -> bool -> Astlib.Ast_502.Parsetree.core_type list -> Astlib.Ast_502.Parsetree.row_field

rtag constructs an Ast.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

val ppat_open : Astlib.Longident.t Astlib.Location.loc -> Astlib.Ast_502.Parsetree.pattern -> Astlib.Ast_502.Parsetree.pattern

ppat_open constructs an Ast.Ppat_open

Example OCaml

Pattern M.(P)

val ppat_extension : (string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) -> Astlib.Ast_502.Parsetree.pattern

ppat_extension constructs an Ast.Ppat_extension

Example OCaml

Pattern [%id]

val ppat_exception : Astlib.Ast_502.Parsetree.pattern -> Astlib.Ast_502.Parsetree.pattern

ppat_exception constructs an Ast.Ppat_exception

Example OCaml

Pattern exception P

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

ppat_unpack constructs an Ast.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)

val ppat_lazy : Astlib.Ast_502.Parsetree.pattern -> Astlib.Ast_502.Parsetree.pattern

ppat_lazy constructs an Ast.Ppat_lazy

Example OCaml

Pattern lazy P

val ppat_type : Astlib.Longident.t Astlib.Location.loc -> Astlib.Ast_502.Parsetree.pattern

ppat_type constructs an Ast.Ppat_type

Example OCaml

Pattern #tconst

val ppat_constraint : Astlib.Ast_502.Parsetree.pattern -> Astlib.Ast_502.Parsetree.core_type -> Astlib.Ast_502.Parsetree.pattern

ppat_constraint constructs an Ast.Ppat_constraint

Example OCaml

Pattern (P : T)

val ppat_or : Astlib.Ast_502.Parsetree.pattern -> Astlib.Ast_502.Parsetree.pattern -> Astlib.Ast_502.Parsetree.pattern

ppat_or constructs an Ast.Ppat_or

Example OCaml

Pattern P1 | P2

val ppat_array : Astlib.Ast_502.Parsetree.pattern list -> Astlib.Ast_502.Parsetree.pattern

ppat_array constructs an Ast.Ppat_array

Example OCaml

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

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

val ppat_variant : string -> Astlib.Ast_502.Parsetree.pattern option -> Astlib.Ast_502.Parsetree.pattern

ppat_variant constructs an Ast.Ppat_variant

Example OCaml

Ppat_variant(`A, pat) represents:

  • `A when pat is None,
  • `A P when pat is Some P
val ppat_tuple : Astlib.Ast_502.Parsetree.pattern list -> Astlib.Ast_502.Parsetree.pattern

ppat_tuple constructs an Ast.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.Ppat_interval

Example OCaml

Patterns such as 'a'..'z'.

Other forms of interval are recognized by the parser but rejected by the type-checker.

val ppat_constant : Astlib.Ast_502.Parsetree.constant -> Astlib.Ast_502.Parsetree.pattern

ppat_constant constructs an Ast.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

ppat_alias constructs an Ast.Ppat_alias

Example OCaml

An alias pattern such as P as 'a

val ppat_var : string Astlib.Location.loc -> Astlib.Ast_502.Parsetree.pattern

ppat_var constructs an Ast.Ppat_var

Example OCaml

A variable pattern such as x

val ppat_any : Astlib.Ast_502.Parsetree.pattern

ppat_any constructs an Ast.Ppat_any

Example OCaml

The pattern _.

Object field

val oinherit : Astlib.Ast_502.Parsetree.core_type -> Astlib.Ast_502.Parsetree.object_field

oinherit constructs an Ast.Oinherit

val otag : string Astlib.Location.loc -> Astlib.Ast_502.Parsetree.core_type -> Astlib.Ast_502.Parsetree.object_field

otag constructs an Ast.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, when pmtd_type is None.

Module type

val pmty_alias : Astlib.Longident.t Astlib.Location.loc -> Astlib.Ast_502.Parsetree.module_type

pmty_alias constructs an Ast.Pmty_alias

Example OCaml

(module M)

val pmty_extension : (string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) -> Astlib.Ast_502.Parsetree.module_type

pmty_extension constructs an Ast.Pmty_extension

Example OCaml

[%id]

val pmty_typeof : Astlib.Ast_502.Parsetree.module_expr -> Astlib.Ast_502.Parsetree.module_type

pmty_typeof constructs an Ast.Pmty_typeof

Example OCaml

module type of ME

val pmty_with : Astlib.Ast_502.Parsetree.module_type -> Astlib.Ast_502.Parsetree.with_constraint list -> Astlib.Ast_502.Parsetree.module_type

pmty_with constructs an Ast.Pmty_with

Example OCaml

MT with ...

val pmty_functor : Astlib.Ast_502.Parsetree.functor_parameter -> Astlib.Ast_502.Parsetree.module_type -> Astlib.Ast_502.Parsetree.module_type

pmty_functor constructs an Ast.Pmty_functor

Example OCaml

functor(X : MT1) -> MT2

val pmty_signature : Astlib.Ast_502.Parsetree.signature_item list -> Astlib.Ast_502.Parsetree.module_type

pmty_signature constructs an Ast.Pmty_signature

Example OCaml

sig ... end

val pmty_ident : Astlib.Longident.t Astlib.Location.loc -> Astlib.Ast_502.Parsetree.module_type

pmty_ident constructs an Ast.Pmty_ident

Example OCaml

Pmty_ident(S) represents S

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

pmod_extension constructs an Ast.Pmod_extension

Example OCaml

[%id]

val pmod_unpack : Astlib.Ast_502.Parsetree.expression -> Astlib.Ast_502.Parsetree.module_expr

pmod_unpack constructs an Ast.Pmod_unpack

Example OCaml

(val E)

val pmod_constraint : Astlib.Ast_502.Parsetree.module_expr -> Astlib.Ast_502.Parsetree.module_type -> Astlib.Ast_502.Parsetree.module_expr

pmod_constraint constructs an Ast.Pmod_constraint

Example OCaml

(ME : MT)

val pmod_apply_unit : Astlib.Ast_502.Parsetree.module_expr -> Astlib.Ast_502.Parsetree.module_expr

pmod_apply_unit constructs an Ast.Pmod_apply_unit

Example OCaml

ME1()

val pmod_apply : Astlib.Ast_502.Parsetree.module_expr -> Astlib.Ast_502.Parsetree.module_expr -> Astlib.Ast_502.Parsetree.module_expr

pmod_apply constructs an Ast.Pmod_apply

Example OCaml

ME1(ME2)

val pmod_functor : Astlib.Ast_502.Parsetree.functor_parameter -> Astlib.Ast_502.Parsetree.module_expr -> Astlib.Ast_502.Parsetree.module_expr

pmod_functor constructs an Ast.Pmod_functor

Example OCaml

functor(X : MT1) -> ME

val pmod_structure : Astlib.Ast_502.Parsetree.structure_item list -> Astlib.Ast_502.Parsetree.module_expr

pmod_structure constructs an Ast.Pmod_structure

Example OCaml

struct ... end

val pmod_ident : Astlib.Longident.t Astlib.Location.loc -> Astlib.Ast_502.Parsetree.module_expr

pmod_ident constructs an Ast.Pmod_ident

Example OCaml

X

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; ... } when pld_mutable is Immutable,
  • { ...; mutable l: T; ... } when pld_mutable is Mutable.

Note: T can be a Ptyp_poly.

Function param

val pparam_newtype : string Astlib.Location.loc -> Astlib.Ast_502.Parsetree.function_param

pparam_newtype constructs an Ast.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.Pparam_val

Example OCaml

Pparam_val (lbl, exp0, P) represents the parameter:

  • P when lbl is Nolabel and exp0 is None
  • ~l:P when lbl is Labelled l and exp0 is None
  • ?l:P when lbl is Optional l and exp0 is None
  • ?l:(P = E0) when lbl is Optional l and exp0 is Some 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_unreachable : Astlib.Ast_502.Parsetree.expression

pexp_unreachable constructs an Ast.Pexp_unreachable

Example OCaml

.

val pexp_extension : (string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) -> Astlib.Ast_502.Parsetree.expression

pexp_extension constructs an Ast.Pexp_extension

Example OCaml

[%id]

val pexp_letop : Astlib.Ast_502.Parsetree.letop -> Astlib.Ast_502.Parsetree.expression

pexp_letop constructs an Ast.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.Pexp_open

Example OCaml

  • M.(E)
  • let open M in E
  • let open! M in E
val pexp_pack : Astlib.Ast_502.Parsetree.module_expr -> Astlib.Ast_502.Parsetree.expression

pexp_pack constructs an Ast.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

pexp_newtype constructs an Ast.Pexp_newtype

Example OCaml

fun (type t) -> E

val pexp_object : Astlib.Ast_502.Parsetree.class_structure -> Astlib.Ast_502.Parsetree.expression

pexp_object constructs an Ast.Pexp_object

Example OCaml

object ... end

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

Example OCaml

Used for method bodies.

Can only be used as the expression under Cfk_concrete for methods (not values).

val pexp_lazy : Astlib.Ast_502.Parsetree.expression -> Astlib.Ast_502.Parsetree.expression

pexp_lazy constructs an Ast.Pexp_lazy

Example OCaml

lazy E

val pexp_assert : Astlib.Ast_502.Parsetree.expression -> Astlib.Ast_502.Parsetree.expression

pexp_assert constructs an Ast.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.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

pexp_letmodule constructs an Ast.Pexp_letmodule

Example OCaml

let module M = ME in E

val pexp_override : (string Astlib.Location.loc * Astlib.Ast_502.Parsetree.expression) list -> Astlib.Ast_502.Parsetree.expression

pexp_override constructs an Ast.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

pexp_setinstvar constructs an Ast.Pexp_setinstvar

Example OCaml

x <- 2

val pexp_new : Astlib.Longident.t Astlib.Location.loc -> Astlib.Ast_502.Parsetree.expression

pexp_new constructs an Ast.Pexp_new

Example OCaml

new M.c

val pexp_send : Astlib.Ast_502.Parsetree.expression -> string Astlib.Location.loc -> Astlib.Ast_502.Parsetree.expression

pexp_send constructs an Ast.Pexp_send

Example OCaml

E # m

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

Example OCaml

Pexp_coerce(E, from, T) represents

  • (E :> T) when from is None,
  • (E : T0 :> T) when from is Some T0.
val pexp_constraint : Astlib.Ast_502.Parsetree.expression -> Astlib.Ast_502.Parsetree.core_type -> Astlib.Ast_502.Parsetree.expression

pexp_constraint constructs an Ast.Pexp_constraint

Example OCaml

(E : T)

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.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
val pexp_while : Astlib.Ast_502.Parsetree.expression -> Astlib.Ast_502.Parsetree.expression -> Astlib.Ast_502.Parsetree.expression

pexp_while constructs an Ast.Pexp_while

Example OCaml

while E1 do E2 done

val pexp_sequence : Astlib.Ast_502.Parsetree.expression -> Astlib.Ast_502.Parsetree.expression -> Astlib.Ast_502.Parsetree.expression

pexp_sequence constructs an Ast.Pexp_sequence

Example OCaml

E1; E2

val pexp_ifthenelse : Astlib.Ast_502.Parsetree.expression -> Astlib.Ast_502.Parsetree.expression -> Astlib.Ast_502.Parsetree.expression option -> Astlib.Ast_502.Parsetree.expression

pexp_ifthenelse constructs an Ast.Pexp_ifthenelse

Example OCaml

if E1 then E2 else E3

val pexp_array : Astlib.Ast_502.Parsetree.expression list -> Astlib.Ast_502.Parsetree.expression

pexp_array constructs an Ast.Pexp_array

Example OCaml

[| E1; ...; En |]

val pexp_setfield : Astlib.Ast_502.Parsetree.expression -> Astlib.Longident.t Astlib.Location.loc -> Astlib.Ast_502.Parsetree.expression -> Astlib.Ast_502.Parsetree.expression

pexp_setfield constructs an Ast.Pexp_setfield

Example OCaml

E1.l <- E2

val pexp_field : Astlib.Ast_502.Parsetree.expression -> Astlib.Longident.t Astlib.Location.loc -> Astlib.Ast_502.Parsetree.expression

pexp_field constructs an Ast.Pexp_field

Example OCaml

E.l

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

val pexp_variant : string -> Astlib.Ast_502.Parsetree.expression option -> Astlib.Ast_502.Parsetree.expression

pexp_variant constructs an Ast.Pexp_variant

Example OCaml

Pexp_variant(`A, exp) represents

  • `A when exp is None
  • `A E when exp is Some 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.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])
val pexp_tuple : Astlib.Ast_502.Parsetree.expression list -> Astlib.Ast_502.Parsetree.expression

pexp_tuple constructs an Ast.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.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.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.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.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.
val pexp_constant : Astlib.Ast_502.Parsetree.constant -> Astlib.Ast_502.Parsetree.expression

pexp_constant constructs an Ast.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

pexp_ident constructs an Ast.Pexp_ident

Example OCaml

Identifiers such as x and M.x

Directive argument

val pdir_bool : bool -> Astlib.Ast_502.Parsetree.directive_argument

pdir_bool constructs an Ast.Pdir_bool

val pdir_ident : Astlib.Longident.t -> Astlib.Ast_502.Parsetree.directive_argument

pdir_ident constructs an Ast.Pdir_ident

val pdir_int : string -> char option -> Astlib.Ast_502.Parsetree.directive_argument

pdir_int constructs an Ast.Pdir_int

val pdir_string : string -> Astlib.Ast_502.Parsetree.directive_argument

pdir_string constructs an Ast.Pdir_string

Core type

val ptyp_extension : (string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) -> Astlib.Ast_502.Parsetree.core_type

ptyp_extension constructs an Ast.Ptyp_extension

Example OCaml

[%id].

val ptyp_open : Astlib.Longident.t Astlib.Location.loc -> Astlib.Ast_502.Parsetree.core_type -> Astlib.Ast_502.Parsetree.core_type

ptyp_open constructs an Ast.Ptyp_open

Example OCaml

M.(T)

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

ptyp_package constructs an Ast.Ptyp_package

Example OCaml

(module S).

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

Example OCaml

'a1 ... 'an. T

Can only appear in the following context:

  • As the core_type of a Ppat_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 a Pctf_method node.
  • As the core_type of a Pexp_poly node.
  • As a core_type of a Ptyp_object node.
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.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"].
val ptyp_alias : Astlib.Ast_502.Parsetree.core_type -> string Astlib.Location.loc -> Astlib.Ast_502.Parsetree.core_type

ptyp_alias constructs an Ast.Ptyp_alias

Example OCaml

T as 'a.

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

Example OCaml

Ptyp_class(tconstr, l) represents:

  • #tconstr when l=[],
  • T #tconstr when l=[T],
  • (T1, ..., Tn) #tconstr when l=[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.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.
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.Ptyp_constr

Example OCaml

Ptyp_constr(lident, l) represents:

  • tconstr when l=[],
  • T tconstr when l=[T],
  • (T1, ..., Tn) tconstr when l=[T1 ; ... ; Tn].
val ptyp_tuple : Astlib.Ast_502.Parsetree.core_type list -> Astlib.Ast_502.Parsetree.core_type

ptyp_tuple constructs an Ast.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.Ptyp_arrow

Example OCaml

Ptyp_arrow(lbl, T1, T2) represents:

  • T1 -> T2 when lbl is Nolabel,
  • ~l:T1 -> T2 when lbl is Labelled,
  • ?l:T1 -> T2 when lbl is Optional.
val ptyp_var : string -> Astlib.Ast_502.Parsetree.core_type

ptyp_var constructs an Ast.Ptyp_var

Example OCaml

A type variable such as 'a

val ptyp_any : Astlib.Ast_502.Parsetree.core_type

ptyp_any constructs an Ast.Ptyp_any

Example OCaml

_

Constructor declaration

Class type field

val pctf_extension : (string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) -> Astlib.Ast_502.Parsetree.class_type_field

pctf_extension constructs an Ast.Pctf_extension

Example OCaml

[%%id]

val pctf_attribute : Astlib.Ast_502.Parsetree.attribute -> Astlib.Ast_502.Parsetree.class_type_field

pctf_attribute constructs an Ast.Pctf_attribute

Example OCaml

[\@\@\@id]

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

Example OCaml

method x: T

Note: T can be a Ptyp_poly.

val pctf_val : (string Astlib.Location.loc * Astlib.Ast_502.Asttypes.mutable_flag * Astlib.Ast_502.Asttypes.virtual_flag * Astlib.Ast_502.Parsetree.core_type) -> Astlib.Ast_502.Parsetree.class_type_field

pctf_val constructs an Ast.Pctf_val

Example OCaml

val x: T

val pctf_inherit : Astlib.Ast_502.Parsetree.class_type -> Astlib.Ast_502.Parsetree.class_type_field

pctf_inherit constructs an Ast.Pctf_inherit

Example OCaml

inherit CT

Class type

val pcty_open : Astlib.Longident.t Astlib.Location.loc Astlib.Ast_502.Parsetree.open_infos -> Astlib.Ast_502.Parsetree.class_type -> Astlib.Ast_502.Parsetree.class_type

pcty_open constructs an Ast.Pcty_open

Example OCaml

let open M in CT

val pcty_extension : (string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) -> Astlib.Ast_502.Parsetree.class_type

pcty_extension constructs an Ast.Pcty_extension

Example OCaml

%id

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

Example OCaml

Pcty_arrow(lbl, T, CT) represents:

  • T -> CT when lbl is Nolabel,
  • ~l:T -> CT when lbl is Labelled l,
  • ?l:T -> CT when lbl is Optional l.
val pcty_signature : Astlib.Ast_502.Parsetree.class_signature -> Astlib.Ast_502.Parsetree.class_type

pcty_signature constructs an Ast.Pcty_signature

Example OCaml

object ... end

val pcty_constr : Astlib.Longident.t Astlib.Location.loc -> Astlib.Ast_502.Parsetree.core_type list -> Astlib.Ast_502.Parsetree.class_type

pcty_constr constructs an Ast.Pcty_constr

Example OCaml

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

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 when pcstr_self is Ppat_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 when pcsig_self is Ptyp_any

Class field

val pcf_extension : (string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) -> Astlib.Ast_502.Parsetree.class_field

pcf_extension constructs an Ast.Pcf_extension

Example OCaml

[%%id]

val pcf_attribute : Astlib.Ast_502.Parsetree.attribute -> Astlib.Ast_502.Parsetree.class_field

pcf_attribute constructs an Ast.Pcf_attribute

Example OCaml

[\@\@\@id]

val pcf_initializer : Astlib.Ast_502.Parsetree.expression -> Astlib.Ast_502.Parsetree.class_field

pcf_initializer constructs an Ast.Pcf_initializer

Example OCaml

initializer E

val pcf_constraint : (Astlib.Ast_502.Parsetree.core_type * Astlib.Ast_502.Parsetree.core_type) -> Astlib.Ast_502.Parsetree.class_field

pcf_constraint constructs an Ast.Pcf_constraint

Example OCaml

constraint T1 = T2

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

Example OCaml

  • method x = E (E can be a Pexp_poly)
  • method virtual x: T (T can be a Ptyp_poly)
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.Pcf_val

Example OCaml

Pcf_val(x,flag, kind) represents:

  • val x = E when flag is Immutable and kind is Cfk_concrete(Fresh, E)
  • val virtual x: T when flag is Immutable and kind is Cfk_virtual(T)
  • val mutable x = E when flag is Mutable and kind is Cfk_concrete(Fresh, E)
  • val mutable virtual x: T when flag is Mutable and kind is Cfk_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.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

val pcl_open : Astlib.Longident.t Astlib.Location.loc Astlib.Ast_502.Parsetree.open_infos -> Astlib.Ast_502.Parsetree.class_expr -> Astlib.Ast_502.Parsetree.class_expr

pcl_open constructs an Ast.Pcl_open

Example OCaml

let open M in CE

val pcl_extension : (string Astlib.Location.loc * Astlib.Ast_502.Parsetree.payload) -> Astlib.Ast_502.Parsetree.class_expr

pcl_extension constructs an Ast.Pcl_extension

Example OCaml

[%id]

val pcl_constraint : Astlib.Ast_502.Parsetree.class_expr -> Astlib.Ast_502.Parsetree.class_type -> Astlib.Ast_502.Parsetree.class_expr

pcl_constraint constructs an Ast.Pcl_constraint

Example OCaml

(CE : CT)

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.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.
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.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.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.
val pcl_structure : Astlib.Ast_502.Parsetree.class_structure -> Astlib.Ast_502.Parsetree.class_expr

pcl_structure constructs an Ast.Pcl_structure

Example OCaml

object ... end

val pcl_constr : Astlib.Longident.t Astlib.Location.loc -> Astlib.Ast_502.Parsetree.core_type list -> Astlib.Ast_502.Parsetree.class_expr

pcl_constr constructs an Ast.Pcl_constr

Example OCaml

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

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

case constructs an Ast.case

Example OCaml

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

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 when popen_override is Override (silences the "used identifier shadowing" warning)
  • open X when popen_override is Fresh

'a include infos

val include_infos : 'a -> 'a Astlib.Ast_502.Parsetree.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.

val eint : int -> Astlib.Ast_502.Parsetree.expression
val echar : char -> Astlib.Ast_502.Parsetree.expression
val estring : string -> Astlib.Ast_502.Parsetree.expression
val efloat : string -> Astlib.Ast_502.Parsetree.expression
val eint32 : int32 -> Astlib.Ast_502.Parsetree.expression
val eint64 : int64 -> Astlib.Ast_502.Parsetree.expression
val enativeint : nativeint -> Astlib.Ast_502.Parsetree.expression
val ebool : bool -> Astlib.Ast_502.Parsetree.expression
val pint : int -> Astlib.Ast_502.Parsetree.pattern
val pchar : char -> Astlib.Ast_502.Parsetree.pattern
val pstring : string -> Astlib.Ast_502.Parsetree.pattern
val pfloat : string -> Astlib.Ast_502.Parsetree.pattern
val pint32 : int32 -> Astlib.Ast_502.Parsetree.pattern
val pint64 : int64 -> Astlib.Ast_502.Parsetree.pattern
val pnativeint : nativeint -> Astlib.Ast_502.Parsetree.pattern
val pbool : bool -> Astlib.Ast_502.Parsetree.pattern
val eunit : Astlib.Ast_502.Parsetree.expression
val punit : Astlib.Ast_502.Parsetree.pattern
val evar : string -> Astlib.Ast_502.Parsetree.expression

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 : string -> Astlib.Ast_502.Parsetree.pattern
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.

val elist : Astlib.Ast_502.Parsetree.expression list -> Astlib.Ast_502.Parsetree.expression

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.

val plist : Astlib.Ast_502.Parsetree.pattern list -> Astlib.Ast_502.Parsetree.pattern

plist ~loc [pat1; pat2; pat3] produces the list pattern [pat1; pat2; pat3].

val pstr_value_list : loc:Ppxlib.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 Ppxlib.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 * Ppxlib.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
  • deprecated [since 2016-10] use Nonrecursive on the P(str|sig)_type instead
val unapplied_type_constr_conv : Ppxlib.Longident.t Ppxlib.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 : Ppxlib.Longident.t Ppxlib.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-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.

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

Compat functions for future AST nodes

The functions in this section provide a safe interface to generate AST nodes that cannot be represented with Ppxlib's own AST but are available with more recent versions of the compiler.

Note that producing such nodes will make the generated code incompatible with compilers older than the feature you are trying to represent. Those nodes also won't play nicely with the driver's default source output or if printed as source using Ppxlib.Pprintast. You can use the --use-compiler-pp flag of the driver to use your current compiler's AST to source printers.

val ppat_effect : Astlib.Ast_502.Parsetree.pattern -> Astlib.Ast_502.Parsetree.pattern -> Astlib.Ast_502.Parsetree.pattern

Returns an encoded effect pattern as introduced in OCaml 5.3

val ptyp_labeled_tuple : (string option * Astlib.Ast_502.Parsetree.core_type) list -> Astlib.Ast_502.Parsetree.core_type

Returns an encoded labeled tuple type as introduced in OCaml 5.4.

val pexp_labeled_tuple : (string option * Astlib.Ast_502.Parsetree.expression) list -> Astlib.Ast_502.Parsetree.expression

Returns an encoded labeled tuple expression as introduced in OCaml 5.4.

val ppat_labeled_tuple : (string option * Astlib.Ast_502.Parsetree.pattern) list -> Astlib.Ast_502.Asttypes.closed_flag -> Astlib.Ast_502.Parsetree.pattern

Returns an encoded labeled tuple pattern as introduced in OCaml 5.4.

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 ppat_construct : Astlib.Longident.t Astlib.Location.loc -> Astlib.Ast_502.Parsetree.pattern option -> Astlib.Ast_502.Parsetree.pattern
val value_binding : pat:Astlib.Ast_502.Parsetree.pattern -> expr:Astlib.Ast_502.Parsetree.expression -> Astlib.Ast_502.Parsetree.value_binding
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