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 *******************************************************)
27 let version = KP.sprintf "This file was generated by %s: do not edit" (G.version_string true)
35 let sub_och = ref stdout
45 let reserved = ["pi"; "sigma"; "nil"; "delay"; "in"; "with"; "resume"; "context"]
48 if List.mem n reserved then !G.alpha ^ n else n
50 let out_preamble och =
51 let ich = open_in !G.preamble in
52 let rec aux () = KP.fprintf och "%s\n" (input_line ich); aux () in
53 try aux () with End_of_file -> close_in ich
55 let out_top_comment och msg =
56 KP.fprintf och "%% %s\n\n" msg
58 let out_comment och msg =
59 KP.fprintf och "%% %s\n" msg
61 let out_clause och msg =
62 KP.fprintf och "%s\n\n" msg
65 let str = U.string_of_uri u in
68 if c = '.' then () else begin
69 output_char och (if c = '/' then '_' else c);
74 if n <= 0 then succ i else
75 strip (String.index_from str (succ i) '/') (pred n)
81 | true -> KP.fprintf och "%s" (alpha n)
82 | false -> KP.fprintf och "_"
84 let err () = f "" false in
87 let rec out_term st e och = function
89 let sort = if k = 0 then "(s+type 0)" else if k = 1 then "(s+prop 0)" else assert false in
90 KP.fprintf och "(sort %s)" sort
92 let _, _, _, y, b = B.get e i in
93 KP.fprintf och "%a" out_name y
95 KP.fprintf och "%a" out_uri s
97 KP.fprintf och "(abbr %a %a x\\ x)" (out_term st e) t (out_term st e) u
99 KP.fprintf och "(appl %a %a)" (out_term st e) t (out_term st e) v
100 | B.Bind (y, B.Abst (r, n, w), t) ->
101 let y = R.alpha B.mem e y in
102 let ee = B.push e B.empty E.empty_node y (B.abst r n w) in
103 let c = match r, N.to_string st n with
104 | false, "1" -> "prod"
105 | false, "2" -> "abst"
106 | _ -> ok := false; "?"
108 KP.fprintf och "(%s %a %a\\ %a)"
109 c (out_term st e) w out_name y (out_term st ee) t
110 | B.Bind (_, B.Void, _) -> C.err ()
111 | B.Bind (_, B.Abbr _, _) -> C.err ()
113 (* PTS variant 2 ************************************************************)
115 let output_entity_pts2 och st (_, na, u, b) =
116 if na.E.n_apix < !G.first then begin
118 | E.Abbr (_, B.Cast (w, v)) ->
119 KP.fprintf och "get_expansion %a %u %a.\n"
120 out_uri u na.E.n_apix (out_term st B.empty) v;
121 KP.fprintf och "get_type %a %a.\n\n"
122 out_uri u (out_term st B.empty) w; !ok
124 KP.fprintf och "get_type %a %a.\n\n"
125 out_uri u (out_term st B.empty) w; !ok
127 end else if na.E.n_apix <= !G.last then begin
129 | E.Abbr (_, B.Cast (w, v)) ->
130 KP.fprintf och "g+line+2 %a %u\n %a\n %a\n.\n\n"
131 out_uri u na.E.n_apix (out_term st B.empty) v (out_term st B.empty) w;
132 uris := (true, u) :: !uris; !ok
134 KP.fprintf och "g+line+1 %a %u\n %a\n.\n\n"
135 out_uri u na.E.n_apix (out_term st B.empty) w;
136 uris := (false, u) :: !uris; !ok
140 let close_out_pts2 och () =
141 let aux_name (b, s) =
142 let gde = if b then "gdef" else "gdec" in
143 KP.fprintf och "(%s %a\n" gde out_uri s
145 let aux_sep _ = KP.fprintf och "%s" ")" in
146 out_clause och "grundlagen :- is+valid";
147 List.iter aux_name (List.rev !uris);
148 KP.fprintf och "%s" "gtop";
149 List.iter aux_sep !uris;
150 out_clause och "\n\n.";
153 (* Interface functions ******************************************************)
155 let open_out_pts2 fname =
156 let dir = KF.concat !G.manager_dir base in
157 let path = KF.concat dir fname in
158 let och = open_out (path ^ "b_pts" ^ ext_lp) in
160 out_top_comment och version;
161 output_entity_pts2 och, close_out_pts2 och