ocaml-indent / main.ml

Diff from to
 open Pos
-open Args
 module State = Machine.State
 module Stack = Machine.Stack
 
 module Sexp = Sexplib.Sexp (* No open Sexplib, since Parser corrides with Sexplib.Parser *)
 
-type region = (int * int) option (* [None] means the whole file *)
-
-(** [l] is in the interested area or not? *)
-let check_line : int -> region -> [> `Before | `Inside | `Over ] = fun l -> function
-  | None -> `Inside
-  | Some (start, end_) ->
-      if l < start then `Before
-      else if l <= end_ then `Inside
-      else `Over
-
 module Printer : sig
-  val print_debug  : region -> int-> string -> unit
-  val print_string : region -> int -> string -> unit
+  val print_debug  : Lines.t -> int-> string -> unit
+  val print_string : Lines.t -> int -> string -> unit
 end = struct
 
-  let print_debug t lnum s = match check_line lnum t with
+  let print_debug t lnum s = match Lines.is_between lnum t with
     | `Before | `Over -> ()
     | `Inside -> print_string s
 
       different number of lines from the original.
   *)
   let print_string t lnum s =
-    let add_line t lnum s = match check_line lnum t with
+    let add_line t lnum s = match Lines.is_between lnum t with
       | `Before -> ()
       | `Over -> raise Exit
       | `Inside -> print_string s
 end
 
 open Tokenstr
+open Planck.Lazylist
 
 let indent_file path =
-  let print_string = Printer.print_string lines in
-  let print_debug = Printer.print_debug lines in
+  let print_string = Printer.print_string Args.lines in
+  let print_debug  = Printer.print_debug  Args.lines in
 
-  let str = if path = "" then Tokenstr.of_channel stdin else Tokenstr.of_path path in
+  let tkstr = if path = "" then Tokenstr.of_channel stdin else Tokenstr.of_path path in
+  let stream = stream tkstr in
 
   let flush_remaining_space info =
     print_string (Region.lnum (fst info.space)) (snd info.space)
   in
 
-  let rec loop last_orig_region state str = match Tokenstr.destr str with
-    | None -> state
+  let rec loop last_orig_region state = function
+    | lazy Null _ -> state
 
-    | Some (({ token = Parser.EOF } as info), _) ->
+    | lazy Cons (({ token = Parser.EOF } as info), _, _) ->
         flush_remaining_space info;
         state
 
-    | Some (({ token = t;
-               region = orig_region;
-               space = (_space_between_region, space_between);
-               substr } as info), str) ->
+    | lazy Cons (({ token = t;
+                    region = orig_region;
+                    space = (_space_between_region, space_between);
+                    substr } as info), 
+                 _, str) ->
 
-        match check_line (Region.lnum orig_region) lines with
+        match Lines.is_between (Region.lnum orig_region) Args.lines with
         | `Over ->
             (* The token is outside of our interest.
                Print the remaining things and go out *)
             in
 
             (* Where the cursor move *)
-            let _cursor_info = match cursor with
+            let _cursor_info = match Args.cursor with
               | None -> None
               | Some lines_cols ->
                   match
               (* CR jfuruse: can be a bug. something from space_between_region *)
               print_string last_line spaces;
 
-              if debug then begin
+              if Args.debug then begin
                 print_string current_line indent_string;
                 if pre == post then
                   print_debug current_line
 
             loop orig_region post str
   in
-  let final_state = loop Region.zero State.init str in
-  if showstate then State.print final_state;
-  Tokenstr.close str
+  let final_state = loop Region.zero State.init stream in
+  if Args.showstate then State.print final_state;
+  Tokenstr.close tkstr
 
-let _ = List.iter indent_file paths
+let () = List.iter indent_file Args.paths
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.