diff options
| author | Estevan Castilho <tevo@riajuu.net> | 2026-09-17 01:52:58 +0000 |
|---|---|---|
| committer | Estevan Castilho <tevo@riajuu.net> | 2026-09-17 01:52:58 +0000 |
| commit | 4a172f7bc032d9d0e16fa446f1f5e19cc4feb0fe (patch) | |
| tree | e2c1bd4b467ee0bc383067ea700ca8333f4989fa /lib/kernel/Path.ml | |
| parent | 9af4d05d98ce64c30a65a21131a2ff4037d7651a (diff) | |
| parent | 2ec420d1542ea64978bdd4666a51ec4959f648b7 (diff) | |
| download | RNT-4a172f7bc032d9d0e16fa446f1f5e19cc4feb0fe.tar.gz RNT-4a172f7bc032d9d0e16fa446f1f5e19cc4feb0fe.zip | |
Merge branch 'master' into evaluator
Diffstat (limited to 'lib/kernel/Path.ml')
| -rw-r--r-- | lib/kernel/Path.ml | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/lib/kernel/Path.ml b/lib/kernel/Path.ml index 803d8cf..629a527 100644 --- a/lib/kernel/Path.ml +++ b/lib/kernel/Path.ml @@ -3,15 +3,44 @@ type t = string list let this = [] let (@/) x y = x::y -let rec lookup handle = function - | [] -> Ok (Some handle) - | x::xs -> - let open Utilities.Result in - let open Protocols in - match Protocols.Directory.from handle with - | None -> Ok None - | Some dir -> - let* elem = Directory.find dir x in - match elem with - | None -> Ok None - | Some elem -> lookup elem xs +let to_string path = + path + |> List.map (fun x -> + let str = BatString.replace ~str:x ~sub:"^" ~by:"^^" |> snd in + BatString.replace ~str ~sub:"/" ~by:"^/" |> snd) + |> BatIO.to_string (BatList.print ~first:"/" ~last:"" ~sep:"/" BatString.print) + +module Error = struct + open Concepts.Condition + + let path_not_found path = condition "path-not-found" "A given path was not found under the specified object" + ("path" |=| Concepts.Value.String (to_string path)) + + let not_a_registry path = condition "not-a-registry" "The specified path did not point to a registry" + ("path" |=| Concepts.Value.String (to_string path)) + + let not_a_directory path = condition "not-a-directory" "The specified path did not point to a directory" + ("path" |=| Concepts.Value.String (to_string path)) +end + +let lookup handle path = + let rec walk handle = function + | [] -> Ok handle + | x::xs -> + let open Utilities.Result in + let open Protocols in + match Directory.from handle with + | None -> Error (Error.path_not_found path) + | Some dir -> + let* elem = Directory.find dir x in + match elem with + | None -> Error (Error.not_a_directory path) + | Some elem -> walk elem xs + in + walk handle path + +let update handle path key reference value = + let open Utilities.Result in + let* handle = lookup handle path in + let* registry = Protocols.Registry.from handle |> Option.to_result ~none:(Error.not_a_registry path) in + Protocols.Registry.update registry key reference value |
