From 320954996e921d7b34eb61f462799b5c6ab8ee09 Mon Sep 17 00:00:00 2001 From: Marcos Magueta Date: Sat, 26 Sep 2026 22:09:11 -0300 Subject: new shrunk API for RNT on sakura --- lib/configuration.ml | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'lib/configuration.ml') diff --git a/lib/configuration.ml b/lib/configuration.ml index af1635f..420dff6 100644 --- a/lib/configuration.ml +++ b/lib/configuration.ml @@ -1,10 +1,11 @@ module type CONFIGURABLE = sig type configuration - val parse : Sexplib.Sexp.t -> (configuration, Condition.t) result + val parse : Sexplib.Sexp.t -> (configuration, Condition.condition) result end module Error = struct + (* open Condition let unknown_section key = @@ -15,12 +16,12 @@ module Error = struct let empty_section key = condition "empty-section" "Empty configuration section (expected a tagged value)" - ("key" |=| of_string key) + ("key" |=| Value.String key) let multiple_values_in_section key = condition "multiple-values-in-section" "Configuration section contains multiple values (expected exactly one)" - ("key" |=| of_string key) + ("key" |=| Value.String key) let invalid_toplevel toplevel = condition "invalid-toplevel" "Configuration must be a (server ...) s-expression" @@ -31,29 +32,33 @@ module Error = struct ("expression" |=| of_sexp expr) let missing_section name = - condition "missing-section" "Missing section in configuration" ("name" |=| of_string name) + condition "missing-section" "Missing section in configuration" ("name" |=| Value.String name) let invalid_tag section tag valid_options = condition "invalid-tag" "Invalid tag for section" - ( "section" |=| of_string section - & "tag" |=| of_string tag - & "valid-options" |=| of_list of_string valid_options ) + ( "section" |=| Value.String section + & "tag" |=| Value.String tag + & "valid-options" |=| of_list Value.String valid_options ) let failed_to_load_file path msg = condition "failed-to-load-file" "Failed to load configuration file" - ("path" |=| of_string path & "message" |=| of_string msg) + ("path" |=| Value.String path & "message" |=| Value.String msg) let syntax_error path msg = condition "syntax-error" "Failed to parse configuration file" - ("path" |=| of_string path & "message" |=| of_string msg) + ("path" |=| Value.String path & "message" |=| Value.String msg) + *) + end +(* + (** Section name -> raw sexp subtree. *) type t = Sexplib.Sexp.t Utilities.StringMap.t let find_section (key : string) (config : t) : Sexplib.Sexp.t option = Utilities.StringMap.find_opt key config - +( (** Check that [key] is expected and not duplicate, then add it. *) let insert_section ~expected acc key body = let ( let* ) = Result.bind in @@ -109,3 +114,4 @@ let require_section ~(name : string) ~(valid_tags : string list) (config : t) : if List.mem tag valid_tags then Ok () else Error (Error.invalid_tag name tag valid_tags) in Ok (tag, body) + *) -- cgit v1.2.3