camlspotter avatar camlspotter committed fd613df

add_debug

Comments (0)

Files changed (1)

 module Printer = struct
 
   type t = (int * int) option
-      
-  let add_string ?(no_exit=false) t lnum s =
+
+  let add_debug t lnum s =
+    match t with
+    | None -> print_string s
+    | Some (start, end_) ->
+        if lnum < start then ()
+        else if lnum > end_ then ()
+        else print_string s
+
+  let add_string t lnum s =
     let add_line t lnum s =
       match t with
       | None -> print_string s
       | Some (start, end_) ->
           if lnum < start then ()
-          else if lnum > end_ then if no_exit then () else raise Exit
+          else if lnum > end_ then raise Exit
           else print_string s
     in
     let get_line s =
     
 end 
 
-let _ = 
+let indent_file path = 
   let printer = lines in
-    
-  List.iter (fun path ->
-    let str = if path = "" then Tokenstr.of_channel stdin else Tokenstr.of_path path in
+  let str = if path = "" then Tokenstr.of_channel stdin else Tokenstr.of_path path in
 
-    let rec loop last_orig_region state str = match Tokenstr.destr str with
-      | None -> ()
+  let rec loop last_orig_region state str = match Tokenstr.destr str with
+    | None -> ()
 
-      | Some (({Tokenstr.token = EOF} as i), _) ->
-          let space_between = i.Tokenstr.space in
-          Printer.add_string printer (Region.lnum last_orig_region) space_between
-            
-      | Some (i, str) ->
-          let t = i.Tokenstr.token in
-          let orig_region = i.Tokenstr.region in
-          let space_between = i.Tokenstr.space in
-          let substr = i.Tokenstr.substr in
+    | Some (({Tokenstr.token = EOF} as i), _) ->
+        let space_between = i.Tokenstr.space in
+        Printer.add_string printer (Region.lnum last_orig_region) space_between
+          
+    | Some (i, str) ->
+        let t = i.Tokenstr.token in
+        let orig_region = i.Tokenstr.region in
+        let space_between = i.Tokenstr.space in
+        let substr = i.Tokenstr.substr in
 
           (*
             Format.eprintf "<%s %d>@."
             if debug then begin
               Printer.add_string printer current_line indent_string;
               if pre == post then 
-                Printer.add_string ~no_exit:true printer current_line 
+                Printer.add_debug printer current_line
                   (Printf.sprintf "-- %s\n" (Sexplib.Sexp.to_string_mach (Stack.sexp_of_t pre.bases)))
               else
-                Printer.add_string ~no_exit:true printer current_line 
+                Printer.add_debug printer current_line
                   (Printf.sprintf "-- %s // %s\n" 
                      (Sexplib.Sexp.to_string_mach (Stack.sexp_of_t pre.bases))
                      (Sexplib.Sexp.to_string_mach (Stack.sexp_of_t post.bases)))
       raise Exit
     with
     | Exit -> Tokenstr.close str
-  ) paths
+
+let _ = List.iter indent_file 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.