diff options
Diffstat (limited to 'bin/main.ml')
| -rw-r--r-- | bin/main.ml | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/bin/main.ml b/bin/main.ml index 16daa49..01cdbf8 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -157,6 +157,51 @@ let day_line (d : (Rite_ef.Vocab_ef.season, Rite_ef.Vocab_ef.rank) Colitur_kerne (Colitur_kernel.Colour.to_string cel.Colitur_kernel.Celebration.colour) commemorations +(* The reading citations for a day, as its own row shape rather than extra + columns on [day_line]'s. + + A SEPARATE COMMAND, not a widening of `colitur day`, and the reason is + mechanical rather than aesthetic: a citation contains spaces and commas + ("Ezech 34:11-16", "Ecclus 51:1-8, 12"), while [day_line]'s row is + space-separated with a variable-length "+slug" commemoration tail. + Appending citations there would leave the row unsplittable -- no [awk]/ + [cut] field number could recover where the Epistle ends -- which is the + opposite of the composability the row is shaped for. So `day` keeps its + format byte-identical (nothing downstream of it changes at all) and the + citations get a row whose own fields are " | "-delimited, safe for values + containing spaces. + + This is deliberately a stopgap, and should not be mistaken for the + project's answer to output formatting: the design calls for one schema + rendered through a logic-less template engine (CSV/JSON/S-expression), + which is where this belongs eventually. Two ad-hoc column formats are + easier to retire later than one overloaded format with parsing rules + nobody wrote down. + + "-" for an absent part, matching [temporal_report]'s own [field] + convention for an empty column. On the EF data as it stands no day can + actually print "-" -- {!Colitur_kernel.Validate}'s "citations"/ + "citations-unresolved" checks assert exactly one First and one Gospel on + every day of every year 1583..9999 -- but the CLI must not assume a + guarantee the kernel makes about DATA rather than about types. *) +let readings_line (d : (Rite_ef.Vocab_ef.season, Rite_ef.Vocab_ef.rank) Colitur_kernel.Liturgical_day.t) + = + let cel = d.Colitur_kernel.Liturgical_day.observed in + let part_ref p = + match + List.find_opt + (fun (c : Colitur_kernel.Citation.t) -> c.Colitur_kernel.Citation.part = p) + d.Colitur_kernel.Liturgical_day.citations + with + | Some c -> c.Colitur_kernel.Citation.reference + | None -> "-" + in + Printf.printf "%s %s | %s | %s\n" + (D.to_iso8601 d.Colitur_kernel.Liturgical_day.date) + (Colitur_kernel.Slug.to_string cel.Colitur_kernel.Celebration.slug) + (part_ref Colitur_kernel.Citation.First) + (part_ref Colitur_kernel.Citation.Gospel) + (* One civil year, Jan 1 - Dec 31, matching [temporal_report]'s own scan -- NOT one liturgical year: [Colitur_kernel.Calendar.year] resolves a single Advent-anchored liturgical year, which straddles two civil years, so a @@ -187,7 +232,12 @@ let load_ef_data () = | Error msg -> Error msg | Ok commons -> Ok (layer, lectionary, commons))) -let day_report y = +(* The resolved-year walk, shared by [day_report] and [readings_report]: they + differ only in how each day is printed, and the two-liturgical-year + indexing below (with its own reasoning about civil-vs-liturgical spans) is + exactly the part that must not be duplicated and drift. [line] is the only + difference between the two commands. *) +let resolved_year_report ~line y = match load_ef_data () with | Error msg -> Printf.eprintf "colitur: %s\n" msg; @@ -211,7 +261,7 @@ let day_report y = let d = ref jan1 in while D.compare !d dec31 <= 0 do (match Hashtbl.find_opt by_rata (D.to_rata !d) with - | Some day -> day_line day + | Some day -> line day | None -> (* Unreachable for any [y] in 1583..9999: the two indexed liturgical years jointly cover [year_start (y-1), year_start @@ -227,8 +277,13 @@ let day_report y = d := D.add_days !d 1 done +let day_report y = resolved_year_report ~line:day_line y +let readings_report y = resolved_year_report ~line:readings_line y + let usage () = - prerr_endline "colitur: usage: colitur easter <year> | colitur temporal <year> | colitur day <year>"; + prerr_endline + "colitur: usage: colitur easter <year> | colitur temporal <year> | colitur day <year> | colitur \ + readings <year>"; exit 2 let with_year ys f = @@ -244,4 +299,5 @@ let () = | [| _; "easter"; ys |] -> with_year ys easter_report | [| _; "temporal"; ys |] -> with_year ys temporal_report | [| _; "day"; ys |] -> with_year ys day_report + | [| _; "readings"; ys |] -> with_year ys readings_report | _ -> usage () |
