Skip to content

Commit 0ca1bb3

Browse files
committed
Add parsing of integer constraints in YAML violation_sequence-s
1 parent 6498145 commit 0ca1bb3

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/util/std/gobYaml.ml

+2
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ let list = function
4444
let entries = function
4545
| `O assoc -> Ok assoc
4646
| _ -> Error (`Msg "Failed to get entries from non-object value")
47+
48+
let int i = float (float_of_int i)

src/witness/yamlWitnessType.ml

+23-3
Original file line numberDiff line numberDiff line change
@@ -447,15 +447,35 @@ struct
447447

448448
module Constraint =
449449
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+
450470
type t = {
451-
value: string;
471+
value: Value.t;
452472
format: string option;
453473
}
454474
[@@deriving ord]
455475

456476
let to_yaml {value; format} =
457477
`O ([
458-
("value", `String value);
478+
("value", Value.to_yaml value);
459479
] @ (match format with
460480
| Some format -> [
461481
("format", `String format);
@@ -466,7 +486,7 @@ struct
466486

467487
let of_yaml y =
468488
let open GobYaml in
469-
let+ value = y |> find "value" >>= to_string
489+
let+ value = y |> find "value" >>= Value.of_yaml
470490
and+ format = y |> Yaml.Util.find "format" >>= option_map to_string in
471491
{value; format}
472492
end

0 commit comments

Comments
 (0)