aboutsummaryrefslogtreecommitdiffstats
path: root/lib/icl/executor.ml
diff options
context:
space:
mode:
authorEstevan Castilho <tevo@riajuu.net>2026-05-27 23:24:12 +0000
committerGitHub <noreply@github.com>2026-05-27 23:24:12 +0000
commit9dc0391443ca16bf1ab3114d002aad83872f8a73 (patch)
treee4f78a2533e5e633b733c1ea21d0159aeca79b75 /lib/icl/executor.ml
parentf9097a0562ea8b40d40a19059578a9280b945de4 (diff)
downloadSakura-9dc0391443ca16bf1ab3114d002aad83872f8a73.tar.gz
Sakura-9dc0391443ca16bf1ab3114d002aad83872f8a73.zip
Improve the error handling situation (#71)
* Sketches of a condition system * `Condition.condition` -> `Condition.t` * Migrate `NT` over * Migrate `Branch` over * Migrate `Sublanguage` et al. over * Migrate the PRL over * Migrate the DRL over * Migrate the DML over * Have `Qualified_name.try_parse` return a `Condition.t` * Migrate the DDL over * Migrate the VCL over * Migrate the SCL over * Migrate the ICL over * Migrate the parsers over * Just inherit the errors from NT and the sublanguages * Migrate `Management.Physical` over * Migrate `Configuration` over * Migrate `Management.Branch` over * Migrate `Transport` over * Migrate `System` over * Migrate `Server` over * Include messages on on all conditions * A prettier stringifier
Diffstat (limited to '')
-rw-r--r--lib/icl/executor.ml31
1 files changed, 9 insertions, 22 deletions
diff --git a/lib/icl/executor.ml b/lib/icl/executor.ml
index 0a77dff..084fb71 100644
--- a/lib/icl/executor.ml
+++ b/lib/icl/executor.ml
@@ -1,31 +1,19 @@
module Make (NT : Nt.S) = struct
- type error =
- | ParseError of string
- | NtError of Nt.error
- | ConversionError of string
- | MultigroupNotFound of string
- | UnqualifiedName of string
-
- let sexp_of_error e =
- let open Sexplib.Sexp in
- match e with
- | ParseError s -> List [ Atom "parse-error"; Atom s ]
- | NtError e -> List [ Atom "nt-error"; Atom (Nt.string_of_error e) ]
- | ConversionError s -> List [ Atom "conversion-error"; Atom s ]
- | MultigroupNotFound s -> List [ Atom "multigroup-not-found"; Atom s ]
- | UnqualifiedName s -> List [ Atom "unqualified-name"; Atom s ]
+ module Error = struct
+ open Condition
+ let multigroup_not_found name = condition "multigroup-not-found" "Multigroup not found" ("name" |=| (of_string name))
+ end
let ( let* ) = Result.bind
- let wrap_nt = Result.map_error (fun e -> NtError e)
- let parse_fqn (s : string) : (Qualified_name.t, error) result =
- Qualified_name.try_parse s |> Result.map_error (fun s -> UnqualifiedName s)
+ let parse_fqn (s : string) : (Qualified_name.t, Condition.t) result =
+ Qualified_name.try_parse s
let lookup_mg (ctx : Sublanguage_context.t) (mg_name : string) :
- (Management.Multigroup.multigroup, error) result =
+ (Management.Multigroup.multigroup, Condition.t) result =
match ctx.branch#mg_of mg_name with
| Some mg -> Ok mg
- | None -> Error (MultigroupNotFound mg_name)
+ | None -> Error (Error.multigroup_not_found mg_name)
let convert_binding_expr : Ast.binding_expr -> Constraint.binding_expr =
function
@@ -52,7 +40,7 @@ module Make (NT : Nt.S) = struct
Constraint.forall ~variable ~quantifier (convert_body body)
let execute (ctx : Sublanguage_context.t) (stmt : Ast.statement) :
- (Sublanguage_types.transition_delta * string, error) result =
+ (Sublanguage_types.transition_delta * string, Condition.t) result =
match stmt with
| Ast.RegisterConstraint { constraint_name; relation_name; body } ->
let* fqn = parse_fqn relation_name in
@@ -61,7 +49,6 @@ module Make (NT : Nt.S) = struct
let* _bh, new_mg =
NT.register_constraint ctx.write_handle mg
~constraint_name ~relation_name:fqn.name ~body:runtime_body
- |> wrap_nt
in
ctx.branch#set_mg ~name:fqn.mg new_mg;
Ok ([ (fqn.mg, new_mg) ], "Constraint registered: " ^ constraint_name)