summaryrefslogtreecommitdiff
path: root/lib/kernel/citation.ml
blob: a819040f568684ff1afa62c2c7f57895f8048d99 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(* Scripture references only -- never scripture text (spec §1: that is lectio's
   job). *)
type part = First | Psalm | Second | Gospel | Tract | Alleluia | Sequence
[@@deriving sexp]

let all_parts = [ First; Psalm; Second; Gospel; Tract; Alleluia; Sequence ]

let part_to_string = function
  | First -> "first" | Psalm -> "psalm" | Second -> "second" | Gospel -> "gospel"
  | Tract -> "tract" | Alleluia -> "alleluia" | Sequence -> "sequence"

let part_of_string = function
  | "first" -> Some First | "psalm" -> Some Psalm | "second" -> Some Second
  | "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