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 *******************************************************)
35 let out_preamble och =
36 let ich = open_in !G.preamble in
37 let rec aux () = KP.fprintf och "%s\n" (input_line ich); aux () in
38 try aux () with End_of_file -> close_in ich
40 let out_top_comment och msg =
41 let padding = width - String.length msg in
42 let padding = if padding >= 0 then padding else 0 in
43 KP.fprintf och "(* %s %s*)\n\n" msg (String.make padding '*')
45 let out_comment och msg =
46 KP.fprintf och "(* %s *)\n" msg
48 let out_include och src =
49 KP.fprintf och "include \"%s.ma\".\n\n" src
52 let str = U.string_of_uri u in
55 if c = '.' then () else begin
56 output_char och (if c = '/' then '_' else c);
61 if n <= 0 then succ i else
62 strip (String.index_from str (succ i) '/') (pred n)
68 | true -> KP.fprintf och "%s" n
69 | false -> KP.fprintf och "_"
71 let err () = f "" false in
74 let rec out_term st p e och = function
76 let sort = if h = 0 then "Type[0]" else if h = 1 then "Prop" else assert false in
77 KP.fprintf och "%s" sort
79 let _, _, a, b = B.get e i in
80 KP.fprintf och "%a" out_name a
82 KP.fprintf och "%a" out_uri s
84 KP.fprintf och "(%a : %a)" (out_term st false e) t (out_term st false e) u
85 | B.Appl (_, _, v, t) ->
86 let pt = match t with B.Appl _ -> false | _ -> true in
87 let op, cp = if p then "(", ")" else "", "" in
88 KP.fprintf och "%s%a %a%s" op (out_term st pt e) t (out_term st true e) v cp
89 | B.Bind (a, B.Abst (r, n, w), t) ->
90 let op, cp = if p then "(", ")" else "", "" in
91 let a = R.alpha B.mem e a in
92 let ee = B.push e B.empty a (B.abst r n w) in
93 let binder = match N.to_string st n, fst a.E.n_main with
97 | _ -> ok := false; "?"
99 KP.fprintf och "%s%s%a:%a.%a%s"
100 op binder out_name a (out_term st false e) w (out_term st false ee) t cp
101 | B.Bind (a, B.Abbr v, t) ->
102 let op, cp = if p then "(", ")" else "", "" in
103 let a = R.alpha B.mem e a in
104 let ee = B.push e B.empty a (B.abbr v) in
105 KP.fprintf och "%slet %a ≝ %a in %a%s"
106 op out_name a (out_term st false e) v (out_term st false ee) t cp
107 | B.Bind (a, B.Void, t) -> C.err ()
109 let close_out och () = close_out och
111 let output_entity och st (_, na, u, b) =
112 out_comment och (KP.sprintf "constant %u" na.E.n_apix);
115 KP.fprintf och "definition %a ≝ %a.\n\n%!" out_uri u (out_term st false B.empty) v; !ok
117 KP.fprintf och "axiom %a : %a.\n\n%!" out_uri u (out_term st false B.empty) w; !ok
120 (* Interface functions ******************************************************)
123 let dir = KF.concat !G.manager_dir base in
124 let path = KF.concat dir fname in
125 let och = open_out (path ^ ext) in
127 out_top_comment och (KP.sprintf "This file was generated by %s: do not edit" G.version_string);
128 out_include och "basics/pts";
129 output_entity och, close_out och