From b5b607c8be47cbfecee6c49849b01aafd4222436 Mon Sep 17 00:00:00 2001
From: Alan Schmitt <alan.schmitt@polytechnique.org>
Date: Wed, 15 Jul 2015 16:59:36 +0200
Subject: [PATCH] trying for better indentation

---
 generator/js_of_ast.ml | 20 ++++++++++----------
 generator/log.ml       | 12 +++++++-----
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/generator/js_of_ast.ml b/generator/js_of_ast.ml
index cedf30a..5d5409b 100644
--- a/generator/js_of_ast.ml
+++ b/generator/js_of_ast.ml
@@ -134,20 +134,20 @@ let is_infix f args = match args with
  *)
 
 let ppf_lambda_wrap s =
-  Printf.sprintf "@[<v 0>function () {@,%s@,}()@]" s
+  Printf.sprintf "(function () {@;<1 2>@[<v 0>%s@]@,}())" s
   
 let ppf_branch case binders expr =
-  Printf.sprintf "@[<v 1>%s: @[<v 2>%s@,return %s;@,@]@,@,@]"
+  Printf.sprintf "%s: @[<v 0>%s@,return %s;@]"
                  case binders expr
 
 let ppf_let_in decl exp =
   let s =
-    Printf.sprintf "@[<v 0>%s@,@,return %s;@]"
+    Printf.sprintf "%s@,return %s;"
                    decl exp
   in ppf_lambda_wrap s
 
 let ppf_function args body=
-  Printf.sprintf "@[<v 0>function (%s) {@,@[<v 2>@,return %s;@,@]@,}@]"
+  Printf.sprintf "function (%s) {@;<1 2>@[<v 0>return %s;@]@,}"
                  args body
 
 let ppf_apply f args =
@@ -160,7 +160,7 @@ let ppf_apply_infix f arg1 arg2 =
     
 let ppf_match value cases =
   let s =
-    Printf.sprintf "@[<v 0>switch (%s.type) {@,@[<v 2>@,%s@,@]@,}@]"
+    Printf.sprintf "switch (%s.type) {@,@[<v 0>%s@]@,}"
                    value cases
   in ppf_lambda_wrap s
 
@@ -224,7 +224,7 @@ let ppf_record llde =
   in aux "" llde
 
 let ppf_decl id expr =
-  Printf.sprintf "@[<v 0>var %s = %s;@,@]" 
+  Printf.sprintf "@[<v 0>var %s = %s;@]" 
                  id expr
 
 let ppf_pat_array id_list array_expr =
@@ -245,13 +245,13 @@ and show_value_binding old_env vb =
     
 and js_of_structure old_env s =
   let new_env = s.str_final_env in
-  show_list_f (fun strct -> js_of_structure_item new_env strct) lin2 s.str_items
+  show_list_f (fun strct -> js_of_structure_item new_env strct) "@,@," s.str_items
     
 and js_of_structure_item old_env s =
   let new_env = s.str_env in
   match s.str_desc with
   | Tstr_eval (e, _)     -> Printf.sprintf "%s" @@ js_of_expression new_env e
-  | Tstr_value (_, vb_l) -> String.concat lin2 @@ List.map (fun vb -> show_value_binding new_env vb) @@ vb_l
+  | Tstr_value (_, vb_l) -> String.concat "@,@," @@ List.map (fun vb -> show_value_binding new_env vb) @@ vb_l
   | Tstr_type tl ->
    let explore_type = function
       | [] -> ()
@@ -312,7 +312,7 @@ and js_of_expression old_env e =
     else ppf_apply se (String.concat ", " sl)
   | Texp_match (exp, l, [], Total) ->
      let se = js_of_expression new_env exp in
-     let sb = List.fold_left (fun acc x -> acc ^ js_of_branch old_env x se) "" l in
+     let sb = String.concat "@," (List.map (fun x -> js_of_branch old_env x se) l) in
      ppf_match se sb
   | Texp_tuple (tl)               -> ppf_tuple @@ show_list_f (fun exp -> js_of_expression new_env exp) ", " tl
   | Texp_construct (loc, cd, el) ->
@@ -411,7 +411,7 @@ and js_of_pattern old_env pat obj =
      let params = Hashtbl.find type_tbl c in
      let binders =
        if List.length el = 0 then ""
-       else Printf.sprintf "@[<v 0>%s@,@]"
+       else Printf.sprintf "@[<v 0>%s@]"
           ("var " ^ show_list ", " (List.map2 (fun x y -> x ^ " = " ^ obj ^ "." ^ y) (List.map (fun x -> fst (js_of_pattern new_env x obj)) el) params) ^ ";") in
      spat, binders
   | Tpat_tuple el -> out_of_scope "tuple matching"
diff --git a/generator/log.ml b/generator/log.ml
index 2fc5839..1f94251 100644
--- a/generator/log.ml
+++ b/generator/log.ml
@@ -131,16 +131,18 @@ struct
   let logged_output s =
     let str_ppf = Format.str_formatter in
     Format.fprintf str_ppf (Scanf.format_from_string s "");
-    let bad_output = Format.flush_str_formatter () in
-    let pretty_output = global_replace lfs "\n" bad_output in
-    add_log_info pretty_output
+    add_log_info (Format.flush_str_formatter ())
+  (* let bad_output = Format.flush_str_formatter () in *)
+  (* let pretty_output = global_replace lfs "\n" bad_output in *)
+  (* add_log_info pretty_output *)
 
   let unlogged_output s =
     let str_ppf = Format.str_formatter in
     let unlogged_info = strip_log_info s in
     Format.fprintf str_ppf (Scanf.format_from_string unlogged_info "");
-    let bad_output = Format.flush_str_formatter () in
-    global_replace lfs "\n" bad_output
+    Format.flush_str_formatter ()
+  (* let bad_output = Format.flush_str_formatter () in *)
+  (*     global_replace lfs "\n" bad_output *)
     
     
 end
-- 
GitLab