1 (* Title: Pure/ProofGeneral/pgip_output.ML
5 PGIP abstraction: output commands.
10 (* These are the PGIP messages which the prover emits. *)
12 Normalresponse of { content: XML.tree list }
13 | Errorresponse of { fatality: PgipTypes.fatality,
14 location: PgipTypes.location option,
15 content: XML.tree list }
16 | Informfileloaded of { url: PgipTypes.pgipurl, completed: bool }
17 | Informfileoutdated of { url: PgipTypes.pgipurl, completed: bool }
18 | Informfileretracted of { url: PgipTypes.pgipurl, completed: bool }
19 | Metainforesponse of { attrs: XML.attributes,
20 content: XML.tree list }
21 | Lexicalstructure of { content: XML.tree list }
22 | Proverinfo of { name: string,
27 filenameextns: string }
28 | Setids of { idtables: PgipTypes.idtable list }
29 | Delids of { idtables: PgipTypes.idtable list }
30 | Addids of { idtables: PgipTypes.idtable list }
31 | Hasprefs of { prefcategory: string option,
32 prefs: PgipTypes.preference list }
33 | Prefval of { name: string, value: string }
34 | Setrefs of { url: PgipTypes.pgipurl option,
35 thyname: PgipTypes.objname option,
36 objtype: PgipTypes.objtype option,
37 name: PgipTypes.objname option,
38 idtables: PgipTypes.idtable list,
39 fileurls : PgipTypes.pgipurl list }
40 | Idvalue of { thyname: PgipTypes.objname option,
41 objtype: PgipTypes.objtype,
42 name: PgipTypes.objname,
44 | Informguise of { file : PgipTypes.pgipurl option,
45 theory: PgipTypes.objname option,
46 theorem: PgipTypes.objname option,
47 proofpos: int option }
48 | Parseresult of { attrs: XML.attributes, doc:PgipMarkup.pgipdocument,
49 errs: XML.tree list } (* errs to become PGML *)
50 | Usespgip of { version: string,
51 pgipelems: (string * bool * string list) list }
52 | Usespgml of { version: string }
53 | Pgip of { tag: string option,
56 destid: string option,
59 content: XML.tree list }
62 val output : pgipoutput -> XML.tree
65 structure PgipOutput : PGIPOUTPUT =
70 Normalresponse of { content: XML.tree list }
71 | Errorresponse of { fatality: fatality,
72 location: location option,
73 content: XML.tree list }
74 | Informfileloaded of { url: Path.T, completed: bool }
75 | Informfileoutdated of { url: Path.T, completed: bool }
76 | Informfileretracted of { url: Path.T, completed: bool }
77 | Metainforesponse of { attrs: XML.attributes, content: XML.tree list }
78 | Lexicalstructure of { content: XML.tree list }
79 | Proverinfo of { name: string, version: string, instance: string,
80 descr: string, url: Url.T, filenameextns: string }
81 | Setids of { idtables: PgipTypes.idtable list }
82 | Delids of { idtables: PgipTypes.idtable list }
83 | Addids of { idtables: PgipTypes.idtable list }
84 | Hasprefs of { prefcategory: string option, prefs: preference list }
85 | Prefval of { name: string, value: string }
86 | Idvalue of { thyname: PgipTypes.objname option,
87 objtype: PgipTypes.objtype,
88 name: PgipTypes.objname,
90 | Setrefs of { url: PgipTypes.pgipurl option,
91 thyname: PgipTypes.objname option,
92 objtype: PgipTypes.objtype option,
93 name: PgipTypes.objname option,
94 idtables: PgipTypes.idtable list,
95 fileurls : PgipTypes.pgipurl list }
96 | Informguise of { file : PgipTypes.pgipurl option,
97 theory: PgipTypes.objname option,
98 theorem: PgipTypes.objname option,
99 proofpos: int option }
100 | Parseresult of { attrs: XML.attributes, doc: PgipMarkup.pgipdocument,
101 errs: XML.tree list } (* errs to become PGML *)
102 | Usespgip of { version: string,
103 pgipelems: (string * bool * string list) list }
104 | Usespgml of { version: string }
105 | Pgip of { tag: string option,
107 seq: int, id: string,
108 destid: string option,
109 refid: string option,
111 content: XML.tree list }
115 (* Construct output XML messages *)
117 fun normalresponse (Normalresponse vs) =
119 val content = #content vs
121 XML.Elem ("normalresponse",
126 fun errorresponse (Errorresponse vs) =
128 val fatality = #fatality vs
129 val location = #location vs
130 val content = #content vs
132 XML.Elem ("errorresponse",
133 attrs_of_fatality fatality @
134 these (Option.map attrs_of_location location),
138 fun informfileloaded (Informfileloaded vs) =
141 val completed = #completed vs
143 XML.Elem ("informfileloaded",
144 attrs_of_pgipurl url @
145 (attr "completed" (PgipTypes.bool_to_pgstring completed)),
149 fun informfileoutdated (Informfileoutdated vs) =
152 val completed = #completed vs
154 XML.Elem ("informfileoutdated",
155 attrs_of_pgipurl url @
156 (attr "completed" (PgipTypes.bool_to_pgstring completed)),
160 fun informfileretracted (Informfileretracted vs) =
163 val completed = #completed vs
165 XML.Elem ("informfileretracted",
166 attrs_of_pgipurl url @
167 (attr "completed" (PgipTypes.bool_to_pgstring completed)),
171 fun metainforesponse (Metainforesponse vs) =
173 val attrs = #attrs vs
174 val content = #content vs
176 XML.Elem ("metainforesponse", attrs, content)
179 fun lexicalstructure (Lexicalstructure vs) =
181 val content = #content vs
183 XML.Elem ("lexicalstructure", [], content)
186 fun proverinfo (Proverinfo vs) =
189 val version = #version vs
190 val instance = #instance vs
191 val descr = #descr vs
193 val filenameextns = #filenameextns vs
195 XML.Elem ("proverinfo",
197 ("version", version),
198 ("instance", instance),
200 ("url", Url.implode url),
201 ("filenameextns", filenameextns)],
205 fun setids (Setids vs) =
207 val idtables = #idtables vs
209 XML.Elem ("setids",[],map idtable_to_xml idtables)
212 fun setrefs (Setrefs vs) =
215 val thyname = #thyname vs
216 val objtype = #objtype vs
218 val idtables = #idtables vs
219 val fileurls = #fileurls vs
220 fun fileurl_to_xml url = XML.Elem ("fileurl", attrs_of_pgipurl url, [])
223 (Option.getOpt (Option.map attrs_of_pgipurl url,[])) @
224 (Option.getOpt (Option.map attrs_of_objtype objtype,[])) @
225 (opt_attr "thyname" thyname) @
226 (opt_attr "name" name),
227 (map idtable_to_xml idtables) @
228 (map fileurl_to_xml fileurls))
231 fun addids (Addids vs) =
233 val idtables = #idtables vs
235 XML.Elem ("addids",[],map idtable_to_xml idtables)
238 fun delids (Delids vs) =
240 val idtables = #idtables vs
242 XML.Elem ("delids",[],map idtable_to_xml idtables)
245 fun hasprefs (Hasprefs vs) =
247 val prefcategory = #prefcategory vs
248 val prefs = #prefs vs
250 XML.Elem("hasprefs",opt_attr "prefcategory" prefcategory, map haspref prefs)
253 fun prefval (Prefval vs) =
256 val value = #value vs
258 XML.Elem("prefval", attr "name" name, [XML.Text value])
261 fun idvalue (Idvalue vs) =
263 val objtype_attrs = attrs_of_objtype (#objtype vs)
264 val thyname = #thyname vs
270 (opt_attr "thyname" thyname) @
275 fun informguise (Informguise vs) =
278 val theory = #theory vs
279 val theorem = #theorem vs
280 val proofpos = #proofpos vs
282 fun elto nm attrfn xo = case xo of NONE=>[] | SOME x=>[XML.Elem(nm,attrfn x,[])]
284 val guisefile = elto "guisefile" attrs_of_pgipurl file
285 val guisetheory = elto "guisetheory" (single o (pair "thyname")) theory
286 val guiseproof = elto "guiseproof"
287 (fn thm=>(attr "thmname" thm) @
288 (opt_attr "proofpos" (Option.map Int.toString proofpos))) theorem
290 XML.Elem("informguise", [], guisefile @ guisetheory @ guiseproof)
293 fun parseresult (Parseresult vs) =
295 val attrs = #attrs vs
298 val xmldoc = PgipMarkup.output_doc doc
300 XML.Elem("parseresult", attrs, errs @ xmldoc)
303 fun acceptedpgipelems (Usespgip vs) =
305 val pgipelems = #pgipelems vs
306 fun async_attrs b = if b then attr "async" "true" else []
307 fun attrs_attrs attrs = if attrs=[] then [] else attr "attributes" (space_implode "," attrs)
308 fun singlepgipelem (e,async,attrs) =
309 XML.Elem("pgipelem", ((async_attrs async) @ (attrs_attrs attrs)),[XML.Text e])
312 XML.Elem ("acceptedpgipelems", [],
313 map singlepgipelem pgipelems)
316 fun usespgip (Usespgip vs) =
318 val version = #version vs
319 val acceptedelems = acceptedpgipelems (Usespgip vs)
321 XML.Elem("usespgip", attr "version" version, [acceptedelems])
324 fun usespgml (Usespgml vs) =
326 val version = #version vs
328 XML.Elem("usespgml", attr "version" version, [])
334 val class = #class vs
337 val destid = #destid vs
338 val refid = #refid vs
339 val refseq = #refseq vs
340 val content = #content vs
345 opt_attr "destid" destid @
347 opt_attr "refid" refid @
348 opt_attr_map string_of_int "refseq" refseq @
349 attr "seq" (string_of_int seq),
353 fun ready (Ready _) = XML.Elem("ready",[],[])
356 fun output pgipoutput = case pgipoutput of
357 Normalresponse _ => normalresponse pgipoutput
358 | Errorresponse _ => errorresponse pgipoutput
359 | Informfileloaded _ => informfileloaded pgipoutput
360 | Informfileoutdated _ => informfileoutdated pgipoutput
361 | Informfileretracted _ => informfileretracted pgipoutput
362 | Metainforesponse _ => metainforesponse pgipoutput
363 | Lexicalstructure _ => lexicalstructure pgipoutput
364 | Proverinfo _ => proverinfo pgipoutput
365 | Setids _ => setids pgipoutput
366 | Setrefs _ => setrefs pgipoutput
367 | Addids _ => addids pgipoutput
368 | Delids _ => delids pgipoutput
369 | Hasprefs _ => hasprefs pgipoutput
370 | Prefval _ => prefval pgipoutput
371 | Idvalue _ => idvalue pgipoutput
372 | Informguise _ => informguise pgipoutput
373 | Parseresult _ => parseresult pgipoutput
374 | Usespgip _ => usespgip pgipoutput
375 | Usespgml _ => usespgml pgipoutput
376 | Pgip _ => pgip pgipoutput
377 | Ready _ => ready pgipoutput