aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-09-09 22:15:35 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-09-11 01:10:27 -0300
commit8baa58d7683b092d9e27e35d46a6b9ecb61fa4ab (patch)
tree55fc96570bbdc1f65ef451ed64b1f53a1725942b /lib/kernel
parent8e5643db833c769f7f0a6fdf30959eec2b37eb47 (diff)
downloadRNT-8baa58d7683b092d9e27e35d46a6b9ecb61fa4ab.tar.gz
RNT-8baa58d7683b092d9e27e35d46a6b9ecb61fa4ab.zip
path utilities on kernel for lookup on registry
Diffstat (limited to '')
-rw-r--r--lib/kernel/Path.ml28
-rw-r--r--lib/kernel/Path.mli2
2 files changed, 17 insertions, 13 deletions
diff --git a/lib/kernel/Path.ml b/lib/kernel/Path.ml
index 803d8cf..cd51efb 100644
--- a/lib/kernel/Path.ml
+++ b/lib/kernel/Path.ml
@@ -1,17 +1,21 @@
-type t = string list
+type t = string BatFingerTree.t
-let this = []
-let (@/) x y = x::y
+let this = BatFingerTree.empty
-let rec lookup handle = function
- | [] -> Ok (Some handle)
- | x::xs ->
- let open Utilities.Result in
- let open Protocols in
+let of_string s =
+ String.split_on_char '/' s |> List.filter (fun s -> s <> "") |> BatFingerTree.of_list
+
+let (@/) segment path = BatFingerTree.cons path segment
+
+let rec lookup handle path =
+ let open Utilities.Result in
+ match BatFingerTree.front path with
+ | None -> Ok (Some handle)
+ | Some (rest, segment) -> (
match Protocols.Directory.from handle with
| None -> Ok None
- | Some dir ->
- let* elem = Directory.find dir x in
- match elem with
+ | Some dir -> (
+ let* found = Protocols.Directory.find dir segment in
+ match found with
| None -> Ok None
- | Some elem -> lookup elem xs
+ | Some handle' -> lookup handle' rest))
diff --git a/lib/kernel/Path.mli b/lib/kernel/Path.mli
index 85d0ca9..9ef4103 100644
--- a/lib/kernel/Path.mli
+++ b/lib/kernel/Path.mli
@@ -1,6 +1,6 @@
type t
val this : t
+val of_string : string -> t
val (@/) : string -> t -> t
-
val lookup : Protocols.Handle.t -> t -> (Protocols.Handle.t option, Concepts.Condition.condition) result