printer.mli 4.16 KB
Newer Older
Andrei Paskevich's avatar
Andrei Paskevich committed
1 2 3
(********************************************************************)
(*                                                                  *)
(*  The Why3 Verification Platform   /   The Why3 Development Team  *)
Jean-Christophe Filliâtre's avatar
Jean-Christophe Filliâtre committed
4
(*  Copyright 2010-2014   --   INRIA - CNRS - Paris-Sud University  *)
Andrei Paskevich's avatar
Andrei Paskevich committed
5 6 7 8 9 10
(*                                                                  *)
(*  This software is distributed under the terms of the GNU Lesser  *)
(*  General Public License version 2.1, with the special exception  *)
(*  on linking described in file LICENSE.                           *)
(*                                                                  *)
(********************************************************************)
11 12 13 14 15 16 17 18 19 20 21 22

open Ident
open Ty
open Term
open Decl
open Theory
open Task

(** Register printers *)

type prelude = string list
type prelude_map = prelude Mid.t
23
type blacklist = string list
24 25 26

type 'a pp = Format.formatter -> 'a -> unit

27 28 29 30 31 32 33 34
type printer_args = {
  env        : Env.env;
  prelude    : prelude;
  th_prelude : prelude_map;
  blacklist  : blacklist;
}

type printer = printer_args -> ?old:in_channel -> task pp
35

36
val register_printer : desc:Pp.formatted -> string -> printer -> unit
37 38 39

val lookup_printer : string -> printer

40
val list_printers : unit -> (string * Pp.formatted) list
41 42 43 44 45 46

(** {2 use printers} *)

val print_prelude : prelude pp
val print_th_prelude : task -> prelude_map pp

Andrei Paskevich's avatar
Andrei Paskevich committed
47 48
val meta_syntax_type : meta
val meta_syntax_logic : meta
49
val meta_remove_prop : meta
François Bobot's avatar
François Bobot committed
50
val meta_remove_logic : meta
Andrei Paskevich's avatar
Andrei Paskevich committed
51 52
val meta_remove_type : meta
val meta_realized_theory : meta
53

Andrei Paskevich's avatar
Andrei Paskevich committed
54 55
val syntax_type : tysymbol -> string -> tdecl
val syntax_logic : lsymbol -> string -> tdecl
56 57
val remove_prop : prsymbol -> tdecl

58 59 60
val check_syntax_type: tysymbol -> string -> unit
val check_syntax_logic: lsymbol -> string -> unit

61 62
type syntax_map = string Mid.t
(* [syntax_map] maps the idents of removed props to "" *)
63

64
val get_syntax_map : task -> syntax_map
65 66
val add_syntax_map : tdecl -> syntax_map -> syntax_map
  (* interprets a declaration as a syntax rule, if any *)
67

68
val query_syntax : syntax_map -> ident -> string option
69

70 71 72 73
val syntax_arguments : string -> 'a pp -> 'a list pp
(** (syntax_arguments templ print_arg fmt l) prints in the formatter fmt
     the list l using the template templ and the printer print_arg *)

74 75 76
val gen_syntax_arguments_typed :
  ('a -> 'b) -> ('a -> 'b array) -> string -> 'a pp -> 'b pp -> 'a -> 'a list pp

77
val syntax_arguments_typed :
78
  string -> term pp -> ty pp -> term -> term list pp
79 80 81
(** (syntax_arguments templ print_arg fmt l) prints in the formatter fmt
     the list l using the template templ and the printer print_arg *)

82 83
(** {2 pretty-printing transformations (useful for caching)} *)

84
val on_syntax_map : (syntax_map -> 'a Trans.trans) -> 'a Trans.trans
85

86
val sprint_tdecl :
87
  ('a -> Format.formatter -> Theory.tdecl -> 'a * string list) ->
88 89 90
    Theory.tdecl -> 'a * string list -> 'a * string list

val sprint_decl :
91
  ('a -> Format.formatter -> Decl.decl -> 'a * string list) ->
92
    Theory.tdecl -> 'a * string list -> 'a * string list
93

94 95 96
(** {2 exceptions to use in transformations and printers} *)

exception UnsupportedType of ty   * string
Andrei Paskevich's avatar
Andrei Paskevich committed
97
exception UnsupportedTerm of term * string
98 99 100
exception UnsupportedDecl of decl * string
exception NotImplemented  of        string

101 102 103 104
val unsupportedType : ty   -> string -> 'a
val unsupportedTerm : term -> string -> 'a
val unsupportedDecl : decl -> string -> 'a
val notImplemented  :         string -> 'a
105 106 107 108 109 110 111

(** {3 functions that catch inner error} *)

exception Unsupported of string
(** This exception must be raised only inside a call
    of one of the catch_* functions below *)

112
val unsupported : string -> 'a
113 114 115 116 117 118 119 120 121 122 123 124 125 126

val catch_unsupportedType : (ty -> 'a) -> (ty -> 'a)
(** [catch_unsupportedType f] return a function which applied on [arg]:
    - return [f arg] if [f arg] does not raise {!Unsupported} exception
    - raise [UnsupportedType (arg,s)] if [f arg] raises [Unsupported s]*)

val catch_unsupportedTerm : (term -> 'a) -> (term -> 'a)
(** same as {! catch_unsupportedType} but use [UnsupportedExpr]
    instead of [UnsupportedType]*)

val catch_unsupportedDecl : (decl -> 'a) -> (decl -> 'a)
(** same as {! catch_unsupportedType} but use [UnsupportedDecl]
    instead of [UnsupportedType] *)