summaryrefslogtreecommitdiff
path: root/lib/kernel/lectionary.ml
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-08-14 16:43:00 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-08-14 16:43:00 +0200
commitbca1a206589bc41bbcb367a7ae9b217c02f0e892 (patch)
treeb5c7ee9972c91bab2da7b888cb64796cd47d934b /lib/kernel/lectionary.ml
parent148729e731370f56a50c3819a7d81808c6e602ca (diff)
downloadcolitur-bca1a206589bc41bbcb367a7ae9b217c02f0e892.tar.gz
colitur-bca1a206589bc41bbcb367a7ae9b217c02f0e892.zip
kernel(lectionary): slug-keyed reading citations
Data only, the same shape and discipline as Layer: slug-canonical, duplicates rejected at construction naming the offending slug, sexp round-trips. Which slug a day falls back to is a rubric and belongs to the rite module, so nothing here knows about ferias or Sundays.
Diffstat (limited to 'lib/kernel/lectionary.ml')
-rw-r--r--lib/kernel/lectionary.ml33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/kernel/lectionary.ml b/lib/kernel/lectionary.ml
new file mode 100644
index 0000000..1da3d1e
--- /dev/null
+++ b/lib/kernel/lectionary.ml
@@ -0,0 +1,33 @@
+open Sexplib0.Sexp_conv
+
+type entry = Slug.t * Citation.t list [@@deriving sexp]
+type t = entry list [@@deriving sexp]
+
+let empty = []
+
+let of_entries es =
+ let sorted = List.stable_sort (fun (a, _) (b, _) -> Slug.compare a b) es in
+ let rec dup = function
+ | (a, _) :: ((b, _) :: _ as rest) ->
+ if Slug.equal a b then Some a else dup rest
+ | _ -> None
+ in
+ match dup sorted with
+ | Some s ->
+ Error (Printf.sprintf "lectionary: duplicate slug %S" (Slug.to_string s))
+ | None -> Ok sorted
+
+let find t s = List.assoc_opt s t
+let mem t s = List.mem_assoc s t
+let entries t = t
+
+let load path =
+ match Sexplib.Sexp.load_sexp path with
+ | exception Sexplib.Sexp.Parse_error e ->
+ Error (Printf.sprintf "lectionary: %s: %s" path e.err_msg)
+ | exception Sys_error e -> Error (Printf.sprintf "lectionary: %s" e)
+ | sexp -> (
+ match t_of_sexp sexp with
+ | exception Sexplib0.Sexp_conv_error.Of_sexp_error (exn, _) ->
+ Error (Printf.sprintf "lectionary: %s: %s" path (Printexc.to_string exn))
+ | parsed -> of_entries parsed)