From 80647a76c5f73f4c79ea5fdd343c5c6fb8c5590f Mon Sep 17 00:00:00 2001 From: Thomas Wood <thomas.wood09@imperial.ac.uk> Date: Thu, 24 Sep 2015 23:08:56 +0100 Subject: [PATCH] Minor formatting tidyup --- generator/js_of_ast.ml | 30 ++++++++++++++---------------- generator/main.ml | 4 ++-- generator/parse_type.ml | 28 ++++++++++++++-------------- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/generator/js_of_ast.ml b/generator/js_of_ast.ml index cc0d92e..c9e1000 100644 --- a/generator/js_of_ast.ml +++ b/generator/js_of_ast.ml @@ -17,7 +17,7 @@ module L = Logged (Token_generator) (struct let size = 256 end) (** * Useful functions (Warning: shadows `show_list' from Mytools) *) - + let show_list_f f sep l = l |> List.map f |> List.fold_left (fun acc x -> acc ^ (if acc = "" then "" else sep) ^ x) "" @@ -25,14 +25,14 @@ let show_list_f f sep l = l let show_list sep l = List.fold_left (fun acc x -> acc ^ (if acc = "" then "" else sep) ^ x) "" l -let is_sbool x = List.mem x ["true" ; "false"] +let is_sbool x = List.mem x ["true" ; "false"] let rec zip l1 l2 = match l1, l2 with | [], x :: xs | x :: xs, [] -> failwith "zip: list must have the same length." | [], [] -> [] | x :: xs, y :: ys -> (x, y) :: zip xs ys -let unzip l = +let unzip l = let rec aux acc1 acc2 = function | [] -> List.rev acc1, List.rev acc2 | (x, y) :: xs -> aux (x :: acc1) (y :: acc2) xs @@ -59,7 +59,7 @@ let is_infix f args = match args with let f_loc = (f.exp_loc.loc_start, f.exp_loc.loc_end) in let args_loc = (x.exp_loc.loc_start, x.exp_loc.loc_end) in if fst args_loc < fst f_loc then true else false - + (** * Before-hand definitions of Pretty-Printer-Format for converting ocaml * to ECMAScript, therefore all of them are in a single place. @@ -67,7 +67,7 @@ let is_infix f args = match args with let ppf_lambda_wrap s = Printf.sprintf "(function () {@;<1 2>@[<v 0>%s@]@,}())@," s - + let ppf_branch case binders expr = Printf.sprintf "%s: @[<v 0>%s@,return %s;@]" case binders expr @@ -89,7 +89,7 @@ let ppf_apply f args = let ppf_apply_infix f arg1 arg2 = Printf.sprintf "%s %s %s" arg1 f arg2 - + let ppf_match value cases = let s = Printf.sprintf "switch (%s.type) {@,@[<v 0>%s@]@,}" @@ -99,9 +99,9 @@ let ppf_match value cases = let ppf_array values = Printf.sprintf "[%s]" values - + let ppf_tuple = ppf_array - + let ppf_ifthen cond iftrue = Printf.sprintf "(function () {@;<1 2>@[<v 2>@,if (%s) {@,return %s;@,}@]@,})()" cond iftrue @@ -119,7 +119,7 @@ let ppf_while cd body = Printf.sprintf "@[<v 2>while(%s) {@;<1 2>%s@,@]}" cd body in ppf_lambda_wrap s - + let ppf_for id start ed flag body = let fl_to_string = function | Upto -> "++" @@ -137,13 +137,11 @@ let ppf_for id start ed flag body = tag *) let ppf_cstr tag value = - Printf.sprintf "%s: %s" - tag value + Printf.sprintf "%s: %s" tag value let ppf_single_cstrs typ = - Printf.sprintf "@[<v 2>{type: \"%s\"}@]" - typ - + Printf.sprintf "@[<v 2>{type: \"%s\"}@]" typ + let ppf_multiple_cstrs typ rest = Printf.sprintf "@[<v 2>{type: \"%s\", %s}@]" typ rest @@ -279,7 +277,7 @@ and js_of_expression e = | Texp_lazy _ -> out_of_scope locn "lazy expressions" | Texp_object (_,_) -> out_of_scope locn "objects" | Texp_pack _ -> out_of_scope locn "packing" - + and js_of_constant = function | Const_int n -> string_of_int n | Const_char c -> String.make 1 c @@ -288,7 +286,7 @@ and js_of_constant = function | Const_int32 n -> Int32.to_string n | Const_int64 n -> Int64.to_string n | Const_nativeint n -> Nativeint.to_string n - + and js_of_longident loc = let res = String.concat "." @@ Longident.flatten loc.txt in if res = "()" then "undefined" else res diff --git a/generator/main.ml b/generator/main.ml index 4fcf742..0cf54c5 100644 --- a/generator/main.ml +++ b/generator/main.ml @@ -14,7 +14,7 @@ let outputfile = ref None (*#########################################################################*) let _ = - + (* disable loading of stdlib *) Clflags.nopervasives := false; @@ -23,7 +23,7 @@ let _ = let files = ref [] in Arg.parse - [ ("-I", Arg.String (fun i -> Clflags.include_dirs := i :: !Clflags.include_dirs), + [ ("-I", Arg.String (fun i -> Clflags.include_dirs := i :: !Clflags.include_dirs), "includes a directory where to look for interface files"); ("-o", Arg.String (fun s -> outputfile := Some s), "set the output file name"); ("-debug", Arg.Set debug, "trace the various steps") diff --git a/generator/parse_type.ml b/generator/parse_type.ml index 38c2785..a834891 100644 --- a/generator/parse_type.ml +++ b/generator/parse_type.ml @@ -118,21 +118,21 @@ let process_implementation_file ppf sourcefile = (*incr Odoc_global.errors ;*) None, inputfile, modulename (* ADDED *) - | Env.Error err -> + | Env.Error err -> Env.report_error ppf err; print_newline(); raise e - | Typecore.Error (loc,env,err) -> + | Typecore.Error (loc,env,err) -> Location.print_error ppf loc; Typecore.report_error env ppf err; print_newline(); raise e - | Typetexp.Error (loc,env,err) -> + | Typetexp.Error (loc,env,err) -> Location.print_error ppf loc; Typetexp.report_error env ppf err; print_newline(); raise e - | Typemod.Error (loc,env,err) -> + | Typemod.Error (loc,env,err) -> Location.print_error ppf loc; Typemod.report_error env ppf err; print_newline(); @@ -179,21 +179,21 @@ let typecheck_implementation_file ppf sourcefile parsetree = prerr_endline s; (*incr Odoc_global.errors ;*) None - | Env.Error err -> + | Env.Error err -> Env.report_error ppf err; print_newline(); raise e - | Typetexp.Error (loc,env,err) -> + | Typetexp.Error (loc,env,err) -> Location.print_error ppf loc; Typetexp.report_error env ppf err; print_newline(); raise e - | Typecore.Error (loc,env,err) -> + | Typecore.Error (loc,env,err) -> Location.print_error ppf loc; - Typecore.report_error env ppf err; + Typecore.report_error env ppf err; print_newline(); raise e - | Typemod.Error (loc,env,err) -> + | Typemod.Error (loc,env,err) -> Location.print_error ppf loc; Typemod.report_error env ppf err; print_newline(); @@ -224,21 +224,21 @@ let typecheck_interface_file ppf sourcefile output_prefix = prerr_endline s; (*incr Odoc_global.errors ;*) None - | Env.Error err -> + | Env.Error err -> Env.report_error ppf err; print_newline(); raise e - | Typetexp.Error (loc,env,err) -> + | Typetexp.Error (loc,env,err) -> Location.print_error ppf loc; Typetexp.report_error env ppf err; print_newline(); raise e - | Typecore.Error (loc,env,err) -> + | Typecore.Error (loc,env,err) -> Location.print_error ppf loc; - Typecore.report_error env ppf err; + Typecore.report_error env ppf err; print_newline(); raise e - | Typemod.Error (loc,env,err) -> + | Typemod.Error (loc,env,err) -> Location.print_error ppf loc; Typemod.report_error env ppf err; print_newline(); -- GitLab