Declarative JSON data manipulation for OCaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocaml-json: drop "_map_" infix from kinded_sort helpers

The [object_map_kinded_sort], [array_map_kinded_sort], and
[any_map_kinded_sort] helpers were needlessly verbose: the argument
type already carries "map", so the function name only needs to
distinguish which GADT variant it specialises on.

Rename to [object_kinded_sort], [array_kinded_sort], and
[any_kinded_sort]. No behaviour change; call sites in json.ml and
json_bytesrw.ml updated.

Also tighten nearby docstrings flagged by merlint E410:

- [object_meta_arg] now has a real one-line description instead of a
half-written "holds the ... to" fragment.
- [Error.sort] / [Error.kinded_sort] wrap their bodies in the [name
args] form so the doc tool can match doc-to-signature.

+22 -21
+1 -1
lib/bytesrw/json_bytesrw.ml
··· 272 272 273 273 let err_unclosed_object d (map : ('o, 'o) Json.Codec.object_map) = 274 274 err_here d "Unclosed %a" Json.Codec.pp_kind 275 - (Json.Codec.object_map_kinded_sort map) 275 + (Json.Codec.object_kinded_sort map) 276 276 277 277 (* Decode next character in d.u *) 278 278
+11 -11
lib/codec.ml
··· 188 188 | Rec l -> with_doc ?kind ?doc (Lazy.force l) 189 189 | Ignore -> Ignore 190 190 191 - let object_map_kinded_sort (map : ('o, 'dec) object_map) = 191 + let object_kinded_sort (map : ('o, 'dec) object_map) = 192 192 Sort.kinded ~kind:map.kind Object 193 193 194 194 let rec kinded_sort : type a. a t -> string = function ··· 196 196 | Bool map -> Sort.kinded ~kind:map.kind Bool 197 197 | Number map -> Sort.kinded ~kind:map.kind Number 198 198 | String map -> Sort.kinded ~kind:map.kind String 199 - | Array map -> array_map_kinded_sort map 200 - | Object map -> object_map_kinded_sort map 201 - | Any map -> if map.kind = "" then any_map_kinded_sort map else map.kind 199 + | Array map -> array_kinded_sort map 200 + | Object map -> object_kinded_sort map 201 + | Any map -> if map.kind = "" then any_kinded_sort map else map.kind 202 202 | Map map -> if map.kind = "" then kinded_sort map.dom else map.kind 203 203 | Rec l -> kinded_sort (Lazy.force l) 204 204 | Ignore -> "ignore" 205 205 206 - and array_map_kinded_sort : type a e b. (a, e, b) array_map -> string = 206 + and array_kinded_sort : type a e b. (a, e, b) array_map -> string = 207 207 fun map -> 208 208 if map.kind <> "" then Sort.kinded ~kind:map.kind Array 209 209 else 210 210 let elt = kinded_sort map.elt in 211 211 String.concat "" [ "array<"; elt; ">" ] 212 212 213 - and any_map_kinded_sort : type a. a any_map -> string = 213 + and any_kinded_sort : type a. a any_map -> string = 214 214 fun map -> 215 215 let add_case ks sort = function 216 216 | None -> ks ··· 257 257 let pp_kind = Fmt.code 258 258 259 259 let error_push_object meta map name e = 260 - Error.push_object (object_map_kinded_sort map, meta) name e 260 + Error.push_object (object_kinded_sort map, meta) name e 261 261 262 262 let error_push_array meta map i e = 263 - Error.push_array (array_map_kinded_sort map, meta) i e 263 + Error.push_array (array_kinded_sort map, meta) i e 264 264 265 265 let type_error meta t ~fnd = Error.kinded_sort meta ~exp:(kinded_sort t) ~fnd 266 266 267 267 let missing_mems_error meta (object_map : ('o, 'o) object_map) ~exp ~fnd = 268 - let kinded_sort = object_map_kinded_sort object_map in 268 + let kinded_sort = object_kinded_sort object_map in 269 269 let exp = 270 270 let add n (Mem_dec m) acc = 271 271 match m.dec_absent with None -> n :: acc | Some _ -> acc ··· 275 275 Error.missing_mems meta ~kinded_sort ~exp ~fnd 276 276 277 277 let unexpected_mems_error meta (object_map : ('o, 'o) object_map) ~fnd = 278 - let kinded_sort = object_map_kinded_sort object_map in 278 + let kinded_sort = object_kinded_sort object_map in 279 279 let exp = List.map (fun (Mem_enc m) -> m.name) object_map.mem_encs in 280 280 Error.unexpected_mems meta ~kinded_sort ~exp ~fnd 281 281 282 282 let unexpected_case_tag_error meta object_map object_cases tag = 283 - let kinded_sort = object_map_kinded_sort object_map in 283 + let kinded_sort = object_kinded_sort object_map in 284 284 let case_to_string (Case c) = 285 285 match object_cases.tag_to_string with 286 286 | None -> None
+7 -6
lib/codec.mli
··· 264 264 val kind : 'a t -> string 265 265 (** [kind t] is the kind of the underlying map, see {!Json.kind}. *) 266 266 267 - val array_map_kinded_sort : ('a, 'elt, 'builder) array_map -> string 268 - (** [array_map_kinded_sort map] is like {!kinded_sort} but acts directly on the 267 + val array_kinded_sort : ('a, 'elt, 'builder) array_map -> string 268 + (** [array_kinded_sort map] is like {!kinded_sort} but acts directly on the 269 269 array [map]. *) 270 270 271 - val object_map_kinded_sort : ('o, 'dec) object_map -> string 272 - (** [object_map_kind map] is like {!kinded_sort} but acts directly on the object 273 - [map]. *) 271 + val object_kinded_sort : ('o, 'dec) object_map -> string 272 + (** [object_kinded_sort map] is like {!kinded_sort} but acts directly on the 273 + object [map]. *) 274 274 275 275 val pp_kind : string Fmt.t 276 276 (** [pp_kind] formats kinds. *) ··· 319 319 (** {1:toolbox Processor toolbox} *) 320 320 321 321 val object_meta_arg : Meta.t Type.Id.t 322 - (** [object_meta_arg] holds the {!Json.Object.mem} to *) 322 + (** [object_meta_arg] is the type identifier used to thread an object's 323 + {!Meta.t} through an object map decode via {!Dict.t}. *) 323 324 324 325 (** Heterogeneous dictionaries. *) 325 326 module Dict : sig
+2 -2
lib/error.mli
··· 44 44 val expected : Loc.Meta.t -> string -> fnd:string -> 'a 45 45 46 46 val sort : Loc.Meta.t -> exp:Sort.t -> fnd:Sort.t -> 'a 47 - (** Raises [Sort_mismatch]. *) 47 + (** [sort meta ~exp ~fnd] raises [Sort_mismatch]. *) 48 48 49 49 val kinded_sort : Loc.Meta.t -> exp:string -> fnd:Sort.t -> 'a 50 - (** Raises [Kinded_sort_mismatch]. *) 50 + (** [kinded_sort meta ~exp ~fnd] raises [Kinded_sort_mismatch]. *) 51 51 52 52 val missing_mems : 53 53 Loc.Meta.t -> kinded_sort:string -> exp:string list -> fnd:string list -> 'a
+1 -1
lib/json.ml
··· 1228 1228 match cases.tag.dec_absent with 1229 1229 | Some tag -> decode_case_tag map meta tag delay [] 1230 1230 | None -> 1231 - let kinded_sort = Codec.object_map_kinded_sort map in 1231 + let kinded_sort = Codec.object_kinded_sort map in 1232 1232 Error.missing_mems meta ~kinded_sort ~exp:[ cases.tag.name ] 1233 1233 ~fnd:(List.map (fun ((n, _), _) -> n) delay)) 1234 1234 | ((((n, meta) as nm), v) as mem) :: mems -> (