diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-20 15:13:37 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-20 15:13:37 +0200 |
| commit | ec70286daa72fd2a2a78a1cbab0fe2c268e5c743 (patch) | |
| tree | 99f515e44b88778360be599c5d987e458a58718a /lib/citation | |
| parent | a2cbb6b85e79fbc59b0879362c0f853757d51c07 (diff) | |
| download | colitur-ec70286daa72fd2a2a78a1cbab0fe2c268e5c743.tar.gz colitur-ec70286daa72fd2a2a78a1cbab0fe2c268e5c743.zip | |
feat(citation): default_spelling, and close two test gaps
Book.default_spelling returns the first registered spelling for an id. It
is the fallback display name, and it exists because the alternative is
worse: a language file's [bible] lookup is total and returns THE KEY on a
miss, so a book with no entry would render as "luke.abbr 5:12-14".
Falling back to the data's own spelling makes it render as "Luke
5:12-14" instead -- what colitur printed before this feature existed.
The degraded case is the old behaviour, the same principle Lang states
for its own key-returning misses.
Two test gaps closed, both found by mutation rather than by reading:
Parse's split_book scans a leading ordinal digit over '1'..'4', and no
case in the suite used an ordinal above 1. Narrowing the range to
'1'..'3' passed every test while seven real citations depend on it
("3 Kings 17:8-16", "4 Kings 5:1-15"). Parse-layer cases added; the
first attempt at this test asserted through Book.of_token, which is a
table lookup and never reaches split_book at all.
default_spelling is asserted to round-trip: every cited id's fallback
spelling must itself resolve back to that id, or Render and Parse
disagree the moment a book goes unnamed.
Diffstat (limited to 'lib/citation')
| -rw-r--r-- | lib/citation/book.ml | 5 | ||||
| -rw-r--r-- | lib/citation/book.mli | 19 |
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/citation/book.ml b/lib/citation/book.ml index 545e324..2a2b9c0 100644 --- a/lib/citation/book.ml +++ b/lib/citation/book.ml @@ -78,6 +78,11 @@ let all = List.map fst table @ tradition_targets let tokens = List.concat_map (fun (id, sp) -> List.map (fun s -> (s, id)) sp) table +let default_spelling id = + match List.assoc_opt id table with + | Some (first :: _) -> first + | Some [] | None -> id + let of_token s = let s = String.trim s in List.assoc_opt s tokens diff --git a/lib/citation/book.mli b/lib/citation/book.mli index 8918bc3..0ca229c 100644 --- a/lib/citation/book.mli +++ b/lib/citation/book.mli @@ -36,6 +36,25 @@ val all : id list (** Every accepted spelling paired with its id. *) val tokens : (string * id) list +(** The first spelling registered for an id -- the form the shipped data + itself uses ([luke] -> ["Luke"], [kings_3] -> ["3 Kings"]). + + This is the FALLBACK display name, and it exists because the obvious + alternative is actively worse. A language file's [\[bible\]] lookup is + total and returns THE KEY on a miss, so a book with no entry would + otherwise render as ["luke.abbr 5:12-14"]. Falling back here instead makes + an unnamed book render as ["Luke 5:12-14"] -- exactly what colitur printed + before this feature existed. The degraded case is the OLD behaviour, not a + broken page, the same principle {!Colitur_naming.Lang} states for its own + key-returning misses. + + An id with no registered spelling -- only a {!tradition} target such as + [kings_1] or [sirach], which the Vulgate data never cites -- returns the id + itself. Reachable only from a user language file that selects a tradition + without naming its target books; every SHIPPED language file is asserted + complete over {!all}. *) +val default_spelling : id -> string + (** A numbering tradition: which book an id denotes. Separate from NAMING (what a book is called), which lives in a language file's [\[bible\]] section, because naming varies by language and this does not -- "modern |
