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)
29 let affiliation = "This file is part of the λΥP engine"
31 let description = "This file contains the Grundlagen for lyp_global: validate by invoking clause (grundlagen)"
35 let trusted = ref false (* "trusted" indicator out? *)
37 let untrusted = ref false (* "untrusted" indicator out? *)
43 let sub_och = ref stdout
53 let ext_tj_sig = ".sig"
55 let reserved = ["pi"; "sigma"; "nil"; "delay"; "in"; "with"; "resume"; "context"]
58 if List.mem n reserved then !G.alpha ^ n else n
60 let appl_fragment (_, ds) (_, dm) = match ds, dm with
65 | _ -> ok := false; "??"
67 let abst_fragment (_, ds) (_, dm) = match ds, dm with
72 | _ -> ok := false; "??"
74 let prod_fragment (_, ds) (_, dm) = match ds, dm with
79 | _ -> ok := false; "??"
81 let entity_level (_, ds) = match ds with
84 | _ -> ok := false; "?"
86 let out_preamble och =
87 let ich = open_in !G.preamble in
88 let rec aux () = KP.fprintf och "%s\n" (input_line ich); aux () in
89 try aux () with End_of_file -> close_in ich
91 let out_top_comment och msg =
92 KP.fprintf och "%% %s\n\n" msg
94 let out_comment och msg =
95 KP.fprintf och "%% %s\n" msg
97 let out_clause och msg =
98 KP.fprintf och "%s\n\n" msg
101 let str = U.string_of_uri u in
104 if c = '.' then () else begin
105 output_char och (if c = '/' then '_' else c);
110 if n <= 0 then succ i else
111 strip (String.index_from str (succ i) '/') (pred n)
117 | true -> KP.fprintf och "%s" (alpha n)
118 | false -> KP.fprintf och "_"
120 let err () = f "" false in
123 let rec out_term st e och = function
125 KP.fprintf och "sort"
127 let _, _, _, y, b = B.get e i in
128 KP.fprintf och "%a" out_name y
130 KP.fprintf och "%a" out_uri s
133 | B.Appl (a, v, t) ->
134 let f = appl_fragment a.E.a_side a.E.a_main in
135 KP.fprintf och "(appl f_%s %a %a)" f (out_term st e) v (out_term st e) t
136 | B.Bind (a, B.Abst (r, n, w), t) -> (* r *)
137 let a = R.alpha B.mem e a in
138 let ee = B.push e B.empty E.empty_node a (B.abst r n w) in
139 let lf = match N.to_string st n with
140 | "1" -> "prod", prod_fragment a.E.b_side a.E.b_main
141 | "2" -> "abst", abst_fragment a.E.b_side a.E.b_main
142 | _ -> ok := false; "????", "??"
144 let l, f = match lf with
145 | "abst", "bs" -> "rest", "bs"
146 | "prod", "bs" -> "rest", "ho"
147 | "abst", "bb" -> "rest", "ho"
148 | "prod", "bb" -> "rest", "bb"
151 KP.fprintf och "(%s f_%s %a %a\\ %a)"
152 l f (out_term st e) w out_name a (out_term st ee) t
153 | B.Bind (_, B.Abbr _, _) -> C.err ()
154 | B.Bind (_, B.Void, _) -> C.err ()
156 (* LYP variant 2 ***********************************************************)
158 let output_entity_lyp2 och st (_, na, u, b) =
159 begin match !trusted, !untrusted with
160 | false, _ when na.E.n_apix < !G.first ->
161 out_top_comment och "Trusted part";
163 | _ , false when !G.first <= na.E.n_apix && na.E.n_apix <= !G.last ->
164 out_top_comment och "Untrusted part";
168 if na.E.n_apix < !G.first then match b with
169 | E.Abbr (a, B.Cast (w, v)) ->
170 KP.fprintf och "type %a @id.\n" out_uri u;
171 KP.fprintf och "dec_l %a d_%s\n %a\n.\n"
172 out_uri u (entity_level a.E.e_side) (out_term st B.empty) w;
173 KP.fprintf och "def_l %a\n %a\n.\n\n"
174 out_uri u (out_term st B.empty) v;
177 KP.fprintf och "type %a @id.\n" out_uri u;
178 KP.fprintf och "dec_l %a d_%s\n %a\n.\n\n"
179 out_uri u (entity_level a.E.e_side) (out_term st B.empty) w;
182 else if na.E.n_apix <= !G.last then match b with
183 | E.Abbr (a, B.Cast (w, v)) ->
184 KP.fprintf och "type %a @id.\n" out_uri u;
185 KP.fprintf och "type c_%u ann.\n" na.E.n_apix;
186 KP.fprintf och "cast_g %a c_%u d_%s\n %a\n %a\n.\n\n"
187 out_uri u na.E.n_apix (entity_level a.E.e_side)
188 (out_term st B.empty) w (out_term st B.empty) v;
189 uris := (true, u) :: !uris; !ok
191 KP.fprintf och "type %a @id.\n" out_uri u;
192 KP.fprintf och "type c_%u ann.\n" na.E.n_apix;
193 KP.fprintf och "type_g %a c_%u d_%s\n %a\n.\n\n"
194 out_uri u na.E.n_apix (entity_level a.E.e_side)
195 (out_term st B.empty) w;
196 uris := (false, u) :: !uris; !ok
200 let close_out_lyp2 och () =
201 let aux_name (b, s) =
202 let gde = if b then "g_def" else "g_dec" in
203 KP.fprintf och "(%s %a\n" gde out_uri s
205 let aux_sep _ = KP.fprintf och "%s" ")" in
206 out_clause och "type grundlagen prop.";
207 out_clause och "grundlagen :- valid_g";
208 List.iter aux_name (List.rev !uris);
209 KP.fprintf och "%s" "g_top";
210 List.iter aux_sep !uris;
211 out_clause och "\n\n.";
214 (* Interface functions ******************************************************)
216 let open_out_lyp2 fname =
217 let dir = KF.concat !G.manager_dir base in
218 let path = KF.concat dir fname in
219 let och = open_out (path ^ "b_lyp" ^ ext_lp) in
221 out_comment och version;
222 out_comment och affiliation;
223 out_top_comment och description;
224 output_entity_lyp2 och, close_out_lyp2 och