Workaround some ocamlformat crashes

These files were not reformatted!
This commit is contained in:
Louis Gesbert 2022-05-04 18:38:28 +02:00
parent e7181b18b1
commit 6cb0d581a6
5 changed files with 90 additions and 67 deletions

View File

@ -41,7 +41,7 @@ COMPILER_DIR=compiler
BUILD_SYSTEM_DIR=build_system BUILD_SYSTEM_DIR=build_system
format: format:
dune build @fmt --auto-promote 2> /dev/null | true dune build @fmt --auto-promote
#> build_dev : Builds the Catala compiler, without formatting code #> build_dev : Builds the Catala compiler, without formatting code
build_dev: build_dev:

View File

@ -1,29 +1,32 @@
(* This file is part of the Catala build system, a specification language for tax and social (* This file is part of the Catala build system, a specification language for
benefits computation rules. Copyright (C) 2020 Inria, contributor: Emile Rolley tax and social benefits computation rules. Copyright (C) 2020 Inria,
<emile.rolley@tuta.io> contributor: Emile Rolley <emile.rolley@tuta.io>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except Licensed under the Apache License, Version 2.0 (the "License"); you may not
in compliance with the License. You may obtain a copy of the License at use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License Unless required by applicable law or agreed to in writing, software
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
or implied. See the License for the specific language governing permissions and limitations under WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License. *) the License. *)
(** This library contains the implementations of utility functions used to generate {{: (** {2 What (** This library contains the implementations of utility functions
https://ninja-build.org}Ninja} build files in OCaml with almost no dependencies -- it only used to generate {{:https://ninja-build.org} Ninja} build files in OCaml
depends on {{: https://v3.ocaml.org/p/re/1.10.3/doc/Re/index.html}Re}. It's currently developed with almost no dependencies -- it only depends on
to be used by {{: {https://github.com/CatalaLang/catala/tree/master/build_system}Clerk}, the {{: {{:https://v3.ocaml.org/p/re/1.10.3/doc/Re/index.html} Re}. It's currently
https://catala-lang.org}Catala} build system. Therefore, the library {b supports only very basic developed to be used by
features} required by Clerk. *) {{:https://github.com/CatalaLang/catala/tree/master/build_system} Clerk},
the {{:https://catala-lang.org} Catala} build system. Therefore, the library
{b supports only very basic features} required by Clerk. *) is Ninja?} *)
(** {2 What is Ninja?} *) (** {{:https://ninja-build.org} Ninja} is a low-level build system. It's
designed to have its input files ({i build.ninja}) generated by a
(** {{:https://ninja-build.org} Ninja} is a low-level build system. It's designed to have its input higher-level build system, and to run builds as fast as possible by
files ({i build.ninja}) generated by a higher-level build system, and to run builds as fast as supporting native cross-platform (Windows and Unix) parallel builds.
possible by supporting native cross-platform (Windows and Unix) parallel builds.
See the {{:https://ninja-build.org/manual.html} manual} for more details. *) See the {{:https://ninja-build.org/manual.html} manual} for more details. *)
@ -31,24 +34,25 @@
(** Helper module to build ninja expressions. *) (** Helper module to build ninja expressions. *)
module Expr : sig module Expr : sig
(** Represents a ninja expression. Which could be either a literal, a {{: (** Represents a ninja expression. Which could be either a literal, a
https://ninja-build.org/manual.html#_variables}variable references} ($_) or {{:https://ninja-build.org/manual.html#_variables} variable references}
a sequence of sub-expressions. ($_) or a sequence of sub-expressions.
{b Note:} for now, there are no visible differences between an [Expr.Seq] {b Note:} for now, there are no visible differences between an [Expr.Seq]
and a list of {!type: Expr.t}, indeed, in both cases, one space is added and a list of {!type: Expr.t}, indeed, in both cases, one space is added
between each expression -- resp. sub-expression. The difference only comes from the semantic: between each expression -- resp. sub-expression. The difference only comes
an [Expr.Seq] is {b a unique} Ninja expression. *) from the semantic: an [Expr.Seq] is {b a unique} Ninja expression. *)
type t = type t =
| Lit of string | Lit of string
(* Literal string. *) (* Literal string. *)
| Var of string | Var of string
(* Variable reference. *) (* Variable reference. *)
| Seq of t list | Seq of t list
(* Sequence of sub-expressions. *) (* Sequence of sub-expressions. *)
val format : Format.formatter -> t -> unit val format : Format.formatter -> t -> unit
(** [format fmt exp] outputs in [fmt] the string representation of the ninja expression [exp]. *) (** [format fmt exp] outputs in [fmt] the string representation of the ninja
expression [exp]. *)
val format_list : Format.formatter -> t list -> unit val format_list : Format.formatter -> t list -> unit
(** [format fmt ls] outputs in [fmt] the string representation of a list [ls] (** [format fmt ls] outputs in [fmt] the string representation of a list [ls]
@ -57,30 +61,31 @@ end
(** {1 Ninja rules} *) (** {1 Ninja rules} *)
(** Helper module to build {{:https://ninja-build.org/manual.html#_rules}ninja rules}. *) (** Helper module to build {{:https://ninja-build.org/manual.html#_rules} ninja
rules}. *)
module Rule : sig module Rule : sig
type t = { type t = { name : string; command : Expr.t; description : Expr.t option }
name : string;
command : Expr.t;
description : Expr.t option;
}
(** Represents the minimal ninja rule representation for Clerk: (** Represents the minimal ninja rule representation for Clerk:
{[ {[
rule <name> rule <name>
command = <command> command = <command>
[description = <description>] [description = <description>]
]} *) ]} *)
val make : string -> command:Expr.t -> description:Expr.t -> t val make : string -> command:Expr.t -> description:Expr.t -> t
(** [make name ~command ~description] returns the corresponding ninja {!type: Rule.t}. *) (** [make name ~command ~description] returns the corresponding ninja {!type:
Rule.t}. *)
val format : Format.formatter -> t -> unit val format : Format.formatter -> t -> unit
(** [format fmt rule] outputs in [fmt] the string representation of the ninja [rule]. *) (** [format fmt rule] outputs in [fmt] the string representation of the ninja
[rule]. *)
end end
(** {1 Ninja builds} *) (** {1 Ninja builds} *)
(** Helper module to build ninja {{: https://ninja-build.org/manual.html#_build_statements}build statements}. *) (** Helper module to build ninja
{{:https://ninja-build.org/manual.html#_build_statements} build statements}. *)
module Build : sig module Build : sig
type t = { type t = {
outputs : Expr.t list; outputs : Expr.t list;
@ -89,49 +94,63 @@ module Build : sig
vars : (string * Expr.t) list; vars : (string * Expr.t) list;
} }
(** Represents the minimal ninja build statement representation for Clerk: (** Represents the minimal ninja build statement representation for Clerk:
{[ {[
build <outputs>: <rule> [<inputs>] build <outputs>: <rule> [<inputs>]
[<vars>] [<vars>]
]}*) ]}*)
val make : outputs:Expr.t list -> rule:string -> t val make : outputs:Expr.t list -> rule:string -> t
(** [make ~outputs ~rule] returns the corresponding ninja {!type: Build.t} with no {!field: inputs} (** [make ~outputs ~rule] returns the corresponding ninja {!type: Build.t}
or {!field: vars}. *) with no {!field: inputs} or {!field: vars}. *)
val make_with_vars : outputs:Expr.t list -> rule:string -> vars:(string * Expr.t) list -> t val make_with_vars :
(** [make_with_vars ~outputs ~rule ~vars] returns the corresponding ninja {!type: Build.t} with no {!field: inputs}. *) outputs:Expr.t list -> rule:string -> vars:(string * Expr.t) list -> t
(** [make_with_vars ~outputs ~rule ~vars] returns the corresponding ninja
{!type: Build.t} with no {!field: inputs}. *)
val make_with_inputs : outputs:Expr.t list -> rule:string -> inputs:Expr.t list -> t val make_with_inputs :
(** [make_with_vars ~outputs ~rule ~inputs] returns the corresponding ninja {!type: Build.t} with no {!field: vars}. *) outputs:Expr.t list -> rule:string -> inputs:Expr.t list -> t
(** [make_with_vars ~outputs ~rule ~inputs] returns the corresponding ninja
{!type: Build.t} with no {!field: vars}. *)
val make_with_vars_and_inputs : val make_with_vars_and_inputs :
outputs:Expr.t list -> rule:string -> inputs:Expr.t list -> vars:(string * Expr.t) list -> t outputs:Expr.t list ->
(** [make_with_vars ~outputs ~rule ~inputs ~vars] returns the corresponding ninja {!type: Build.t}. *) rule:string ->
inputs:Expr.t list ->
vars:(string * Expr.t) list ->
t
(** [make_with_vars ~outputs ~rule ~inputs ~vars] returns the corresponding
ninja {!type: Build.t}. *)
val empty : t val empty : t
(** [empty] is the minimal ninja {!type: Build.t} with ["empty"] as {!field: outputs} and ["phony"] as {!field: rule}. *) (** [empty] is the minimal ninja {!type: Build.t} with ["empty"] as {!field:
outputs} and ["phony"] as {!field: rule}. *)
val unpath : ?sep:string -> string -> string val unpath : ?sep:string -> string -> string
(** [unpath ~sep path] replaces all [/] occurences with [sep] in [path] to avoid ninja writing the (** [unpath ~sep path] replaces all [/] occurences with [sep] in [path] to
corresponding file and use it as sub command. By default, [sep] is set to ["-"]. *) avoid ninja writing the corresponding file and use it as sub command. By
default, [sep] is set to ["-"]. *)
val format : Format.formatter -> t -> unit val format : Format.formatter -> t -> unit
(** [format fmt build] outputs in [fmt] the string representation of the ninja [build]. *) (** [format fmt build] outputs in [fmt] the string representation of the ninja
[build]. *)
end end
(** {1 Maps} *) (** {1 Maps} *)
module RuleMap : Map.S with type key = String.t module RuleMap : Map.S with type key = String.t
module BuildMap : Map.S with type key = String.t module BuildMap : Map.S with type key = String.t
(** {1 Ninja} *) (** {1 Ninja} *)
type ninja = { rules : Rule.t RuleMap.t; builds : Build.t BuildMap.t } type ninja = { rules : Rule.t RuleMap.t; builds : Build.t BuildMap.t }
(** Represents the minimal ninja architecture (list of rule and build statements) needed for clerk. *) (** Represents the minimal ninja architecture (list of rule and build
statements) needed for clerk. *)
val empty : ninja val empty : ninja
(** [empty] returns the empty empty ninja structure. *) (** [empty] returns the empty empty ninja structure. *)
val format : Format.formatter -> ninja -> unit val format : Format.formatter -> ninja -> unit
(** [format fmt build] outputs in [fmt] the string representation of all [ninja.rules] and [ninja.builds]. *) (** [format fmt build] outputs in [fmt] the string representation of all
[ninja.rules] and [ninja.builds]. *)

View File

@ -249,9 +249,10 @@ let make_none (pos : Pos.t) : expr Pos.marked Bindlib.box =
let make_some (e : expr Pos.marked Bindlib.box) : expr Pos.marked Bindlib.box = let make_some (e : expr Pos.marked Bindlib.box) : expr Pos.marked Bindlib.box =
let pos = Pos.get_position @@ Bindlib.unbox e in let pos = Pos.get_position @@ Bindlib.unbox e in
let mark : 'a -> 'a Pos.marked = Pos.mark pos in let mark : 'a -> 'a Pos.marked = Pos.mark pos in
let+ e = e [@ocamlformat "disable"] in begin[@ocamlformat "disable"]
let+ e = e in
mark @@ EInj (e, 1, option_enum, [ (D.TLit D.TUnit, pos); (D.TAny, pos) ]) mark @@ EInj (e, 1, option_enum, [ (D.TLit D.TUnit, pos); (D.TAny, pos) ])
end
(** [make_matchopt_with_abs_arms arg e_none e_some] build an expression (** [make_matchopt_with_abs_arms arg e_none e_some] build an expression
[match arg with |None -> e_none | Some -> e_some] and requires e_some and [match arg with |None -> e_none | Some -> e_some] and requires e_some and
@ -262,11 +263,12 @@ let make_matchopt_with_abs_arms
(e_some : expr Pos.marked Bindlib.box) : expr Pos.marked Bindlib.box = (e_some : expr Pos.marked Bindlib.box) : expr Pos.marked Bindlib.box =
let pos = Pos.get_position @@ Bindlib.unbox arg in let pos = Pos.get_position @@ Bindlib.unbox arg in
let mark : 'a -> 'a Pos.marked = Pos.mark pos in let mark : 'a -> 'a Pos.marked = Pos.mark pos in
let+ arg = arg begin[@ocamlformat "disable"]
and+ e_none = e_none let+ arg = arg
and+ e_some = e_some [@ocamlformat "disable"] in and+ e_none = e_none
and+ e_some = e_some in
mark @@ EMatch (arg, [ e_none; e_some ], option_enum) mark @@ EMatch (arg, [ e_none; e_some ], option_enum)
end
(** [make_matchopt pos v tau arg e_none e_some] builds an expression (** [make_matchopt pos v tau arg e_none e_some] builds an expression
[match arg with | None () -> e_none | Some v -> e_some]. It binds v to [match arg with | None () -> e_none | Some v -> e_some]. It binds v to

View File

@ -29,7 +29,8 @@ let begins_with_uppercase (s : string) : bool =
let first_letter = CamomileLibraryDefault.Camomile.UTF8.get s 0 in let first_letter = CamomileLibraryDefault.Camomile.UTF8.get s 0 in
is_uppercase first_letter is_uppercase first_letter
(** @note: (EmileRolley) seems to be factorizable with Dcalc.Print.format_lit. *) (** {b Note:} (EmileRolley) seems to be factorizable with
Dcalc.Print.format_lit. *)
let format_lit (fmt : Format.formatter) (l : lit Pos.marked) : unit = let format_lit (fmt : Format.formatter) (l : lit Pos.marked) : unit =
match Pos.unmark l with match Pos.unmark l with
| LBool b -> Dcalc.Print.format_lit_style fmt (string_of_bool b) | LBool b -> Dcalc.Print.format_lit_style fmt (string_of_bool b)

View File

@ -0,0 +1 @@
*.cppo.ml