package ppx_hegel_compat

  1. Overview
  2. Docs
Internal ppxlib AST shim shared by Hegel's PPX packages

Install

dune-project
 Dependency

Authors

Maintainers

Sources

hegel-0.16.0-opam.tar.gz
md5=d9f942e6f52eebae812a7de84ca8925c
sha512=07516c2970feebd58c10d4ad0390dbc9ab083f94b46b11ab4be6ddd162105dd52ab992f22042efb32595fe7ff5ee0b956c3f6a7af4b8b817865681724edc6426

doc/ppx_hegel_compat/Ppx_compat/index.html

Module Ppx_compatSource

Platform compatibility shim for ppxlib types.

On OxCaml, ppxlib's AST types differ from standard OCaml (labeled tuples, constructor modalities, etc.). This module abstracts over those differences so the PPX deriver can work on both platforms.

Sourceval extract_tuple_types : Ppxlib.core_type -> Ppxlib.core_type list option

extract_tuple_types ct returns Some types if ct is a tuple type, None otherwise. On OxCaml, strips the optional labels from labeled tuples.

Sourcetype constr_args =
  1. | Tuple of Ppxlib.core_type list
    (*

    Positional arguments (C of t1 * t2).

    *)
  2. | Record of Ppxlib.label_declaration list
    (*

    Inline-record arguments (C of { f : t }).

    *)

Constructor arguments with a uniform representation on every platform.

Sourceval extract_constr_args : Ppxlib.constructor_arguments -> constr_args

extract_constr_args args converts constructor_arguments to constr_args. On OxCaml, extracts the core types from constructor_argument records.

map_constr_arg_types f args applies f to each argument core type of args, in both the tuple and the inline-record form.

Sourceval sexp_of_str_type_decl : loc:Ppxlib.Location.t -> path:string -> (Ppxlib.rec_flag * Ppxlib.type_declaration list) -> Ppxlib.structure

sexp_of_str_type_decl ~loc ~path decls emits sexp_of_<t> definitions for decls through ppx_sexp_conv's expander. On OxCaml, fills the extra mode arguments (unboxed/stackify/portable/localize) with false.

Sourceval extract_expr_tuple : Ppxlib.expression -> Ppxlib.expression list option

extract_expr_tuple e returns Some es if e is a tuple expression, None otherwise. On OxCaml, strips the optional labels from labeled tuples.

Sourceval unwrap_pattern_constraint : Ppxlib.pattern -> Ppxlib.pattern option

unwrap_pattern_constraint pat returns Some inner if pat is a type-constraint pattern ((p : ty)), None otherwise. On OxCaml, Ppat_constraint carries an extra modes argument.

Sourceval expr_first_param_pat : Ppxlib.expression -> Ppxlib.pattern option

expr_first_param_pat e returns Some pat for the pattern of the first value parameter of a function expression e (fun pat … -> …), or None if e is not a function or has no value parameter. Abstracts over the OxCaml Pexp_function/standard Pexp_fun split.

peel_fun_params e strips the leading value-parameter lambdas of e and returns the function body, or e unchanged when it is not such a function.

Sourceval is_function_expr : Ppxlib.expression -> bool

is_function_expr e is true when e is a function literal (fun … -> … or function …).

Sourceval extract_let_bindings : Ppxlib.expression -> Ppxlib.value_binding list option

extract_let_bindings e returns Some vbs if e is a let … in … expression, None otherwise. On OxCaml, Pexp_let carries an extra mutable_flag.

map_let_value_bindings f e rewrites the bindings of a let … in … expression e with f, preserving every other field (recursion flag, body, and the OxCaml-only mutable_flag); returns e unchanged if it is not a let.