diff options
| author | Estevan Castilho <tevo@riajuu.net> | 2026-04-29 23:29:54 +0000 |
|---|---|---|
| committer | Estevan Castilho <tevo@riajuu.net> | 2026-04-30 00:05:09 +0000 |
| commit | c6a0b4483e4c2c06c62466d726733b7b26759cec (patch) | |
| tree | dab5d2d6c48e07acbccf163a5c3a329fcd694cd0 | |
| parent | c88ba9ba60e0f6753b3031b0c7dfb0133ea10f06 (diff) | |
| download | Sakura-c6a0b4483e4c2c06c62466d726733b7b26759cec.tar.gz Sakura-c6a0b4483e4c2c06c62466d726733b7b26759cec.zip | |
Some configuration parsing utilities
| -rw-r--r-- | lib/configuration.ml | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/configuration.ml b/lib/configuration.ml index 3f66ac0..f15bb17 100644 --- a/lib/configuration.ml +++ b/lib/configuration.ml @@ -84,3 +84,23 @@ let require_section ~(name : string) ~(valid_tags : string list) (config : t) : if List.mem tag valid_tags then Ok () else errorf "Unknown %s: %s" name tag in Ok (tag, body) + +let map_of_sexp : Sexplib.Sexp.t -> (Sexplib.Sexp.t Utilities.StringMap.t, string) result = + let open Sexplib.Sexp in + let open Utilities.StringMap in + function + | List pairs -> List.fold_right + (fun sexp acc -> + match (sexp, acc) with + | List [ Atom k; v ], Ok acc' -> Ok (add k v acc') + | _, Error e -> Error e + | _ -> Error "Malformed pair") + pairs + (Ok empty) + | _ -> Error "Expected list of pairs" + +let atom_of_sexp : Sexplib.Sexp.t -> (string, string) result = + let open Sexplib.Sexp in + function + | Atom s -> Ok s + | _ -> Error "Expected atom" |
