catala/compiler/catala_utils/message.mli

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

114 lines
3.7 KiB
OCaml
Raw Normal View History

2021-02-12 19:20: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:
2021-02-12 19:20:14 +03:00
Denis Merigoux <denis.merigoux@inria.fr>
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
http://www.apache.org/licenses/LICENSE-2.0
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
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
2023-05-30 17:22:05 +03:00
module Content : sig
2023-06-07 19:10:50 +03:00
type message = Format.formatter -> unit
2023-06-19 14:59:56 +03:00
type position = { pos_message : message option; pos : Pos.t }
type suggestions = string list option
2023-05-30 17:22:05 +03:00
type t
2023-06-07 19:10:50 +03:00
val of_message : (Format.formatter -> unit) -> t
val of_string : string -> t
2023-06-13 21:10:42 +03:00
val mark_as_internal_error : t -> t
val prepend_message : t -> (Format.formatter -> unit) -> t
2023-05-30 17:22:05 +03:00
end
2021-02-12 19:20:14 +03:00
2023-05-30 17:22:05 +03:00
type content_type = Error | Warning | Debug | Log | Result
2021-02-12 19:20:14 +03:00
2023-05-30 17:22:05 +03:00
val emit_content : Content.t -> content_type -> unit
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
(** {1 Common error raising} *)
2021-02-12 19:20:14 +03:00
val raise_spanned_error :
2023-06-07 19:15:14 +03:00
?span_msg:Content.message ->
Pos.t ->
2023-06-19 14:59:56 +03:00
?suggestions:string list ->
2023-06-07 19:15:14 +03:00
('a, Format.formatter, unit, 'b) format4 ->
'a
2023-06-07 19:10:50 +03:00
val raise_multispanned_error_full :
2023-06-07 19:15:14 +03:00
(Content.message option * Pos.t) list ->
('a, Format.formatter, unit, 'b) format4 ->
'a
2021-02-12 19:20:14 +03:00
val raise_multispanned_error :
(string option * Pos.t) list -> ('a, Format.formatter, unit, 'b) format4 -> 'a
2021-02-12 19:20:14 +03:00
val raise_error : ('a, Format.formatter, unit, 'b) format4 -> 'a
2023-02-13 18:30:12 +03:00
val raise_internal_error : ('a, Format.formatter, unit, 'b) format4 -> 'a
2021-02-12 19:20:14 +03:00
val assert_internal_error :
bool -> ('a, Format.formatter, unit, unit, unit, unit) format6 -> 'a
(** {1 Common warning emission}*)
2021-02-12 19:20:14 +03:00
2023-05-30 16:41:49 +03:00
val emit_multispanned_warning :
2023-06-07 19:15:14 +03:00
(Content.message option * Pos.t) list ->
('a, Format.formatter, unit) format ->
'a
2021-02-12 19:20:14 +03:00
2023-05-30 16:41:49 +03:00
val emit_spanned_warning :
2023-06-07 19:15:14 +03:00
?span_msg:Content.message ->
Pos.t ->
('a, Format.formatter, unit) format ->
'a
2021-02-12 19:20:14 +03:00
2023-05-30 16:41:49 +03:00
val emit_warning : ('a, Format.formatter, unit) format -> 'a
(** {1 Common log emission}*)
val emit_log : ('a, Format.formatter, unit) format -> 'a
(** {1 Common debug emission}*)
val emit_debug : ('a, Format.formatter, unit) format -> 'a
(** {1 Common result emission}*)
val emit_result : ('a, Format.formatter, unit) format -> 'a
2023-06-07 19:10:50 +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
(** Converts [f] to a string, discarding formatting and skipping newlines and
indents *)
2023-06-07 19:10:50 +03:00
(* {1 More general color-enabled formatting helpers}*)
2023-06-07 19:10:50 +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. *)