2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
16 type ('a, 'b) item = Term of 'a * 'b
22 type ('a, 'b) message = ('a, 'b) item list
24 type ('a, 'b) specs = {
25 pp_term: 'a -> F.formatter -> 'b -> unit;
26 pp_lenv: F.formatter -> 'a -> unit
31 let loc = ref "unknown location"
33 (* Internal functions *******************************************************)
36 level := 0; loc := "unknown location"
38 let std = F.std_formatter
40 let err = F.err_formatter
42 let pp_items frm st l items =
43 let pp_item frm = function
44 | Term (c, t) -> F.fprintf frm "@,%a" (st.pp_term c) t
45 | LEnv c -> F.fprintf frm "%a" st.pp_lenv c
46 | Warn s -> F.fprintf frm "@,%s" s
47 | String s -> F.fprintf frm "%s " s
48 | Loc -> F.fprintf frm " <%s>" !loc
50 let iter map frm l = List.iter (map frm) l in
51 if !level >= l then F.fprintf frm "%a" (iter pp_item) items
53 (* Interface functions ******************************************************)
57 begin F.fprintf std "@,@[<v 2>%s" " "; F.pp_print_if_newline std () end
59 let unbox l = if !level >= l then F.fprintf std "@]"
61 let flush l = if !level >= l then F.fprintf std "@]@."
63 let box_err () = F.fprintf err "@[<v>"
65 let flush_err () = F.fprintf err "@]@."
67 let log st l items = pp_items std st l items
69 let error st items = pp_items err st 0 items
71 let items1 s = [Warn s]
74 [Warn st; Term (c, t)]
76 let et_items1 sc c st t =
77 [Warn sc; LEnv c; Warn st; Term (c, t)]
79 let et_items2 sc1 c1 st1 t1 ?sc2 ?c2 st2 t2 =
80 let tl = match sc2, c2 with
81 | Some sc2, Some c2 -> et_items1 sc2 c2 st2 t2
82 | None, None -> t_items1 st2 c1 t2
85 et_items1 sc1 c1 st1 t1 @ tl
87 let et_items3 sc1 c1 st1 t1 ?sc2 ?c2 st2 t2 ?sc3 ?c3 st3 t3 =
88 let tl = match sc3, c3 with
89 | Some sc3, Some c3 -> et_items1 sc3 c3 st3 t3
90 | None, None -> t_items1 st3 c1 t3
93 et_items2 sc1 c1 st1 t1 ?sc2 ?c2 st2 t2 @ tl
95 let warn msg = F.fprintf std "@,%s" msg