1 (* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (******************************************************************************)
30 (* A tactic to print Coq objects in XML *)
32 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
35 (* This module defines a pretty-printer and the stream of commands to the pp *)
37 (******************************************************************************)
40 (* the type token for XML cdata, empty elements and not-empty elements *)
43 (* Empty (prefix, element_name, *)
44 (* [prefix1, attrname1, value1 ; ... ; prefixn, attrnamen, valuen] *)
45 (* NEmpty (prefix, element_name, *)
46 (* [prefix1, attrname1, value1 ; ... ; prefixn, attrnamen, valuen], *)
50 | Empty of string option * string * (string option * string * string) list
51 | NEmpty of string option * string * (string option * string * string) list *
55 (* currified versions of the constructors make the code more readable *)
56 let xml_empty ?prefix name attrs =
57 [< 'Empty(prefix,name,attrs) >]
58 let xml_nempty ?prefix name attrs content =
59 [< 'NEmpty(prefix,name,attrs,content) >]
63 (** low level for other PPs: pretty print each token of strm applying 'f' to a
64 canonical string representation of each token *)
69 | Some p -> p ^ ":" in
76 | [< 'Empty(p,n,l) ; s >] ->
78 f ("<" ^ (pprefix p) ^ n) ;
79 List.iter (fun (p,n,v) -> f (" " ^ (pprefix p) ^ n ^ "=\"" ^ v ^ "\"")) l;
82 | [< 'NEmpty(p,n,l,c) ; s >] ->
84 f ("<" ^ (pprefix p) ^ n) ;
85 List.iter (fun (p,n,v) -> f (" " ^ (pprefix p) ^ n ^ "=\"" ^ v ^ "\"")) l;
89 f ("</" ^ (pprefix p) ^ n ^ ">\n") ;
93 for i = 1 to m do f " " done
98 (** pretty printer on output channels *)
99 let pp_to_outchan strm oc =
100 pp_gen (fun s -> output_string oc s) strm;
104 (** pretty printer to string *)
105 let pp_to_string strm =
106 let buf = Buffer.create 10240 in
107 pp_gen (Buffer.add_string buf) strm;
111 (** pretty printer to file *)
113 (* pp tokens None pretty prints the output on stdout *)
114 (* pp tokens (Some filename) pretty prints the output on the file filename *)
115 let pp ?(quiet=false) strm fn =
118 let outchan = open_out filename in
120 pp_to_outchan strm outchan;
127 print_string ("\nWriting on file \"" ^ filename ^
128 "\" was succesfull\n");
131 | None -> pp_to_outchan strm stdout