diff --git a/.ocamlformat b/.ocamlformat index e8450b9a..f538edb1 100644 --- a/.ocamlformat +++ b/.ocamlformat @@ -9,3 +9,5 @@ cases-exp-indent=2 indicate-multiline-delimiters=no parens-tuple=multi-line-only space-around-lists=false +break-infix-before-func +break-infix= fit-or-vertical diff --git a/build_system/clerk_driver.ml b/build_system/clerk_driver.ml index 06616f22..cc33bc5b 100644 --- a/build_system/clerk_driver.ml +++ b/build_system/clerk_driver.ml @@ -24,7 +24,8 @@ module Nj = Ninja_utils let files_or_folders = Arg.( - non_empty & pos_right 0 file [] + non_empty + & pos_right 0 file [] & info [] ~docv:"FILE(S)" ~doc:"File(s) or folder(s) to process") let command = @@ -38,7 +39,8 @@ let debug = let reset_test_outputs = Arg.( - value & flag + value + & flag & info ["r"; "reset"] ~doc: "Used with the `test` command, resets the test output to whatever is \ @@ -88,8 +90,16 @@ let catala_opts = let clerk_t f = Term.( - const f $ files_or_folders $ command $ catalac $ catala_opts $ makeflags - $ debug $ scope $ reset_test_outputs $ ninja_output) + const f + $ files_or_folders + $ command + $ catalac + $ catala_opts + $ makeflags + $ debug + $ scope + $ reset_test_outputs + $ ninja_output) let version = "0.5.0" @@ -336,7 +346,8 @@ let collect_all_ninja_build let expected_output_file = expected_output.output_dir ^ Filename.basename expected_output.tested_filename - ^ "." ^ expected_output.id + ^ "." + ^ expected_output.id in let vars = [ @@ -392,7 +403,8 @@ let add_root_test_build (all_file_names : string list) (all_test_builds : string) : ninja = let file_names_str = - List.hd all_file_names ^ "" + List.hd all_file_names + ^ "" ^ List.fold_left (fun acc name -> acc ^ "; " ^ name) "" (List.tl all_file_names) @@ -440,9 +452,11 @@ let get_catala_files_in_folder (dir : string) : string list = false in if f_is_dir then - readdir_sort f |> Array.to_list + readdir_sort f + |> Array.to_list |> List.map (Filename.concat f) - |> List.append fs |> loop result + |> List.append fs + |> loop result else loop (f :: result) fs | [] -> result in diff --git a/compiler/dcalc/ast.ml b/compiler/dcalc/ast.ml index 0873fae9..dd36e835 100644 --- a/compiler/dcalc/ast.ml +++ b/compiler/dcalc/ast.ml @@ -463,14 +463,17 @@ let rec free_vars_expr (e : 'm marked_expr) : VarSet.t = | EInj (e1, _, _, _) -> free_vars_expr e1 | EApp (e1, es) | EMatch (e1, es, _) -> - e1 :: es |> List.map free_vars_expr + e1 :: es + |> List.map free_vars_expr |> List.fold_left VarSet.union VarSet.empty | EDefault (es, ejust, econs) -> - ejust :: econs :: es |> List.map free_vars_expr + ejust :: econs :: es + |> List.map free_vars_expr |> List.fold_left VarSet.union VarSet.empty | EOp _ | ELit _ -> VarSet.empty | EIfThenElse (e1, e2, e3) -> - [e1; e2; e3] |> List.map free_vars_expr + [e1; e2; e3] + |> List.map free_vars_expr |> List.fold_left VarSet.union VarSet.empty | EAbs (binder, _) -> let vs, body = Bindlib.unmbind binder in @@ -672,7 +675,8 @@ let rec equal_exprs (e1 : 'm marked_expr) (e2 : 'm marked_expr) : bool = | EAssert e1, EAssert e2 -> equal_exprs e1 e2 | EOp op1, EOp op2 -> equal_ops op1 op2 | EDefault (exc1, def1, cons1), EDefault (exc2, def2, cons2) -> - equal_exprs def1 def2 && equal_exprs cons1 cons2 + equal_exprs def1 def2 + && equal_exprs cons1 cons2 && equal_exprs_list exc1 exc2 | EIfThenElse (if1, then1, else1), EIfThenElse (if2, then2, else2) -> equal_exprs if1 if2 && equal_exprs then1 then2 && equal_exprs else1 else2 diff --git a/compiler/dcalc/interpreter.ml b/compiler/dcalc/interpreter.ml index 90045f77..55cfccbf 100644 --- a/compiler/dcalc/interpreter.ml +++ b/compiler/dcalc/interpreter.ml @@ -198,7 +198,8 @@ let rec evaluate_operator A.ELit (LBool (try - en1 = en2 && i1 = i2 + en1 = en2 + && i1 = i2 && match evaluate_operator ctx op pos [e1; e2] with | A.ELit (LBool b) -> b diff --git a/compiler/desugared/dependency.ml b/compiler/desugared/dependency.ml index d67fc886..9aad2351 100644 --- a/compiler/desugared/dependency.ml +++ b/compiler/desugared/dependency.ml @@ -132,7 +132,8 @@ let check_for_cycle (scope : Ast.scope) (g : ScopeDependencies.t) : unit = Marked.get_mark var_info ); ( Some ("Used here in the definition of another cycle variable " - ^ succ_str ^ ":"), + ^ succ_str + ^ ":"), edge_pos ); ]) scc) @@ -468,12 +469,15 @@ let check_for_exception_cycle (g : ExceptionsDependencies.t) : unit = in [ ( Some - ("Cyclic exception for definition of variable \"" ^ var_str - ^ "\", declared here:"), + ("Cyclic exception for definition of variable \"" + ^ var_str + ^ "\", declared here:"), Marked.get_mark var_info ); ( Some ("Used here in the definition of another cyclic exception \ - for defining \"" ^ var_str ^ "\":"), + for defining \"" + ^ var_str + ^ "\":"), List.hd edge_pos ); ]) scc) diff --git a/compiler/desugared/desugared_to_scope.ml b/compiler/desugared/desugared_to_scope.ml index 5c67b43e..cfeefa41 100644 --- a/compiler/desugared/desugared_to_scope.ml +++ b/compiler/desugared/desugared_to_scope.ml @@ -688,7 +688,8 @@ let translate_program (pgrm : Ast.program) : Scopelang.Ast.program = in ( Marked.unmark (Ast.ScopeVar.get_info scope_var) - ^ "_" ^ state_name, + ^ "_" + ^ state_name, state_pos )) )) states)) ctx.scope_var_mapping; diff --git a/compiler/driver.ml b/compiler/driver.ml index 3b2f22aa..bf4c1e10 100644 --- a/compiler/driver.ml +++ b/compiler/driver.ml @@ -101,7 +101,8 @@ let driver source_file (options : Cli.options) : int = let output_file, with_output = get_output ~ext:".d" () in Cli.debug_print "Writing list of dependencies to %s..." (Option.value ~default:"stdout" output_file); - with_output @@ fun oc -> + with_output + @@ fun oc -> Printf.fprintf oc "%s:\\\n%s\n%s:" (String.concat "\\\n" (Option.value ~default:"stdout" output_file @@ -165,7 +166,8 @@ let driver source_file (options : Cli.options) : int = match backend with | `Scopelang -> let _output_file, with_output = get_output_format () in - with_output @@ fun fmt -> + with_output + @@ fun fmt -> if Option.is_some options.ex_scope then Format.fprintf fmt "%a\n" (Scopelang.Print.format_scope ~debug:options.debug) @@ -191,7 +193,8 @@ let driver source_file (options : Cli.options) : int = match backend with | `Dcalc -> let _output_file, with_output = get_output_format () in - with_output @@ fun fmt -> + with_output + @@ fun fmt -> if Option.is_some options.ex_scope then Format.fprintf fmt "%a\n" (Dcalc.Print.format_scope ~debug:options.debug prgm.decl_ctx) @@ -295,7 +298,8 @@ let driver source_file (options : Cli.options) : int = match backend with | `Lcalc -> let _output_file, with_output = get_output_format () in - with_output @@ fun fmt -> + with_output + @@ fun fmt -> if Option.is_some options.ex_scope then Format.fprintf fmt "%a\n" (Lcalc.Print.format_scope ~debug:options.debug prgm.decl_ctx) @@ -326,7 +330,8 @@ let driver source_file (options : Cli.options) : int = let output_file, with_output = get_output_format ~ext:".ml" () in - with_output @@ fun fmt -> + with_output + @@ fun fmt -> Cli.debug_print "Compiling program into OCaml..."; Cli.debug_print "Writing to %s..." (Option.value ~default:"stdout" output_file); @@ -344,7 +349,8 @@ let driver source_file (options : Cli.options) : int = match backend with | `Scalc -> let _output_file, with_output = get_output_format () in - with_output @@ fun fmt -> + with_output + @@ fun fmt -> if Option.is_some options.ex_scope then Format.fprintf fmt "%a\n" (Scalc.Print.format_scope ~debug:options.debug @@ -367,7 +373,8 @@ let driver source_file (options : Cli.options) : int = Cli.debug_print "Compiling program into Python..."; Cli.debug_print "Writing to %s..." (Option.value ~default:"stdout" output_file); - with_output @@ fun fmt -> + with_output + @@ fun fmt -> Scalc.To_python.format_program fmt prgm type_ordering | `Plugin (Plugin.Lcalc _) -> assert false | `Plugin (Plugin.Scalc p) -> diff --git a/compiler/lcalc/ast.ml b/compiler/lcalc/ast.ml index 379a70f0..7c642462 100644 --- a/compiler/lcalc/ast.ml +++ b/compiler/lcalc/ast.ml @@ -222,7 +222,8 @@ let option_enum_config : (D.EnumConstructor.t * D.typ Marked.pos) list = let make_none m = let mark = Marked.mark m in let tunit = D.TLit D.TUnit, D.mark_pos m in - Bindlib.box @@ mark + Bindlib.box + @@ mark @@ EInj ( Marked.mark (D.map_mark (fun pos -> pos) (fun _ -> tunit) m) diff --git a/compiler/lcalc/to_ocaml.ml b/compiler/lcalc/to_ocaml.ml index bcefc908..7bd63bf5 100644 --- a/compiler/lcalc/to_ocaml.ml +++ b/compiler/lcalc/to_ocaml.ml @@ -148,7 +148,10 @@ let avoid_keywords (s : string) : string = let format_struct_name (fmt : Format.formatter) (v : Dcalc.Ast.StructName.t) : unit = Format.asprintf "%a" Dcalc.Ast.StructName.format_t v - |> to_ascii |> to_snake_case |> avoid_keywords |> Format.fprintf fmt "%s" + |> to_ascii + |> to_snake_case + |> avoid_keywords + |> Format.fprintf fmt "%s" let format_to_module_name (fmt : Format.formatter) @@ -156,9 +159,13 @@ let format_to_module_name (match name with | `Ename v -> Format.asprintf "%a" D.EnumName.format_t v | `Sname v -> Format.asprintf "%a" D.StructName.format_t v) - |> to_ascii |> to_snake_case |> avoid_keywords |> String.split_on_char '_' + |> to_ascii + |> to_snake_case + |> avoid_keywords + |> String.split_on_char '_' |> List.map String.capitalize_ascii - |> String.concat "" |> Format.fprintf fmt "%s" + |> String.concat "" + |> Format.fprintf fmt "%s" let format_struct_field_name (fmt : Format.formatter) diff --git a/compiler/literate/html.ml b/compiler/literate/html.ml index ebe30383..34f9d570 100644 --- a/compiler/literate/html.ml +++ b/compiler/literate/html.ml @@ -160,7 +160,8 @@ let pygmentize_code (c : string Marked.pos) (language : C.backend_lang) : string (** {1 Weaving} *) let sanitize_html_href str = - str |> Ubase.from_utf8 + str + |> Ubase.from_utf8 |> R.substitute ~rex:(R.regexp "[' '°]") ~subst:(function _ -> "%20") let rec law_structure_to_html diff --git a/compiler/literate/latex.ml b/compiler/literate/latex.ml index 8678e68c..d5f18435 100644 --- a/compiler/literate/latex.ml +++ b/compiler/literate/latex.ml @@ -182,7 +182,8 @@ let check_exceeding_lines (start_line : int) (filename : string) (content : string) = - content |> String.split_on_char '\n' + content + |> String.split_on_char '\n' |> List.iteri (fun i s -> if String.length s > max_len then ( Cli.warning_print "The line %s in %s is exceeding %s characters:" diff --git a/compiler/plugins/api_web.ml b/compiler/plugins/api_web.ml index ee9cc95b..ee9c784e 100644 --- a/compiler/plugins/api_web.ml +++ b/compiler/plugins/api_web.ml @@ -42,7 +42,10 @@ module To_jsoo = struct (v : Dcalc.Ast.StructFieldName.t) : unit = let s = Format.asprintf "%a" Dcalc.Ast.StructFieldName.format_t v - |> to_ascii |> to_snake_case |> avoid_keywords |> to_camel_case + |> to_ascii + |> to_snake_case + |> avoid_keywords + |> to_camel_case in Format.fprintf fmt "%s" s @@ -128,10 +131,14 @@ module To_jsoo = struct let format_var_camel_case (fmt : Format.formatter) (v : 'm var) : unit = let lowercase_name = - Bindlib.name_of v |> to_ascii |> to_snake_case + Bindlib.name_of v + |> to_ascii + |> to_snake_case |> Re.Pcre.substitute ~rex:(Re.Pcre.regexp "\\.") ~subst:(fun _ -> "_dot_") - |> to_ascii |> avoid_keywords |> to_camel_case + |> to_ascii + |> avoid_keywords + |> to_camel_case in if List.mem lowercase_name ["handle_default"; "handle_default_opt"] diff --git a/compiler/plugins/json_schema.ml b/compiler/plugins/json_schema.ml index 78240bb2..63624cac 100644 --- a/compiler/plugins/json_schema.ml +++ b/compiler/plugins/json_schema.ml @@ -40,7 +40,10 @@ module To_json = struct (v : Dcalc.Ast.StructFieldName.t) : unit = let s = Format.asprintf "%a" Dcalc.Ast.StructFieldName.format_t v - |> to_ascii |> to_snake_case |> avoid_keywords |> to_camel_case + |> to_ascii + |> to_snake_case + |> avoid_keywords + |> to_camel_case in Format.fprintf fmt "%s" s diff --git a/compiler/plugins/python.ml b/compiler/plugins/python.ml index 24a8bb59..3f9a8300 100644 --- a/compiler/plugins/python.ml +++ b/compiler/plugins/python.ml @@ -26,7 +26,7 @@ let extension = ".py" let apply ~source_file ~output_file ~scope prgm type_ordering = ignore source_file; ignore scope; - Utils.File.with_formatter_of_opt_file output_file @@ fun fmt -> - Scalc.To_python.format_program fmt prgm type_ordering + Utils.File.with_formatter_of_opt_file output_file + @@ fun fmt -> Scalc.To_python.format_program fmt prgm type_ordering let () = Driver.Plugin.register_scalc ~name ~extension apply diff --git a/compiler/scalc/to_python.ml b/compiler/scalc/to_python.ml index 695690d9..38ae02f3 100644 --- a/compiler/scalc/to_python.ml +++ b/compiler/scalc/to_python.ml @@ -193,9 +193,13 @@ let rec format_typ (fmt : Format.formatter) (typ : Dcalc.Ast.typ Marked.pos) : | TAny -> Format.fprintf fmt "Any" let format_name_cleaned (fmt : Format.formatter) (s : string) : unit = - s |> to_ascii |> to_snake_case + s + |> to_ascii + |> to_snake_case |> Re.Pcre.substitute ~rex:(Re.Pcre.regexp "\\.") ~subst:(fun _ -> "_dot_") - |> to_ascii |> avoid_keywords |> Format.fprintf fmt "%s" + |> to_ascii + |> avoid_keywords + |> Format.fprintf fmt "%s" module StringMap = Map.Make (String) module IntMap = Map.Make (Int) diff --git a/compiler/scopelang/dependency.ml b/compiler/scopelang/dependency.ml index 352149c0..05248304 100644 --- a/compiler/scopelang/dependency.ml +++ b/compiler/scopelang/dependency.ml @@ -103,7 +103,8 @@ let check_for_cycle_in_scope (g : SDependencies.t) : unit = Marked.get_mark var_info ); ( Some ("Used here in the definition of another cycle variable " - ^ succ_str ^ ":"), + ^ succ_str + ^ ":"), edge_pos ); ]) scc) @@ -254,7 +255,8 @@ let check_type_cycles (structs : Ast.struct_ctx) (enums : Ast.enum_ctx) : Marked.get_mark var_info ); ( Some ("Used here in the definition of another cycle type " - ^ succ_str ^ ":"), + ^ succ_str + ^ ":"), edge_pos ); ]) scc) diff --git a/compiler/scopelang/scope_to_dcalc.ml b/compiler/scopelang/scope_to_dcalc.ml index 2c6b7fd2..764fdf81 100644 --- a/compiler/scopelang/scope_to_dcalc.ml +++ b/compiler/scopelang/scope_to_dcalc.ml @@ -464,7 +464,8 @@ let translate_rule let a_name = Marked.map_under_mark (fun str -> - str ^ "." + str + ^ "." ^ Marked.unmark (Ast.ScopeVar.get_info (Marked.unmark subs_var))) (Ast.SubScopeName.get_info (Marked.unmark subs_index)) in diff --git a/compiler/utils/cli.ml b/compiler/utils/cli.ml index 7a8af56e..5efcc913 100644 --- a/compiler/utils/cli.ml +++ b/compiler/utils/cli.ml @@ -109,7 +109,8 @@ let color = let unstyled = Arg.( - value & flag + value + & flag & info ["unstyled"; "u"] ~doc: "Removes styling (colors, etc.) from terminal output. Equivalent to \ @@ -120,7 +121,8 @@ let optimize = let trace_opt = Arg.( - value & flag + value + & flag & info ["trace"; "t"] ~doc: "Displays a trace of the interpreter's computation or generates \ @@ -128,25 +130,29 @@ let trace_opt = let avoid_exceptions = Arg.( - value & flag + value + & flag & info ["avoid_exceptions"] ~doc:"Compiles the default calculus without exceptions") let closure_conversion = Arg.( - value & flag + value + & flag & info ["closure_conversion"] ~doc:"Performs closure conversion on the lambda calculus") let wrap_weaved_output = Arg.( - value & flag + value + & flag & info ["wrap"; "w"] ~doc:"Wraps literate programming output with a minimal preamble.") let print_only_law = Arg.( - value & flag + value + & flag & info ["print_only_law"] ~doc: "In literate programming output, skip all code and metadata sections \ @@ -189,7 +195,8 @@ let max_prec_digits_opt = let disable_counterexamples_opt = Arg.( - value & flag + value + & flag & info ["disable_counterexamples"] ~doc: @@ -268,10 +275,23 @@ let options = } in Term.( - const make $ debug $ color $ unstyled $ wrap_weaved_output - $ avoid_exceptions $ closure_conversion $ backend $ plugins_dirs $ language - $ max_prec_digits_opt $ trace_opt $ disable_counterexamples_opt $ optimize - $ ex_scope $ output $ print_only_law) + const make + $ debug + $ color + $ unstyled + $ wrap_weaved_output + $ avoid_exceptions + $ closure_conversion + $ backend + $ plugins_dirs + $ language + $ max_prec_digits_opt + $ trace_opt + $ disable_counterexamples_opt + $ optimize + $ ex_scope + $ output + $ print_only_law) let catala_t f = Term.(const f $ file $ options) @@ -432,7 +452,9 @@ let concat_with_line_depending_prefix_and_suffix let out, _ = List.fold_left (fun (acc, i) s -> - ( (acc ^ prefix i ^ s + ( (acc + ^ prefix i + ^ s ^ if i = List.length ss - 1 then "" else suffix i), i + 1 )) ((prefix 0 ^ hd ^ if 0 = List.length ss - 1 then "" else suffix 0), 1) diff --git a/runtimes/jsoo/runtime.ml b/runtimes/jsoo/runtime.ml index f6f20d89..adf3b748 100644 --- a/runtimes/jsoo/runtime.ml +++ b/runtimes/jsoo/runtime.ml @@ -91,12 +91,15 @@ let event_manager : event_manager Js.t = Js.wrap_meth_callback (fun () -> Js.array (Array.of_list - (R_ocaml.retrieve_log () |> R_ocaml.EventParser.parse_raw_events + (R_ocaml.retrieve_log () + |> R_ocaml.EventParser.parse_raw_events |> List.map (fun event -> object%js val mutable data = - event |> R_ocaml.yojson_of_event - |> Yojson.Safe.to_string |> Js.string + event + |> R_ocaml.yojson_of_event + |> Yojson.Safe.to_string + |> Js.string end)))) method retrieveRawEvents = @@ -130,7 +133,8 @@ let event_manager : event_manager Js.t = | EndCall _ | BeginCall _ | DecisionTaken _ -> R_ocaml.unembeddable ()) |> R_ocaml.yojson_of_runtime_value - |> Yojson.Safe.to_string |> Js.string + |> Yojson.Safe.to_string + |> Js.string val mutable sourcePosition = match evt with diff --git a/runtimes/ocaml/runtime.ml b/runtimes/ocaml/runtime.ml index d25956cb..cb9827e6 100644 --- a/runtimes/ocaml/runtime.ml +++ b/runtimes/ocaml/runtime.ml @@ -436,16 +436,19 @@ module EventParser = struct { pos = Some pos; name; value; fun_calls = Some fun_calls } ) | event :: _ -> failwith - ("Invalid function call ([ " ^ String.concat ", " infos - ^ " ]): expected variable definition (function output), found: " - ^ raw_event_to_string event ^ "[" + ("Invalid function call ([ " + ^ String.concat ", " infos + ^ " ]): expected variable definition (function output), found: " + ^ raw_event_to_string event + ^ "[" ^ (nb_raw_events - List.length rest + 1 |> string_of_int) ^ "]") | [] -> failwith - ("Invalid function call ([ " ^ String.concat ", " infos - ^ " ]): expected variable definition (function output), found: \ - end of tokens") + ("Invalid function call ([ " + ^ String.concat ", " infos + ^ " ]): expected variable definition (function output), found: \ + end of tokens") in parse_events { ctx with events = var_comp :: ctx.events; rest }