Skip to content
Snippets Groups Projects
Commit b5b607c8 authored by Alan Schmitt's avatar Alan Schmitt Committed by Thomas Wood
Browse files

trying for better indentation

parent 9d657861
No related branches found
No related tags found
No related merge requests found
......@@ -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"
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment