1
1
open Core_kernel
2
2
open Ppxlib
3
- module Conv_to_ppx_deriving =
4
- Migrate_parsetree. Convert (Selected_ast ) (Migrate_parsetree. OCaml_current )
5
- module Conv_from_ppx_deriving =
6
- Migrate_parsetree. Convert (Migrate_parsetree. OCaml_current ) (Selected_ast )
7
3
8
4
let deriver = " register_event"
9
5
10
6
let digest s = Md5. digest_string s |> Md5. to_hex
11
7
12
8
let checked_interpolations_statically ~loc msg label_names =
13
9
match msg with
14
- | { pexp_desc = Pexp_constant (Pconst_string (s , _ )); _ } -> (
10
+ | { pexp_desc = Pexp_constant (Pconst_string (s , _ , _ )); _ } -> (
15
11
(* check that every interpolation point $foo in msg has a matching label;
16
12
OK to have extra labels not mentioned in message
17
13
*)
@@ -107,42 +103,34 @@ let generate_loggers_and_parsers ~loc:_ ~path ty_ext msg_opt =
107
103
let event_name = String. lowercase ctor in
108
104
let event_path = path ^ " ." ^ ctor in
109
105
let split_path = String. split path ~on: '.' in
110
- let to_yojson x =
111
- Conv_from_ppx_deriving. copy_expression
112
- @@ Ppx_deriving_yojson. ser_expr_of_typ
113
- @@ Conv_to_ppx_deriving. copy_core_type x
106
+ let to_yojson = Ppx_deriving_yojson. ser_expr_of_typ
114
107
in
115
- let of_yojson ~path x =
116
- Conv_from_ppx_deriving. copy_expression
117
- @@ Ppx_deriving_yojson. desu_expr_of_typ ~path
118
- @@ Conv_to_ppx_deriving. copy_core_type x
108
+ let of_yojson = Ppx_deriving_yojson. desu_expr_of_typ
119
109
in
120
110
let elist ~f l = elist (List. map ~f l) in
121
111
let record_pattern =
122
- let open Ast_helper.Pat in
123
112
let arg =
124
113
if has_record_arg then
125
114
let fields =
126
115
List. map label_names ~f: (fun label ->
127
116
(Located. mk (Lident label), pvar label) )
128
117
in
129
- Some (record fields Closed )
118
+ Some (ppat_record fields Closed )
130
119
else None
131
120
in
132
- construct (Located. mk (Lident ctor)) arg
121
+ ppat_construct (Located. mk (Lident ctor)) arg
133
122
in
134
123
let record_expr =
135
- let open Ast_helper.Exp in
136
124
let arg =
137
125
if has_record_arg then
138
126
let fields =
139
127
List. map label_names ~f: (fun label ->
140
128
(Located. mk (Lident label), evar label) )
141
129
in
142
- Some (record fields None )
130
+ Some (pexp_record fields None )
143
131
else None
144
132
in
145
- construct (Located. mk (Lident ctor)) arg
133
+ pexp_construct (Located. mk (Lident ctor)) arg
146
134
in
147
135
let stris =
148
136
[ [% stri
@@ -165,9 +153,7 @@ let generate_loggers_and_parsers ~loc:_ ~path ty_ext msg_opt =
165
153
elist label_decls
166
154
~f: (fun { pld_name = { txt = name ; _ } ; pld_type; _ }
167
155
->
168
- Conv_from_ppx_deriving. copy_expression
169
- @@ Ppx_deriving_yojson. wrap_runtime
170
- @@ Conv_to_ppx_deriving. copy_expression
156
+ Ppx_deriving_yojson. wrap_runtime
171
157
@@ [% expr
172
158
[% e estring name]
173
159
, [% e to_yojson pld_type] [% e evar name]] )] )
@@ -182,9 +168,7 @@ let generate_loggers_and_parsers ~loc:_ ~path ty_ext msg_opt =
182
168
[% e
183
169
List. fold_right label_decls
184
170
~f: (fun { pld_name = { txt = name ; _ } ; pld_type; _ } acc ->
185
- Conv_from_ppx_deriving. copy_expression
186
- @@ Ppx_deriving_yojson. wrap_runtime
187
- @@ Conv_to_ppx_deriving. copy_expression
171
+ Ppx_deriving_yojson. wrap_runtime
188
172
@@ [% expr
189
173
match
190
174
Core_kernel.Map. find args_list [% e estring name]
0 commit comments