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_______________________________________________________________ *)
23 (* Internal functions *******************************************************)
33 let out_preamble och =
34 let ich = open_in !G.ma_preamble in
35 let rec aux () = P.fprintf och "%s\n" (input_line ich); aux () in
36 try aux () with End_of_file -> close_in ich
38 let out_top_comment och msg =
39 let padding = width - String.length msg in
40 let padding = if padding >= 0 then padding else 0 in
41 P.fprintf och "(* %s %s*)\n\n" msg (String.make padding '*')
43 let out_comment och msg =
44 P.fprintf och "(* %s *)\n" msg
46 let out_include och src =
47 P.fprintf och "include \"%s.ma\".\n\n" src
50 let str = U.string_of_uri u in
53 if c = '.' then () else begin
54 output_char och (if c = '/' then '_' else c);
59 if n <= 0 then succ i else
60 strip (String.index_from str (succ i) '/') (pred n)
66 | true -> P.fprintf och "%s" n
71 let rec out_term st p e och = function
73 let sort = if h = 0 then "Type[0]" else if h = 1 then "Prop" else assert false in
74 P.fprintf och "%s" sort
76 let _, _, a, b = B.get e i in
77 P.fprintf och "%a" out_name a
79 P.fprintf och "%a" out_uri s
81 P.fprintf och "(%a : %a)" (out_term st false e) t (out_term st false e) u
83 let pt = match t with B.Appl _ -> false | _ -> true in
84 let op, cp = if p then "(", ")" else "", "" in
85 P.fprintf och "%s%a %a%s" op (out_term st pt e) t (out_term st true e) v cp
86 | B.Bind (a, B.Abst (n, w), t) ->
87 let op, cp = if p then "(", ")" else "", "" in
88 let a = R.alpha B.mem e a in
89 let ee = B.push e B.empty a (B.abst n w) in
90 let binder = match N.to_string st n with
93 | _ -> ok := false; "?"
95 P.fprintf och "%s%s%a:%a.%a%s"
96 op binder out_name a (out_term st false e) w (out_term st false ee) t cp
97 | B.Bind (a, B.Abbr v, 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 a (B.abbr v) in
101 P.fprintf och "%slet %a ≝ %a in %a%s"
102 op out_name a (out_term st false e) v (out_term st false ee) t cp
103 | B.Bind (a, B.Void, t) -> C.err ()
105 (* Interface functions ******************************************************)
108 let dir = F.concat !G.ma_dir base in
109 let path = F.concat dir fname in
110 let och = open_out (path ^ ext) in
112 out_top_comment och (P.sprintf "This file is generated by %s: do not edit" G.version_string);
113 out_include och "basics/pts";
116 let output_entity st och (_, na, s, b) =
118 out_comment och (P.sprintf "notion %u" i);
121 P.fprintf och "definition %a ≝ %a.\n\n%!" out_uri s (out_term st false B.empty) t; !ok
123 P.fprintf och "axiom %a : %a.\n\n%!" out_uri s (out_term st false B.empty) t; !ok
128 let close_out och = close_out och