Commits

camlspotter  committed 9380583

fixed a type error

  • Participants
  • Parent commits 69ca6e2
  • Branches dev

Comments (0)

Files changed (2)

         (* The token is white space *)
  
 
-    | Some (({Tokenstr.token = Parser.EOF} as i), _) ->
-        let space_between_region, space_between = i.Tokenstr.space in
-        (try Printer.add_string printer (Region.lnum space_between_region) space_between with Exit -> ());
-        state
+    | Some (({Tokenstr.token = Parser.EOF} as i), _) -> state
 
     | Some ({ Tokenstr.token = t; region = orig_region; 
               space = (space_between_region, space_between); substr }, str) ->
 open Parser
 
 type 'a desc = 
-  | Cons of 'a * 'a t * in_channel
-  | Null
+  | Cons of 'a * 'a t * in_channel option ref
+  | Null of in_channel option ref
 
 and 'a t = 'a desc lazy_t
 
   substr : string;
 }
 
+let close = function
+  | lazy (Null icoptref | Cons (_, _, icoptref)) ->
+      match !icoptref with
+      | None -> ()
+      | Some ic -> icoptref := None; close_in ic 
+
 let of_channel ic = 
+  let icoptref = ref (Some ic) in
   try
     let reader = LexReader.create_from_channel ic in
     let rec loop last_region = 
 
       let l = 
         Cons ({ token = Some token ; region; substr },
-               lazy (match token with
-               | EOF -> Null
-               | _ -> loop region),
-               ic)
+              begin match token with
+              | EOF -> 
+                  let null = Lazy.lazy_from_val (Null icoptref) in
+                  close null;
+                  null
+              | _ -> lazy (loop region)
+              end,
+              icoptref)
       in
       match space with
       | None -> l
-      | Some space ->
-          Cons ( space, Lazy.lazy_from_val l, ic )
+      | Some space -> Cons ( space, Lazy.lazy_from_val l, icoptref )
     in
     lazy (loop Region.zero)
   with
   let ic = open_in path in
   of_channel ic
 
-let close = function
-  | lazy Null -> ()
-  | lazy (Cons (_, _, ic)) -> close_in ic
-
 let destr = function
-  | lazy Null -> None
-  | lazy (Cons (car, cdr, _ic)) -> Some (car, cdr)
+  | lazy Null _ -> None
+  | lazy (Cons (car, cdr, _)) -> Some (car, cdr)