2022-08-17 17:14:14 +03:00
|
|
|
(* This file is part of the Catala compiler, a specification language for tax
|
|
|
|
and social benefits computation rules. Copyright (C) 2020 Inria, contributor:
|
|
|
|
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. *)
|
|
|
|
|
|
|
|
(** Printing functions for the default calculus AST *)
|
|
|
|
|
2022-11-21 12:46:17 +03:00
|
|
|
open Catala_utils
|
2022-08-22 19:53:30 +03:00
|
|
|
open Definitions
|
2022-08-17 17:14:14 +03:00
|
|
|
|
|
|
|
(** {1 Common syntax highlighting helpers}*)
|
|
|
|
|
|
|
|
val base_type : Format.formatter -> string -> unit
|
|
|
|
val keyword : Format.formatter -> string -> unit
|
2023-04-17 16:10:47 +03:00
|
|
|
|
2022-08-17 17:14:14 +03:00
|
|
|
val punctuation : Format.formatter -> string -> unit
|
2023-04-17 16:10:47 +03:00
|
|
|
(** The argument is assumed to be 1-column wide (but can be a multi-char utf8
|
|
|
|
character) *)
|
|
|
|
|
Add overloaded operators for the common operations
This uses the same disambiguation mechanism put in place for
structures, calling the typer on individual rules on the desugared AST
to propagate types, in order to resolve ambiguous operators like `+`
to their strongly typed counterparts (`+!`, `+.`, `+$`, `+@`, `+$`) in
the translation to scopelang.
The patch includes some normalisation of the definition of all the
operators, and classifies them based on their typing policy instead of
their arity. It also adds a little more flexibility:
- a couple new operators, like `-` on date and duration
- optional type annotation on some aggregation constructions
The `Shared_ast` lib is also lightly restructured, with the `Expr`
module split into `Type`, `Operator` and `Expr`.
2022-11-29 11:47:53 +03:00
|
|
|
val op_style : Format.formatter -> string -> unit
|
2022-08-17 17:14:14 +03:00
|
|
|
val lit_style : Format.formatter -> string -> unit
|
|
|
|
|
2023-05-02 17:46:36 +03:00
|
|
|
(** {1 Some basic stringifiers} *)
|
|
|
|
|
|
|
|
val operator_to_string : 'a operator -> string
|
|
|
|
(** Prints the operator symbols with kind suffixes, as expected by the OCaml
|
|
|
|
backend (e.g. "+^", "+$", etc.) *)
|
|
|
|
|
2022-08-17 17:14:14 +03:00
|
|
|
(** {1 Formatters} *)
|
|
|
|
|
|
|
|
val uid_list : Format.formatter -> Uid.MarkedString.info list -> unit
|
|
|
|
val tlit : Format.formatter -> typ_lit -> unit
|
2022-08-25 13:09:51 +03:00
|
|
|
val location : Format.formatter -> 'a glocation -> unit
|
2023-08-10 17:52:39 +03:00
|
|
|
val external_ref : Format.formatter -> external_ref Mark.pos -> unit
|
2022-08-25 18:29:00 +03:00
|
|
|
val typ : decl_ctx -> Format.formatter -> typ -> unit
|
2023-03-30 19:53:07 +03:00
|
|
|
val lit : Format.formatter -> lit -> unit
|
2023-05-02 12:59:39 +03:00
|
|
|
val operator : ?debug:bool -> Format.formatter -> 'a operator -> unit
|
2022-08-17 17:14:14 +03:00
|
|
|
val log_entry : Format.formatter -> log_entry -> unit
|
|
|
|
val except : Format.formatter -> except -> unit
|
|
|
|
val var : Format.formatter -> 'e Var.t -> unit
|
2022-11-17 19:13:35 +03:00
|
|
|
val var_debug : Format.formatter -> 'e Var.t -> unit
|
2022-08-17 17:14:14 +03:00
|
|
|
|
2023-07-11 18:10:00 +03:00
|
|
|
val expr : ?debug:bool -> unit -> Format.formatter -> ('a, 'm) gexpr -> unit
|
|
|
|
(** Expression printer.
|
|
|
|
|
|
|
|
@param debug
|
|
|
|
(default to the global setting) turns on printing of logging nodes,
|
|
|
|
variable indices and operator suffixes. See the interface below for more
|
|
|
|
detailed control. *)
|
|
|
|
|
|
|
|
(** {2 Generic expression printer interface} *)
|
|
|
|
|
|
|
|
module type EXPR_PARAM = sig
|
|
|
|
val bypass : Format.formatter -> ('a, 't) gexpr -> bool
|
|
|
|
(** can be used to customise printing of any specific nodes or subtrees: will
|
|
|
|
cancel normal printing upon returning [true]. *)
|
|
|
|
|
|
|
|
val operator : Format.formatter -> 'a operator -> unit
|
|
|
|
val var : Format.formatter -> ('a, 't) gexpr Var.t -> unit
|
|
|
|
val lit : Format.formatter -> lit -> unit
|
|
|
|
|
|
|
|
val pre_map : ('a, 't) gexpr -> ('a, 't) gexpr
|
|
|
|
(** pre-processing on expressions: can be used to skip log calls, etc. *)
|
|
|
|
end
|
|
|
|
|
|
|
|
module ExprGen (C : EXPR_PARAM) : sig
|
|
|
|
val expr : Format.formatter -> ('a, 't) gexpr -> unit
|
|
|
|
end
|
|
|
|
|
|
|
|
module ExprConciseParam : EXPR_PARAM
|
|
|
|
module ExprDebugParam : EXPR_PARAM
|
2022-09-30 17:37:43 +03:00
|
|
|
|
|
|
|
(** {1 Debugging versions that don't require a context} *)
|
|
|
|
|
|
|
|
val typ_debug : Format.formatter -> typ -> unit
|
2023-04-07 12:26:10 +03:00
|
|
|
|
|
|
|
val scope :
|
|
|
|
?debug:bool ->
|
|
|
|
decl_ctx ->
|
|
|
|
Format.formatter ->
|
2023-05-17 17:15:00 +03:00
|
|
|
ScopeName.t * ('a, 'm) gexpr scope_body ->
|
2023-04-07 12:26:10 +03:00
|
|
|
unit
|
|
|
|
|
2023-05-17 17:15:00 +03:00
|
|
|
val program : ?debug:bool -> Format.formatter -> ('a, 'm) gexpr program -> unit
|
2023-07-03 17:14:22 +03:00
|
|
|
|
|
|
|
(** User-facing, localised printer *)
|
|
|
|
module UserFacing : sig
|
|
|
|
val unit : Cli.backend_lang -> Format.formatter -> Runtime.unit -> unit
|
|
|
|
val bool : Cli.backend_lang -> Format.formatter -> Runtime.bool -> unit
|
|
|
|
val integer : Cli.backend_lang -> Format.formatter -> Runtime.integer -> unit
|
|
|
|
val decimal : Cli.backend_lang -> Format.formatter -> Runtime.decimal -> unit
|
|
|
|
val money : Cli.backend_lang -> Format.formatter -> Runtime.money -> unit
|
|
|
|
val date : Cli.backend_lang -> Format.formatter -> Runtime.date -> unit
|
|
|
|
|
|
|
|
val duration :
|
|
|
|
Cli.backend_lang -> Format.formatter -> Runtime.duration -> unit
|
|
|
|
|
|
|
|
val lit : Cli.backend_lang -> Format.formatter -> lit -> unit
|
|
|
|
val lit_to_string : Cli.backend_lang -> lit -> string
|
|
|
|
|
|
|
|
val value :
|
2023-07-11 18:10:00 +03:00
|
|
|
?fallback:(Format.formatter -> ('a, 't) gexpr -> unit) ->
|
2023-07-03 17:14:22 +03:00
|
|
|
Cli.backend_lang ->
|
|
|
|
Format.formatter ->
|
2023-07-11 18:10:00 +03:00
|
|
|
('a, 't) gexpr ->
|
2023-07-03 17:14:22 +03:00
|
|
|
unit
|
2023-07-11 18:10:00 +03:00
|
|
|
(** Prints a value in a localised format, intended to be read by an end-user.
|
|
|
|
|
|
|
|
@param fallback
|
|
|
|
is called upon non-value expressions (by default, [Invalid_argument] is
|
|
|
|
raised) *)
|
|
|
|
|
|
|
|
val expr : Cli.backend_lang -> Format.formatter -> (_, _) gexpr -> unit
|
|
|
|
(** This combines the user-facing value printer and the generic expression
|
|
|
|
printer to handle all AST nodes *)
|
2023-07-03 17:14:22 +03:00
|
|
|
end
|