diff options
author | Clombrong <cromblong@egregore.fun> | 2025-08-16 01:03:43 +0200 |
---|---|---|
committer | Clombrong <cromblong@egregore.fun> | 2025-08-17 14:58:49 +0200 |
commit | e1d851acc39747c4d26662c2e53071a8243adc70 (patch) | |
tree | 001c93169749db4885bca8fcaa2113f35aea0a5a /lib/xml.ml | |
parent | ef054dfae34971a28811c5082a4b6041bdfe58dd (diff) |
feat(xml): tree fails in lwt-land directly
Diffstat (limited to 'lib/xml.ml')
-rw-r--r-- | lib/xml.ml | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -1,5 +1,6 @@ open Lwt.Syntax +exception Malformed exception InvalidStanza of string type element = { @@ -9,9 +10,9 @@ type element = { children : (element, string) Either.t list; } -(** [tree s] is a promise to an [element option] representing the XML element inside of +(** [tree s] is a promise to an [element] 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 tree s : element Lwt.t = let element (namespace, name) attributes children = Either.Left { namespace; @@ -26,8 +27,11 @@ let tree s : element option Lwt.t = children; } and text ss = Either.Right (String.concat "" ss) in - let+ opt_el = Markup_lwt.tree ~text ~element s in - Option.bind opt_el (Either.fold ~left:Option.some ~right:(fun _ -> None)) + let* el = Markup_lwt.tree ~text ~element s + in match el with + | Some Left el -> Lwt.return el + | _ -> Lwt.fail Malformed +(* 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 [element], for debugging purposes. |