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_______________________________________________________________ *)
25 (* Internal functions *******************************************************)
38 if List.mem n reserved then !G.alpha ^ n else n
40 let out_preamble och =
41 let ich = open_in !G.preamble in
42 let rec aux () = KP.fprintf och "%s\n" (input_line ich); aux () in
43 try aux () with End_of_file -> close_in ich
45 let out_top_comment och msg =
46 let padding = width - String.length msg in
47 let padding = if padding >= 0 then padding else 0 in
48 KP.fprintf och "(* %s %s*)\n\n" msg (String.make padding '*')
50 let out_comment och msg =
51 KP.fprintf och "(* %s *)\n" msg
53 let out_include och src =
54 KP.fprintf och "include \"%s.ma\".\n\n" src
57 let str = U.string_of_uri u in
60 if c = '.' then () else begin
61 output_char och (if c = '/' then '_' else c);
66 if n <= 0 then succ i else
67 strip (String.index_from str (succ i) '/') (pred n)
73 | true -> KP.fprintf och "%s" (alpha n)
74 | false -> KP.fprintf och "_"
76 let err () = f "" false in
79 let rec out_term st p e och = function
81 let sort = if k = 0 then "Type" else if k = 1 then "Prop" else assert false in
82 KP.fprintf och "%s" sort
84 let _, _, _, y, b = B.get e i in
85 KP.fprintf och "%a" out_name y
87 KP.fprintf och "%a" out_uri s
89 KP.fprintf och "(%a : %a)" (out_term st false e) t (out_term st false e) u
91 let pt = match t with B.Appl _ -> false | _ -> true in
92 let op, cp = if p then "(", ")" else "", "" in
93 KP.fprintf och "%s%a %a%s" op (out_term st pt e) t (out_term st true e) v cp
94 | B.Bind (y, B.Abst (r, n, w), t) ->
96 let op, cp = if p then "(", ")" else "", "" in
97 let y = R.alpha B.mem e y in
98 let ee = B.push e B.empty E.empty_node y (B.abst r n w) in
99 let ob, cb = match N.to_string st n with
100 | "1" -> "forall", ","
101 | "2" -> "fun", " =>"
102 | _ -> ok := false; "?", "?"
104 KP.fprintf och "%s%s (%a:%a)%s %a%s"
105 op ob out_name y (out_term st false e) w cb (out_term st false ee) t cp
106 | B.Bind (y, B.Abbr v, t) ->
107 let op, cp = if p then "(", ")" else "", "" in
108 let y = R.alpha B.mem e y in
109 let ee = B.push e B.empty E.empty_node y (B.abbr v) in
110 KP.fprintf och "%slet %a := %a in %a%s"
111 op out_name y (out_term st false e) v (out_term st false ee) t cp
112 | B.Bind (a, B.Void, t) -> C.err ()
114 let close_out och () = close_out och
116 let output_entity och st (_, na, u, b) =
117 out_comment och (KP.sprintf "constant %u" na.E.n_apix);
120 KP.fprintf och "Definition %a := %a.\n\n%!" out_uri u (out_term st false B.empty) v;
121 (* KP.fprintf och "Strategy -%u [ %a ].\n\n%!" na.E.n_apix out_uri u; *) !ok
123 KP.fprintf och "Axiom %a : %a.\n\n%!" out_uri u (out_term st false B.empty) w; !ok
126 (* Interface functions ******************************************************)
129 let dir = KF.concat !G.manager_dir base in
130 let path = KF.concat dir fname in
131 let och = open_out (path ^ ext) in
133 out_top_comment och (KP.sprintf "This file was generated by %s: do not edit" G.version_string);
134 output_entity och, close_out och