tangled
alpha
login
or
join now
anil.recoil.org
/
ocaml-tomlt
1
fork
atom
TOML 1.1 codecs for OCaml
1
fork
atom
overview
issues
pulls
pipelines
dead code
anil.recoil.org
1 month ago
31fe302d
a5164358
-52
1 changed file
expand all
collapse all
unified
split
lib
tomlt.ml
-52
lib/tomlt.ml
···
434
434
enc = (fun i -> Toml.String (Int64.to_string i));
435
435
}
436
436
437
437
-
(* ---- Internal datetime codecs (for structured datetime types) ---- *)
438
438
-
(* These are used internally but not exposed in the mli - only ptime codecs are public *)
439
439
-
440
440
-
let datetime_ = {
441
441
-
kind = "datetime";
442
442
-
doc = "";
443
443
-
dec = (function
444
444
-
| Toml.Datetime s ->
445
445
-
Result.map_error (fun msg -> Value_error msg) (Datetime.of_string s)
446
446
-
| v -> type_error ~expected:"datetime" v);
447
447
-
enc = (fun dt -> Toml.Datetime (Datetime.to_string dt));
448
448
-
}
449
449
-
450
450
-
let datetime_local_ = {
451
451
-
kind = "datetime-local";
452
452
-
doc = "";
453
453
-
dec = (function
454
454
-
| Toml.Datetime_local s ->
455
455
-
Result.map_error (fun msg -> Value_error msg) (Datetime_local.of_string s)
456
456
-
| v -> type_error ~expected:"datetime-local" v);
457
457
-
enc = (fun dt -> Toml.Datetime_local (Datetime_local.to_string dt));
458
458
-
}
459
459
-
460
460
-
let date_local_ = {
461
461
-
kind = "date-local";
462
462
-
doc = "";
463
463
-
dec = (function
464
464
-
| Toml.Date_local s ->
465
465
-
Result.map_error (fun msg -> Value_error msg) (Date.of_string s)
466
466
-
| v -> type_error ~expected:"date-local" v);
467
467
-
enc = (fun d -> Toml.Date_local (Date.to_string d));
468
468
-
}
469
469
-
470
470
-
let time_local_ = {
471
471
-
kind = "time-local";
472
472
-
doc = "";
473
473
-
dec = (function
474
474
-
| Toml.Time_local s ->
475
475
-
Result.map_error (fun msg -> Value_error msg) (Time.of_string s)
476
476
-
| v -> type_error ~expected:"time-local" v);
477
477
-
enc = (fun t -> Toml.Time_local (Time.to_string t));
478
478
-
}
479
479
-
480
480
-
(* Silence unused warnings for internal codecs *)
481
481
-
let _ = datetime_
482
482
-
let _ = datetime_local_
483
483
-
let _ = date_local_
484
484
-
let _ = time_local_
485
485
-
486
437
(* ---- Ptime codecs ---- *)
487
438
488
439
(* Helper to get current timezone offset from explicit value or function *)
···
1297
1248
| None -> failwith "any: enc not provided");
1298
1249
}
1299
1250
1300
1300
-
(* ---- Encoding and decoding ---- *)
1301
1301
-
1302
1251
let to_tomlt_error e =
1303
1252
Toml.Error.make (Toml.Error.Semantic (Toml.Error.Duplicate_key (codec_error_to_string e)))
1304
1253
···
1311
1260
1312
1261
let encode c v = c.enc v
1313
1262
1314
1314
-
(* Re-export the Toml module for accessing raw TOML values *)
1315
1263
module Toml = Toml
1316
1264
module Error = Toml.Error