package ppx_hegel_compat

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file ppx_compat.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
open Ppxlib

let extract_tuple_types ct =
  match ct.ptyp_desc with
  | Ptyp_tuple cts -> Some cts
  | _ -> None
;;

let extract_constr_tuple_types = function
  | Pcstr_tuple cts -> Some cts
  | Pcstr_record _ -> None
;;

let extract_expr_tuple e =
  match e.pexp_desc with
  | Pexp_tuple es -> Some es
  | _ -> None
;;

let unwrap_pattern_constraint pat =
  match pat.ppat_desc with
  | Ppat_constraint (inner, _) -> Some inner
  | _ -> None
;;

let expr_first_param_pat e =
  match e.pexp_desc with
  | Pexp_function (params, _, _) ->
    List.find_map
      (fun param ->
         match param.pparam_desc with
         | Pparam_val (_, _, pat) -> Some pat
         | Pparam_newtype _ -> None)
      params
  | _ -> None
;;

let rec peel_fun_params e =
  match e.pexp_desc with
  | Pexp_function (_, _, Pfunction_body body) -> peel_fun_params body
  | _ -> e
;;

let is_function_expr e =
  match e.pexp_desc with
  | Pexp_function _ -> true
  | _ -> false
;;

let extract_let_bindings e =
  match e.pexp_desc with
  | Pexp_let (_, vbs, _) -> Some vbs
  | _ -> None
;;

let map_let_value_bindings f e =
  match e.pexp_desc with
  | Pexp_let (rec_flag, vbs, body) ->
    { e with pexp_desc = Pexp_let (rec_flag, f vbs, body) }
  | _ -> e
;;