camlspotter avatar camlspotter committed 6a6cb74

bug fix of multi-line comment

Comments (0)

Files changed (4)

         let rec f bases = match bases with
           | { k = (KParen cols | KBegin cols | KBracket cols | KBrace cols | KLet (_, cols)) | KTry cols | KMatch cols | KFun cols | KFunction cols } :: _ ->
               fix cols, bases
-          | { k = (KThen cols | KElse cols) } :: bs ->
+          | { k = (KThen cols | KElse cols ) } :: bs ->
+              fix cols, bs
+          | { k = KExpr cols } :: bs ->
               fix cols, bs
           | [] -> bases0, bases0 (* if overrun, keep the original *)
           | _ :: bs -> f bs
 
     |PREFIXOP _|OPTLABEL _|NATIVEINT _|LABEL _
     |WHEN|VIRTUAL|UNDERSCORE|TO|TILDE|
-      SHARP|REC|QUOTE|QUESTIONQUESTION|QUESTION|
-      PRIVATE|OR|OF|NEW|MUTABLE|METHOD
+          SHARP|REC|QUOTE|QUESTIONQUESTION|QUESTION|
+          PRIVATE|OR|OF|NEW|MUTABLE|METHOD
           |LESSMINUS|LBRACKETGREATER|LBRACKETLESS|LBRACKETBAR|
-      LBRACELESS|LAZY|INITIALIZER|INHERIT|INCLUDE|GREATERRBRACKET|
-      GREATERRBRACE|FUNCTOR|FOR|EXTERNAL|EOF|
-      DOWNTO|DOTDOT|DOT|CONSTRAINT|COLONGREATER|COLONEQUAL|
-      COLONCOLON|COLON|CLASS|BARRBRACKET|BARBAR|BANG|BACKQUOTE|ASSERT|AS
-        -> bases0, bases0
+          LBRACELESS|LAZY|INITIALIZER|INHERIT|INCLUDE|GREATERRBRACKET|
+          GREATERRBRACE|FUNCTOR|FOR|EXTERNAL|EOF|
+          DOWNTO|DOTDOT|DOT|CONSTRAINT|COLONGREATER|COLONEQUAL|
+          COLONCOLON|COLON|CLASS|BARRBRACKET|BARBAR|BANG|BACKQUOTE|ASSERT|AS
+          -> bases0, bases0
   in
   { state with bases = pre_bases },
   { state with bases = post_bases }
     in
     iter lnum s
 
-  let add_string t lnum s = try add_string t lnum s with Exit -> ()
-
 end
 
 let indent_file path =
 
         let last_line = Region.lnum last_orig_region in
         let current_line = Region.lnum orig_region in
-        let new_line = last_line <>  current_line in
+        let new_line = last_line <>  current_line in (* Is this token at a new line? *)
 
         (* Where the cursor move *)
-         let _cursor_info = 
-          match cursor with
+        let _cursor_info = match cursor with
           | None -> None
           | Some lines_cols ->
               match
 
         match check_lines (Region.lnum orig_region) lines with
         | `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;
             state
         | (`Before | `Inside as line_status) -> 
             (*
               Format.eprintf "<%s %d>@."
-              (Sexplib.Sexp.to_string_mach (Parser.sexp_of_token t))
-              Fatal error: exception Lexer.Error(0, _)
             *)
 
-
             let state =
               if new_line then { state with State.orig_indent = Region.columns orig_region } else state
             in
   if showstate then State.print final_state;
   Tokenstr.close str
 
+let indent_file path = try indent_file path with Exit -> ()
+
 let _ = List.iter indent_file paths
 	(with-current-buffer (get-buffer-create ocaml-indent-process-buffer)
 	  (erase-buffer))
 
-	(let* ((base-command '(call-process-region 1 end-char
+	;; We cannot stop sending contenst to the process at end-char,
+	;; Since comments and strings may not end at end-char
+	(let* ((base-command '(call-process-region 1 (point-max)
 						   ocaml-indent-command
 						   nil ; delete
 						   ocaml-indent-process-buffer ; buffer
   try
     let reader = LexReader.create_from_channel ic in
     let rec loop last_region = 
-      let token = LexReader.lex reader Lexer.token in
+      let token = 
+        try
+          LexReader.lex reader Lexer.token 
+        with
+        | 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
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.