Commits

camlspotter committed b85a312

tests

  • Participants
  • Parent commits eaca8e2

Comments (0)

Files changed (6)

 
   type elt = { k : k;
                indent : int }
-  with sexp
 
-  type t = elt list with sexp
+  let sexp_of_elt { k; indent } =
+    Sexplib.Sexp.List [ sexp_of_k k;
+                        sexp_of_int indent ]
+
+  type t = elt list with sexp_of
 
   let rec indent last_indent  = function
     | [] -> 0
                           At line head, snd pass: the fixed indent of the current line
                           Otherwise: the fixed indent of the current line *)
     last_token : Parser.token option;
-  } with sexp
+  } with sexp_of
 
   let init = { bases = []; orig_indent = 0; last_indent = 0; last_token = None; }
 
             let indent_string = String.make (State.indent pre) ' ' in
             if debug then begin
               print_string indent_string;
-              Format.printf "-- %s@." (Sexplib.Sexp.to_string_mach (Stack.sexp_of_t pre.bases))
+              if pre == post then 
+                Format.printf "-- %s@." (Sexplib.Sexp.to_string_mach (Stack.sexp_of_t pre.bases))
+              else
+                Format.printf "-- %s // %s@." 
+                  (Sexplib.Sexp.to_string_mach (Stack.sexp_of_t pre.bases))
+                  (Sexplib.Sexp.to_string_mach (Stack.sexp_of_t post.bases))
             end;
 
             print_string indent_string;

File tests/comma.ml

   2
 
 let x y = 1
-          , 2 
+  , 2 
 
 let x y = 1,
-          2 
+  2 
 
 let x y = ( 1
           , 2) 

File tests/fun_arrow.ml

+
+let id = fun x y z w 
+  ->  (* Mmmm, I have no idea for this *)
+  x y z w
+
+let id = fun x y 
+             z w -> (* Mmmm, a TODO *)
+  x
+
+

File tests/function.ml

+let f = function X -> 1 
+               | Y -> 2 

File tests/module_type.ml

+module type X = sig
+  val x : int
+end
+
+module type X = 
+  sig
+    val x : int
+  end
+
+
+

File tests/style.ml

+(************************************************** Parens *)
+
 (* ( / { / [ + newline does not move the indent to the token's column,
    but just shifts the indent.
 
   3
 ) (* closing corresponds the line indent of the opening *)
   
-(* If something follows after (, {, [ in the line, 
+(* Paren-20: If something follows after (, {, [ in the line, 
    these open-parens introduce a block.
    The indent is moved to the columns of the open-parens.
 *)
   x : foo;
   y : boo;
 }
+
+(* begin/end *)
+
+(* begin looks like (, but not exactly. It does not follow Paren-20,
+   since begin/end are not used for tuples but for codes, mainly. 
+ *)
+let _ = begin 1,
+  2,
+  3
+end
+
+let _ = begin 
+  1,
+  2,
+  3
+end
+
+(************************************************** Commas *)
+
+(* Comma w/ an open-paren uses the pos of the paren *)
+let x = ( 1, 
+          2 )
+
+(* Commas-20: Comma w/o an open-paren shifts the current indent *)
+let x = 1, 
+  2        (* Having the same indentation as the version w/ paren is,
+              actually hard. *)
+
+(* Comma w/ paren unwinds the indentation to the paren *)
+let x = ( 1
+        , 2 )  
+
+(* Comma is not separator of list elements, so 
+   it cannot unwinds the level upto [ *)
+let x = [ 1
+          , 2,
+          3 ]  
+
+let x = { x = 1, 
+          2 } (* Hmmm, I do not like this, but it follows Commas-20 *)
+
+(************************************************** Semis *)
+
+let x = [ 1;
+          2 ]
+
+let x = f;
+  g
+
+let f = [ 1
+        ; 2
+        ; 3
+        ]
+         
+let f = [
+; 1
+; 2
+; 3
+]
+
+let x = begin
+  f;
+  g;
+  h;
+end
+
+let x = begin f;
+  g;
+; h
+end
+
+let x = { x = 1;
+          y = 2;
+        ; z = 3 
+        }
+
+let x = { 
+  x = 1;
+  y = 2;
+; z = 3 
+}
+
+(*************************************************************** fun *) 
+
+let f = fun x y z w -> (* fun does not introduce a block *)
+  x y z w
+
+let f = fun x -> g x (* but if there is a code after ->, it overrides *)
+                   y
+
+(********************************************************** function *) 
+
+let f = function X -> 1 
+               | Y -> 2 
+
+let f = function 
+    X -> 1 
+  | Y -> 2 
+
+let f = function 
+  | X -> 1 
+  | Y -> 2 
+
+let f = 
+  zzz (function 
+    | X -> 1
+    | Y -> 2
+  )
+
+let f = 
+  zzz (function X -> 1
+              | Y -> 2
+      )
+
+(************************************************************* match *) 
+
+let x = match y with
+  | X -> 1
+  | Y -> 2
+
+let x = 
+  match y with
+  | X -> 1
+  | Y -> 2
+
+let x = match y with X -> 1
+                   | Y -> 2
+
+(******************************************************** OR pattern *) 
+
+let x = match y with
+  | X | Y -> 1
+  | Z 
+  | W -> 2
+  | ( A | B ) -> 3
+  | ( A |
+      B
+    | C ) -> 4
+
+(****************************************************** struct / sig *)
+
+module X = struct
+  let x = 1
+end
+
+module X = 
+  struct
+    let x = 1
+  end
+
+module X : sig
+  val x : int
+end = struct
+  let x = 1
+end
+
+module type X = sig
+  val x : int
+end
+
+module type X = 
+  sig
+    val x : int
+  end
+
+
+