Support PGIP communication for preferences in Emacs mode.
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}
103 (* Construct output XML messages *)
105 fun cleardisplay vs =
109 XML.Elem ("cleardisplay", (attrs_of_displayarea area), [])
112 fun normalresponse vs =
115 val urgent = #urgent vs
116 val messagecategory = #messagecategory vs
117 val content = #content vs
119 XML.Elem ("normalresponse",
120 (attrs_of_displayarea area) @
121 (if urgent then [("urgent", "true")] else []) @
122 (attrs_of_messagecategory messagecategory),
126 fun errorresponse vs =
129 val fatality = #fatality vs
130 val location = #location vs
131 val content = #content vs
133 XML.Elem ("errorresponse",
134 (the_default [] (Option.map attrs_of_displayarea area)) @
135 (attrs_of_fatality fatality) @
136 (the_default [] (Option.map attrs_of_location location)),
141 fun informfile lr vs =
145 XML.Elem ("informfile" ^ lr, attrs_of_pgipurl url, [])
148 val informfileloaded = informfile "loaded"
149 val informfileretracted = informfile "retracted"
155 XML.Elem("proofstate", [], pgml)
158 fun metainforesponse vs =
160 val attrs = #attrs vs
161 val content = #content vs
163 XML.Elem ("metainforesponse", attrs, content)
166 fun lexicalstructure vs =
168 val content = #content vs
170 XML.Elem ("lexicalstructure", [], content)
176 val version = #version vs
177 val instance = #instance vs
178 val descr = #descr vs
180 val filenameextns = #filenameextns vs
182 XML.Elem ("proverinfo",
184 ("version", version),
185 ("instance", instance),
187 ("url", Url.pack url),
188 ("filenameextns", filenameextns)],
194 val objtype = #objtype vs
195 val objtype_attrs = attr [("objtype", objtype)]
196 val context = #context vs
197 val context_attrs = opt_attr "context" context
199 val ids_content = map (fn x => XML.Elem("identifier",[],[XML.Text x])) ids
202 objtype_attrs @ context_attrs,
208 val idtables = #idtables vs
210 XML.Elem ("setids",[],idtables)
215 val idtables = #idtables vs
217 XML.Elem ("addids",[],idtables)
222 val idtables = #idtables vs
224 XML.Elem ("delids",[],idtables)
228 fun acceptedpgipelems vs =
230 val pgipelems = #pgipelems vs
231 fun async_attrs b = if b then [("async","true")] else []
232 fun attrs_attrs attrs = if attrs=[] then [] else [("attributes",space_implode "," attrs)]
233 fun singlepgipelem (e,async,attrs) =
234 XML.Elem("pgipelem", ((async_attrs async) @ (attrs_attrs attrs)),[])
237 XML.Elem ("acceptedpgipelems", [],
238 map singlepgipelem pgipelems)
244 val prefcategory = #prefcategory vs
245 val prefs = #prefs vs
247 XML.Elem("hasprefs",opt_attr "prefcategory" prefcategory, map haspref prefs)
253 val value = #value vs
255 XML.Elem("prefval", [("name",name)], [XML.Text value])
261 val objtype = #objtype vs
264 XML.Elem("idvalue", [("name",name),("objtype",objtype)], text)
271 val theory = #theory vs
272 val theorem = #theorem vs
273 val proofpos = #proofpos vs
275 fun elto nm attrfn xo = case xo of NONE=>[] | SOME x=>[XML.Elem(nm,attrfn x,[])]
277 val guisefile = elto "guisefile" attrs_of_pgipurl file
278 val guisetheory = elto "guisetheory" (single o (pair "thyname")) theory
279 val guiseproof = elto "guiseproof"
280 (fn thm=>[("thmname",thm)]@
281 (opt_attr "proofpos" (Option.map Int.toString proofpos))) theorem
283 XML.Elem("informguise", [], guisefile @ guisetheory @ guiseproof)
288 val attrs = #attrs vs
289 val content = #content vs
291 XML.Elem("parseresult", attrs, content)
296 val version = #version vs
297 val acceptedelems = acceptedpgipelems vs
299 XML.Elem("usespgip", [("version", version)], [acceptedelems])
304 val version = #version vs
306 XML.Elem("usespgml", [("version", version)], [])
312 val class = #class vs
315 val destid = #destid vs
316 val refid = #refid vs
317 val refseq = #refseq vs
318 val content = #content vs
323 opt_attr "destid" destid @
325 opt_attr "refid" refid @
326 opt_attr_map string_of_int "refseq" refseq @
327 [("seq", string_of_int seq)],
331 fun ready vs = XML.Elem("ready",[],[])
334 fun output pgipoutput = case pgipoutput of
335 Cleardisplay vs => cleardisplay vs
336 | Normalresponse vs => normalresponse vs
337 | Errorresponse vs => errorresponse vs
338 | Informfileloaded vs => informfileloaded vs
339 | Informfileretracted vs => informfileretracted vs
340 | Proofstate vs => proofstate vs
341 | Metainforesponse vs => metainforesponse vs
342 | Lexicalstructure vs => lexicalstructure vs
343 | Proverinfo vs => proverinfo vs
344 | Idtable vs => idtable vs
345 | Setids vs => setids vs
346 | Addids vs => addids vs
347 | Delids vs => delids vs
348 | Hasprefs vs => hasprefs vs
349 | Prefval vs => prefval vs
350 | Idvalue vs => idvalue vs
351 | Informguise vs => informguise vs
352 | Parseresult vs => parseresult vs
353 | Usespgip vs => usespgip vs
354 | Usespgml vs => usespgml vs
356 | Ready vs => ready vs