My aggregated monorepo of OCaml code, automaintained
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Squashed 'ocaml-tomlt/' changes from 83f4ef93..31fe302d

31fe302d dead code
a5164358 clean up comparison operator

git-subtree-dir: ocaml-tomlt
git-subtree-split: 31fe302da4642a46361be4ef6b3b347ee820a549

+12 -73
+12 -73
lib/tomlt.ml
··· 56 56 else kind ^ " " ^ to_string sort 57 57 end 58 58 59 - (* ---- Helpers ---- *) 60 - 61 - (* Result syntax for cleaner monadic chaining *) 62 - module Result_syntax = struct 63 - let ( let* ) = Result.bind 64 - let ( let+ ) r f = Result.map f r 65 - end 66 - 67 - (* Chain comparisons: return first non-zero, or final comparison *) 68 - let ( <?> ) c lazy_c = if c <> 0 then c else Lazy.force lazy_c 59 + let ( <?> ) c c' = if c <> 0 then c else c' 69 60 70 61 (* Find first char matching predicate *) 71 62 let string_index_opt p s = ··· 102 93 | UTC, Offset _ -> -1 103 94 | Offset _, UTC -> 1 104 95 | Offset { hours = h1; minutes = m1 }, Offset { hours = h2; minutes = m2 } -> 105 - Int.compare h1 h2 <?> lazy (Int.compare m1 m2) 96 + Int.compare h1 h2 <?> Int.compare m1 m2 106 97 107 98 let to_string = function 108 99 | UTC -> "Z" ··· 136 127 137 128 let compare a b = 138 129 Int.compare a.year b.year 139 - <?> lazy (Int.compare a.month b.month) 140 - <?> lazy (Int.compare a.day b.day) 130 + <?> Int.compare a.month b.month 131 + <?> Int.compare a.day b.day 141 132 142 133 let to_string d = Printf.sprintf "%04d-%02d-%02d" d.year d.month d.day 143 134 ··· 171 162 172 163 let compare a b = 173 164 Int.compare a.hour b.hour 174 - <?> lazy (Int.compare a.minute b.minute) 175 - <?> lazy (Int.compare a.second b.second) 176 - <?> lazy (Float.compare a.frac b.frac) 165 + <?> Int.compare a.minute b.minute 166 + <?> Int.compare a.second b.second 167 + <?> Float.compare a.frac b.frac 177 168 178 169 (* Remove trailing zeros from a string, keeping at least one char *) 179 170 let rstrip_zeros s = ··· 221 212 222 213 let compare a b = 223 214 Date.compare a.date b.date 224 - <?> lazy (Time.compare a.time b.time) 225 - <?> lazy (Tz.compare a.tz b.tz) 215 + <?> Time.compare a.time b.time 216 + <?> Tz.compare a.tz b.tz 226 217 227 218 let to_string dt = 228 219 Printf.sprintf "%sT%s%s" ··· 233 224 let pp fmt dt = Format.pp_print_string fmt (to_string dt) 234 225 235 226 let of_string s = 236 - let open Result_syntax in 227 + let open Result.Syntax in 237 228 match find_datetime_sep s with 238 229 | None -> Error "missing date/time separator" 239 230 | Some idx -> ··· 266 257 let equal a b = Date.equal a.date b.date && Time.equal a.time b.time 267 258 268 259 let compare a b = 269 - Date.compare a.date b.date <?> lazy (Time.compare a.time b.time) 260 + Date.compare a.date b.date <?> Time.compare a.time b.time 270 261 271 262 let to_string dt = 272 263 Printf.sprintf "%sT%s" (Date.to_string dt.date) (Time.to_string dt.time) ··· 274 265 let pp fmt dt = Format.pp_print_string fmt (to_string dt) 275 266 276 267 let of_string s = 277 - let open Result_syntax in 268 + let open Result.Syntax in 278 269 match find_datetime_sep s with 279 270 | None -> Error "missing date/time separator" 280 271 | Some idx -> ··· 442 433 | v -> type_error ~expected:"string" v); 443 434 enc = (fun i -> Toml.String (Int64.to_string i)); 444 435 } 445 - 446 - (* ---- Internal datetime codecs (for structured datetime types) ---- *) 447 - (* These are used internally but not exposed in the mli - only ptime codecs are public *) 448 - 449 - let datetime_ = { 450 - kind = "datetime"; 451 - doc = ""; 452 - dec = (function 453 - | Toml.Datetime s -> 454 - Result.map_error (fun msg -> Value_error msg) (Datetime.of_string s) 455 - | v -> type_error ~expected:"datetime" v); 456 - enc = (fun dt -> Toml.Datetime (Datetime.to_string dt)); 457 - } 458 - 459 - let datetime_local_ = { 460 - kind = "datetime-local"; 461 - doc = ""; 462 - dec = (function 463 - | Toml.Datetime_local s -> 464 - Result.map_error (fun msg -> Value_error msg) (Datetime_local.of_string s) 465 - | v -> type_error ~expected:"datetime-local" v); 466 - enc = (fun dt -> Toml.Datetime_local (Datetime_local.to_string dt)); 467 - } 468 - 469 - let date_local_ = { 470 - kind = "date-local"; 471 - doc = ""; 472 - dec = (function 473 - | Toml.Date_local s -> 474 - Result.map_error (fun msg -> Value_error msg) (Date.of_string s) 475 - | v -> type_error ~expected:"date-local" v); 476 - enc = (fun d -> Toml.Date_local (Date.to_string d)); 477 - } 478 - 479 - let time_local_ = { 480 - kind = "time-local"; 481 - doc = ""; 482 - dec = (function 483 - | Toml.Time_local s -> 484 - Result.map_error (fun msg -> Value_error msg) (Time.of_string s) 485 - | v -> type_error ~expected:"time-local" v); 486 - enc = (fun t -> Toml.Time_local (Time.to_string t)); 487 - } 488 - 489 - (* Silence unused warnings for internal codecs *) 490 - let _ = datetime_ 491 - let _ = datetime_local_ 492 - let _ = date_local_ 493 - let _ = time_local_ 494 436 495 437 (* ---- Ptime codecs ---- *) 496 438 ··· 1306 1248 | None -> failwith "any: enc not provided"); 1307 1249 } 1308 1250 1309 - (* ---- Encoding and decoding ---- *) 1310 - 1311 1251 let to_tomlt_error e = 1312 1252 Toml.Error.make (Toml.Error.Semantic (Toml.Error.Duplicate_key (codec_error_to_string e))) 1313 1253 ··· 1320 1260 1321 1261 let encode c v = c.enc v 1322 1262 1323 - (* Re-export the Toml module for accessing raw TOML values *) 1324 1263 module Toml = Toml 1325 1264 module Error = Toml.Error