aboutsummaryrefslogtreecommitdiff
path: root/lib/segment.ml
blob: b278c50121c96c52d424bb736c5a25884a0ee6a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
open Lwt.Infix
open Markup
open Xml

(** [next stream] is a promise containing a full stanza of the fragments of
    [stream]. *)
let next (stream : (signal, async) stream) : (signal, sync) stream Lwt.t =
  let traverse_stanza depth fragment =
    let depth = match fragment with
      | `Start_element _ -> depth + 1
      | `End_element -> depth - 1
      | _ -> depth
    in ([fragment], if depth = 0 then None else Some depth)
  in transform traverse_stanza 0 stream |> Markup_lwt.load

(** [get stream] is a promise containing a single Xml element of [stream]. *)
let get (stream : (signal, async) stream) : element Lwt.t =
  next stream >>= tree