aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorClombrong <cromblong@egregore.fun>2025-08-16 00:42:18 +0200
committerClombrong <cromblong@egregore.fun>2025-08-16 00:42:18 +0200
commitef054dfae34971a28811c5082a4b6041bdfe58dd (patch)
treec17bb8836b0aa6bc9b3a989510e9b13076acbf9f /lib
parent96855075812e692cd4ae099f0d27964e306f0f2b (diff)
feat(xml): make tree function async
Diffstat (limited to 'lib')
-rw-r--r--lib/segment.ml5
-rw-r--r--lib/xml.ml10
2 files changed, 8 insertions, 7 deletions
diff --git a/lib/segment.ml b/lib/segment.ml
index ce50f78..7023098 100644
--- a/lib/segment.ml
+++ b/lib/segment.ml
@@ -15,7 +15,8 @@ let next (stream : (signal, async) stream) : (signal, sync) stream Lwt.t =
(** [get stream] is a promise containing a single Xml element of [stream]. *)
let get (stream : (signal, async) stream) : element Lwt.t =
- let* signal = next stream
- in match tree signal with
+ let* signal = next stream in
+ let* el = tree signal
+ in match el with
| Some xml -> Lwt.return xml
| None -> Lwt.fail (InvalidStanza (signal |> write_xml |> to_string))
diff --git a/lib/xml.ml b/lib/xml.ml
index 99a388f..dcb3e79 100644
--- a/lib/xml.ml
+++ b/lib/xml.ml
@@ -1,4 +1,4 @@
-open Markup
+open Lwt.Syntax
exception InvalidStanza of string
@@ -9,9 +9,9 @@ type element = {
children : (element, string) Either.t list;
}
-(** [tree s] is an [element option] representing the XML element inside of stream [s],
- if [s] is a complete element from start to end. *)
-let tree s : element option =
+(** [tree s] is a promise to an [element option] representing the XML element inside of
+ stream [s], if [s] is a complete element from start to end. *)
+let tree s : element option Lwt.t =
let element (namespace, name) attributes children =
Either.Left {
namespace;
@@ -26,7 +26,7 @@ let tree s : element option =
children;
}
and text ss = Either.Right (String.concat "" ss) in
- let opt_el = tree ~text ~element s in
+ let+ opt_el = Markup_lwt.tree ~text ~element s in
Option.bind opt_el (Either.fold ~left:Option.some ~right:(fun _ -> None))
(** [element_to_string element] is a string representation of the underlying XML in