src/Pure/ProofGeneral/pgip_input.ML
changeset 28020 1ff5167592ba
parent 26548 41bbcaf3e481
child 29606 fedb8be05f24
equal deleted inserted replaced
28019:359764333bf4 28020:1ff5167592ba
    28     | Forget         of { thyname: string option, name: string option, 
    28     | Forget         of { thyname: string option, name: string option, 
    29                           objtype: PgipTypes.objtype option }
    29                           objtype: PgipTypes.objtype option }
    30     | Restoregoal    of { thmname : string }
    30     | Restoregoal    of { thmname : string }
    31     (* context inspection commands *)
    31     (* context inspection commands *)
    32     | Askids         of { url: PgipTypes.pgipurl option,
    32     | Askids         of { url: PgipTypes.pgipurl option,
    33 			  thyname: PgipTypes.objname option,
    33                           thyname: PgipTypes.objname option,
    34 			  objtype: PgipTypes.objtype option }
    34                           objtype: PgipTypes.objtype option }
    35     | Askrefs        of { url: PgipTypes.pgipurl option,
    35     | Askrefs        of { url: PgipTypes.pgipurl option,
    36 			  thyname: PgipTypes.objname option,
    36                           thyname: PgipTypes.objname option,
    37 			  objtype: PgipTypes.objtype option,
    37                           objtype: PgipTypes.objtype option,
    38 			  name: PgipTypes.objname option }
    38                           name: PgipTypes.objname option }
    39     | Showid         of { thyname: PgipTypes.objname option, 
    39     | Showid         of { thyname: PgipTypes.objname option, 
    40 			  objtype: PgipTypes.objtype, 
    40                           objtype: PgipTypes.objtype, 
    41 			  name: PgipTypes.objname }
    41                           name: PgipTypes.objname }
    42     | Askguise       of { }
    42     | Askguise       of { }
    43     | Parsescript    of { text: string, location: PgipTypes.location,
    43     | Parsescript    of { text: string, location: PgipTypes.location,
    44                           systemdata: string option } 
    44                           systemdata: string option } 
    45     | Showproofstate of { }
    45     | Showproofstate of { }
    46     | Showctxt       of { }
    46     | Showctxt       of { }
    72 open PgipTypes
    72 open PgipTypes
    73 
    73 
    74 (*** PGIP input ***)
    74 (*** PGIP input ***)
    75 
    75 
    76 datatype pgipinput = 
    76 datatype pgipinput = 
    77 	 (* protocol/prover config *)
    77          (* protocol/prover config *)
    78 	 Askpgip 	of { }
    78          Askpgip        of { }
    79        | Askpgml 	of { } 
    79        | Askpgml        of { } 
    80        | Askconfig	of { }
    80        | Askconfig      of { }
    81        | Askprefs	of { }
    81        | Askprefs       of { }
    82        | Setpref 	of { name:string, prefcategory:string option, value:string }
    82        | Setpref        of { name:string, prefcategory:string option, value:string }
    83        | Getpref 	of { name:string, prefcategory:string option }
    83        | Getpref        of { name:string, prefcategory:string option }
    84        (* prover control *)
    84        (* prover control *)
    85        | Proverinit 	of { }
    85        | Proverinit     of { }
    86        | Proverexit 	of { }
    86        | Proverexit     of { }
    87        | Setproverflag  of { flagname:string, value: bool }
    87        | Setproverflag  of { flagname:string, value: bool }
    88        (* improper proof commands: control proof state *)
    88        (* improper proof commands: control proof state *)
    89        | Dostep		of { text: string }
    89        | Dostep         of { text: string }
    90        | Undostep	of { times: int }
    90        | Undostep       of { times: int }
    91        | Redostep	of { }
    91        | Redostep       of { }
    92        | Abortgoal	of { }
    92        | Abortgoal      of { }
    93        | Forget		of { thyname: string option, name: string option, 
    93        | Forget         of { thyname: string option, name: string option, 
    94 			     objtype: PgipTypes.objtype option }
    94                              objtype: PgipTypes.objtype option }
    95        | Restoregoal    of { thmname : string }
    95        | Restoregoal    of { thmname : string }
    96        (* context inspection commands *)
    96        (* context inspection commands *)
    97        | Askids         of { url: PgipTypes.pgipurl option,
    97        | Askids         of { url: PgipTypes.pgipurl option,
    98 			     thyname: PgipTypes.objname option,
    98                              thyname: PgipTypes.objname option,
    99 			     objtype: PgipTypes.objtype option }
    99                              objtype: PgipTypes.objtype option }
   100        | Askrefs        of { url: PgipTypes.pgipurl option,
   100        | Askrefs        of { url: PgipTypes.pgipurl option,
   101 			     thyname: PgipTypes.objname option,
   101                              thyname: PgipTypes.objname option,
   102 			     objtype: PgipTypes.objtype option,
   102                              objtype: PgipTypes.objtype option,
   103 			     name: PgipTypes.objname option }
   103                              name: PgipTypes.objname option }
   104        | Showid         of { thyname: PgipTypes.objname option, 
   104        | Showid         of { thyname: PgipTypes.objname option, 
   105 			     objtype: PgipTypes.objtype, 
   105                              objtype: PgipTypes.objtype, 
   106 			     name: PgipTypes.objname }
   106                              name: PgipTypes.objname }
   107        | Askguise	of { }
   107        | Askguise       of { }
   108        | Parsescript	of { text: string, location: location,
   108        | Parsescript    of { text: string, location: location,
   109 			     systemdata: string option } 
   109                              systemdata: string option } 
   110        | Showproofstate of { }
   110        | Showproofstate of { }
   111        | Showctxt	of { }
   111        | Showctxt       of { }
   112        | Searchtheorems of { arg: string }
   112        | Searchtheorems of { arg: string }
   113        | Setlinewidth   of { width: int }
   113        | Setlinewidth   of { width: int }
   114        | Viewdoc	of { arg: string }
   114        | Viewdoc        of { arg: string }
   115        (* improper theory-level commands *)
   115        (* improper theory-level commands *)
   116        | Doitem		of { text: string }
   116        | Doitem         of { text: string }
   117        | Undoitem	of { }
   117        | Undoitem       of { }
   118        | Redoitem	of { }
   118        | Redoitem       of { }
   119        | Aborttheory	of { }
   119        | Aborttheory    of { }
   120        | Retracttheory  of { thyname: string }
   120        | Retracttheory  of { thyname: string }
   121        | Loadfile 	of { url: pgipurl }
   121        | Loadfile       of { url: pgipurl }
   122        | Openfile 	of { url: pgipurl }
   122        | Openfile       of { url: pgipurl }
   123        | Closefile	of { }
   123        | Closefile      of { }
   124        | Abortfile	of { }
   124        | Abortfile      of { }
   125        | Retractfile    of { url: pgipurl }
   125        | Retractfile    of { url: pgipurl }
   126        | Changecwd 	of { url: pgipurl }
   126        | Changecwd      of { url: pgipurl }
   127        | Systemcmd 	of { arg: string }
   127        | Systemcmd      of { arg: string }
   128        (* unofficial escape command for debugging *)
   128        (* unofficial escape command for debugging *)
   129        | Quitpgip	of { }
   129        | Quitpgip       of { }
   130 
   130 
   131 (* Extracting content from input XML elements to make a PGIPinput *)
   131 (* Extracting content from input XML elements to make a PGIPinput *)
   132 local
   132 local
   133 
   133 
   134     val thyname_attro = get_attr_opt "thyname"
   134     val thyname_attro = get_attr_opt "thyname"
   138     val thmname_attr = get_attr "thmname"
   138     val thmname_attr = get_attr "thmname"
   139     val flagname_attr = get_attr "flagname"
   139     val flagname_attr = get_attr "flagname"
   140     val value_attr = get_attr "value"
   140     val value_attr = get_attr "value"
   141 
   141 
   142     fun objtype_attro attrs = if has_attr "objtype" attrs then
   142     fun objtype_attro attrs = if has_attr "objtype" attrs then
   143 				  SOME (objtype_of_attrs attrs)
   143                                   SOME (objtype_of_attrs attrs)
   144 			      else NONE
   144                               else NONE
   145 
   145 
   146     fun pgipurl_attro attrs = if has_attr "url" attrs then
   146     fun pgipurl_attro attrs = if has_attr "url" attrs then
   147 				  SOME (pgipurl_of_attrs attrs)
   147                                   SOME (pgipurl_of_attrs attrs)
   148 			      else NONE
   148                               else NONE
   149 
   149 
   150     val times_attr = read_pgipnat o (get_attr_dflt "times" "1")
   150     val times_attr = read_pgipnat o (get_attr_dflt "times" "1")
   151     val prefcat_attr = get_attr_opt "prefcategory"
   151     val prefcat_attr = get_attr_opt "prefcategory"
   152 
   152 
   153     fun xmltext (XML.Text text :: ts) = text ^ xmltext ts
   153     fun xmltext (XML.Text text :: ts) = text ^ xmltext ts
   169    | "askpgml"        => Askpgml { }
   169    | "askpgml"        => Askpgml { }
   170    | "askconfig"      => Askconfig { }
   170    | "askconfig"      => Askconfig { }
   171    (* proverconfig *)
   171    (* proverconfig *)
   172    | "askprefs"       => Askprefs { }
   172    | "askprefs"       => Askprefs { }
   173    | "getpref"        => Getpref { name = name_attr attrs, 
   173    | "getpref"        => Getpref { name = name_attr attrs, 
   174 				   prefcategory = prefcat_attr attrs }
   174                                    prefcategory = prefcat_attr attrs }
   175    | "setpref"        => Setpref { name = name_attr attrs, 
   175    | "setpref"        => Setpref { name = name_attr attrs, 
   176 				   prefcategory = prefcat_attr attrs,
   176                                    prefcategory = prefcat_attr attrs,
   177 				   value = xmltext data }
   177                                    value = xmltext data }
   178    (* provercontrol *)
   178    (* provercontrol *)
   179    | "proverinit"     => Proverinit { }
   179    | "proverinit"     => Proverinit { }
   180    | "proverexit"     => Proverexit { }
   180    | "proverexit"     => Proverexit { }
   181    | "setproverflag"  => Setproverflag { flagname = flagname_attr attrs,
   181    | "setproverflag"  => Setproverflag { flagname = flagname_attr attrs,
   182 					 value = read_pgipbool (value_attr attrs) }
   182                                          value = read_pgipbool (value_attr attrs) }
   183    (* improperproofcmd: improper commands not in script *)
   183    (* improperproofcmd: improper commands not in script *)
   184    | "dostep"         => Dostep    { text = xmltext data }
   184    | "dostep"         => Dostep    { text = xmltext data }
   185    | "undostep"       => Undostep  { times = times_attr attrs }
   185    | "undostep"       => Undostep  { times = times_attr attrs }
   186    | "redostep"       => Redostep  { } 
   186    | "redostep"       => Redostep  { } 
   187    | "abortgoal"      => Abortgoal { }
   187    | "abortgoal"      => Abortgoal { }
   188    | "forget"         => Forget { thyname = thyname_attro attrs, 
   188    | "forget"         => Forget { thyname = thyname_attro attrs, 
   189 				  name = name_attro attrs,
   189                                   name = name_attro attrs,
   190 				  objtype = objtype_attro attrs }
   190                                   objtype = objtype_attro attrs }
   191    | "restoregoal"    => Restoregoal { thmname = thmname_attr attrs}
   191    | "restoregoal"    => Restoregoal { thmname = thmname_attr attrs}
   192    (* proofctxt: improper commands *)
   192    (* proofctxt: improper commands *)
   193    | "askids"         => Askids { url = pgipurl_attro attrs,
   193    | "askids"         => Askids { url = pgipurl_attro attrs,
   194 				  thyname = thyname_attro attrs, 
   194                                   thyname = thyname_attro attrs, 
   195 				  objtype = objtype_attro attrs }
   195                                   objtype = objtype_attro attrs }
   196    | "askrefs"        => Askrefs { url = pgipurl_attro attrs,
   196    | "askrefs"        => Askrefs { url = pgipurl_attro attrs,
   197 				   thyname = thyname_attro attrs, 
   197                                    thyname = thyname_attro attrs, 
   198 				   objtype = objtype_attro attrs,
   198                                    objtype = objtype_attro attrs,
   199 				   name = name_attro attrs }
   199                                    name = name_attro attrs }
   200    | "showid"         => Showid { thyname = thyname_attro attrs,
   200    | "showid"         => Showid { thyname = thyname_attro attrs,
   201 				  objtype = objtype_of_attrs attrs,
   201                                   objtype = objtype_of_attrs attrs,
   202 				  name = name_attr attrs }
   202                                   name = name_attr attrs }
   203    | "askguise"       => Askguise { }
   203    | "askguise"       => Askguise { }
   204    | "parsescript"    => Parsescript { text = (xmltext data),
   204    | "parsescript"    => Parsescript { text = (xmltext data),
   205 				       systemdata = get_attr_opt "systemdata" attrs,
   205                                        systemdata = get_attr_opt "systemdata" attrs,
   206 				       location = location_of_attrs attrs }
   206                                        location = location_of_attrs attrs }
   207    | "showproofstate" => Showproofstate { }
   207    | "showproofstate" => Showproofstate { }
   208    | "showctxt"       => Showctxt { }
   208    | "showctxt"       => Showctxt { }
   209    | "searchtheorems" => Searchtheorems { arg = xmltext data }
   209    | "searchtheorems" => Searchtheorems { arg = xmltext data }
   210    | "setlinewidth"   => Setlinewidth   { width = read_pgipnat (xmltext data) }
   210    | "setlinewidth"   => Setlinewidth   { width = read_pgipnat (xmltext data) }
   211    | "viewdoc"        => Viewdoc { arg = xmltext data }
   211    | "viewdoc"        => Viewdoc { arg = xmltext data }
   221    | "abortfile"      => Abortfile { }
   221    | "abortfile"      => Abortfile { }
   222    | "retractfile"    => Retractfile { url = pgipurl_of_attrs attrs }
   222    | "retractfile"    => Retractfile { url = pgipurl_of_attrs attrs }
   223    | "changecwd"      => Changecwd { url = pgipurl_of_attrs attrs }
   223    | "changecwd"      => Changecwd { url = pgipurl_of_attrs attrs }
   224    | "systemcmd"      => Systemcmd { arg = xmltext data }
   224    | "systemcmd"      => Systemcmd { arg = xmltext data }
   225    (* unofficial command for debugging *)
   225    (* unofficial command for debugging *)
   226    | "quitpgip"	=> Quitpgip { }
   226    | "quitpgip" => Quitpgip { }
   227 
   227 
   228    (* We allow sending proper document markup too; we map it back to dostep   *)
   228    (* We allow sending proper document markup too; we map it back to dostep   *)
   229    (* and strip out metainfo elements. Markup correctness isn't checked: this *)
   229    (* and strip out metainfo elements. Markup correctness isn't checked: this *)
   230    (* is a compatibility measure to make it easy for interfaces.              *)
   230    (* is a compatibility measure to make it easy for interfaces.              *)
   231    | x => if (x mem PgipMarkup.doc_markup_elements) then
   231    | x => if (x mem PgipMarkup.doc_markup_elements) then
   232 	      if (x mem PgipMarkup.doc_markup_elements_ignored) then
   232               if (x mem PgipMarkup.doc_markup_elements_ignored) then
   233 		  raise NoAction
   233                   raise NoAction
   234 	      else 
   234               else 
   235 		  Dostep { text = xmltext data } (* could separate out Doitem too *)
   235                   Dostep { text = xmltext data } (* could separate out Doitem too *)
   236 	  else raise Unknown) 
   236           else raise Unknown) 
   237     handle Unknown => NONE | NoAction => NONE
   237     handle Unknown => NONE | NoAction => NONE
   238 end
   238 end
   239 
   239 
   240 end
   240 end