3 module Msg = Khatus_msg
4 module Msg_parser = Khatus_msg_parser
5 module State = Khatus_state
9 ; stream : Msg.t Stream.t
12 let init ~node ~modul =
15 match read_line () with
16 | exception End_of_file ->
22 let rec parse_next msg_count =
23 (match Stream.next line_stream with
24 | exception Stream.Failure ->
27 (match (Msg_parser.parse_msg (Lexing.from_string line)) with
33 | `Bad_format_of_msg_head -> "Bad_format_of_msg_head"
34 | `Bad_format_of_msg_content -> "Bad_format_of_msg_content"
42 { location = "khatus_msg_stream:fold"
44 ; msg = sprintf "Parse error %s in %s" e line
51 { state = State.init ~node ~modul
52 ; stream = Stream.from parse_next
55 let rec fold ({state; stream} as t) ~f ~init =
56 match Stream.next stream with
57 | exception Stream.Failure ->
60 let state = State.update state ~msg in
61 fold {t with state} ~f ~init:(f init ~state ~msg)