Commits

camlspotter committed 1ee3f3c

type checked for tokenstr

Comments (0)

Files changed (4)

     { p  with pos_cnum = p .pos_cnum + diff },
     { p' with pos_cnum = p'.pos_cnum + diff } 
 
+  let show (p1,p2) = Printf.sprintf "%s-%s" (Position.show p1) (Position.show p2)
+  let format ppf = Format.string ppf @@ show
+
   let contain (start, end_) pos = 
     match Position.compare start pos, Position.compare pos end_ with
     | (-1 | 0), (-1 | 0) -> `In
   val current_substring : t -> string
   val region : t -> Region.t
 end = struct
-  (* open Lexbuf *)
+  (* CR jfuruse: we should set lexer file name *)
 
   type t = Lexbuf.t * Lexing.lexbuf
 
 
 module Attr = struct
   type t = {
-    region       : Region.t;
-    substr       : string;
-    space        : Region.t * string;
+    region : Region.t;
+    substr : string;
+    space  : Region.t * string;
   }
+
+  let position t = t.region
+
+  let default = { region = Region.none;
+                  substr = "";
+                  space = Region.none, "" }
 end
 
-type t = (Elem.t, Attr.t) zlist * in_channel
+module Stream = Planck.Stream.Make(struct
+  module Elem = Elem
+  module Pos = Pos.Region
+  module Attr = Attr
+end)
+
+type t = Stream.t * in_channel
 
 let stream = fst
 let close (_, ic) = close_in ic
     | EOF -> null_desc attr
     | _ -> cons_desc token attr (lazy (loop region))
   in
-  lazy (loop Region.zero), ic
+  lazy (loop & Region.top ""), ic
 
-let of_path path =
-  let ic = open_in path in
-  of_channel ic
+let of_path = of_channel @@ open_in
 open Planck.Lazylist
 open Pos
 
-type token = Parser.token     (** parsed token *)
-type attr = {
-  region : Region.t;         (** the position of the token *)
-  substr : string;           (** the actual string for the token *)
-  space  : Region.t * string (** space before the token *)
-}
+module Attr : sig
+  type t = {
+    region : Region.t;         (** the position of the token *)
+    substr : string;           (** the actual string for the token *)
+    space  : Region.t * string (** space before the token *)
+  }
+end
+
+module Stream : Planck.Stream_intf.S 
+  with type Elem.t = Parser.token
+  and  type Attr.t = Attr.t
+  and  type Pos.t  = Pos.Region.t
 
 type t
 
-val stream : t -> (token, attr) zlist (* EOF is in info *)
+val stream : t -> Stream.t
 val close : t -> unit
 val of_channel : in_channel -> t
 val of_path : string -> t