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.
|
|
|
|
|
|
|
|
All messages are expected to use the [Format] module. Flush, ["@?"], ["@."],
|
|
|
|
["%!"] etc. are not supposed to be used outside of this module.
|
|
|
|
|
|
|
|
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-07-30 16:11:08 +03:00
|
|
|
val emit_n : ?ppf:Format.formatter -> level -> t list -> unit
|
|
|
|
val emit : ?ppf:Format.formatter -> 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]. *)
|
|
|
|
|
2024-06-17 16:36:38 +03:00
|
|
|
(** {1 Error exceptions} *)
|
2023-05-30 16:41:49 +03:00
|
|
|
|
2023-05-30 17:22:05 +03:00
|
|
|
exception CompilerError of Content.t
|
2024-06-17 16:36:38 +03:00
|
|
|
exception CompilerErrors of Content.t list
|
2023-05-30 16:41:49 +03:00
|
|
|
|
2024-07-30 16:11:08 +03:00
|
|
|
type lsp_error_kind = Lexing | Parsing | Typing | Generic
|
|
|
|
|
|
|
|
type lsp_error = {
|
|
|
|
kind : lsp_error_kind;
|
|
|
|
message : Content.message;
|
|
|
|
pos : Pos.t option;
|
|
|
|
suggestion : string list option;
|
|
|
|
}
|
|
|
|
|
|
|
|
val register_lsp_error_notifier : (lsp_error -> unit) -> unit
|
|
|
|
|
2023-06-08 13:06:27 +03:00
|
|
|
(** {1 Some formatting helpers}*)
|
2023-06-07 19:10:50 +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
|
2024-04-26 16:40:55 +03:00
|
|
|
val set_terminal_width_function : (unit -> int) -> unit
|
Generate tests reports from 'clerk test'
This is a proper replacement for the previous shell-based placeholder hack.
Here is a summary:
- `clerk runtest` (normally run by ninja) is much extended:
* besides generating the test@out file, it checks individual tests for success
and can write a report file containing their status, and the positions for
their (expected/current) outputs (this uses `Marshal`)
* it now handles out-tests directly in addition to inline-tests, for which
it generates the separate output file ; they are included in the report
- ninja is now tasked with building all the test reports (which shouldn't fail);
for directories, individual reports are concatenated (as before).
Removing intermediate report rules, and out-test rules means that the ninja
file is much simplified.
- then, clerk takes back control, reads the final reports and formats them in a
user-friendly way. Printing the reports may imply running `diff` internally.
In particular, the commands to easily reproduce each test are provided.
Resetting the test results if required is also done directly by clerk, at this
stage.
A few switches are available to customise the output, but I am waiting for some
feedback before deciding what to make available from the CLI.
The `clerk report` command is available to manually explore test reports, but
normally the processing is done directly at the end of `clerk test` (i.e. ninja
will no longer call that command)
2024-06-14 22:05:19 +03:00
|
|
|
val terminal_columns : unit -> int
|
2023-11-14 18:05:54 +03:00
|
|
|
|
2024-06-18 16:10:29 +03:00
|
|
|
val pad : int -> string -> Format.formatter -> unit
|
|
|
|
(** Prints the given character the given number of times (assuming it is of
|
|
|
|
width 1) *)
|
|
|
|
|
2023-06-08 13:06:27 +03:00
|
|
|
(* {1 More general color-enabled formatting helpers}*)
|
2023-06-07 19:10:50 +03:00
|
|
|
|
2024-05-04 18:45:22 +03:00
|
|
|
val formatter_of_out_channel : out_channel -> unit -> Format.formatter
|
2023-06-08 13:06:27 +03:00
|
|
|
(** 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-05-03 13:20:09 +03:00
|
|
|
?outcome:Content.message 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
|
2024-07-30 16:11:08 +03:00
|
|
|
val error : ?kind:lsp_error_kind -> ('a, 'exn) emitter
|
2024-05-03 16:04:56 +03:00
|
|
|
val results : Content.message list -> unit
|
2024-06-17 16:36:38 +03:00
|
|
|
|
|
|
|
(** Multiple errors *)
|
|
|
|
|
2024-06-17 18:38:27 +03:00
|
|
|
val with_delayed_errors : ?stop_on_error:bool -> (unit -> 'a) -> 'a
|
|
|
|
(** [with_delayed_errors ?stop_on_error f] calls [f] and registers each error
|
|
|
|
triggered using [delayed_error]. [stop_on_error] defaults to
|
|
|
|
[Global.options.stop_on_error].
|
|
|
|
|
|
|
|
@raise CompilerErrors when delayed errors were registered.
|
|
|
|
@raise CompilerError
|
|
|
|
on the first error encountered when the [stop_on_error] flag is set. *)
|
2024-06-17 16:36:38 +03:00
|
|
|
|
2024-07-30 16:11:08 +03:00
|
|
|
val delayed_error : ?kind:lsp_error_kind -> 'b -> ('a, 'b) emitter
|