2022-03-08 17:03:14 +03:00
|
|
|
(* This file is part of the Catala compiler, a specification language for tax
|
2023-05-30 16:41:49 +03:00
|
|
|
and social benefits computation rules. Copyright (C) 2023 Inria, contributor:
|
2022-03-08 17:03:14 +03:00
|
|
|
Denis Merigoux <denis.merigoux@inria.fr>
|
2021-02-12 19:20:14 +03:00
|
|
|
|
2022-03-08 17:03:14 +03:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
the License at
|
2021-02-12 19:20:14 +03:00
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
2022-03-08 17:03:14 +03:00
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
License for the specific language governing permissions and limitations under
|
2021-02-12 19:20:14 +03:00
|
|
|
the License. *)
|
|
|
|
|
2023-06-07 19:10:50 +03:00
|
|
|
(** Interface for emitting compiler messages.
|
|
|
|
|
2023-06-07 19:15:14 +03:00
|
|
|
All messages are expected to use the [Format] module. Flush, ["@?"], ["@."],
|
|
|
|
["%!"] etc. are not supposed to be used outside of this module.
|
2023-06-07 19:10:50 +03:00
|
|
|
|
2023-06-07 19:15:14 +03:00
|
|
|
WARNING: this module performs side-effects at load time, adding support for
|
|
|
|
ocolor tags (e.g. ["@{<blue>text@}"]) to the standard string formatter used
|
|
|
|
by e.g. [Format.sprintf]. (In this case, the tags are ignored, for color
|
|
|
|
output you should use the functions of this module that toggle support
|
|
|
|
depending on cli flags and terminal support). *)
|
2021-02-12 19:20:14 +03:00
|
|
|
|
2023-05-30 16:41:49 +03:00
|
|
|
(** {1 Message content} *)
|
2021-02-12 19:20:14 +03:00
|
|
|
|
2024-04-09 14:30:01 +03:00
|
|
|
type level = Error | Warning | Debug | Log | Result
|
2023-06-19 18:08:16 +03:00
|
|
|
|
2023-05-30 17:22:05 +03:00
|
|
|
module Content : sig
|
2023-06-19 18:08:16 +03:00
|
|
|
(** {2 Types}*)
|
|
|
|
|
2023-06-07 19:10:50 +03:00
|
|
|
type message = Format.formatter -> unit
|
2023-05-30 17:22:05 +03:00
|
|
|
type t
|
|
|
|
|
2023-06-19 18:08:16 +03:00
|
|
|
(** {2 Content creation}*)
|
|
|
|
|
|
|
|
val of_message : message -> t
|
|
|
|
|
|
|
|
val of_result : message -> t
|
|
|
|
(** Similar as [of_message] but tailored for when you want to print the result
|
|
|
|
of a value, etc. *)
|
|
|
|
|
2023-06-07 19:10:50 +03:00
|
|
|
val of_string : string -> t
|
2023-06-13 21:10:42 +03:00
|
|
|
val prepend_message : t -> (Format.formatter -> unit) -> t
|
2021-02-12 19:20:14 +03:00
|
|
|
|
2023-06-19 18:08:16 +03:00
|
|
|
(** {2 Content manipulation}*)
|
|
|
|
|
|
|
|
val to_internal_error : t -> t
|
2023-07-09 18:58:07 +03:00
|
|
|
val add_suggestion : t -> string list -> t
|
2024-04-09 14:30:01 +03:00
|
|
|
val add_position : t -> ?message:message -> Pos.t -> t
|
2023-06-19 18:08:16 +03:00
|
|
|
|
|
|
|
(** {2 Content emission}*)
|
|
|
|
|
2024-04-09 14:30:01 +03:00
|
|
|
val emit : t -> level -> unit
|
2023-06-19 18:08:16 +03:00
|
|
|
end
|
2021-02-12 19:20:14 +03:00
|
|
|
|
2023-05-30 16:41:49 +03:00
|
|
|
(** This functions emits the message according to the emission type defined by
|
|
|
|
[Cli.message_format_flag]. *)
|
|
|
|
|
|
|
|
(** {1 Error exception} *)
|
|
|
|
|
2023-05-30 17:22:05 +03:00
|
|
|
exception CompilerError of Content.t
|
2023-05-30 16:41:49 +03:00
|
|
|
|
2023-06-08 13:06:27 +03:00
|
|
|
(** {1 Some formatting helpers}*)
|
2023-06-07 19:10:50 +03:00
|
|
|
|
2023-06-07 19:15:14 +03:00
|
|
|
val unformat : (Format.formatter -> unit) -> string
|
2023-06-08 13:06:27 +03:00
|
|
|
(** Converts [f] to a string, discarding formatting and skipping newlines and
|
|
|
|
indents *)
|
2023-06-07 19:10:50 +03:00
|
|
|
|
2023-11-14 18:05:54 +03:00
|
|
|
val has_color : out_channel -> bool
|
|
|
|
|
2023-06-08 13:06:27 +03:00
|
|
|
(* {1 More general color-enabled formatting helpers}*)
|
2023-06-07 19:10:50 +03:00
|
|
|
|
2023-06-08 13:06:27 +03:00
|
|
|
val formatter_of_out_channel : out_channel -> Format.formatter
|
|
|
|
(** Creates a new formatter from the given out channel, with correct handling of
|
|
|
|
the ocolor tags. Actual use of escape codes in the output depends on
|
|
|
|
[Cli.style_flag] -- and wether the channel is a tty if that is set to auto. *)
|
2024-04-09 14:30:01 +03:00
|
|
|
|
2024-04-09 19:39:54 +03:00
|
|
|
(** {1 Simple interface for various message emission} *)
|
2024-04-09 14:30:01 +03:00
|
|
|
|
|
|
|
type ('a, 'b) emitter =
|
|
|
|
?header:Content.message ->
|
|
|
|
?internal:bool ->
|
|
|
|
?pos:Pos.t ->
|
|
|
|
?pos_msg:Content.message ->
|
2024-04-09 20:08:29 +03:00
|
|
|
?extra_pos:(string * Pos.t) list ->
|
|
|
|
?fmt_pos:(Content.message * Pos.t) list ->
|
2024-04-09 14:30:01 +03:00
|
|
|
?suggestion:string list ->
|
|
|
|
('a, Format.formatter, unit, 'b) format4 ->
|
|
|
|
'a
|
|
|
|
|
2024-04-10 19:39:30 +03:00
|
|
|
val log : ('a, unit) emitter
|
|
|
|
val debug : ('a, unit) emitter
|
|
|
|
val result : ('a, unit) emitter
|
|
|
|
val warning : ('a, unit) emitter
|
|
|
|
val error : ('a, 'b) emitter
|