From 660e5775de9a74c204f2e4b656ca9da6fb2fe516 Mon Sep 17 00:00:00 2001 From: Louis Gesbert Date: Mon, 21 Nov 2022 10:46:17 +0100 Subject: [PATCH] Rename utils to catala_utils --- build_system/clerk_driver.ml | 2 +- build_system/dune | 2 +- .../catala_utils.mld} | 6 ++-- compiler/{utils => catala_utils}/cli.ml | 0 compiler/{utils => catala_utils}/cli.mli | 0 compiler/{utils => catala_utils}/dune | 6 ++-- compiler/{utils => catala_utils}/errors.ml | 0 compiler/{utils => catala_utils}/errors.mli | 0 compiler/{utils => catala_utils}/file.ml | 0 compiler/{utils => catala_utils}/file.mli | 0 compiler/{utils => catala_utils}/marked.ml | 0 compiler/{utils => catala_utils}/marked.mli | 0 compiler/{utils => catala_utils}/pos.ml | 0 compiler/{utils => catala_utils}/pos.mli | 0 .../{utils => catala_utils}/string_common.ml | 0 .../{utils => catala_utils}/string_common.mli | 0 compiler/{utils => catala_utils}/uid.ml | 6 ++-- compiler/{utils => catala_utils}/uid.mli | 2 +- compiler/catala_web_interpreter.ml | 4 ++- compiler/dcalc/dune | 2 +- compiler/dcalc/from_scopelang.ml | 8 ++--- compiler/dcalc/interpreter.ml | 2 +- compiler/dcalc/interpreter.mli | 2 +- compiler/dcalc/optimizations.ml | 2 +- compiler/desugared/ast.ml | 2 +- compiler/desugared/ast.mli | 2 +- compiler/desugared/dependency.ml | 2 +- compiler/desugared/dependency.mli | 2 +- compiler/desugared/dune | 2 +- compiler/desugared/from_surface.ml | 2 +- compiler/desugared/name_resolution.ml | 14 ++++---- compiler/desugared/name_resolution.mli | 2 +- compiler/driver.ml | 5 +-- compiler/driver.mli | 4 ++- compiler/dune | 2 +- compiler/index.mld | 2 +- compiler/lcalc/ast.ml | 2 +- compiler/lcalc/ast.mli | 3 +- compiler/lcalc/closure_conversion.ml | 2 +- compiler/lcalc/compile_with_exceptions.ml | 4 +-- compiler/lcalc/compile_without_exceptions.ml | 2 +- compiler/lcalc/optimizations.ml | 2 +- compiler/lcalc/to_ocaml.ml | 4 +-- compiler/literate/dune | 2 +- compiler/literate/html.ml | 4 +-- compiler/literate/html.mli | 2 +- compiler/literate/latex.ml | 4 +-- compiler/literate/latex.mli | 2 +- compiler/literate/literate_common.ml | 2 +- compiler/literate/literate_common.mli | 14 ++++---- compiler/plugin.ml | 8 +++-- compiler/plugin.mli | 4 ++- compiler/plugins/api_web.ml | 2 +- compiler/plugins/json_schema.ml | 2 +- compiler/plugins/python.ml | 4 ++- compiler/scalc/ast.ml | 2 +- compiler/scalc/compile_from_lambda.ml | 2 +- compiler/scalc/print.ml | 2 +- compiler/scalc/to_python.ml | 4 +-- compiler/scopelang/ast.ml | 2 +- compiler/scopelang/ast.mli | 2 +- compiler/scopelang/dependency.ml | 2 +- compiler/scopelang/dependency.mli | 2 +- compiler/scopelang/dune | 2 +- compiler/scopelang/from_desugared.ml | 4 +-- compiler/scopelang/print.ml | 2 +- compiler/shared_ast/definitions.ml | 2 +- compiler/shared_ast/dune | 2 +- compiler/shared_ast/expr.ml | 2 +- compiler/shared_ast/expr.mli | 2 +- compiler/shared_ast/print.ml | 32 ++++++++--------- compiler/shared_ast/print.mli | 2 +- compiler/shared_ast/scope.ml | 4 +-- compiler/shared_ast/scope.mli | 2 +- compiler/shared_ast/typing.ml | 6 ++-- compiler/surface/ast.ml | 2 +- compiler/surface/dune | 2 +- compiler/surface/fill_positions.ml | 2 +- compiler/surface/lexer.cppo.ml | 2 +- compiler/surface/lexer_common.ml | 2 +- compiler/surface/lexer_common.mli | 2 +- compiler/surface/parser.mly | 2 +- compiler/surface/parser_driver.ml | 2 +- compiler/surface/parser_driver.mli | 2 +- compiler/verification/conditions.ml | 2 +- compiler/verification/conditions.mli | 2 +- compiler/verification/dune | 2 +- compiler/verification/io.ml | 2 +- compiler/verification/solver.ml | 4 ++- compiler/verification/z3backend.dummy.ml | 2 +- compiler/verification/z3backend.real.ml | 2 +- french_law/catala_legifrance/api.ml | 17 ++++----- .../catala_legifrance/catala_legifrance.ml | 36 ++++++++++--------- french_law/catala_legifrance/date.ml | 4 ++- french_law/catala_legifrance/dune | 2 +- .../{cli.ml => legifrance_cli.ml} | 3 +- 96 files changed, 173 insertions(+), 157 deletions(-) rename compiler/{utils/utils.mld => catala_utils/catala_utils.mld} (90%) rename compiler/{utils => catala_utils}/cli.ml (100%) rename compiler/{utils => catala_utils}/cli.mli (100%) rename compiler/{utils => catala_utils}/dune (58%) rename compiler/{utils => catala_utils}/errors.ml (100%) rename compiler/{utils => catala_utils}/errors.mli (100%) rename compiler/{utils => catala_utils}/file.ml (100%) rename compiler/{utils => catala_utils}/file.mli (100%) rename compiler/{utils => catala_utils}/marked.ml (100%) rename compiler/{utils => catala_utils}/marked.mli (100%) rename compiler/{utils => catala_utils}/pos.ml (100%) rename compiler/{utils => catala_utils}/pos.mli (100%) rename compiler/{utils => catala_utils}/string_common.ml (100%) rename compiler/{utils => catala_utils}/string_common.mli (100%) rename compiler/{utils => catala_utils}/uid.ml (93%) rename compiler/{utils => catala_utils}/uid.mli (97%) rename french_law/catala_legifrance/{cli.ml => legifrance_cli.ml} (96%) diff --git a/build_system/clerk_driver.ml b/build_system/clerk_driver.ml index a5494d94..2428d3bf 100644 --- a/build_system/clerk_driver.ml +++ b/build_system/clerk_driver.ml @@ -16,7 +16,7 @@ the License. *) open Cmdliner -open Utils +open Catala_utils open Ninja_utils module Nj = Ninja_utils diff --git a/build_system/dune b/build_system/dune index c1ffbcba..50c30752 100644 --- a/build_system/dune +++ b/build_system/dune @@ -9,7 +9,7 @@ (public_name clerk.driver) (libraries catala.runtime_ocaml - catala.utils + catala.catala_utils ninja_utils cmdliner re diff --git a/compiler/utils/utils.mld b/compiler/catala_utils/catala_utils.mld similarity index 90% rename from compiler/utils/utils.mld rename to compiler/catala_utils/catala_utils.mld index 17fb6c01..ff4215d0 100644 --- a/compiler/utils/utils.mld +++ b/compiler/catala_utils/catala_utils.mld @@ -7,12 +7,12 @@ In {{: desugared.html} the desugared representation} or in the global identifiers. These identifiers use OCaml's type system to statically distinguish e.g. a scope identifier from a struct identifier. -The {!module: Utils.Uid} module provides a generative functor whose output is +The {!module: Uid} module provides a generative functor whose output is a fresh sort of global identifiers. Related modules: -{!modules: Utils.Uid} +{!modules: Uid} {1 Source code positions} @@ -22,7 +22,7 @@ code. These annotations are critical to produce readable error messages. Related modules: -{!modules: Utils.Pos} +{!modules: Pos} {1 Error messages} diff --git a/compiler/utils/cli.ml b/compiler/catala_utils/cli.ml similarity index 100% rename from compiler/utils/cli.ml rename to compiler/catala_utils/cli.ml diff --git a/compiler/utils/cli.mli b/compiler/catala_utils/cli.mli similarity index 100% rename from compiler/utils/cli.mli rename to compiler/catala_utils/cli.mli diff --git a/compiler/utils/dune b/compiler/catala_utils/dune similarity index 58% rename from compiler/utils/dune rename to compiler/catala_utils/dune index e267b3b2..a5bebf6e 100644 --- a/compiler/utils/dune +++ b/compiler/catala_utils/dune @@ -1,8 +1,8 @@ (library - (name utils) - (public_name catala.utils) + (name catala_utils) + (public_name catala.catala_utils) (libraries cmdliner ubase ANSITerminal re bindlib catala.runtime_ocaml)) (documentation (package catala) - (mld_files utils)) + (mld_files catala_utils)) diff --git a/compiler/utils/errors.ml b/compiler/catala_utils/errors.ml similarity index 100% rename from compiler/utils/errors.ml rename to compiler/catala_utils/errors.ml diff --git a/compiler/utils/errors.mli b/compiler/catala_utils/errors.mli similarity index 100% rename from compiler/utils/errors.mli rename to compiler/catala_utils/errors.mli diff --git a/compiler/utils/file.ml b/compiler/catala_utils/file.ml similarity index 100% rename from compiler/utils/file.ml rename to compiler/catala_utils/file.ml diff --git a/compiler/utils/file.mli b/compiler/catala_utils/file.mli similarity index 100% rename from compiler/utils/file.mli rename to compiler/catala_utils/file.mli diff --git a/compiler/utils/marked.ml b/compiler/catala_utils/marked.ml similarity index 100% rename from compiler/utils/marked.ml rename to compiler/catala_utils/marked.ml diff --git a/compiler/utils/marked.mli b/compiler/catala_utils/marked.mli similarity index 100% rename from compiler/utils/marked.mli rename to compiler/catala_utils/marked.mli diff --git a/compiler/utils/pos.ml b/compiler/catala_utils/pos.ml similarity index 100% rename from compiler/utils/pos.ml rename to compiler/catala_utils/pos.ml diff --git a/compiler/utils/pos.mli b/compiler/catala_utils/pos.mli similarity index 100% rename from compiler/utils/pos.mli rename to compiler/catala_utils/pos.mli diff --git a/compiler/utils/string_common.ml b/compiler/catala_utils/string_common.ml similarity index 100% rename from compiler/utils/string_common.ml rename to compiler/catala_utils/string_common.ml diff --git a/compiler/utils/string_common.mli b/compiler/catala_utils/string_common.mli similarity index 100% rename from compiler/utils/string_common.mli rename to compiler/catala_utils/string_common.mli diff --git a/compiler/utils/uid.ml b/compiler/catala_utils/uid.ml similarity index 93% rename from compiler/utils/uid.ml rename to compiler/catala_utils/uid.ml index 6704930b..a159f4a2 100644 --- a/compiler/utils/uid.ml +++ b/compiler/catala_utils/uid.ml @@ -18,7 +18,7 @@ module type Info = sig type info val to_string : info -> string - val format_info : Format.formatter -> info -> unit + val format : Format.formatter -> info -> unit val equal : info -> info -> bool val compare : info -> info -> int end @@ -59,7 +59,7 @@ module Make (X : Info) () : Id with type info = X.info = struct let get_info (uid : t) : X.info = uid.info let format_t (fmt : Format.formatter) (x : t) : unit = - X.format_info fmt x.info + X.format fmt x.info let hash (x : t) : int = x.id @@ -71,7 +71,7 @@ module MarkedString = struct type info = string Marked.pos let to_string (s, _) = s - let format_info fmt i = Format.pp_print_string fmt (to_string i) + let format fmt i = Format.pp_print_string fmt (to_string i) let equal i1 i2 = String.equal (Marked.unmark i1) (Marked.unmark i2) let compare i1 i2 = String.compare (Marked.unmark i1) (Marked.unmark i2) end diff --git a/compiler/utils/uid.mli b/compiler/catala_utils/uid.mli similarity index 97% rename from compiler/utils/uid.mli rename to compiler/catala_utils/uid.mli index 6f698943..5e479f95 100644 --- a/compiler/utils/uid.mli +++ b/compiler/catala_utils/uid.mli @@ -21,7 +21,7 @@ module type Info = sig type info val to_string : info -> string - val format_info : Format.formatter -> info -> unit + val format : Format.formatter -> info -> unit val equal : info -> info -> bool (** Equality disregards position *) diff --git a/compiler/catala_web_interpreter.ml b/compiler/catala_web_interpreter.ml index c4089647..fd0db195 100644 --- a/compiler/catala_web_interpreter.ml +++ b/compiler/catala_web_interpreter.ml @@ -1,3 +1,5 @@ +open Catala_utils + open Driver open Js_of_ocaml @@ -12,7 +14,7 @@ let _ = driver (Contents (Js.to_string contents)) { - Utils.Cli.debug = false; + Cli.debug = false; color = Never; wrap_weaved_output = false; avoid_exceptions = false; diff --git a/compiler/dcalc/dune b/compiler/dcalc/dune index c0875ed2..a5caa02e 100644 --- a/compiler/dcalc/dune +++ b/compiler/dcalc/dune @@ -4,7 +4,7 @@ (libraries bindlib unionFind - utils + catala_utils re ubase catala.runtime_ocaml diff --git a/compiler/dcalc/from_scopelang.ml b/compiler/dcalc/from_scopelang.ml index ab904e7a..58dd9460 100644 --- a/compiler/dcalc/from_scopelang.ml +++ b/compiler/dcalc/from_scopelang.ml @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Shared_ast type scope_var_ctx = { @@ -102,7 +102,7 @@ let merge_defaults caller callee = let tag_with_log_entry (e : 'm Ast.expr boxed) (l : log_entry) - (markings : Utils.Uid.MarkedString.info list) : 'm Ast.expr boxed = + (markings : Uid.MarkedString.info list) : 'm Ast.expr boxed = let m = mark_tany (Marked.get_mark e) (Expr.pos e) in Expr.eapp (Expr.eop (Unop (Log (l, markings))) m) [e] m @@ -375,7 +375,7 @@ let rec translate_expr (ctx : 'm ctx) (e : 'm Scopelang.Ast.expr) : let translate_rule (ctx : 'm ctx) (rule : 'm Scopelang.Ast.rule) - ((sigma_name, pos_sigma) : Utils.Uid.MarkedString.info) : + ((sigma_name, pos_sigma) : Uid.MarkedString.info) : ('m Ast.expr scope_body_expr Bindlib.box -> 'm Ast.expr scope_body_expr Bindlib.box) * 'm ctx = @@ -645,7 +645,7 @@ let translate_rule let translate_rules (ctx : 'm ctx) (rules : 'm Scopelang.Ast.rule list) - ((sigma_name, pos_sigma) : Utils.Uid.MarkedString.info) + ((sigma_name, pos_sigma) : Uid.MarkedString.info) (mark : 'm mark) (scope_sig : 'm scope_sig_ctx) : 'm Ast.expr scope_body_expr Bindlib.box * 'm ctx = diff --git a/compiler/dcalc/interpreter.ml b/compiler/dcalc/interpreter.ml index d3e2f712..18481a7e 100644 --- a/compiler/dcalc/interpreter.ml +++ b/compiler/dcalc/interpreter.ml @@ -16,7 +16,7 @@ (** Reference interpreter for the default calculus *) -open Utils +open Catala_utils open Shared_ast module Runtime = Runtime_ocaml.Runtime diff --git a/compiler/dcalc/interpreter.mli b/compiler/dcalc/interpreter.mli index f117c0b4..1bc4e9c3 100644 --- a/compiler/dcalc/interpreter.mli +++ b/compiler/dcalc/interpreter.mli @@ -16,7 +16,7 @@ (** Reference interpreter for the default calculus *) -open Utils +open Catala_utils open Shared_ast val evaluate_expr : decl_ctx -> 'm Ast.expr -> 'm Ast.expr diff --git a/compiler/dcalc/optimizations.ml b/compiler/dcalc/optimizations.ml index bfaadffb..5b28dff4 100644 --- a/compiler/dcalc/optimizations.ml +++ b/compiler/dcalc/optimizations.ml @@ -14,7 +14,7 @@ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Shared_ast open Ast diff --git a/compiler/desugared/ast.ml b/compiler/desugared/ast.ml index b40f9d46..da91ed93 100644 --- a/compiler/desugared/ast.ml +++ b/compiler/desugared/ast.ml @@ -16,7 +16,7 @@ (** Abstract syntax tree of the desugared representation *) -open Utils +open Catala_utils open Shared_ast (** {1 Names, Maps and Keys} *) diff --git a/compiler/desugared/ast.mli b/compiler/desugared/ast.mli index ab4d7d2f..0d80d781 100644 --- a/compiler/desugared/ast.mli +++ b/compiler/desugared/ast.mli @@ -16,7 +16,7 @@ (** Abstract syntax tree of the desugared representation *) -open Utils +open Catala_utils open Shared_ast (** Inside a scope, a definition can refer either to a scope def, or a subscope diff --git a/compiler/desugared/dependency.ml b/compiler/desugared/dependency.ml index 4da66bc7..a8233c55 100644 --- a/compiler/desugared/dependency.ml +++ b/compiler/desugared/dependency.ml @@ -17,7 +17,7 @@ (** Scope dependencies computations using {{:http://ocamlgraph.lri.fr/} OCamlgraph} *) -open Utils +open Catala_utils open Shared_ast (** {1 Scope variables dependency graph} *) diff --git a/compiler/desugared/dependency.mli b/compiler/desugared/dependency.mli index 6858aca0..d1b07cd2 100644 --- a/compiler/desugared/dependency.mli +++ b/compiler/desugared/dependency.mli @@ -17,7 +17,7 @@ (** Scope dependencies computations using {{:http://ocamlgraph.lri.fr/} OCamlgraph} *) -open Utils +open Catala_utils open Shared_ast (** {1 Scope variables dependency graph} *) diff --git a/compiler/desugared/dune b/compiler/desugared/dune index 0b066eb9..77efc84a 100644 --- a/compiler/desugared/dune +++ b/compiler/desugared/dune @@ -1,7 +1,7 @@ (library (name desugared) (public_name catala.desugared) - (libraries ocamlgraph utils shared_ast surface)) + (libraries ocamlgraph catala_utils shared_ast surface)) (documentation (package catala) diff --git a/compiler/desugared/from_surface.ml b/compiler/desugared/from_surface.ml index ff49420b..6a071ccf 100644 --- a/compiler/desugared/from_surface.ml +++ b/compiler/desugared/from_surface.ml @@ -15,7 +15,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils module SurfacePrint = Surface.Print open Shared_ast module Runtime = Runtime_ocaml.Runtime diff --git a/compiler/desugared/name_resolution.ml b/compiler/desugared/name_resolution.ml index 64be33bc..fa150669 100644 --- a/compiler/desugared/name_resolution.ml +++ b/compiler/desugared/name_resolution.ml @@ -18,7 +18,7 @@ (** Builds a context that allows for mapping each name to a precise uid, taking lexical scopes into account *) -open Utils +open Catala_utils open Shared_ast (** {1 Name resolution context} *) @@ -105,7 +105,7 @@ let raise_unsupported_feature (msg : string) (pos : Pos.t) = let raise_unknown_identifier (msg : string) (ident : ident Marked.pos) = Errors.raise_spanned_error (Marked.get_mark ident) "\"%s\": unknown identifier %s" - (Utils.Cli.with_style [ANSITerminal.yellow] "%s" (Marked.unmark ident)) + (Cli.with_style [ANSITerminal.yellow] "%s" (Marked.unmark ident)) msg (** Gets the type associated to an uid *) @@ -254,7 +254,7 @@ let process_subscope_decl Errors.raise_multispanned_error [Some "first use", Marked.get_mark info; Some "second use", s_pos] "Subscope name \"%a\" already used" - (Utils.Cli.format_with_style [ANSITerminal.yellow]) + (Cli.format_with_style [ANSITerminal.yellow]) subscope | None -> let sub_scope_uid = SubScopeName.fresh (name, name_pos) in @@ -310,7 +310,7 @@ let rec process_base_typ | None -> Errors.raise_spanned_error typ_pos "Unknown type \"%a\", not a struct or enum previously declared" - (Utils.Cli.format_with_style [ANSITerminal.yellow]) + (Cli.format_with_style [ANSITerminal.yellow]) ident)) (** Process a type (function or not) *) @@ -342,7 +342,7 @@ let process_data_decl Errors.raise_multispanned_error [Some "First use:", Marked.get_mark info; Some "Second use:", pos] "Variable name \"%a\" already used" - (Utils.Cli.format_with_style [ANSITerminal.yellow]) + (Cli.format_with_style [ANSITerminal.yellow]) name | None -> let uid = ScopeVar.fresh (name, pos) in @@ -576,7 +576,7 @@ let process_name_item (ctxt : context) (item : Surface.Ast.code_item Marked.pos) Some "Second definition:", pos; ] "%s name \"%a\" already defined" msg - (Utils.Cli.format_with_style [ANSITerminal.yellow]) + (Cli.format_with_style [ANSITerminal.yellow]) name in match Marked.unmark item with @@ -854,7 +854,7 @@ let process_scope_use (ctxt : context) (suse : Surface.Ast.scope_use) : context Errors.raise_spanned_error (Marked.get_mark suse.Surface.Ast.scope_use_name) "\"%a\": this scope has not been declared anywhere, is it a typo?" - (Utils.Cli.format_with_style [ANSITerminal.yellow]) + (Cli.format_with_style [ANSITerminal.yellow]) (Marked.unmark suse.Surface.Ast.scope_use_name) in List.fold_left diff --git a/compiler/desugared/name_resolution.mli b/compiler/desugared/name_resolution.mli index f7c419a5..d06aa4f2 100644 --- a/compiler/desugared/name_resolution.mli +++ b/compiler/desugared/name_resolution.mli @@ -18,7 +18,7 @@ (** Builds a context that allows for mapping each name to a precise uid, taking lexical scopes into account *) -open Utils +open Catala_utils open Shared_ast (** {1 Name resolution context} *) diff --git a/compiler/driver.ml b/compiler/driver.ml index cfa96a6f..54fa466b 100644 --- a/compiler/driver.ml +++ b/compiler/driver.ml @@ -15,10 +15,7 @@ License for the specific language governing permissions and limitations under the License. *) -module Cli = Utils.Cli -module File = Utils.File -module Errors = Utils.Errors -module Pos = Utils.Pos +open Catala_utils (** Associates a {!type: Cli.backend_lang} with its string represtation. *) let languages = ["en", Cli.En; "fr", Cli.Fr; "pl", Cli.Pl] diff --git a/compiler/driver.mli b/compiler/driver.mli index af6243f1..14608721 100644 --- a/compiler/driver.mli +++ b/compiler/driver.mli @@ -15,9 +15,11 @@ License for the specific language governing permissions and limitations under the License. *) +open Catala_utils + module Plugin = Plugin.PluginAPI -val driver : Utils.Pos.input_file -> Utils.Cli.options -> int +val driver : Pos.input_file -> Cli.options -> int (** Entry function for the executable. Returns a negative number in case of error. *) diff --git a/compiler/dune b/compiler/dune index c5e056b2..35eb2f42 100644 --- a/compiler/dune +++ b/compiler/dune @@ -3,7 +3,7 @@ (public_name catala.driver) (libraries dynlink - utils + catala_utils surface desugared literate diff --git a/compiler/index.mld b/compiler/index.mld index c84b5a89..42e93883 100644 --- a/compiler/index.mld +++ b/compiler/index.mld @@ -103,7 +103,7 @@ Two more modules contain additional features for the compiler: {ul {li {{: literate.html} Literate programming}} -{li {{: utils.html} Compiler utilities}} +{li {{: catala_utils.html} Compiler utilities}} } The Catala runtimes documentation is available here: diff --git a/compiler/lcalc/ast.ml b/compiler/lcalc/ast.ml index f4ae7597..a94f73b9 100644 --- a/compiler/lcalc/ast.ml +++ b/compiler/lcalc/ast.ml @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils include Shared_ast type lit = lcalc glit diff --git a/compiler/lcalc/ast.mli b/compiler/lcalc/ast.mli index 3fb0583d..be417680 100644 --- a/compiler/lcalc/ast.mli +++ b/compiler/lcalc/ast.mli @@ -14,6 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) +open Catala_utils open Shared_ast (** Abstract syntax tree for the lambda calculus *) @@ -40,7 +41,7 @@ val make_matchopt_with_abs_arms : 'm expr boxed -> 'm expr boxed -> 'm expr boxed -> 'm expr boxed val make_matchopt : - Utils.Pos.t -> + Pos.t -> 'm expr Var.t -> typ -> 'm expr boxed -> diff --git a/compiler/lcalc/closure_conversion.ml b/compiler/lcalc/closure_conversion.ml index 554bb2aa..d85241ea 100644 --- a/compiler/lcalc/closure_conversion.ml +++ b/compiler/lcalc/closure_conversion.ml @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Shared_ast open Ast module D = Dcalc.Ast diff --git a/compiler/lcalc/compile_with_exceptions.ml b/compiler/lcalc/compile_with_exceptions.ml index aefa6668..4550bec4 100644 --- a/compiler/lcalc/compile_with_exceptions.ml +++ b/compiler/lcalc/compile_with_exceptions.ml @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Shared_ast module D = Dcalc.Ast module A = Ast @@ -43,7 +43,7 @@ let rec translate_default Expr.make_app (Expr.make_var (Var.translate A.handle_default) - (Expr.with_ty mark_default (Utils.Marked.mark pos TAny))) + (Expr.with_ty mark_default (Marked.mark pos TAny))) [ Expr.earray exceptions mark_default; thunk_expr (translate_expr ctx just); diff --git a/compiler/lcalc/compile_without_exceptions.ml b/compiler/lcalc/compile_without_exceptions.ml index daf67af0..494589b8 100644 --- a/compiler/lcalc/compile_without_exceptions.ml +++ b/compiler/lcalc/compile_without_exceptions.ml @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils module D = Dcalc.Ast module A = Ast diff --git a/compiler/lcalc/optimizations.ml b/compiler/lcalc/optimizations.ml index 556e89cd..869d6b88 100644 --- a/compiler/lcalc/optimizations.ml +++ b/compiler/lcalc/optimizations.ml @@ -13,7 +13,7 @@ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Shared_ast open Ast module D = Dcalc.Ast diff --git a/compiler/lcalc/to_ocaml.ml b/compiler/lcalc/to_ocaml.ml index 3388c271..b7cab4ad 100644 --- a/compiler/lcalc/to_ocaml.ml +++ b/compiler/lcalc/to_ocaml.ml @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Shared_ast open Ast open String_common @@ -91,7 +91,7 @@ let format_uid_list (fmt : Format.formatter) (uids : Uid.MarkedString.info list) (Format.pp_print_list ~pp_sep:(fun fmt () -> Format.fprintf fmt ";@ ") (fun fmt info -> - Format.fprintf fmt "\"%a\"" Utils.Uid.MarkedString.format_info info)) + Format.fprintf fmt "\"%a\"" Uid.MarkedString.format info)) uids let format_string_list (fmt : Format.formatter) (uids : string list) : unit = diff --git a/compiler/literate/dune b/compiler/literate/dune index 70ed9a39..04b48853 100644 --- a/compiler/literate/dune +++ b/compiler/literate/dune @@ -1,7 +1,7 @@ (library (name literate) (public_name catala.literate) - (libraries re utils surface ubase)) + (libraries re catala_utils surface ubase)) (documentation (package catala) diff --git a/compiler/literate/html.ml b/compiler/literate/html.ml index 5aed9a7f..aae3f92c 100644 --- a/compiler/literate/html.ml +++ b/compiler/literate/html.ml @@ -18,7 +18,7 @@ (** This modules weaves the source code and the legislative text together into a document that law professionals can understand. *) -open Utils +open Catala_utils open Literate_common module A = Surface.Ast module P = Printf @@ -91,7 +91,7 @@ let wrap_html \n" css_as_string (literal_title language) (literal_generated_by language) - Utils.Cli.version + Cli.version (pre_html (literal_disclaimer_and_link language)) (literal_source_files language) (String.concat "\n" diff --git a/compiler/literate/html.mli b/compiler/literate/html.mli index 6cbd65d1..53d071c9 100644 --- a/compiler/literate/html.mli +++ b/compiler/literate/html.mli @@ -17,7 +17,7 @@ (** This modules weaves the source code and the legislative text together into a document that law professionals can understand. *) -open Utils +open Catala_utils (** {1 Helpers} *) diff --git a/compiler/literate/latex.ml b/compiler/literate/latex.ml index 080e1f88..c7bf528f 100644 --- a/compiler/literate/latex.ml +++ b/compiler/literate/latex.ml @@ -18,7 +18,7 @@ (** This modules weaves the source code and the legislative text together into a document that law professionals can understand. *) -open Utils +open Catala_utils open Literate_common module A = Surface.Ast module R = Re.Pcre @@ -158,7 +158,7 @@ codes={\catcode`\$=3\catcode`\^=7} https://gouvfr.atlassian.net/wiki/spaces/DB/pages/223019527/Typographie+-+Typography *) (literal_title language) (literal_generated_by language) - Utils.Cli.version + Cli.version (pre_latexify (literal_disclaimer_and_link language)) (literal_source_files language) (String.concat diff --git a/compiler/literate/latex.mli b/compiler/literate/latex.mli index 012d0ec6..28ba0801 100644 --- a/compiler/literate/latex.mli +++ b/compiler/literate/latex.mli @@ -17,7 +17,7 @@ (** This modules weaves the source code and the legislative text together into a document that law professionals can understand. *) -open Utils +open Catala_utils (** {1 Helpers} *) diff --git a/compiler/literate/literate_common.ml b/compiler/literate/literate_common.ml index 68aa6f6d..7513bb04 100644 --- a/compiler/literate/literate_common.ml +++ b/compiler/literate/literate_common.ml @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Cli let literal_title = function diff --git a/compiler/literate/literate_common.mli b/compiler/literate/literate_common.mli index 24741079..d3bcf7a6 100644 --- a/compiler/literate/literate_common.mli +++ b/compiler/literate/literate_common.mli @@ -14,32 +14,32 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils val literal_title : Cli.backend_lang -> string (** Return the title traduction according the given - {!type:Utils.Cli.backend_lang}. *) + {!type:Cli.backend_lang}. *) val literal_generated_by : Cli.backend_lang -> string (** Return the 'generated by' traduction according the given - {!type:Utils.Cli.backend_lang}. *) + {!type:Cli.backend_lang}. *) val literal_source_files : Cli.backend_lang -> string (** Return the 'source files weaved' traduction according the given - {!type:Utils.Cli.backend_lang}. *) + {!type:Cli.backend_lang}. *) val literal_disclaimer_and_link : Cli.backend_lang -> string (** Return the traduction of a paragraph giving a basic disclaimer about Catala and a link to the website according the given {!type: - Utils.Cli.backend_lang}. *) + Cli.backend_lang}. *) val literal_last_modification : Cli.backend_lang -> string (** Return the 'last modification' traduction according the given - {!type:Utils.Cli.backend_lang}. *) + {!type:Cli.backend_lang}. *) val get_language_extension : Cli.backend_lang -> string (** Return the file extension corresponding to the given - {!type:Utils.Cli.backend_lang}. *) + {!type:Cli.backend_lang}. *) val run_pandoc : string -> [ `Html | `Latex ] -> string (** Runs the [pandoc] on a string to pretty-print markdown features into the diff --git a/compiler/plugin.ml b/compiler/plugin.ml index 1378c2da..cac96c3c 100644 --- a/compiler/plugin.ml +++ b/compiler/plugin.ml @@ -14,8 +14,10 @@ License for the specific language governing permissions and limitations under the License. *) +open Catala_utils + type 'ast plugin_apply_fun_typ = - source_file:Utils.Pos.input_file -> + source_file:Pos.input_file -> output_file:string option -> scope:string option -> 'ast -> @@ -51,9 +53,9 @@ let find name = Hashtbl.find backend_plugins (String.lowercase_ascii name) let load_file f = try Dynlink.loadfile f; - Utils.Cli.debug_print "Plugin %S loaded" f + Cli.debug_print "Plugin %S loaded" f with e -> - Utils.Errors.format_warning "Could not load plugin %S: %s" f + Errors.format_warning "Could not load plugin %S: %s" f (Printexc.to_string e) let load_dir d = diff --git a/compiler/plugin.mli b/compiler/plugin.mli index b6d678f9..acfdf56a 100644 --- a/compiler/plugin.mli +++ b/compiler/plugin.mli @@ -16,8 +16,10 @@ (** {2 catala-facing API} *) +open Catala_utils + type 'ast plugin_apply_fun_typ = - source_file:Utils.Pos.input_file -> + source_file:Pos.input_file -> output_file:string option -> scope:string option -> 'ast -> diff --git a/compiler/plugins/api_web.ml b/compiler/plugins/api_web.ml index 33cbd2e4..c45c1776 100644 --- a/compiler/plugins/api_web.ml +++ b/compiler/plugins/api_web.ml @@ -18,7 +18,7 @@ (** Catala plugin for generating web APIs. It generates OCaml code before the the associated [js_of_ocaml] wrapper. *) -open Utils +open Catala_utils open Shared_ast open String_common open Lcalc diff --git a/compiler/plugins/json_schema.ml b/compiler/plugins/json_schema.ml index 89a97319..f68ba8c2 100644 --- a/compiler/plugins/json_schema.ml +++ b/compiler/plugins/json_schema.ml @@ -20,7 +20,7 @@ let name = "json_schema" let extension = "_schema.json" -open Utils +open Catala_utils open String_common open Shared_ast open Lcalc.Ast diff --git a/compiler/plugins/python.ml b/compiler/plugins/python.ml index 3f9a8300..5154b808 100644 --- a/compiler/plugins/python.ml +++ b/compiler/plugins/python.ml @@ -20,13 +20,15 @@ The code for the Python backend already has first-class support, so there would be no reason to use this plugin instead *) +open Catala_utils + let name = "python-plugin" 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 + 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/ast.ml b/compiler/scalc/ast.ml index 44e00999..4273149e 100644 --- a/compiler/scalc/ast.ml +++ b/compiler/scalc/ast.ml @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Shared_ast module D = Dcalc.Ast module L = Lcalc.Ast diff --git a/compiler/scalc/compile_from_lambda.ml b/compiler/scalc/compile_from_lambda.ml index dc60a137..e35fadec 100644 --- a/compiler/scalc/compile_from_lambda.ml +++ b/compiler/scalc/compile_from_lambda.ml @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Shared_ast module A = Ast module L = Lcalc.Ast diff --git a/compiler/scalc/print.ml b/compiler/scalc/print.ml index 17588ae4..24cdb17c 100644 --- a/compiler/scalc/print.ml +++ b/compiler/scalc/print.ml @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Shared_ast open Ast diff --git a/compiler/scalc/to_python.ml b/compiler/scalc/to_python.ml index a4f9a69c..90bdc843 100644 --- a/compiler/scalc/to_python.ml +++ b/compiler/scalc/to_python.ml @@ -15,7 +15,7 @@ the License. *) [@@@warning "-32-27"] -open Utils +open Catala_utils open Shared_ast open Ast open String_common @@ -77,7 +77,7 @@ let format_uid_list (fmt : Format.formatter) (uids : Uid.MarkedString.info list) (Format.pp_print_list ~pp_sep:(fun fmt () -> Format.fprintf fmt ",@ ") (fun fmt info -> - Format.fprintf fmt "\"%a\"" Utils.Uid.MarkedString.format_info info)) + Format.fprintf fmt "\"%a\"" Uid.MarkedString.format info)) uids let format_string_list (fmt : Format.formatter) (uids : string list) : unit = diff --git a/compiler/scopelang/ast.ml b/compiler/scopelang/ast.ml index 277457ef..f7f35c1d 100644 --- a/compiler/scopelang/ast.ml +++ b/compiler/scopelang/ast.ml @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Shared_ast type location = scopelang glocation diff --git a/compiler/scopelang/ast.mli b/compiler/scopelang/ast.mli index 1208cc21..342b506c 100644 --- a/compiler/scopelang/ast.mli +++ b/compiler/scopelang/ast.mli @@ -16,7 +16,7 @@ (** Abstract syntax tree of the scope language *) -open Utils +open Catala_utils open Shared_ast (** {1 Identifiers} *) diff --git a/compiler/scopelang/dependency.ml b/compiler/scopelang/dependency.ml index 9b7510ea..72177d8a 100644 --- a/compiler/scopelang/dependency.ml +++ b/compiler/scopelang/dependency.ml @@ -17,7 +17,7 @@ (** Graph representation of the dependencies between scopes in the Catala program. Vertices are functions, x -> y if x is used in the definition of y. *) -open Utils +open Catala_utils open Shared_ast module SVertex = ScopeName diff --git a/compiler/scopelang/dependency.mli b/compiler/scopelang/dependency.mli index 5ccf1790..f4d40dba 100644 --- a/compiler/scopelang/dependency.mli +++ b/compiler/scopelang/dependency.mli @@ -17,7 +17,7 @@ (** Graph representation of the dependencies between scopes in the Catala program. Vertices are functions, x -> y if x is used in the definition of y. *) -open Utils +open Catala_utils open Shared_ast (** {1 Scope dependencies} *) diff --git a/compiler/scopelang/dune b/compiler/scopelang/dune index 43607aab..9b798ce4 100644 --- a/compiler/scopelang/dune +++ b/compiler/scopelang/dune @@ -1,7 +1,7 @@ (library (name scopelang) (public_name catala.scopelang) - (libraries utils ocamlgraph desugared) + (libraries catala_utils ocamlgraph desugared) (flags (:standard -short-paths))) diff --git a/compiler/scopelang/from_desugared.ml b/compiler/scopelang/from_desugared.ml index 9577db60..cf36c799 100644 --- a/compiler/scopelang/from_desugared.ml +++ b/compiler/scopelang/from_desugared.ml @@ -16,7 +16,7 @@ (** Translation from {!module: Desugared.Ast} to {!module: Scopelang.Ast} *) -open Utils +open Catala_utils open Shared_ast (** {1 Expression translation}*) @@ -33,7 +33,7 @@ type ctx = { let tag_with_log_entry (e : untyped Ast.expr boxed) (l : log_entry) - (markings : Utils.Uid.MarkedString.info list) : untyped Ast.expr boxed = + (markings : Uid.MarkedString.info list) : untyped Ast.expr boxed = Expr.eapp (Expr.eop (Unop (Log (l, markings))) (Marked.get_mark e)) [e] (Marked.get_mark e) diff --git a/compiler/scopelang/print.ml b/compiler/scopelang/print.ml index 6bd26bc9..927ea834 100644 --- a/compiler/scopelang/print.ml +++ b/compiler/scopelang/print.ml @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Shared_ast open Ast diff --git a/compiler/shared_ast/definitions.ml b/compiler/shared_ast/definitions.ml index 0beb6e01..926e3358 100644 --- a/compiler/shared_ast/definitions.ml +++ b/compiler/shared_ast/definitions.ml @@ -20,7 +20,7 @@ (* Doesn't define values, so OK to have without an mli *) -open Utils +open Catala_utils module Runtime = Runtime_ocaml.Runtime module ScopeName = Uid.Gen () module StructName = Uid.Gen () diff --git a/compiler/shared_ast/dune b/compiler/shared_ast/dune index 64a1668b..03ffd8de 100644 --- a/compiler/shared_ast/dune +++ b/compiler/shared_ast/dune @@ -3,4 +3,4 @@ (public_name catala.shared_ast) (flags (:standard -short-paths)) - (libraries bindlib unionFind utils catala.runtime_ocaml)) + (libraries bindlib unionFind catala_utils catala.runtime_ocaml)) diff --git a/compiler/shared_ast/expr.ml b/compiler/shared_ast/expr.ml index dec67ebc..2c4d55fc 100644 --- a/compiler/shared_ast/expr.ml +++ b/compiler/shared_ast/expr.ml @@ -15,7 +15,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Definitions (** Functions handling the types of [shared_ast] *) diff --git a/compiler/shared_ast/expr.mli b/compiler/shared_ast/expr.mli index b51bc230..bfbf24fa 100644 --- a/compiler/shared_ast/expr.mli +++ b/compiler/shared_ast/expr.mli @@ -17,7 +17,7 @@ (** Functions handling the expressions of [shared_ast] *) -open Utils +open Catala_utils open Definitions (** {2 Boxed constructors} *) diff --git a/compiler/shared_ast/print.ml b/compiler/shared_ast/print.ml index b5bd7a09..7bac8821 100644 --- a/compiler/shared_ast/print.ml +++ b/compiler/shared_ast/print.ml @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open String_common open Definitions @@ -26,27 +26,27 @@ let uid_list (fmt : Format.formatter) (infos : Uid.MarkedString.info list) : Format.pp_print_list ~pp_sep:(fun fmt () -> Format.pp_print_char fmt '.') (fun fmt info -> - Utils.Cli.format_with_style + Cli.format_with_style (if begins_with_uppercase (Marked.unmark info) then [ANSITerminal.red] else []) fmt - (Utils.Uid.MarkedString.to_string info)) + (Uid.MarkedString.to_string info)) fmt infos let keyword (fmt : Format.formatter) (s : string) : unit = - Utils.Cli.format_with_style [ANSITerminal.red] fmt s + Cli.format_with_style [ANSITerminal.red] fmt s let base_type (fmt : Format.formatter) (s : string) : unit = - Utils.Cli.format_with_style [ANSITerminal.yellow] fmt s + Cli.format_with_style [ANSITerminal.yellow] fmt s let punctuation (fmt : Format.formatter) (s : string) : unit = - Utils.Cli.format_with_style [ANSITerminal.cyan] fmt s + Cli.format_with_style [ANSITerminal.cyan] fmt s let operator (fmt : Format.formatter) (s : string) : unit = - Utils.Cli.format_with_style [ANSITerminal.green] fmt s + Cli.format_with_style [ANSITerminal.green] fmt s let lit_style (fmt : Format.formatter) (s : string) : unit = - Utils.Cli.format_with_style [ANSITerminal.yellow] fmt s + Cli.format_with_style [ANSITerminal.yellow] fmt s let tlit (fmt : Format.formatter) (l : typ_lit) : unit = base_type fmt @@ -68,7 +68,7 @@ let location (type a) (fmt : Format.formatter) (l : a glocation) : unit = ScopeVar.format_t (Marked.unmark subvar) let enum_constructor (fmt : Format.formatter) (c : EnumConstructor.t) : unit = - Utils.Cli.format_with_style [ANSITerminal.magenta] fmt + Cli.format_with_style [ANSITerminal.magenta] fmt (Format.asprintf "%a" EnumConstructor.format_t c) let rec typ (ctx : decl_ctx option) (fmt : Format.formatter) (ty : typ) : unit = @@ -127,9 +127,9 @@ let lit (type a) (fmt : Format.formatter) (l : a glit) : unit = | LUnit -> lit_style fmt "()" | LRat i -> lit_style fmt - (Runtime.decimal_to_string ~max_prec_digits:!Utils.Cli.max_prec_digits i) + (Runtime.decimal_to_string ~max_prec_digits:!Cli.max_prec_digits i) | LMoney e -> ( - match !Utils.Cli.locale_lang with + match !Cli.locale_lang with | En -> lit_style fmt (Format.asprintf "$%s" (Runtime.money_to_string e)) | Fr -> lit_style fmt (Format.asprintf "%s €" (Runtime.money_to_string e)) | Pl -> lit_style fmt (Format.asprintf "%s PLN" (Runtime.money_to_string e)) @@ -172,11 +172,11 @@ let ternop (fmt : Format.formatter) (op : ternop) : unit = let log_entry (fmt : Format.formatter) (entry : log_entry) : unit = Format.fprintf fmt "@<2>%a" (fun fmt -> function - | VarDef _ -> Utils.Cli.format_with_style [ANSITerminal.blue] fmt "≔ " - | BeginCall -> Utils.Cli.format_with_style [ANSITerminal.yellow] fmt "→ " - | EndCall -> Utils.Cli.format_with_style [ANSITerminal.yellow] fmt "← " + | VarDef _ -> Cli.format_with_style [ANSITerminal.blue] fmt "≔ " + | BeginCall -> Cli.format_with_style [ANSITerminal.yellow] fmt "→ " + | EndCall -> Cli.format_with_style [ANSITerminal.yellow] fmt "← " | PosRecordIfTrueBool -> - Utils.Cli.format_with_style [ANSITerminal.green] fmt "☛ ") + Cli.format_with_style [ANSITerminal.green] fmt "☛ ") entry let unop (fmt : Format.formatter) (op : unop) : unit = @@ -187,7 +187,7 @@ let unop (fmt : Format.formatter) (op : unop) : unit = Format.fprintf fmt "log@[[%a|%a]@]" log_entry entry (Format.pp_print_list ~pp_sep:(fun fmt () -> Format.fprintf fmt ".") - (fun fmt info -> Utils.Uid.MarkedString.format_info fmt info)) + (fun fmt info -> Uid.MarkedString.format fmt info)) infos | Length -> Format.pp_print_string fmt "length" | IntToRat -> Format.pp_print_string fmt "int_to_rat" diff --git a/compiler/shared_ast/print.mli b/compiler/shared_ast/print.mli index 936887dc..f99440d7 100644 --- a/compiler/shared_ast/print.mli +++ b/compiler/shared_ast/print.mli @@ -16,7 +16,7 @@ (** Printing functions for the default calculus AST *) -open Utils +open Catala_utils open Definitions (** {1 Common syntax highlighting helpers}*) diff --git a/compiler/shared_ast/scope.ml b/compiler/shared_ast/scope.ml index fc1f0704..037741b5 100644 --- a/compiler/shared_ast/scope.ml +++ b/compiler/shared_ast/scope.ml @@ -15,7 +15,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Definitions let rec fold_left_lets ~f ~init scope_body_expr = @@ -106,7 +106,7 @@ let rec get_body_expr_mark = function get_body_expr_mark e | Result e -> let m = Marked.get_mark e in - Expr.with_ty m (Utils.Marked.mark (Expr.mark_pos m) TAny) + Expr.with_ty m (Marked.mark (Expr.mark_pos m) TAny) let get_body_mark scope_body = let _, e = Bindlib.unbind scope_body.scope_body_expr in diff --git a/compiler/shared_ast/scope.mli b/compiler/shared_ast/scope.mli index 6e18ee5e..eea0ae9b 100644 --- a/compiler/shared_ast/scope.mli +++ b/compiler/shared_ast/scope.mli @@ -17,7 +17,7 @@ (** Functions handling the scope structures of [shared_ast] *) -open Utils +open Catala_utils open Definitions (** {2 Traversal functions} *) diff --git a/compiler/shared_ast/typing.ml b/compiler/shared_ast/typing.ml index c1202054..2c528eda 100644 --- a/compiler/shared_ast/typing.ml +++ b/compiler/shared_ast/typing.ml @@ -17,16 +17,16 @@ (** Typing for the default calculus. Because of the error terms, we perform type inference using the classical W algorithm with union-find unification. *) -open Utils +open Catala_utils module A = Definitions module Any = - Utils.Uid.Make + Uid.Make (struct type info = unit let to_string _ = "any" - let format_info fmt () = Format.fprintf fmt "any" + let format fmt () = Format.fprintf fmt "any" let equal _ _ = true let compare _ _ = 0 end) diff --git a/compiler/surface/ast.ml b/compiler/surface/ast.ml index 4f2af2e3..4a7706fe 100644 --- a/compiler/surface/ast.ml +++ b/compiler/surface/ast.ml @@ -19,7 +19,7 @@ [@@@ocaml.warning "-7"] -open Utils +open Catala_utils (** {1 Visitor classes for programs} *) (** To allow for quick traversal and/or modification of this AST structure, we diff --git a/compiler/surface/dune b/compiler/surface/dune index d8724a3b..7f39f538 100644 --- a/compiler/surface/dune +++ b/compiler/surface/dune @@ -2,7 +2,7 @@ (name surface) (public_name catala.surface) (libraries - utils + catala_utils menhirLib sedlex re diff --git a/compiler/surface/fill_positions.ml b/compiler/surface/fill_positions.ml index f8d3db55..6fa2ec94 100644 --- a/compiler/surface/fill_positions.ml +++ b/compiler/surface/fill_positions.ml @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils let fill_pos_with_legislative_info (p : Ast.program) : Ast.program = let visitor = diff --git a/compiler/surface/lexer.cppo.ml b/compiler/surface/lexer.cppo.ml index 1dd3d232..0e701a02 100644 --- a/compiler/surface/lexer.cppo.ml +++ b/compiler/surface/lexer.cppo.ml @@ -14,7 +14,7 @@ open Tokens open Sedlexing -open Utils +open Catala_utils module L = Lexer_common module R = Re.Pcre diff --git a/compiler/surface/lexer_common.ml b/compiler/surface/lexer_common.ml index 9d05302a..4ecbf0e1 100644 --- a/compiler/surface/lexer_common.ml +++ b/compiler/surface/lexer_common.ml @@ -17,7 +17,7 @@ open Tokens open Sedlexing -open Utils +open Catala_utils module R = Re.Pcre (* Calculates the precedence according a {!val: matched_regex} of the form : diff --git a/compiler/surface/lexer_common.mli b/compiler/surface/lexer_common.mli index 129a0b85..384059b1 100644 --- a/compiler/surface/lexer_common.mli +++ b/compiler/surface/lexer_common.mli @@ -31,7 +31,7 @@ val code_buffer : Buffer.t val update_acc : Sedlexing.lexbuf -> unit (** Updates {!val:code_buffer} with the current lexeme *) -val raise_lexer_error : Utils.Pos.t -> string -> 'a +val raise_lexer_error : Catala_utils.Pos.t -> string -> 'a (** Error-generating helper *) val token_list_language_agnostic : (string * Tokens.token) list diff --git a/compiler/surface/parser.mly b/compiler/surface/parser.mly index 2925c593..80195c90 100644 --- a/compiler/surface/parser.mly +++ b/compiler/surface/parser.mly @@ -18,7 +18,7 @@ *) %{ - open Utils + open Catala_utils %} %parameter Cli.backend_lang -> Ast.program diff --git a/compiler/verification/conditions.ml b/compiler/verification/conditions.ml index d8fd8419..b2ff1331 100644 --- a/compiler/verification/conditions.ml +++ b/compiler/verification/conditions.ml @@ -15,7 +15,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Shared_ast open Dcalc open Ast diff --git a/compiler/verification/conditions.mli b/compiler/verification/conditions.mli index 55829300..d0325f09 100644 --- a/compiler/verification/conditions.mli +++ b/compiler/verification/conditions.mli @@ -17,7 +17,7 @@ (** Generates verification conditions from scope definitions *) -open Utils +open Catala_utils open Shared_ast type verification_condition_kind = diff --git a/compiler/verification/dune b/compiler/verification/dune index 37df5b9a..56e49368 100644 --- a/compiler/verification/dune +++ b/compiler/verification/dune @@ -3,7 +3,7 @@ (public_name catala.verification) (libraries bindlib - utils + catala_utils dcalc catala.runtime_ocaml dates_calc diff --git a/compiler/verification/io.ml b/compiler/verification/io.ml index 9d63f485..b84fb7fc 100644 --- a/compiler/verification/io.ml +++ b/compiler/verification/io.ml @@ -15,7 +15,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Shared_ast module type Backend = sig diff --git a/compiler/verification/solver.ml b/compiler/verification/solver.ml index fb4b4f0e..c885090d 100644 --- a/compiler/verification/solver.ml +++ b/compiler/verification/solver.ml @@ -14,6 +14,8 @@ License for the specific language governing permissions and limitations under the License. *) +open Catala_utils + (** [solve_vc] is the main entry point of this module. It takes a list of expressions [vcs] corresponding to verification conditions that must be discharged by Z3, and attempts to solve them **) @@ -45,4 +47,4 @@ let solve_vc true z3_vcs in if all_proven then - Utils.Cli.result_format "No errors found during the proof mode run." + Cli.result_format "No errors found during the proof mode run." diff --git a/compiler/verification/z3backend.dummy.ml b/compiler/verification/z3backend.dummy.ml index 52f7193b..060e63ba 100644 --- a/compiler/verification/z3backend.dummy.ml +++ b/compiler/verification/z3backend.dummy.ml @@ -18,7 +18,7 @@ without the expected backend. All functions print an error message and exit *) let dummy () = - Utils.Cli.error_print + Cli.error_print "This instance of Catala was compiled without Z3 support."; exit 124 diff --git a/compiler/verification/z3backend.real.ml b/compiler/verification/z3backend.real.ml index bb2f9a04..69519ca5 100644 --- a/compiler/verification/z3backend.real.ml +++ b/compiler/verification/z3backend.real.ml @@ -14,7 +14,7 @@ License for the specific language governing permissions and limitations under the License. *) -open Utils +open Catala_utils open Shared_ast open Dcalc open Ast diff --git a/french_law/catala_legifrance/api.ml b/french_law/catala_legifrance/api.ml index 7c44d8c3..bd90693b 100644 --- a/french_law/catala_legifrance/api.ml +++ b/french_law/catala_legifrance/api.ml @@ -15,6 +15,7 @@ the License. *) open Lwt +open Catala_utils type access_token = string @@ -54,11 +55,11 @@ let get_token (client_id : string) (client_secret : string) : string = |> Yojson.Basic.Util.member "access_token" |> Yojson.Basic.Util.to_string in - Utils.Cli.debug_format "The LegiFrance API access token is %s" token; + Cli.debug_format "The LegiFrance API access token is %s" token; token end else begin - Utils.Cli.debug_format + Cli.debug_format "The API access token request went wrong ; status is %s and the body is\n\ %s" resp body; @@ -109,7 +110,7 @@ let run_request (request : (string * string t) t) : Yojson.Basic.t = if resp = "200 OK" then try body |> Yojson.Basic.from_string with | Yojson.Basic.Util.Type_error (msg, obj) -> - Utils.Cli.error_print + Cli.error_print "Error while parsing JSON answer from API: %s\n\ Specific JSON:\n\ %s\n\ @@ -128,10 +129,10 @@ let run_request (request : (string * string t) t) : Yojson.Basic.t = with Failure _ -> if n > 0 then ( Unix.sleep 2; - Utils.Cli.debug_format "Retrying request..."; + Cli.debug_format "Retrying request..."; try_n_times (n - 1)) else ( - Utils.Cli.error_print + Cli.error_print "The API request went wrong ; status is %s and the body is\n%s" resp body; exit (-1)) @@ -153,7 +154,7 @@ let parse_id (id : string) : article_id = else if Re.execp ceta_tex id then CETATEXT else if Re.execp jorf_rex id then JORFARTI else - Utils.Errors.raise_error + Errors.raise_error "LégiFrance ID \"%s\" does not correspond to an ID format recognized \ by the LégiFrance API" id @@ -161,7 +162,7 @@ let parse_id (id : string) : article_id = { id; typ } let retrieve_article (access_token : string) (obj : article_id) : article = - Utils.Cli.debug_format "Accessing article %s" obj.id; + Cli.debug_format "Accessing article %s" obj.id; { content = run_request @@ -179,7 +180,7 @@ let raise_article_parsing_error (json : Yojson.Basic.t) (msg : string) (obj : Yojson.Basic.t) = - Utils.Cli.error_print + Cli.error_print "Error while manipulating JSON answer from API: %s\n\ Specific JSON:\n\ %s\n\ diff --git a/french_law/catala_legifrance/catala_legifrance.ml b/french_law/catala_legifrance/catala_legifrance.ml index dad14fe8..9e7e5771 100644 --- a/french_law/catala_legifrance/catala_legifrance.ml +++ b/french_law/catala_legifrance/catala_legifrance.ml @@ -14,6 +14,8 @@ License for the specific language governing permissions and limitations under the License. *) +open Catala_utils + (** Main logic for interacting with LégiFrance when traversing Catala source files *) @@ -46,12 +48,12 @@ let check_article_expiration Some new_version else None in - Utils.Cli.warning_print + Cli.warning_print "%s %s has expired! Its expiration date is %s according to \ LégiFrance.%s" - (Utils.Marked.unmark law_heading.Surface.Ast.law_heading_name) - (Utils.Pos.to_string - (Utils.Marked.get_mark law_heading.Surface.Ast.law_heading_name)) + (Marked.unmark law_heading.Surface.Ast.law_heading_name) + (Pos.to_string + (Marked.get_mark law_heading.Surface.Ast.law_heading_name)) (Date.print_tm legifrance_expiration_date) (match new_version with | None -> "" @@ -61,7 +63,7 @@ let check_article_expiration else None type law_article_text = { - article_title : string * Utils.Pos.t; + article_title : string * Pos.t; text : string; new_version : Api.article_id option; current_version : Api.article_id option; @@ -110,7 +112,7 @@ let compare_to_versions (law_article_text : law_article_text) (access_token : Api.access_token) : unit = let print_diff msg diff = - Utils.Cli.warning_print "%s\n%s" msg + Cli.warning_print "%s\n%s" msg (String.concat "\n" (List.map (fun chunk -> @@ -138,7 +140,7 @@ let compare_to_versions "There is a diff between the source code version of %s %s and the \ text stored on LégiFrance:\n" (fst law_article_text.article_title) - (Utils.Pos.to_string (snd law_article_text.article_title))) + (Pos.to_string (snd law_article_text.article_title))) diff) | None -> () end; @@ -154,14 +156,14 @@ let compare_to_versions "Here is the diff between the current version of %s %s and what it \ will become in the future:\n" (fst law_article_text.article_title) - (Utils.Pos.to_string (snd law_article_text.article_title))) + (Pos.to_string (snd law_article_text.article_title))) diff) | None -> () (** Fill an [@@Include ...@@] tag inside the Catala source file with the legislative contents retrieved from LégiFrance *) let include_legislative_text - (id : string * Utils.Pos.t) + (id : string * Pos.t) (access_token : Api.access_token) : string = let excerpt = Api.retrieve_law_excerpt access_token (fst id) in let title = "#" ^ Api.get_law_excerpt_title excerpt in @@ -179,12 +181,12 @@ let include_legislative_text in let to_insert = title ^ "\n\n" ^ String.concat "\n\n" articles in let pos = snd id in - Utils.Cli.debug_format "Position: %s" (Utils.Pos.to_string_short pos); - let file = Utils.Pos.get_file pos in - let include_line = Utils.Pos.get_end_line pos in + Cli.debug_format "Position: %s" (Pos.to_string_short pos); + let file = Pos.get_file pos in + let include_line = Pos.get_end_line pos in let ic = open_in file in let new_file = file ^ ".new" in - Utils.Cli.warning_print + Cli.warning_print "LégiFrance inclusion detected, writing new contents to %s" new_file; let oc = open_out new_file in (* Pos.t lines start at 1 *) @@ -258,7 +260,7 @@ let driver (client_id : string) (client_secret : string) = try - if debug then Utils.Cli.debug_flag := true; + if debug then Cli.debug_flag := true; let access_token = Api.get_token client_id client_secret in (* LégiFrance is only supported for French texts *) let program = @@ -276,9 +278,9 @@ let driver item)) program.program_items; 0 - with Utils.Errors.StructuredError (msg, pos) -> + with Errors.StructuredError (msg, pos) -> let bt = Printexc.get_raw_backtrace () in - Utils.Cli.error_print "%s" (Utils.Errors.print_structured_error msg pos); + Cli.error_print "%s" (Errors.print_structured_error msg pos); if Printexc.backtrace_status () then Printexc.print_raw_backtrace stderr bt; -1 @@ -286,4 +288,4 @@ let driver let _ = Stdlib.exit @@ Cmdliner.Cmd.eval' - (Cmdliner.Cmd.v Cli.info (Cli.catala_legifrance_t driver)) + (Cmdliner.Cmd.v Cli.info (Legifrance_cli.catala_legifrance_t driver)) diff --git a/french_law/catala_legifrance/date.ml b/french_law/catala_legifrance/date.ml index fd53307c..a1f69895 100644 --- a/french_law/catala_legifrance/date.ml +++ b/french_law/catala_legifrance/date.ml @@ -14,6 +14,8 @@ License for the specific language governing permissions and limitations under the License. *) +open Catala_utils + (** Helper functions to interact with {!Unix.tm} dates *) type date_format = DDMMYYYY | ISO @@ -53,7 +55,7 @@ let parse_expiration_date (date_format : date_format) (expiration_date : string) Unix.tm_isdst = false; }) with _ -> - Utils.Errors.raise_error "Error while parsing expiration date argument (%s)" + Errors.raise_error "Error while parsing expiration date argument (%s)" expiration_date (** Prints an [Unix.tm] under the ISO formatting [YYYY-MM-DD] *) diff --git a/french_law/catala_legifrance/dune b/french_law/catala_legifrance/dune index 3e3018a6..61bff043 100644 --- a/french_law/catala_legifrance/dune +++ b/french_law/catala_legifrance/dune @@ -3,7 +3,7 @@ (package catala_legifrance) (libraries catala.surface - catala.utils + catala.catala_utils cmdliner cohttp lwt diff --git a/french_law/catala_legifrance/cli.ml b/french_law/catala_legifrance/legifrance_cli.ml similarity index 96% rename from french_law/catala_legifrance/cli.ml rename to french_law/catala_legifrance/legifrance_cli.ml index 3622df64..9fedb900 100644 --- a/french_law/catala_legifrance/cli.ml +++ b/french_law/catala_legifrance/legifrance_cli.ml @@ -17,6 +17,7 @@ (** Command line arguments specification of [legifrance_catala] *) open Cmdliner +open Catala_utils let file = Arg.( @@ -96,4 +97,4 @@ let info = ] in let exits = Cmd.Exit.defaults @ [Cmd.Exit.info ~doc:"on error" 1] in - Cmd.info "legifrance_catala" ~version:Utils.Cli.version ~doc ~exits ~man + Cmd.info "legifrance_catala" ~version:Cli.version ~doc ~exits ~man