diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-11 11:54:16 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-11 11:54:16 +0200 |
| commit | 8b6c0036cb6c7f0e48a9370f53be25fd2bb243f4 (patch) | |
| tree | 64fd346b9893fe9870785e3f91e440c952cd237d /lib/kernel/date_spec.ml | |
| parent | 57322e766a0ece579dafcddcfe2572676a98fca8 (diff) | |
| download | colitur-8b6c0036cb6c7f0e48a9370f53be25fd2bb243f4.tar.gz colitur-8b6c0036cb6c7f0e48a9370f53be25fd2bb243f4.zip | |
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).
Diffstat (limited to 'lib/kernel/date_spec.ml')
| -rw-r--r-- | lib/kernel/date_spec.ml | 34 |
1 files changed, 3 insertions, 31 deletions
diff --git a/lib/kernel/date_spec.ml b/lib/kernel/date_spec.ml index 1d0da00..76e21e3 100644 --- a/lib/kernel/date_spec.ml +++ b/lib/kernel/date_spec.ml @@ -1,8 +1,10 @@ +open Sexplib0.Sexp_conv + (* How a sanctoral entry expresses its date. Plan 2 ships the only form the EF sanctoral needs -- a fixed calendar date -- because EF movable feasts come from the rite's temporal code, not from data. Sunday-relative and Easter-relative forms arrive with the OF sanctoral. *) -type t = Fixed of { month : int; day : int } +type t = Fixed of { month : int; day : int } [@@deriving sexp] (* Leap-year maximum, so 29 February is constructible; it simply does not resolve in a common year. *) @@ -21,33 +23,3 @@ let fixed ~month ~day = let resolve t ~year = match t with | Fixed { month; day } -> Result.to_option (Date.make ~year ~month ~day) - -let sexp_of_t = function - | Fixed { month; day } -> - Sexplib0.Sexp.List [ - Sexplib0.Sexp_conv.sexp_of_string "Fixed"; - Sexplib0.Sexp.List [ - Sexplib0.Sexp.List [ - Sexplib0.Sexp_conv.sexp_of_string "month"; - Sexplib0.Sexp_conv.sexp_of_int month - ]; - Sexplib0.Sexp.List [ - Sexplib0.Sexp_conv.sexp_of_string "day"; - Sexplib0.Sexp_conv.sexp_of_int day - ] - ] - ] - -let t_of_sexp sexp = - match sexp with - | Sexplib0.Sexp.List [ - Sexplib0.Sexp.Atom "Fixed"; - Sexplib0.Sexp.List [ - Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "month"; month_sexp ]; - Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "day"; day_sexp ] - ] - ] -> - let month = Sexplib0.Sexp_conv.int_of_sexp month_sexp in - let day = Sexplib0.Sexp_conv.int_of_sexp day_sexp in - Fixed { month; day } - | _ -> Sexplib0.Sexp_conv.of_sexp_error "Date_spec.t_of_sexp: expected Fixed record format" sexp |
