Commits

Dmitry Grebeniuk  committed 44fb15c

mb bug?

  • Participants
  • Parent commits 332aa26

Comments (0)

Files changed (2)

 <**/*> : warn_A
 <**/*.ml> | <**/*.mli> : camlp4r
 <test_it.*> : pkg_iteratees
+
+<dumbstreaming_it.*> : annot

File dumbstreaming_it.ml

       iteratee 'el (iteratee 'el' 'a) -> iteratee 'el 'a
     ;
 
+    value liftI : It_IO.m (iteratee 'el 'a) -> iteratee 'el 'a
+    ;
+
     value drop : int -> iteratee 'el unit
     ;
 
     value stream2list : iteratee 'el (list 'el)
     ;
 
+    value run : iteratee 'el 'a -> It_IO.m 'a
+    ;
+
+    value feedI :
+      (stream 'el -> It_IO.m (iteratee 'el 'a  *  stream 'el)) ->
+      stream 'el ->
+      It_IO.m (iteratee 'el 'a)
+    ;
+
+    module Ops
+     :
+      sig
+        (* IO binds: *)
+        value ( %<< ) : ('a -> It_IO.m 'b) -> It_IO.m 'a -> It_IO.m 'b;
+        value ( >>% ) : It_IO.m 'a -> ('a -> It_IO.m 'b) -> It_IO.m 'b;
+
+        (* Iteratees binds: *)
+        value ( =<< ) :
+        ('a -> iteratee 'el 'b) -> iteratee 'el 'a -> iteratee 'el 'b;
+        value ( >>= ) :
+          iteratee 'el 'a -> ('a -> iteratee 'el 'b) -> iteratee 'el 'b;
+
+        (* Enumerators sequence: *)
+(*
+        value ( >>> ) :
+          enumerator 'el 'a -> enumerator 'el 'a -> enumerator 'el 'a
+        ;
+*)
+
+      end
+    ;
+
   end
 ;
 
     (* None of EOF *)
 
     value read :
-      (~ntotal:ntotal -> ~npart:npart -> ~nbytes:nbytes -> I.iteratee char 'i)
-      -> I.iteratee 'i 'a
+      ~get_piece_it :
+       ( ~ntotal:ntotal -> ~npart:npart -> ~nbytes:nbytes
+         -> I.iteratee char 'i
+       )
+      -> ~combine_it : (I.iteratee 'i 'a)
       -> I.iteratee char (option 'a)
     ;
 
  =
   struct
 
+    value ie_cont k = I.IE_cont None k
+    ;
+
+    (* to iteratees: *)
+    value junk = I.drop 1
+    ;
+
+
     (* todo: move to ocaml-iteratees: *)
     module It_add
      :
             ]
         ;
 
-        value ie_cont k = IE_cont None k
-        ;
-
         value ie_contM k = IO.return (IE_cont None k, empty_stream)
         ;
 
             value is_not_digit c = not (is_digit c)
             ;
 
-            (* to iteratees: *)
-            value junk = drop 1
-            ;
-
             value inan msg = I.throw_err (SInt_not_a_number msg)
             ;
 
     open It_add
     ;
 
+    open Printf
+    ;
+
+    module IO = I.It_IO;
+    open I.Ops;
+
+
     value read_uint = read_uint;
     value read_uint_nz = read_uint_nz;
     value read_uint64 = read_uint64;
       fmt
     ;
 
-    value ( >>= ) m f = I.bindI f m
-    ;
-
     value read_the_char c =
-      let err txt = ds_error "read_char: %C expected, %s found" c in
+      let err txt = ds_error "read_char: %C expected, %s found" c txt in
       I.peek >>= fun
       [ Some c' ->
           if c == c'
     ;
 
 
-    value read_data_lens ~get_piece_it ~combine_it ~ntotal lens =
-      loop ~combine_it ~npart:0
-      where rec loop ~combine_it ~npart =
-        match lens with
-        [ [] -> I.joinI (I.return combine_it)
-        | [piece_len :: lens] ->
-            let this_piece_it = get_piece_it
-              ~ntotal ~npart ~nbytes:piece_len in
-            I.joinI (I.take piece_len this_piece_it) >>= fun piece_res ->
-
-            .. скормить piece_res, идти дальше.
-
-            combine_it ..
-
-
-        ]
+    value ie_doneM
+     (x : 'a)
+     (s : I.stream 'el)
+     : IO.m (I.iteratee 'el 'a  *  I.stream 'el)
+     = IO.return (I.IE_done x, s)
     ;
 
 
+
+    value (read_data_lens :
+      ~get_piece_it :
+       ( ~ntotal:ntotal -> ~npart:npart -> ~nbytes:nbytes
+         -> I.iteratee char 'i
+       )
+      -> ~combine_it : (I.iteratee 'i 'a)
+      -> ~ntotal : ntotal
+      -> ~lens : list nbytes
+      -> I.iteratee char 'a
+    )
+      ~get_piece_it
+      ~combine_it
+      ~ntotal
+      ~lens
+     =
+      let rec read_data_lens ~combine_it ~lens ~npart : I.iteratee char 'a =
+        let () = ignore ( combine_it : (I.iteratee 'i 'a) ) in
+        match (lens, (combine_it : I.iteratee _ _)) with
+        [ ([], _) ->
+           read_x0A >>= fun () ->
+           I.joinI (I.return combine_it)
+        | ([len :: lens], (I.IE_done _ | I.IE_cont (Some _) _)) ->
+            I.drop len >>= fun () ->
+            read_x0A >>= fun () ->
+            read_data_lens ~combine_it ~lens ~npart:(npart + 1)
+        | ([len :: _lens], I.IE_done None k) ->
+            let this_piece_it = get_piece_it
+              ~ntotal ~npart ~nbytes:len in
+            (I.joinI & I.take len this_piece_it) >>= fun this_it_framed ->
+            this_it_framed >>= fun this_piece_res ->
+            read_x0A >>= fun () ->
+
+            I.liftI (I.feedI k (I.chunk_of this_piece_res))
+              >>= fun _combine_it ->
+(*
+            read_data_lens ~combine_it ~lens ~npart:(npart + 1)
+*)
+failwith "qq"
+        ]
+      in
+        read_data_lens ~combine_it ~npart:0 ~lens
+    ;
+
+(**
+
+**)
+
+
+(*
     value read_data ~get_piece_it ~combine_it packet_length lens =
       let sum_lens = List.fold_left Int64.add 0L
         (List.map Int64.of_int lens) in
         "total length (%Li) is not equal to sum of pieces' lengths (%Li)"
           packet_length sum_lens
       else
-        read_data_lens ~get_piece_it ~combine_it lens
+        read_data_lens ~get_piece_it ~combine_it ~ntotal:packet_length ~lens
     ;
+*)
 
 
     value read_lengths count : I.iteratee char (list int) =
         else I.return (Int64.to_int x)
     ;
 
-    value read_some ~get_piece_it ~combine_it =
+(*
+    value read_some ~get_piece_it ~combine_it : I.iteratee _ _ =
       read_uint64 >>= fun packet_length ->
       let read_data_gen = read_data ~get_piece_it ~combine_it
       in
           "space or \\x0A expected after packet length"
       ]
     ;
+*)
 
-    value read ~get_piece_it ~combine_it =
+    value (read :
+      ~get_piece_it :
+       ( ~ntotal:ntotal -> ~npart:npart -> ~nbytes:nbytes
+         -> I.iteratee char 'i
+       )
+      -> ~combine_it : (I.iteratee 'i 'a)
+      -> I.iteratee char (option 'a)
+    )
+     ~get_piece_it ~combine_it
+     =
+      let () = ignore combine_it in
+      let () = ignore get_piece_it in
       I.peek >>= fun
       [ None | Some '\x0A' -> I.return None
       | Some _ ->
           I.catch
             (fun () ->
-               read_some ~get_piece_it ~combine_it >>= fun r ->
+(*
+               read_some ~get_piece_it ~combine_it >>= fun (r : _) ->
                I.return (Some r)
+*)
+I.return None
             )
             (fun e -> ds_error "%s" & Printexc.to_string e
             )