File tree 2 files changed +25
-3
lines changed
2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -44,3 +44,5 @@ let list = function
44
44
let entries = function
45
45
| `O assoc -> Ok assoc
46
46
| _ -> Error (`Msg " Failed to get entries from non-object value" )
47
+
48
+ let int i = float (float_of_int i)
Original file line number Diff line number Diff line change @@ -447,15 +447,35 @@ struct
447
447
448
448
module Constraint =
449
449
struct
450
+
451
+ module Value =
452
+ struct
453
+ type t =
454
+ | String of string
455
+ | Int of int (* Why doesn't format consider ints (for switch branches) as strings here, like everywhere else? *)
456
+ [@@ deriving ord ]
457
+
458
+ let to_yaml = function
459
+ | String s -> GobYaml. string s
460
+ | Int i -> GobYaml. int i
461
+
462
+ let of_yaml y =
463
+ let open GobYaml in
464
+ match y with
465
+ | `String s -> Ok (String s)
466
+ | `Float f -> Ok (Int (int_of_float f))
467
+ | _ -> Error (`Msg " Expected a string or integer value" )
468
+ end
469
+
450
470
type t = {
451
- value : string ;
471
+ value : Value .t ;
452
472
format : string option ;
453
473
}
454
474
[@@ deriving ord ]
455
475
456
476
let to_yaml {value; format} =
457
477
`O ([
458
- (" value" , `String value);
478
+ (" value" , Value. to_yaml value);
459
479
] @ (match format with
460
480
| Some format -> [
461
481
(" format" , `String format);
@@ -466,7 +486,7 @@ struct
466
486
467
487
let of_yaml y =
468
488
let open GobYaml in
469
- let + value = y |> find " value" >> = to_string
489
+ let + value = y |> find " value" >> = Value. of_yaml
470
490
and + format = y |> Yaml.Util. find " format" >> = option_map to_string in
471
491
{value; format}
472
492
end
You can’t perform that action at this time.
0 commit comments