From 8b6c0036cb6c7f0e48a9370f53be25fd2bb243f4 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Tue, 11 Aug 2026 11:54:16 +0200 Subject: kernel: fix sexp deriving, add missing tests, canonicalize remove Use [@@deriving sexp] with open Sexplib0.Sexp_conv instead of hand-rolling converters (fixes non-standard Citation shape and missing field validation). Names.t_of_sexp wraps derived version to enforce canonical sort on load. Add tests: - Names of_list duplicate handling - Names sexp canonical sort guarantee (identical serialization) - Names and Date_spec sexp roundtrips Fix Names.remove to canonicalize output (defensive against non-canonical input). --- lib/kernel/citation.ml | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'lib/kernel/citation.ml') diff --git a/lib/kernel/citation.ml b/lib/kernel/citation.ml index a819040..4485958 100644 --- a/lib/kernel/citation.ml +++ b/lib/kernel/citation.ml @@ -1,3 +1,5 @@ +open Sexplib0.Sexp_conv + (* Scripture references only -- never scripture text (spec ยง1: that is lectio's job). *) type part = First | Psalm | Second | Gospel | Tract | Alleluia | Sequence @@ -14,20 +16,4 @@ let part_of_string = function | "gospel" -> Some Gospel | "tract" -> Some Tract | "alleluia" -> Some Alleluia | "sequence" -> Some Sequence | _ -> None -type t = { part : part; reference : string } - -let sexp_of_t { part; reference } = - Sexplib0.Sexp.List [ - Sexplib0.Sexp_conv.sexp_of_string "part"; - sexp_of_part part; - Sexplib0.Sexp_conv.sexp_of_string "reference"; - Sexplib0.Sexp_conv.sexp_of_string reference - ] - -let t_of_sexp sexp = - match sexp with - | Sexplib0.Sexp.List [ _; part_sexp; _; ref_sexp ] -> - let part = part_of_sexp part_sexp in - let reference = Sexplib0.Sexp_conv.string_of_sexp ref_sexp in - { part; reference } - | _ -> Sexplib0.Sexp_conv.of_sexp_error "Citation.t_of_sexp: expected record format" sexp +type t = { part : part; reference : string } [@@deriving sexp] -- cgit v1.3