aboutsummaryrefslogtreecommitdiffstats
path: root/lib/condition.ml
diff options
context:
space:
mode:
authorEstevan Castilho <tevo@riajuu.net>2026-05-21 00:28:51 +0000
committerEstevan Castilho <tevo@riajuu.net>2026-05-21 00:29:27 +0000
commit8c56a2250888c529fd14cf97c07317776bb0690d (patch)
treedddabd442832421d3e207816b9c1e49f3f203a8b /lib/condition.ml
parentf9097a0562ea8b40d40a19059578a9280b945de4 (diff)
downloadSakura-8c56a2250888c529fd14cf97c07317776bb0690d.tar.gz
Sakura-8c56a2250888c529fd14cf97c07317776bb0690d.zip
Sketches of a condition system
Diffstat (limited to 'lib/condition.ml')
-rw-r--r--lib/condition.ml32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/condition.ml b/lib/condition.ml
new file mode 100644
index 0000000..72eb773
--- /dev/null
+++ b/lib/condition.ml
@@ -0,0 +1,32 @@
+
+class type serializable = object
+ method as_sexp : Sexplib.Sexp.t
+end
+
+class literal (expr : Sexplib.Sexp.t) : serializable = object
+ method as_sexp = expr
+end
+
+let of_sexp (expr : Sexplib.Sexp.t) = new literal expr
+let of_string (s : string) = new literal (Sexplib.Sexp.Atom s)
+
+type condition = { name : string; properties : (string, serializable) BatMap.t }
+
+let condition name ?parent props =
+ { name;
+ properties =
+ parent
+ |> Option.map (fun { properties; _ } -> properties)
+ |> Option.value ~default:BatMap.empty
+ |> props }
+
+let ( |=| ) name value = (fun p -> BatMap.add name value p)
+let ( & ) l r = (fun p -> r (l p))
+
+let to_sexp { name; properties } =
+ let open Sexplib.Sexp in
+ let properties' =
+ BatMap.to_seq properties
+ |> BatSeq.map (fun (k, v) -> List [Atom k; v#as_sexp])
+ |> BatList.of_seq in
+ List (Atom name :: properties')