diff options
| author | Estevan Castilho <tevo@riajuu.net> | 2026-05-23 01:13:06 +0000 |
|---|---|---|
| committer | Estevan Castilho <tevo@riajuu.net> | 2026-05-23 01:13:06 +0000 |
| commit | 7933c52af71162080aa01ed7055c8b70fe023cd8 (patch) | |
| tree | e4f78a2533e5e633b733c1ea21d0159aeca79b75 | |
| parent | db3198d7c5ad7bc60bd24bd1bb2c7b122a6dfbd0 (diff) | |
| download | Sakura-7933c52af71162080aa01ed7055c8b70fe023cd8.tar.gz Sakura-7933c52af71162080aa01ed7055c8b70fe023cd8.zip | |
A prettier stringifiererror-handling
| -rw-r--r-- | lib/condition.ml | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/condition.ml b/lib/condition.ml index 9c98df0..44ef2ff 100644 --- a/lib/condition.ml +++ b/lib/condition.ml @@ -1,10 +1,12 @@ class type serializable = object method as_sexp : Sexplib.Sexp.t + method as_string : string end class literal (expr : Sexplib.Sexp.t) : serializable = object method as_sexp = expr + method as_string = Sexplib.Sexp.to_string_hum expr end let of_sexp (expr : Sexplib.Sexp.t) = new literal expr @@ -32,10 +34,16 @@ let empty = (fun p -> p) let to_sexp { name; message; properties } = let open Sexplib.Sexp in let properties' = - BatMap.to_seq properties + properties + |> BatMap.to_seq |> BatSeq.map (fun (k, v) -> List [Atom k; v#as_sexp]) |> BatList.of_seq in List (Atom name :: Atom message :: properties') -let to_string e = (* FIXME *) - Sexplib.Sexp.to_string_hum (to_sexp e) +let to_string { name; message; properties } = + let properties' = + properties + |> BatMap.to_seq + |> BatSeq.to_string ~sep:"\n" (fun (k, v) -> "\t" ^ k ^ ": " ^ v#as_string) + in + name ^ ": " ^ message ^ properties' |
