Skip to content

Commit

Permalink
Add parsing of integer constraints in YAML violation_sequence-s
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Nov 22, 2024
1 parent 6498145 commit 0ca1bb3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/util/std/gobYaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ let list = function
let entries = function
| `O assoc -> Ok assoc
| _ -> Error (`Msg "Failed to get entries from non-object value")

let int i = float (float_of_int i)
26 changes: 23 additions & 3 deletions src/witness/yamlWitnessType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -447,15 +447,35 @@ struct

module Constraint =
struct

module Value =
struct
type t =
| String of string
| Int of int (* Why doesn't format consider ints (for switch branches) as strings here, like everywhere else? *)
[@@deriving ord]

let to_yaml = function
| String s -> GobYaml.string s
| Int i -> GobYaml.int i

let of_yaml y =
let open GobYaml in
match y with
| `String s -> Ok (String s)
| `Float f -> Ok (Int (int_of_float f))
| _ -> Error (`Msg "Expected a string or integer value")
end

type t = {
value: string;
value: Value.t;
format: string option;
}
[@@deriving ord]

let to_yaml {value; format} =
`O ([
("value", `String value);
("value", Value.to_yaml value);
] @ (match format with
| Some format -> [
("format", `String format);
Expand All @@ -466,7 +486,7 @@ struct

let of_yaml y =
let open GobYaml in
let+ value = y |> find "value" >>= to_string
let+ value = y |> find "value" >>= Value.of_yaml
and+ format = y |> Yaml.Util.find "format" >>= option_map to_string in
{value; format}
end
Expand Down

0 comments on commit 0ca1bb3

Please sign in to comment.