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 *******************************************************)
29 let version = KP.sprintf "This file was generated by %s: do not edit" (G.version_string true)
40 if List.mem n reserved then !G.alpha ^ n else n
42 let out_preamble och =
43 let ich = open_in !G.preamble in
44 let rec aux () = KP.fprintf och "%s\n" (input_line ich); aux () in
45 try aux () with End_of_file -> close_in ich
47 let out_top_comment och msg =
48 let padding = width - String.length msg in
49 let padding = if padding >= 0 then padding else 0 in
50 KP.fprintf och "(* %s %s*)\n\n" msg (String.make padding '*')
52 let out_comment och msg =
53 KP.fprintf och "(* %s *)\n" msg
55 let out_include och src =
56 KP.fprintf och "include \"%s.ma\".\n\n" src
59 let str = U.string_of_uri u in
62 if c = '.' then () else begin
63 output_char och (if c = '/' then '_' else c);
68 if n <= 0 then succ i else
69 strip (String.index_from str (succ i) '/') (pred n)
75 | true -> KP.fprintf och "%s" (alpha n)
76 | false -> KP.fprintf och "_"
78 let err () = f "" false in
81 let rec out_term st p e och = function
83 let sort = if k = 0 then "Type" else if k = 1 then "Prop" else assert false in
84 KP.fprintf och "%s" sort
86 let _, _, _, y, b = B.get e i in
87 KP.fprintf och "%a" out_name y
89 KP.fprintf och "%a" out_uri s
91 KP.fprintf och "(%a : %a)" (out_term st false e) t (out_term st false e) u
93 let pt = match t with B.Appl _ -> false | _ -> true in
94 let op, cp = if p then "(", ")" else "", "" in
95 KP.fprintf och "%s%a %a%s" op (out_term st pt e) t (out_term st true e) v cp
96 | B.Bind (a, B.Abst (r, n, w), t) ->
98 let op, cp = if p then "(", ")" else "", "" in
99 let a = R.alpha B.mem e a in
100 let ee = B.push e B.empty E.empty_node a (B.abst r n w) in
101 let ob, cb = match N.to_string st n with
102 | "1" -> "forall", ","
103 | "2" -> "fun", " =>"
104 | _ -> ok := false; "?", "?"
106 KP.fprintf och "%s%s (%a:%a)%s %a%s"
107 op ob out_name a (out_term st false e) w cb (out_term st false ee) t cp
108 | B.Bind (a, B.Abbr v, t) ->
109 let op, cp = if p then "(", ")" else "", "" in
110 let a = R.alpha B.mem e a in
111 let ee = B.push e B.empty E.empty_node a (B.abbr v) in
112 KP.fprintf och "%slet %a := %a in %a%s"
113 op out_name a (out_term st false e) v (out_term st false ee) t cp
114 | B.Bind (a, B.Void, t) -> C.err ()
116 let close_out och () = close_out och
118 let output_entity och st (_, na, u, b) =
119 out_comment och (KP.sprintf "constant %u" na.E.n_apix);
122 | E.Abbr (B.Cast (w, v)) ->
123 KP.fprintf och "Definition %a : %a.\n%!" out_uri u (out_term st false B.empty) w;
124 KP.fprintf och "exact %a.\n%!" (out_term st true B.empty) v;
125 KP.fprintf och "Time Defined.\n\n%!";
128 KP.fprintf och "Definition %a := %a.\n\n%!" out_uri u (out_term st false B.empty) v;
129 (* KP.fprintf och "Strategy -%u [ %a ].\n\n%!" na.E.n_apix out_uri u; *) !ok
131 KP.fprintf och "Axiom %a : %a.\n\n%!" out_uri u (out_term st false B.empty) w; !ok
134 (* Interface functions ******************************************************)
137 let dir = KF.concat !G.manager_dir base in
138 let path = KF.concat dir fname in
139 let och = open_out (path ^ ext) in
141 out_top_comment och version;
142 output_entity och, close_out och