Skip to content

Commit

Permalink
move to deserialize_any
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries committed Mar 1, 2024
1 parent c167f91 commit 993d221
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion derive/de.ml
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ module Record_deserializer = struct
Ast.case ~lhs:invalid_tag_lhs ~guard:None
~rhs:
[%expr
let* () = skip_field ctx in
let* () = ignore_any ctx in
read_fields ()];
Ast.case
~lhs:
Expand Down
8 changes: 4 additions & 4 deletions derive/ppx.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
let* v = field ctx "rank_scores" (d (list string))
in (rank_scores := (Some v); read_fields ())
| Some `invalid_tag ->
let* () = skip_field ctx
let* () = ignore_any ctx
in read_fields ()
| None -> Ok () in
let* () = read_fields ()
Expand Down Expand Up @@ -273,7 +273,7 @@
let* v = field ctx "name" string
in (name := (Some v); read_fields ())
| Some `invalid_tag ->
let* () = skip_field ctx
let* () = ignore_any ctx
in read_fields ()
| None -> Ok () in
let* () = read_fields ()
Expand Down Expand Up @@ -373,7 +373,7 @@
let* v = field ctx "stuff" (d (list (d deserialize_t)))
in (stuff := (Some v); read_fields ())
| Some `invalid_tag ->
let* () = skip_field ctx
let* () = ignore_any ctx
in read_fields ()
| None -> Ok () in
let* () = read_fields ()
Expand Down Expand Up @@ -545,7 +545,7 @@ Now we test the variants:
let* v = field ctx "name" string
in (name := (Some v); read_fields ())
| Some `invalid_tag ->
let* () = skip_field ctx
let* () = ignore_any ctx
in read_fields ()
| None -> Ok () in
let* () = read_fields ()
Expand Down
11 changes: 6 additions & 5 deletions serde/serde.ml
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ module rec De_base : sig
val deserialize_option :
state ctx -> state -> ('value, state) t -> ('value option, error) result

val skip_field : state ctx -> state -> (unit, error) result
val deserialize_ignored_any : state ctx -> state -> (unit, error) result
end

type 'state deserializer = (module Deserializer with type state = 'state)
Expand Down Expand Up @@ -584,7 +584,7 @@ end = struct
val deserialize_option :
state ctx -> state -> ('value, state) t -> ('value option, error) result

val skip_field : state ctx -> state -> (unit, error) result
val deserialize_ignored_any : state ctx -> state -> (unit, error) result
end

type 'state deserializer = (module Deserializer with type state = 'state)
Expand Down Expand Up @@ -691,8 +691,9 @@ module De = struct
de =
D.deserialize_option ctx state de

let skip_field (type state) (((module D), state) as ctx : state ctx) =
D.skip_field ctx state
let deserialize_ignored_any (type state)
(((module D), state) as ctx : state ctx) =
D.deserialize_ignored_any ctx state

let record ctx name size de = deserialize_record ctx name size de

Expand Down Expand Up @@ -732,7 +733,7 @@ module De = struct
let* list = list de ctx in
Ok (Array.of_list list)

let skip_field ctx = skip_field ctx
let ignore_any ctx = deserialize_ignored_any ctx

let d (type state) de ((((module D) as self), state) : state ctx) =
let state = D.nest state in
Expand Down
3 changes: 2 additions & 1 deletion serde/serde_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ module Serde_bin = struct
Visitor.visit_variant self visitor

(* TODO: Could probably test this but I don't think it's worth it? *)
let skip_field _ _ = failwith "Should not be called in this test"
let deserialize_ignored_any _ _ =
failwith "Should not be called in this test"
end

let to_string ser value =
Expand Down
5 changes: 1 addition & 4 deletions serde_json/serde_json.ml
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ module Deserializer = struct
Parser.skip_space s.reader;
De.deserialize self de

(* TODO: ME GO BACK AND DO THIS SMARTER THAN THIS *)
let skip_field self s =
let _, _ = (self, s) in
let deserialize_ignored_any self s =
Parser.skip_space s.reader;
match Parser.peek s.reader with
| Some '}' -> Ok ()
Expand Down Expand Up @@ -335,7 +333,6 @@ module Deserializer = struct
Parser.skip_space s.reader;
Ok ()
| None -> failwith "unexpected eof"
(* failwith "IN THE SKIP FIELD" *)
end

let to_string ser value =
Expand Down

0 comments on commit 993d221

Please sign in to comment.