1 (******************************************************************************)
5 (* A tactic to print Coq objects in XML *)
7 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
10 (* This module defines a pretty-printer and the stream of commands to the pp *)
12 (******************************************************************************)
15 (* the type token for XML cdata, empty elements and not-empty elements *)
18 (* Empty (element_name, [attrname1, value1 ; ... ; attrnamen, valuen] *)
19 (* NEmpty (element_name, [attrname1, value2 ; ... ; attrnamen, valuen], *)
21 type token = Str of string
22 | Empty of string * (string * string) list
23 | NEmpty of string * (string * string) list * token Stream.t
26 (* currified versions of the constructors make the code more readable *)
27 let xml_empty name attrs = [< 'Empty(name,attrs) >]
28 let xml_nempty name attrs content = [< 'NEmpty(name,attrs,content) >]
29 let xml_cdata str = [< 'Str str >]
32 (* pp tokens None pretty prints the output on stdout *)
33 (* pp tokens (Some filename) pretty prints the output on the file filename *)
35 let channel = ref stdout in
40 fprint_string (a ^ "\n") ;
42 | [< 'Empty(n,l) ; s >] ->
44 fprint_string ("<" ^ n) ;
45 List.iter (function (n,v) -> fprint_string (" " ^ n ^ "=\"" ^ v ^ "\"")) l;
46 fprint_string "/>\n" ;
48 | [< 'NEmpty(n,l,c) ; s >] ->
50 fprint_string ("<" ^ n) ;
51 List.iter (function (n,v) -> fprint_string (" " ^ n ^ "=\"" ^ v ^ "\"")) l;
55 fprint_string ("</" ^ n ^ ">\n") ;
59 for i = 1 to m do fprint_string " " done
60 and fprint_string str =
61 output_string !channel str
65 channel := open_out filename ;
68 print_string ("\nWriting on file \"" ^ filename ^ "\" was succesfull\n");