OCaml codecs for the Citation File Format (CFF)
1(*---------------------------------------------------------------------------
2 Copyright (c) 2026 The ocaml-cff programmers. All rights reserved.
3 SPDX-License-Identifier: ISC
4 ---------------------------------------------------------------------------*)
5
6(** Identifier type for CFF. *)
7
8type t =
9 { type_ : Cff_enums.Identifier_type.t
10 ; value : string
11 ; description : string option
12 }
13
14let make ~type_ ~value ?description () = { type_; value; description }
15let type_ t = t.type_
16let value t = t.value
17let description t = t.description
18
19let equal a b =
20 Cff_enums.Identifier_type.equal a.type_ b.type_ && String.equal a.value b.value
21;;
22
23let compare a b =
24 match Cff_enums.Identifier_type.compare a.type_ b.type_ with
25 | 0 -> String.compare a.value b.value
26 | n -> n
27;;
28
29let pp ppf t = Format.fprintf ppf "%a: %s" Cff_enums.Identifier_type.pp t.type_ t.value
30
31let jsont =
32 Jsont.Object.map ~kind:"Identifier" (fun type_ value description ->
33 { type_; value; description })
34 |> Jsont.Object.mem "type" Cff_enums.Identifier_type.jsont ~enc:(fun i -> i.type_)
35 |> Jsont.Object.mem "value" Jsont.string ~enc:(fun i -> i.value)
36 |> Jsont.Object.opt_mem "description" Jsont.string ~enc:(fun i -> i.description)
37 |> Jsont.Object.skip_unknown
38 |> Jsont.Object.finish
39;;