fix: address code review findings for public API

This commit is contained in:
2026-10-23 16:38:24 +02:00
committed by owenrees
parent 4f50ff020e
commit 16fcaa3b13
13 changed files with 161 additions and 104 deletions
+17 -9
View File
@@ -5,23 +5,31 @@ open Yojson.Safe.Util
let path_key path_moves = String.concat " " path_moves
let parse_diagrams_json diagrams_json_str =
let fail () = raise Exit in
try
let json = Yojson.Safe.from_string diagrams_json_str in
let diagrams_list = to_list json in
List.fold_left
(fun acc item ->
let fen = item |> member "fen" |> to_string in
let acc =
match item |> member "ply" with
| `Int ply ->
{ acc with Ast.by_ply = MoveMap.add ply fen acc.Ast.by_ply }
| _ -> acc
let fields = match item with `Assoc fields -> fields | _ -> fail () in
let fen =
match List.assoc_opt "fen" fields with
| Some (`String fen) -> fen
| _ -> fail ()
in
match item |> member "path" with
| `List path_items ->
let acc =
match List.assoc_opt "ply" fields with
| None -> acc
| Some (`Int ply) ->
{ acc with Ast.by_ply = MoveMap.add ply fen acc.Ast.by_ply }
| Some _ -> fail ()
in
match List.assoc_opt "path" fields with
| None -> acc
| Some (`List path_items) ->
let key = path_items |> List.map to_string |> path_key in
{ acc with Ast.by_path = PathMap.add key fen acc.Ast.by_path }
| _ -> acc)
| Some _ -> fail ())
Ast.empty_diagrams diagrams_list
with _ -> Ast.empty_diagrams
+4 -4
View File
@@ -33,11 +33,11 @@ let build_author_string author white black white_elo black_elo =
(* Title string builder *)
let build_title_string event title subtitle =
match (event, title, subtitle) with
| event, "", "" -> "\\title{" ^ escape_tex event ^ "}"
| _event, title, "" -> "\\title{" ^ escape_tex title ^ "}"
| event, "", "" -> "\\title{" ^ event ^ "}"
| _event, "", subtitle -> "\\title{" ^ subtitle ^ "}"
| _event, title, "" -> "\\title{" ^ title ^ "}"
| _event, title, subtitle ->
"\\title{" ^ escape_tex title ^ "\\\\[2ex]\\large{" ^ escape_tex subtitle
^ "}}"
"\\title{" ^ title ^ "\\\\[2ex]\\large{" ^ subtitle ^ "}}"
(* Date and Site string builder *)
let build_date_site_string date site =