(** Parser for validator/tests/messages.json *) type t = (string, string) Hashtbl.t (** Maps test file path to expected error message *) let json_string = function | Jsont.String (s, _) -> s | _ -> failwith "Expected string" let json_object = function | Jsont.Object (obj, _) -> obj | _ -> failwith "Expected object" let load path = let messages = Hashtbl.create 4096 in let ic = open_in path in let content = really_input_string ic (in_channel_length ic) in close_in ic; (* Parse JSON *) let json = match Jsont_bytesrw.decode_string Jsont.json content with | Ok j -> j | Error e -> failwith (Printf.sprintf "JSON parse error: %s" e) in let obj = json_object json in List.iter (fun ((key, _), value) -> let msg = json_string value in Hashtbl.replace messages key msg ) obj; messages let get messages path = Hashtbl.find_opt messages path let count messages = Hashtbl.length messages