package ppx_deriving_rpc

  1. Overview
  2. Docs

Module CommonSource

Sourceval list_assoc_find_exn : ('a * 'b) list -> equal:('c -> 'a -> bool) -> 'c -> 'b
Sourceval list_assoc_mem : ('a * 'b) list -> equal:('c -> 'a -> bool) -> 'c -> bool
Sourceval string_concat : ?sep:string -> string list -> string
Sourceval string_split_on_chars : string -> on:Char.t list -> string list
Sourceval is_whitespace : char -> bool
Sourceval string_strip : ?drop:(char -> bool) -> string -> string
Sourceval list_partition_tf : 'a list -> f:('a -> bool) -> 'a list * 'a list
Sourceval core_types : Ppxlib.location -> (string * Ppxlib_ast.Ast.expression) list

Many of the following functions are lifted from ppx_deriving. It's quite likely that there are good alternatives to these somewhere in ppxlib, but I've not yet found them.

They are used to deal with parameterised types. When declaring a function derived from a parameterised type, the function will be extended to take an argument for each type parameter. The important functions below are `poly_fun_of_type_decl` and `poly_apply_of_type_decl` - for declaring and using the derived functions respectively.

Sourceval fold_right_type_params : (string -> 'a -> 'a) -> (Ppxlib.core_type * 'b) list -> 'a -> 'a
Sourceval fold_right_type_decl : (string -> 'a -> 'a) -> Ppxlib.type_declaration -> 'a -> 'a

fold_right_type_decl fn accum type_ performs a right fold over all type variable (i.e. not wildcard) parameters in type_.

Sourceval poly_fun_of_type_decl : loc:Ppxlib__.Location.t -> Ppxlib.type_declaration -> Ppxlib__.Import.expression -> Ppxlib__.Import.expression

poly_fun_of_type_decl type_ expr wraps expr into fun poly_N -> ... for every type parameter 'N present in type_. For example, if type_ refers to type ('a, 'b) map, expr will be wrapped into fun poly_a poly_b -> [%e expr].

Sourceval fold_left_type_params : ('a -> string -> 'a) -> 'a -> (Ppxlib.core_type * 'b) list -> 'a
Sourceval fold_left_type_decl : ('a -> string -> 'a) -> 'a -> Ppxlib.type_declaration -> 'a

fold_left_type_decl fn accum type_ performs a left fold over all type variable (i.e. not wildcard) parameters in type_.

Sourceval poly_apply_of_type_decl : loc:Ppxlib__.Location.t -> Ppxlib.type_declaration -> Astlib.Ast_500.Parsetree.expression -> Astlib.Ast_500.Parsetree.expression

poly_apply_of_type_decl type_ expr wraps expr into expr poly_N for every type parameter 'N present in type_. For example, if type_ refers to type ('a, 'b) map, expr will be wrapped into [%e expr] poly_a poly_b. _ parameters are ignored.

Sourceval expr_of_option : loc:Ppxlib.location -> Ppxlib_ast.Ast.expression option -> Ppxlib_ast.Ast.expression

expr_of_option ~loc o turns an optional expression into an expression of an optional value. In several places there are optional attributes, e.g. @@version foo, which end up as values of type `expression option`. These are often turned into optional values in the generated code.

Sourcemodule Attrs : sig ... end

Typed attribute getters

Sourceval attr : Ppxlib__.Location.t -> String.t -> Ppxlib.attribute list -> string option
Sourceval split : string -> string list
Sourceval convert_doc : string -> string list
Sourceval get_doc : loc:Ppxlib__.Location.t -> Ppxlib__.Import.expression option -> Ppxlib.attributes -> Ppxlib__.Import.expression

get_doc loc rpcdoc attrs extracts documentation from the type declarations. rpcdoc is the result of looking for @doc tags. If this is found, we use that. If not, we look for ocamldoc docstrings and return them instead. In both cases, the result is an expression of type list