1 (*********************)
2 (* Utility functions *)
3 (*********************)
6 Pp.warning "XmlTheory: AST not recognized"
9 (* name is the name of the function to hook *)
10 (* hook is an hook partial-function to recognize particular inputs *)
11 let set_hook name hook =
12 let module V = Vernacinterp in
13 let old = V.vinterp_map name in
22 (*****************************************************)
23 (* Vernacular administrative commands for the module *)
24 (*****************************************************)
27 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ^
28 "<!DOCTYPE Theory SYSTEM \"http://www.cs.unibo.it/helm/dtd/maththeory.dtd\">\n"
31 (*Vecchio, ma funzionante
32 let module V = Vernacinterp in
33 V.vinterp_add "XMLTHEORYBEGIN"
35 [V.VARG_STRING curi ; V.VARG_STRING filename] ->
37 IXml.reset_output filename ;
38 IXml.output (Xml.xml_cdata header) ;
39 IXml.open_non_empty_element "Theory" ["uri","cic:" ^ curi]
40 | _ -> V.bad_vernac_args "XMLTHEORYBEGIN"
45 let module V = Vernacinterp in
46 let module L = Library in
47 let module S = System in
48 let module N = Names in
49 V.vinterp_add "XMLTHEORYBEGIN"
51 [V.VARG_IDENTIFIER id ; V.VARG_STRING root_dir] ->
53 let s = N.string_of_id id in
55 S.find_file_in_path (L.get_load_path ()) (s^".v")
57 let curi = "/" ^ String.concat "/" lpe.S.coq_dirpath in
58 let dirname = root_dir ^ curi in
59 Unix.system ("mkdir -p " ^ dirname) ;
60 let filename = dirname ^ "/" ^ s ^ ".theory" in
61 IXml.reset_output filename ;
62 IXml.output (Xml.xml_cdata header) ;
63 IXml.open_non_empty_element "Theory" ["uri","cic:" ^ curi ^ "/" ^ s]
64 | _ -> V.bad_vernac_args "XMLTHEORYBEGIN"
68 let module V = Vernacinterp in
69 V.vinterp_add "XMLTHEORYEND"
73 IXml.close_non_empty_element () ;
75 | _ -> V.bad_vernac_args "XMLTHEORYEND"
80 (**********************************************************)
81 (* All the vernacular commands on which one is interested *)
82 (* should be overridden here *)
83 (**********************************************************)
85 let module V = Vernacinterp in
86 let module N = Names in
87 let module S = System in
88 let module L = Library in
91 [V.VARG_STRING import; V.VARG_STRING specif; V.VARG_IDENTIFIER id] ->
92 (* id is the identifier of the module, but we need the absolute *)
93 (* identifier as an URI. *)
94 (* E.g.: Logic ==> theory:/Coq/Init/Logic.theory *)
95 let name = N.string_of_id id in
96 let ({S.coq_dirpath = coq_dirpath},_) = L.module_filename name in
98 "theory:/" ^ (String.concat "/" coq_dirpath) ^ "/" ^ name ^ ".theory"
101 (Xml.xml_nempty "vernacular" []
104 ["import",import; "specif",specif; "uri",uri]
111 let module V = Vernacinterp in
112 let module T = Nametab in
113 let module N = Names in
114 set_hook "HintsResolve"
116 (V.VARG_VARGLIST l)::lh ->
118 (Xml.xml_nempty "vernacular" []
121 [< Xml.xml_nempty "dbs" []
124 (V.VARG_IDENTIFIER x) ->
126 [< Xml.xml_empty "db" ["name",N.string_of_id x];
130 | _ -> Vernacinterp.bad_vernac_args "HintsResolve"
133 Xml.xml_nempty "hints" []
138 [< Xml.xml_empty "hint" ["name",T.string_of_qualid x];
142 | _ -> Vernacinterp.bad_vernac_args "HintsResolve"
153 let module V = Vernacinterp in
154 set_hook "IMPLICIT_ARGS_ON"
158 (Xml.xml_nempty "vernacular" []
168 let module V = Vernacinterp in
169 set_hook "DEFINITION"
171 (* Coq anomaly: a Local definition is a Definition at the syntax *)
172 (* level but a Variable at the logical level. Here we have to *)
173 (* recognize the two cases and treat them differently *)
174 (V.VARG_STRING "LOCAL":: V.VARG_IDENTIFIER id:: V.VARG_CONSTR c:: rest) ->
176 (Xml.xml_nempty "VARIABLES" ["as","LOCAL"]
179 ["uri",Names.string_of_id id ^ ".var"]
182 | (V.VARG_STRING kind:: V.VARG_IDENTIFIER id:: V.VARG_CONSTR c :: rest) ->
186 ["uri", Names.string_of_id id ^ ".con" ; "as",kind]
192 let module V = Vernacinterp in
193 set_hook "BeginSection"
195 [V.VARG_IDENTIFIER id] ->
196 IXml.open_non_empty_element "SECTION" ["uri", Names.string_of_id id]
201 let module V = Vernacinterp in
202 set_hook "EndSection"
204 [V.VARG_IDENTIFIER id] ->
205 IXml.close_non_empty_element ()
210 let module V = Vernacinterp in
211 set_hook "StartProof"
213 [V.VARG_STRING kind;V.VARG_IDENTIFIER s;V.VARG_CONSTR com] ->
217 ["uri", Names.string_of_id s ^ ".con"; "as",kind]
223 let module V = Vernacinterp in
224 set_hook "MUTUALINDUCTIVE"
226 [V.VARG_STRING f; V.VARG_VARGLIST indl] ->
227 (* we need the name of the first inductive defined *)
228 (* type in the block to get the URI *)
231 (V.VARG_VARGLIST ((V.VARG_IDENTIFIER name)::_))::_ -> name
237 ["uri", Names.string_of_id name ^ ".ind"; "as",f]
243 let module V = Vernacinterp in
246 [V.VARG_STRING kind; V.VARG_BINDERLIST slcl] ->
247 (* here we need all the names *)
249 List.flatten (List.map fst slcl)
252 (Xml.xml_nempty "VARIABLES" ["as",kind]
257 ["uri",Names.string_of_id name ^ ".var"]
267 let module V = Vernacinterp in
268 let module T = Nametab in
269 let module N = Names in
272 [V.VARG_STRING kind; V.VARG_STRING identity; V.VARG_QUALID qid;
273 V.VARG_QUALID qids; V.VARG_QUALID qidt] ->
274 (* let's substitute empty strings with non-empty strings *)
275 (* to get a stricter DTD *)
276 let remove_empty_string s = if s = "" then "UNSPECIFIED" else s in
277 let kind = remove_empty_string kind in
278 let identity = remove_empty_string identity in
280 (Xml.xml_nempty "vernacular" []
283 ["kind",kind; "identity",identity ; "name",T.string_of_qualid qid ;
284 "source",T.string_of_qualid qids;"target",T.string_of_qualid qidt]
291 let module V = Vernacinterp in
292 set_hook "MUTUALRECURSIVE"
294 [V.VARG_VARGLIST lmi] ->
295 (* we need the name of the first inductive defined *)
296 (* type in the block to get the URI *)
299 (V.VARG_VARGLIST ((V.VARG_IDENTIFIER name)::_))::_ -> name
305 ["uri", Names.string_of_id name ^ ".con" ; "as","Fixpoint"]
311 let module V = Vernacinterp in
312 set_hook "MUTUALCORECURSIVE"
314 [V.VARG_VARGLIST lmi] ->
315 (* we need the name of the first inductive defined *)
316 (* type in the block to get the URI *)
319 (V.VARG_VARGLIST ((V.VARG_IDENTIFIER name)::_))::_ -> name
325 ["uri", Names.string_of_id name ^ ".con" ; "as","CoFixpoint"]
331 let module V = Vernacinterp in
335 V.VARG_IDENTIFIER struc;
336 V.VARG_BINDERLIST binders;
338 V.VARG_VARGLIST namec;
339 V.VARG_VARGLIST cfs] ->
343 ["uri", Names.string_of_id struc ^ ".ind" ; "as","Record"]
349 let module V = Vernacinterp in
352 [V.VARG_STRING kind; V.VARG_BINDERLIST slcl] ->
353 (* here we need all the names *)
355 List.flatten (List.map fst slcl)
358 (Xml.xml_nempty "AXIOMS" ["as",kind]
363 ["uri",Names.string_of_id name ^ ".con"]