camlspotter avatar camlspotter committed 69ca6e2

fixing all

Comments (0)

Files changed (7)

 
 OCAMLINCLUDES +=
 
-OCAMLFLAGS    += -annot -w Aelz-9
+OCAMLFLAGS    = -annot -w A-4-9 -warn-error A-4-9
 OCAMLCFLAGS   +=
 OCAMLOPTFLAGS +=
 OCAML_LINK_FLAGS +=
     reader
     tokenstr
     machine
+    args
     main
 
 lexer.cmi: parser.cmi
 
   type t = elt list with sexp_of
 
-  let rec indent last_indent  = function
+  (* CR jfuruse: strange *)
+  let rec indent _last_indent  = function
     | [] -> 0
     | { indent = n } :: _ -> n
 end
   | Some (i, _) when Region.lnum i.Tokenstr.region <> lnum -> false
   | Some (i, str) ->
       match i.Tokenstr.token with
-      | FUN -> false
-      | FUNCTION -> false
-      | COMMENT -> lparen_read_ahead lnum str
+      | None | Some COMMENT -> lparen_read_ahead lnum str
+      | Some FUN -> false
+      | Some FUNCTION -> false
       | _ -> true
 
 let rec lbrace_read_ahead lnum str =
   | Some (i, _) when Region.lnum i.Tokenstr.region <> lnum -> false
   | Some (i, str) ->
       match i.Tokenstr.token with
-      | COMMENT -> lparen_read_ahead lnum str
+      | None | Some COMMENT -> lparen_read_ahead lnum str
       | _ -> true
 
 let lbracket_read_ahead = lbrace_read_ahead
            - for non definition equals *)
         let rec f bases = match bases with
           (* Definition equal rolls things back to its head *)
-          | {k = (KLet (_,cols) | KType cols | KModule cols) } :: _ ->
+          | {k = (KLet (_, _cols) | KType _cols | KModule _cols) } :: _ ->
               bases, bases
           (* Equal can exceed the following *)
           | { k = (KExpr _ | KNone) } :: bs -> f bs
           (* Equal cannot exceed the other *)
-          | _ :: bs -> bases0, bases0
+          | _ :: _bs -> bases0, bases0
           | [] -> [], []
         in
         f bases0
 open Pos
 open Machine
 
-let paths, debug, lines, showstate, cursor =
-  let rev_paths = ref [] in
-  let debug = ref false in
-  let lines = ref None in
-  let showstate = ref false in
-  let cursor = ref None in
-  Arg.parse [
-    ("-debug", Arg.Set debug, "debugging");
-    ("-lines", Arg.String (fun s ->
-      try
-        let pos = String.index s '-' in
-        let (start,end_) = (int_of_string (String.sub s 0 pos),
-                            int_of_string (String.sub s (pos+1) (String.length s - pos - 1))) in
-        if start <= 0 || end_ <= 0 || start > end_ then
-          failwith (Printf.sprintf "Wrong -lines specification: %s" s);
-        lines := Some (start, end_)
-      with
-      | _ -> failwith (Printf.sprintf "Wrong -lines specification: %s" s)),
-     "lines, ex. 10-12") ;
-    ("-cursor", Arg.String (fun s ->
-      try
-        let pos = String.index s ':' in
-        let (rows,cols) = (int_of_string (String.sub s 0 pos),
-                           int_of_string (String.sub s (pos+1) (String.length s - pos - 1))) in
-        if rows <= 0 || cols < 0 then
-          failwith (Printf.sprintf "Wrong -cursor specification: %s" s);
-        cursor := Some (rows, cols)
-      with
-      | _ -> failwith (Printf.sprintf "Wrong -cursor specification: %s" s)),
-     "cursor position, ex. 10:12") ;
-    ("-show-state", Arg.Set showstate, "show state at the last");
-  ] (fun s -> rev_paths := s :: !rev_paths) "indent paths";
-  let paths = List.rev !rev_paths in
-  let paths = if paths = [] then [""] else paths in (* CR jfuruse: ugly *)
-  begin match paths, !lines with
-  | [], _ -> assert false
-  | [_], _ -> ()
-  | _, Some _ -> failwith "Region can be specified with at most one file"
-  | _ -> ()
-  end;
-  paths, !debug, !lines, !showstate, !cursor
+open Args
 
 let check_lines l = function
   | None -> `Inside
     | `Before | `Over -> ()
     | `Inside -> print_string s
 
+  (** Print a string [s] for the line number [lnum].
+      If the printing text exceeds the interested region,
+      It stops printing and raises Exit
+
+      Currently it cannot print a string correctly if it has 
+      different number of lines from the original. 
+  *)
   let add_string t lnum s =
     let add_line t lnum s = match check_lines lnum t with
       | `Before -> ()
   let rec loop last_orig_region state str = match Tokenstr.destr str with
     | None -> state
 
+    | Some (({ Tokenstr.token = None } as i), str) ->
+        (* The token is white space *)
+ 
+
     | Some (({Tokenstr.token = Parser.EOF} as i), _) ->
-        let space_between = i.Tokenstr.space in
-        Printer.add_string printer (Region.lnum last_orig_region) space_between;
+        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 = t; region = orig_region; space = space_between; substr }, str) ->
+    | Some ({ Tokenstr.token = t; region = orig_region; 
+              space = (space_between_region, space_between); substr }, str) ->
 
         let last_line = Region.lnum last_orig_region in
         let current_line = Region.lnum orig_region in
         | `Over -> 
             (* The token is outside of our interest. 
                Print the remaining things and go out *)
-            (* Wrong. The line can be over in the previous token,
-               and in this case, we need no space_between printing *) 
-            Printer.add_string printer last_line space_between;
+            (try Printer.add_string printer (Region.lnum space_between_region) space_between with Exit -> ());
             state
         | (`Before | `Inside as line_status) -> 
             (*
               let spaces = try String.sub space_between 0 (String.rindex space_between '\n' + 1) with _ -> "" in
               let indent_string = String.make (State.indent pre) ' ' in
 
+              (* CR jfuruse: can be a bug. something from space_between_region *)
               Printer.add_string printer last_line spaces;
 
               if debug then begin
                 { post with
                   State.last_token = (if t <> Parser.COMMENT then Some t else state.State.last_token)
                 }
-
             in
 
             loop orig_region post str
       (lexbuf.Lexing.lex_curr_p.Position.pos_cnum - 
          lexbuf.Lexing.lex_start_p.Position.pos_cnum)
 
-  (* It is not correct! *)
+  (* It is not correct! *) (* CR jfuruse: but how? *)
   let region (_, lexbuf) = lexbuf.Lexing.lex_start_p, lexbuf.Lexing.lex_curr_p
 end
 

tests/semi_in_case.ml

+let rec loop last_orig_region state str = match Tokenstr.destr str with
+  | None -> state
+
+  | Some (({Tokenstr.token = Parser.EOF} as i), _) ->
+      let space_between = i.Tokenstr.space in
+      Printer.add_string printer (Region.lnum last_orig_region) space_between;
+      state
 and 'a t = 'a desc lazy_t
 
 type 'a info = {
-  space : string;
-  token : 'a;
+  token : 'a option; (* None means white space *)
   region : Region.t;
   substr : string;
 }
         try
           LexReader.lex reader Lexer.token 
         with
-        | Lexer.Error (e, loc) ->
+        | Lexer.Error (e, _loc) ->
             Format.eprintf "%a@." Lexer.report_error e;
             assert false
       in
       let region = LexReader.region reader in
-      let space_between = 
-        let last_end = (snd last_region).Position.pos_cnum in
-        LexReader.substring 
-          reader last_end ((fst region).Position.pos_cnum - last_end)
-      in
       (* token's string *)
       let substr = LexReader.current_substring reader in
-      
-      Cons ({ space = space_between; token; region; substr },
-            lazy (match token with
-            | EOF -> Null
-            | _ -> loop region),
-            ic)
+
+      let space =
+        let space_between = 
+          let last_end = (snd last_region).Position.pos_cnum in
+          LexReader.substring 
+            reader last_end ((fst region).Position.pos_cnum - last_end)
+        in
+        if space_between = "" then None
+        else Some { token = None; 
+                    region = (snd last_region, fst region);
+                    substr = space_between }
+      in
+
+      let l = 
+        Cons ({ token = Some token ; region; substr },
+               lazy (match token with
+               | EOF -> Null
+               | _ -> loop region),
+               ic)
+      in
+      match space with
+      | None -> l
+      | Some space ->
+          Cons ( space, Lazy.lazy_from_val l, ic )
     in
     lazy (loop Region.zero)
   with
 type 'a t
 
 type 'a info = {
-  space : string;
-  token : 'a;
+  token : 'a option; (** None means whilte space *)
   region : Pos.Region.t;
   substr : string;
 }
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.