package ppx_core

  1. Overview
  2. Docs

Build Ast helpers with the location argument factorized.

Parameters

Signature

module Located : sig ... end
include sig ... end
val loc : Location.t
val pcl_constr : Ppx_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_404.Parsetree.core_type list -> Migrate_parsetree.Ast_404.Parsetree.class_expr
val pcty_constr : Ppx_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_404.Parsetree.core_type list -> Migrate_parsetree.Ast_404.Parsetree.class_type
val ptyp_constr : Ppx_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_404.Parsetree.core_type list -> Migrate_parsetree.Ast_404.Parsetree.core_type
val ptyp_class : Ppx_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_404.Parsetree.core_type list -> Migrate_parsetree.Ast_404.Parsetree.core_type
val ptyp_package : (Ppx_ast__.Import.Longident.t Location.loc * (Ppx_ast__.Import.Longident.t Location.loc * Migrate_parsetree.Ast_404.Parsetree.core_type) list) -> Migrate_parsetree.Ast_404.Parsetree.core_type
val pexp_ident : Ppx_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_404.Parsetree.expression
val pexp_construct : Ppx_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_404.Parsetree.expression option -> Migrate_parsetree.Ast_404.Parsetree.expression
val pexp_field : Migrate_parsetree.Ast_404.Parsetree.expression -> Ppx_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_404.Parsetree.expression
val pexp_new : Ppx_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_404.Parsetree.expression
val location : start:Lexing.position -> end_:Lexing.position -> ghost:bool -> Warnings.loc
val pmod_ident : Ppx_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_404.Parsetree.module_expr
val pmty_ident : Ppx_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_404.Parsetree.module_type
val pmty_alias : Ppx_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_404.Parsetree.module_type
val module_type_declaration : name:string Location.loc -> type_:Migrate_parsetree.Ast_404.Parsetree.module_type option -> Migrate_parsetree.Ast_404.Parsetree.module_type_declaration
val open_description : lid:Ppx_ast__.Import.Longident.t Location.loc -> override:Migrate_parsetree.Ast_404.Asttypes.override_flag -> Migrate_parsetree.Ast_404.Parsetree.open_description
val ppat_var : string Location.loc -> Migrate_parsetree.Ast_404.Parsetree.pattern
val ppat_construct : Ppx_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_404.Parsetree.pattern option -> Migrate_parsetree.Ast_404.Parsetree.pattern
val ppat_type : Ppx_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_404.Parsetree.pattern
val ppat_unpack : string Location.loc -> Migrate_parsetree.Ast_404.Parsetree.pattern
val ppat_open : Ppx_ast__.Import.Longident.t Location.loc -> Migrate_parsetree.Ast_404.Parsetree.pattern -> Migrate_parsetree.Ast_404.Parsetree.pattern
val position : fname:string -> lnum:int -> bol:int -> cnum:int -> Lexing.position
val value_description : name:string Location.loc -> type_:Migrate_parsetree.Ast_404.Parsetree.core_type -> prim:string list -> Migrate_parsetree.Ast_404.Parsetree.value_description
val eint : Ppx_core__.Import.Int.t -> Migrate_parsetree.Ast_404.Parsetree.expression
val echar : Ppx_core__.Import.Char.t -> Migrate_parsetree.Ast_404.Parsetree.expression
val estring : Ppx_core__.Import.String.t -> Migrate_parsetree.Ast_404.Parsetree.expression
val efloat : Ppx_core__.Import.String.t -> Migrate_parsetree.Ast_404.Parsetree.expression
val eint32 : Ppx_core__.Import.Int32.t -> Migrate_parsetree.Ast_404.Parsetree.expression
val eint64 : Ppx_core__.Import.Int64.t -> Migrate_parsetree.Ast_404.Parsetree.expression
val enativeint : Ppx_core__.Import.Nativeint.t -> Migrate_parsetree.Ast_404.Parsetree.expression
val ebool : Ppx_core__.Import.Bool.t -> Migrate_parsetree.Ast_404.Parsetree.expression
val pint : Ppx_core__.Import.Int.t -> Migrate_parsetree.Ast_404.Parsetree.pattern
val pchar : Ppx_core__.Import.Char.t -> Migrate_parsetree.Ast_404.Parsetree.pattern
val pstring : Ppx_core__.Import.String.t -> Migrate_parsetree.Ast_404.Parsetree.pattern
val pfloat : Ppx_core__.Import.String.t -> Migrate_parsetree.Ast_404.Parsetree.pattern
val pint32 : Ppx_core__.Import.Int32.t -> Migrate_parsetree.Ast_404.Parsetree.pattern
val pint64 : Ppx_core__.Import.Int64.t -> Migrate_parsetree.Ast_404.Parsetree.pattern
val pnativeint : Ppx_core__.Import.Nativeint.t -> Migrate_parsetree.Ast_404.Parsetree.pattern
val pbool : Ppx_core__.Import.Bool.t -> Migrate_parsetree.Ast_404.Parsetree.pattern
val evar : Ppx_core__.Import.String.t -> Migrate_parsetree.Ast_404.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 : Ppx_core__.Import.String.t -> Migrate_parsetree.Ast_404.Parsetree.pattern
val ppat_tuple_opt : Migrate_parsetree.Ast_404.Parsetree.pattern Ppx_core__.Import.List.t -> Migrate_parsetree.Ast_404.Parsetree.pattern Ppx_core__.Import.Option.t
val pexp_tuple_opt : Migrate_parsetree.Ast_404.Parsetree.expression Ppx_core__.Import.List.t -> Migrate_parsetree.Ast_404.Parsetree.expression Ppx_core__.Import.Option.t

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 : Longident.t Loc.t -> f:(Ppx_core__.Import.String.t -> Ppx_core__.Import.String.t) -> Migrate_parsetree.Ast_404.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:(Ppx_core__.Import.String.t -> Ppx_core__.Import.String.t) -> Migrate_parsetree.Ast_404.Parsetree.expression Ppx_core__.Import.List.t -> Migrate_parsetree.Ast_404.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.

OCaml

Innovation. Community. Security.