Revamped Proof General interface.
1 (* Title: Pure/ProofGeneral/pgip_output.ML
5 PGIP abstraction: output commands
10 (* These are the PGIP messages which the prover emits. *)
12 Cleardisplay of { area: PgipTypes.displayarea }
13 | Normalresponse of { area: PgipTypes.displayarea,
15 messagecategory: PgipTypes.messagecategory,
16 content: XML.tree list }
17 | Errorresponse of { fatality: PgipTypes.fatality,
18 area: PgipTypes.displayarea option,
19 location: PgipTypes.location option,
20 content: XML.tree list }
21 | Informfileloaded of { url: PgipTypes.pgipurl }
22 | Informfileretracted of { url: PgipTypes.pgipurl }
23 | Proofstate of { pgml: XML.tree list }
24 | Metainforesponse of { attrs: XML.attributes,
25 content: XML.tree list }
26 | Lexicalstructure of { content: XML.tree list }
27 | Proverinfo of { name: string,
32 filenameextns: string }
33 | Idtable of { objtype: string,
34 context: string option,
36 | Setids of { idtables: XML.tree list }
37 | Delids of { idtables: XML.tree list }
38 | Addids of { idtables: XML.tree list }
39 | Hasprefs of { prefcategory: string option,
40 prefs: PgipTypes.preference list }
41 | Prefval of { name: string, value: string }
42 | Idvalue of { name: string, objtype: string, text: XML.tree list }
43 | Informguise of { file : PgipTypes.pgipurl option,
44 theory: string option,
45 theorem: string option,
46 proofpos: int option }
47 | Parseresult of { attrs: XML.attributes, content: XML.tree list }
48 | Usespgip of { version: string,
49 pgipelems: (string * bool * string list) list }
50 | Usespgml of { version: string }
51 | Pgip of { tag: string option,
54 destid: string option,
57 content: XML.tree list }
60 val output : pgipoutput -> XML.tree
63 structure PgipOutput : PGIPOUTPUT =
68 Cleardisplay of { area: displayarea }
69 | Normalresponse of { area: displayarea, urgent: bool,
70 messagecategory: messagecategory, content: XML.tree list }
71 | Errorresponse of { area: displayarea option, fatality: fatality,
72 location: location option, content: XML.tree list }
73 | Informfileloaded of { url: Path.T }
74 | Informfileretracted of { url: Path.T }
75 | Proofstate of { pgml: XML.tree list }
76 | Metainforesponse of { attrs: XML.attributes, content: XML.tree list }
77 | Lexicalstructure of { content: XML.tree list }
78 | Proverinfo of { name: string, version: string, instance: string,
79 descr: string, url: Url.T, filenameextns: string }
80 | Idtable of { objtype: string, context: string option, ids: string list }
81 | Setids of { idtables: XML.tree list }
82 | Delids of { idtables: XML.tree list }
83 | Addids of { idtables: XML.tree list }
84 | Hasprefs of { prefcategory: string option, prefs: preference list }
85 | Prefval of { name: string, value: string }
86 | Idvalue of { name: string, objtype: string, text: XML.tree list }
87 | Informguise of { file : pgipurl option, theory: string option,
88 theorem: string option, proofpos: int option }
89 | Parseresult of { attrs: XML.attributes, content: XML.tree list }
90 | Usespgip of { version: string,
91 pgipelems: (string * bool * string list) list }
92 | Usespgml of { version: string }
93 | Pgip of { tag: string option,
96 destid: string option,
99 content: XML.tree list}
105 fun attrsome attr f x = case x of NONE => [] | SOME x => [(attr,f x)]
107 (* Construct output XML messages *)
109 fun cleardisplay vs =
113 XML.Elem ("cleardisplay", (attrs_of_displayarea area), [])
116 fun normalresponse vs =
119 val urgent = #urgent vs
120 val messagecategory = #messagecategory vs
121 val content = #content vs
123 XML.Elem ("normalresponse",
124 (attrs_of_displayarea area) @
125 (if urgent then [("urgent", "true")] else []) @
126 (attrs_of_messagecategory messagecategory),
130 fun errorresponse vs =
133 val fatality = #fatality vs
134 val location = #location vs
135 val content = #content vs
137 XML.Elem ("errorresponse",
138 (the_default [] (Option.map attrs_of_displayarea area)) @
139 (attrs_of_fatality fatality) @
140 (the_default [] (Option.map attrs_of_location location)),
145 fun informfile lr vs =
149 XML.Elem ("informfile" ^ lr, attrs_of_pgipurl url, [])
152 val informfileloaded = informfile "loaded"
153 val informfileretracted = informfile "retracted"
159 XML.Elem("proofstate", [], pgml)
162 fun metainforesponse vs =
164 val attrs = #attrs vs
165 val content = #content vs
167 XML.Elem ("metainforesponse", attrs, content)
170 fun lexicalstructure vs =
172 val content = #content vs
174 XML.Elem ("lexicalstructure", [], content)
180 val version = #version vs
181 val instance = #instance vs
182 val descr = #descr vs
184 val filenameextns = #filenameextns vs
186 XML.Elem ("proverinfo",
188 ("version", version),
189 ("instance", instance),
191 ("url", Url.pack url),
192 ("filenameextns", filenameextns)],
198 val objtype = #objtype vs
199 val objtype_attrs = [("objtype", objtype)]
200 val context = #context vs
201 val context_attrs = opt_attr "context" context
203 val ids_content = map (fn x => XML.Elem("identifier",[],[XML.Text x])) ids
206 objtype_attrs @ context_attrs,
212 val idtables = #idtables vs
214 XML.Elem ("setids",[],idtables)
219 val idtables = #idtables vs
221 XML.Elem ("addids",[],idtables)
226 val idtables = #idtables vs
228 XML.Elem ("delids",[],idtables)
232 fun acceptedpgipelems vs =
234 val pgipelems = #pgipelems vs
235 fun async_attrs b = if b then [("async","true")] else []
236 fun attrs_attrs attrs = if attrs=[] then [] else [("attributes",space_implode "," attrs)]
237 fun singlepgipelem (e,async,attrs) =
238 XML.Elem("pgipelem", ((async_attrs async) @ (attrs_attrs attrs)),[])
241 XML.Elem ("acceptedpgipelems", [],
242 map singlepgipelem pgipelems)
246 fun attro x yo = case yo of NONE => [] | SOME y => [(x,y)] : XML.attributes
250 val prefcategory = #prefcategory vs
251 val prefs = #prefs vs
253 XML.Elem("hasprefs",attro "prefcategory" prefcategory, map haspref prefs)
259 val value = #value vs
261 XML.Elem("prefval", [("name",name)], [XML.Text value])
267 val objtype = #objtype vs
270 XML.Elem("idvalue", [("name",name),("objtype",objtype)], text)
277 val theory = #theory vs
278 val theorem = #theorem vs
279 val proofpos = #proofpos vs
281 fun elto nm attrfn xo = case xo of NONE=>[] | SOME x=>[XML.Elem(nm,attrfn x,[])]
283 val guisefile = elto "guisefile" attrs_of_pgipurl file
284 val guisetheory = elto "guisetheory" (single o (pair "thyname")) theory
285 val guiseproof = elto "guiseproof"
286 (fn thm=>[("thmname",thm)]@
287 (attro "proofpos" (Option.map Int.toString proofpos))) theorem
289 XML.Elem("informguise", [], guisefile @ guisetheory @ guiseproof)
294 val attrs = #attrs vs
295 val content = #content vs
297 XML.Elem("parseresult", attrs, content)
302 val version = #version vs
303 val acceptedelems = acceptedpgipelems vs
305 XML.Elem("usespgip", [("version", version)], [acceptedelems])
310 val version = #version vs
312 XML.Elem("usespgml", [("version", version)], [])
318 val class = #class vs
321 val destid = #destid vs
322 val refid = #refid vs
323 val refseq = #refseq vs
324 val content = #content vs
329 opt_attr "destid" destid @
331 opt_attr "refid" refid @
332 opt_attr_map string_of_int "refseq" refseq @
333 [("seq", string_of_int seq)],
338 XML.Elem("ready",[],[])
341 fun output pgipoutput = case pgipoutput of
342 Cleardisplay vs => cleardisplay vs
343 | Normalresponse vs => normalresponse vs
344 | Errorresponse vs => errorresponse vs
345 | Informfileloaded vs => informfileloaded vs
346 | Informfileretracted vs => informfileretracted vs
347 | Proofstate vs => proofstate vs
348 | Metainforesponse vs => metainforesponse vs
349 | Lexicalstructure vs => lexicalstructure vs
350 | Proverinfo vs => proverinfo vs
351 | Idtable vs => idtable vs
352 | Setids vs => setids vs
353 | Addids vs => addids vs
354 | Delids vs => delids vs
355 | Hasprefs vs => hasprefs vs
356 | Prefval vs => prefval vs
357 | Idvalue vs => idvalue vs
358 | Informguise vs => informguise vs
359 | Parseresult vs => parseresult vs
360 | Usespgip vs => usespgip vs
361 | Usespgml vs => usespgml vs
363 | Ready vs => ready vs