Skip to content

Commit d4a6aa3

Browse files
Merge pull request #27 from kit-ty-kate/410
Support ppxlib 0.9.0 (+ OCaml 4.10 for free)
2 parents a814c05 + 6857f29 commit d4a6aa3

7 files changed

Lines changed: 28 additions & 30 deletions

ppx/ppx_protocol_conv.ml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,11 @@ let location_of_attrib t name (attribs:attributes) =
8686
let prefix = module_name t.driver in
8787
let has_name s = String.equal s name || String.equal s (sprintf "%s.%s" prefix name) in
8888
List.find_map_exn
89-
~f:(function ({ loc=_; txt}, Parsetree.PStr [{pstr_loc; _}]) when has_name txt -> Some pstr_loc
89+
~f:(function {attr_name = {txt; _}; attr_payload = Parsetree.PStr [{pstr_loc; _}]; _} when has_name txt -> Some pstr_loc
9090
| _ -> None
9191
) attribs
9292

93-
let row_loc = function
94-
| Rtag (sloc, _, _, _) -> sloc.loc
95-
| Rinherit typ -> typ.ptyp_loc
93+
let row_loc row = row.prf_loc
9694

9795
let get_variant_name t row =
9896
match Attribute.get t.variant_name row, Attribute.get t.variant_key row with
@@ -132,9 +130,9 @@ let test_constructor_mapping t constrs =
132130

133131
let test_row_mapping t rows =
134132
let base, mapped = List.partition_map ~f:(fun row ->
135-
let (row_name, attrs) = match row with
133+
let (row_name, attrs) = match row.prf_desc with
136134
| Rinherit _ -> raise_errorf "Inherited polymorphic variant types not supported"
137-
| Rtag (name, attrs, _, _) -> name, attrs
135+
| Rtag (name, _, _) -> name, row.prf_attributes
138136
in
139137
match get_variant_name t row with
140138
| Some name when String.equal row_name.txt name -> `Fst name
@@ -248,7 +246,7 @@ and serialize_variant t ~loc type_ ~name ~alias pcstr =
248246
let f_name = { loc; txt = sprintf "_%s_of_record_" name } in
249247
let lhs = ppat_constr ~loc name (Some patt) in
250248
let rhs = pexp_apply ~loc (pexp_ident_string_loc f_name) [Nolabel, pexp_tuple ~loc (List.map ~f:snd args)] in
251-
let binding = value_binding ~loc ~pat:{ppat_desc = Ppat_var f_name; ppat_loc = loc; ppat_attributes=[]} ~expr:f in
249+
let binding = value_binding ~loc ~pat:{ppat_desc = Ppat_var f_name; ppat_loc = loc; ppat_attributes=[]; ppat_loc_stack=[]} ~expr:f in
252250
binding, case ~lhs ~guard:None ~rhs
253251
| Pcstr_tuple core_types ->
254252
let f_name = { loc; txt = sprintf "_%s_of_tuple" name } in
@@ -261,7 +259,7 @@ and serialize_variant t ~loc type_ ~name ~alias pcstr =
261259
[%e estring ~loc alias] Protocol_conv.Runtime.Tuple_out.([%e spec])
262260
]
263261
in
264-
let binding = value_binding ~loc ~pat:{ppat_desc = Ppat_var f_name; ppat_loc = loc; ppat_attributes=[]} ~expr:f in
262+
let binding = value_binding ~loc ~pat:{ppat_desc = Ppat_var f_name; ppat_loc = loc; ppat_attributes=[]; ppat_loc_stack=[]} ~expr:f in
265263

266264
let lhs = ppat_constr ~loc name (mk_pattern core_types) in
267265
let args =
@@ -331,9 +329,9 @@ and serialize_expr_of_type_descr t ~loc = function
331329
| Ptyp_variant (rows, _closed, None) ->
332330
test_row_mapping t rows;
333331
let bindings, cases =
334-
List.map ~f:(function
332+
List.map ~f:(fun row -> match row.prf_desc with
335333
| Rinherit _ -> raise_errorf ~loc "Inherited types not supported"
336-
| Rtag (name, _attributes, _bool, core_types) as row ->
334+
| Rtag (name, _bool, core_types) ->
337335
let alias = match get_variant_name t row with
338336
| Some key -> key
339337
| None -> name.txt
@@ -510,9 +508,9 @@ and deserialize_expr_of_type_descr t ~loc = function
510508

511509
| Ptyp_variant (rows, _closed, None) ->
512510
test_row_mapping t rows;
513-
let mk_elem = function
511+
let mk_elem row = match row.prf_desc with
514512
| Rinherit _ -> raise_errorf ~loc "Inherited variant types not supported"
515-
| Rtag (name, _attributes, _bool, core_types) as row ->
513+
| Rtag (name, _bool, core_types) ->
516514
let ser_name = match get_variant_name t row with
517515
| Some key -> key
518516
| None -> name.txt
@@ -602,8 +600,8 @@ let rec is_recursive_ct types = function
602600
| { ptyp_desc = Ptyp_class _; _} -> false
603601
| { ptyp_desc = Ptyp_alias (c, _); _} -> is_recursive_ct types c
604602
| { ptyp_desc = Ptyp_variant (rows, _, _); _} ->
605-
List.exists ~f:(function
606-
| Rtag (_, _, _, cts) -> List.exists ~f:(is_recursive_ct types) cts
603+
List.exists ~f:(fun row -> match row.prf_desc with
604+
| Rtag (_, _, cts) -> List.exists ~f:(is_recursive_ct types) cts
607605
| Rinherit _ -> false
608606
) rows
609607
| { ptyp_desc = Ptyp_poly (_, ct); _} -> is_recursive_ct types ct

ppx_protocol_conv.opam

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ build: [
1111
]
1212
depends: [
1313
"ocaml" {>= "4.04"}
14-
"base" {< "v0.13"}
14+
"base"
1515
"dune" {>= "1.2"}
16-
"ppxlib" {>= "0.3.0" & < "0.9.0"}
17-
"ppx_sexp_conv" {with-test & < "v0.13"}
18-
"sexplib" {with-test & < "v0.13"}
16+
"ppxlib" {>= "0.9.0"}
17+
"ppx_sexp_conv" {with-test}
18+
"sexplib" {with-test}
1919
"alcotest" {with-test & >= "0.8.0"}
2020
]
2121
synopsis:

ppx_protocol_conv_json.opam

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ depends: [
1414
"ppx_protocol_conv" {= version}
1515
"yojson" {>= "1.5.0" & < "2.0.0"}
1616
"dune" {>= "1.2"}
17-
"ppx_expect" {< "v0.13"}
18-
"ppx_inline_test" {< "v0.13"}
19-
"ppx_sexp_conv" {with-test & < "v0.13"}
20-
"sexplib" {with-test & < "v0.13"}
17+
"ppx_expect"
18+
"ppx_inline_test"
19+
"ppx_sexp_conv" {with-test}
20+
"sexplib" {with-test}
2121
"alcotest" {with-test & >= "0.8.0"}
2222
]
2323
synopsis: "Json driver for Ppx_protocol_conv"

ppx_protocol_conv_jsonm.opam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ depends: [
1414
"ppx_protocol_conv" {= version}
1515
"ezjsonm"
1616
"dune" {>= "1.2"}
17-
"ppx_sexp_conv" {with-test & < "v0.13"}
18-
"sexplib" {with-test & < "v0.13"}
17+
"ppx_sexp_conv" {with-test}
18+
"sexplib" {with-test}
1919
"alcotest" {with-test & >= "0.8.0"}
2020
]
2121
synopsis: "Jsonm driver for Ppx_protocol_conv"

ppx_protocol_conv_msgpack.opam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ depends: [
1414
"ppx_protocol_conv" {= version}
1515
"msgpck"
1616
"dune" {>= "1.2"}
17-
"ppx_sexp_conv" {with-test & < "v0.13"}
18-
"sexplib" {with-test & < "v0.13"}
17+
"ppx_sexp_conv" {with-test}
18+
"sexplib" {with-test}
1919
"alcotest" {with-test & >= "0.8.0"}
2020
]
2121
synopsis: "MessagePack driver for Ppx_protocol_conv"

ppx_protocol_conv_xml_light.opam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ depends: [
1414
"ppx_protocol_conv" {= version}
1515
"xml-light"
1616
"dune" {>= "1.2"}
17-
"ppx_sexp_conv" {with-test & < "v0.13"}
18-
"sexplib" {with-test & < "v0.13"}
17+
"ppx_sexp_conv" {with-test}
18+
"sexplib" {with-test}
1919
"alcotest" {with-test & >= "0.8.0"}
2020
]
2121
synopsis: "Xml driver for Ppx_protocol_conv"

ppx_protocol_conv_yaml.opam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ depends: [
1414
"dune" {>= "1.2"}
1515
"ppx_protocol_conv" {= version}
1616
"yaml" { >= "2.0.0"}
17-
"ppx_sexp_conv" {with-test & < "v0.13"}
18-
"sexplib" {with-test & < "v0.13"}
17+
"ppx_sexp_conv" {with-test}
18+
"sexplib" {with-test}
1919
"alcotest" {with-test & >= "0.8.0"}
2020
]
2121
synopsis: "Json driver for Ppx_protocol_conv"

0 commit comments

Comments
 (0)