Commits

camlspotter committed a64e029

Stream => Pstream

Comments (0)

Files changed (10)

+v.2.1.1
+        - Renamed Stream by Pstream, to avoid the name clash with OCaml's Stream.
 v.2.1.0
 	- bug fixes
 	- refactored module types lot
    position
    elem
    stream_intf
-   stream
+   pstream
    schar
    sstring
    smemo
+open Stream_intf
+
+(** Import the constructors *)
+type 'a desc = 'a Spotlib.Spot.Stream.desc = 
+  | Cons of 'a * 'a desc lazy_t
+  | Null
+
+module Extend(P : Base) = struct
+
+  type elem = P.Elem.t
+  type pos = P.Pos.t
+  type attr = P.Attr.t
+
+  open Spotlib.Spot.Stream
+  open P
+
+  type desc = (Elem.t option * Attr.t) Spotlib.Spot.Stream.desc
+  type t = (Elem.t option * Attr.t) Spotlib.Spot.Stream.t (* None means EOS *)
+
+  let cons_desc e attr v = Cons ((Some e,attr), v)
+  let null_desc attr = Cons ((None, attr), Spotlib.Spot.Stream.null)
+  let null attr = Lazy.lazy_from_val (null_desc attr)
+
+  let peek = function
+    | lazy Cons ((Some elem, _), t') -> Some (elem, t')
+    | _ -> None
+
+  let is_null = is_null
+    
+  let to_list t = 
+    let rec to_list st = function
+      | lazy Cons ((Some elem, _), t) -> to_list (elem :: st) t
+      | _ -> List.rev st
+    in
+    to_list [] t
+
+  let rec iter f = function
+    | lazy Cons ((Some elem, _), t) -> f elem; iter f t
+    | _ -> ()
+
+  let rec fold_right f lst st = match lst with
+    | lazy Cons ((Some v, _), lst') -> f v (fold_right f lst' st)
+    | _ -> st
+
+  let rec map f lst = lazy (match lst with
+    | lazy Cons ((Some v, _pos), lst') -> Cons (f v, map f lst')
+    | _ -> Null)
+
+  (* [t2] must be a postfix of [t1] otherwise, it loops forever *)
+  let rev_between t1 t2 =
+    let rec loop st t =
+      if t == t2 then st (* CR jfuruse: we cannot always use pointer eq *)
+      else 
+        match t with
+        | lazy Cons ((Some elem, _), t') -> loop (elem::st) t'
+        | _ -> st
+    in
+    loop [] t1
+
+  let between t1 t2 = List.rev (rev_between t1 t2)
+
+  let attr = function
+    | lazy Cons ((_, attr), _) -> attr
+    | _ -> assert false
+
+  let position s = Attr.position (attr s)
+
+end
+
+module Make(P : Base) = struct
+  include P
+  include Extend(P)
+end
+
+(** Stream module. See Stream_intf for more details *)
+open Stream_intf
+
+(** Import the constructors *)
+type 'a desc = 'a Spotlib.Spot.Stream.desc = 
+  | Cons of 'a * 'a desc lazy_t
+  | Null
+
+(* CR jfuruse: Bad naming: It is a real creator of the stream, but called Extend. *)
+module Extend (Base : Base) : X
+  with type pos  = Base.Pos.t
+  and  type elem = Base.Elem.t
+  and  type attr = Base.Attr.t
+(** The functor [Extend] creates a stream module based on [Base] *)
+
+module Make (Base : Base) : S
+  with type Pos.t  = Base.Pos.t
+  and  type Elem.t = Base.Elem.t
+  and  type Attr.t = Base.Attr.t
+(** Same as [Extend] but includes [Base : Base].
+    Do not use [Make] if your [Base] contains something more than [Stream_intf.Base],
+    since the [Base] in the result of [Make] does not contain the extra things not 
+    in [Stream_intf.Base]. Instead, you must declare:
+
+    module M = struct
+      include Base
+      include Extend(Base)
+    end
+*)
 
 end
 
-module Str = Stream.Make(Base)
+module Str = Pstream.Make(Base)
 include Str
 
 (* Extend Str with buffering *)
   
 end
 
-module NonBuffered = Stream.Make(Base)
+module NonBuffered = Pstream.Make(Base)
 
 include NonBuffered
 
-include Stream.Make(struct
+include Pstream.Make(struct
   module Pos = Position.None
   module Attr = struct
     type t = Pos.t
   end
   include Base
 
-  module Str = Stream.Extend(Base)
+  module Str = Pstream.Extend(Base)
   include Str
 
   include Smemo.Extend(struct

lib/stream.ml

-open Stream_intf
-
-(** Import the constructors *)
-type 'a desc = 'a Spotlib.Spot.Stream.desc = 
-  | Cons of 'a * 'a desc lazy_t
-  | Null
-
-module Extend(P : Base) = struct
-
-  type elem = P.Elem.t
-  type pos = P.Pos.t
-  type attr = P.Attr.t
-
-  open Spotlib.Spot.Stream
-  open P
-
-  type desc = (Elem.t option * Attr.t) Spotlib.Spot.Stream.desc
-  type t = (Elem.t option * Attr.t) Spotlib.Spot.Stream.t (* None means EOS *)
-
-  let cons_desc e attr v = Cons ((Some e,attr), v)
-  let null_desc attr = Cons ((None, attr), Spotlib.Spot.Stream.null)
-  let null attr = Lazy.lazy_from_val (null_desc attr)
-
-  let peek = function
-    | lazy Cons ((Some elem, _), t') -> Some (elem, t')
-    | _ -> None
-
-  let is_null = is_null
-    
-  let to_list t = 
-    let rec to_list st = function
-      | lazy Cons ((Some elem, _), t) -> to_list (elem :: st) t
-      | _ -> List.rev st
-    in
-    to_list [] t
-
-  let rec iter f = function
-    | lazy Cons ((Some elem, _), t) -> f elem; iter f t
-    | _ -> ()
-
-  let rec fold_right f lst st = match lst with
-    | lazy Cons ((Some v, _), lst') -> f v (fold_right f lst' st)
-    | _ -> st
-
-  let rec map f lst = lazy (match lst with
-    | lazy Cons ((Some v, _pos), lst') -> Cons (f v, map f lst')
-    | _ -> Null)
-
-  (* [t2] must be a postfix of [t1] otherwise, it loops forever *)
-  let rev_between t1 t2 =
-    let rec loop st t =
-      if t == t2 then st (* CR jfuruse: we cannot always use pointer eq *)
-      else 
-        match t with
-        | lazy Cons ((Some elem, _), t') -> loop (elem::st) t'
-        | _ -> st
-    in
-    loop [] t1
-
-  let between t1 t2 = List.rev (rev_between t1 t2)
-
-  let attr = function
-    | lazy Cons ((_, attr), _) -> attr
-    | _ -> assert false
-
-  let position s = Attr.position (attr s)
-
-end
-
-module Make(P : Base) = struct
-  include P
-  include Extend(P)
-end
-

lib/stream.mli

-(** Stream module. See Stream_intf for more details *)
-open Stream_intf
-
-(** Import the constructors *)
-type 'a desc = 'a Spotlib.Spot.Stream.desc = 
-  | Cons of 'a * 'a desc lazy_t
-  | Null
-
-(* CR jfuruse: Bad naming: It is a real creator of the stream, but called Extend. *)
-module Extend (Base : Base) : X
-  with type pos  = Base.Pos.t
-  and  type elem = Base.Elem.t
-  and  type attr = Base.Attr.t
-(** The functor [Extend] creates a stream module based on [Base] *)
-
-module Make (Base : Base) : S
-  with type Pos.t  = Base.Pos.t
-  and  type Elem.t = Base.Elem.t
-  and  type Attr.t = Base.Attr.t
-(** Same as [Extend] but includes [Base : Base].
-    Do not use [Make] if your [Base] contains something more than [Stream_intf.Base],
-    since the [Base] in the result of [Make] does not contain the extra things not 
-    in [Stream_intf.Base]. Instead, you must declare:
-
-    module M = struct
-      include Base
-      include Extend(Base)
-    end
-*)