src/Pure/ProofGeneral/pgip_isabelle.ML
author aspinall
Sat, 03 Mar 2007 12:38:36 +0100
changeset 22403 12892a6677c6
parent 22165 eaec72532dd7
child 23603 4a2e36475367
permissions -rw-r--r--
Add Isabelle-specific objtypes
aspinall@21637
     1
(*  Title:      Pure/ProofGeneral/pgip_isabelle.ML
aspinall@21637
     2
    ID:         $Id$
aspinall@21637
     3
    Author:     David Aspinall
aspinall@21637
     4
aspinall@22165
     5
Prover-side PGIP abstraction: Isabelle configuration and mapping to Isabelle types.
aspinall@21637
     6
*)
aspinall@21637
     7
aspinall@21637
     8
signature PGIP_ISABELLE =
aspinall@21637
     9
sig
aspinall@21637
    10
    val isabelle_pgml_version_supported : string
aspinall@21637
    11
    val isabelle_pgip_version_supported : string
aspinall@21637
    12
    val accepted_inputs : (string * bool * (string list)) list 
aspinall@22165
    13
aspinall@22165
    14
    val location_of_position : Position.T -> PgipTypes.location
aspinall@22403
    15
aspinall@22403
    16
    (* Additional types of objects in Isar scripts *)
aspinall@22403
    17
aspinall@22403
    18
    val ObjTheoryBody : PgipTypes.objtype
aspinall@22403
    19
    val ObjTheoryDecl : PgipTypes.objtype
aspinall@22403
    20
    val ObjTheoryBodySubsection : PgipTypes.objtype
aspinall@22403
    21
    val ObjProofBody : PgipTypes.objtype
aspinall@22403
    22
    val ObjFormalComment : PgipTypes.objtype
aspinall@22403
    23
    val ObjClass : PgipTypes.objtype
aspinall@22403
    24
    val ObjTheoremSet : PgipTypes.objtype
aspinall@22403
    25
    val ObjOracle : PgipTypes.objtype
aspinall@22403
    26
    val ObjLocale : PgipTypes.objtype
aspinall@22403
    27
	
aspinall@21637
    28
end
aspinall@21637
    29
aspinall@21637
    30
structure PgipIsabelle : PGIP_ISABELLE =
aspinall@21637
    31
struct
aspinall@21637
    32
aspinall@21637
    33
val isabelle_pgml_version_supported = "1.0";
aspinall@21637
    34
val isabelle_pgip_version_supported = "2.0"
aspinall@21637
    35
aspinall@21637
    36
(** Accepted commands **)
aspinall@21637
    37
aspinall@21637
    38
local
aspinall@21637
    39
aspinall@21637
    40
    (* These element names are a subset of those in pgip_input.ML.
aspinall@21637
    41
       They must be handled in proof_general_pgip.ML/process_pgip_element. *)
aspinall@21637
    42
						    
aspinall@21637
    43
    val accepted_names =
aspinall@21637
    44
    (* not implemented: "askconfig", "forget", "restoregoal" *)
aspinall@21637
    45
    ["askpgip","askpgml","askprefs","getpref","setpref",
aspinall@21637
    46
     "proverinit","proverexit","startquiet","stopquiet",
aspinall@21637
    47
     "pgmlsymbolson", "pgmlsymbolsoff",
aspinall@21637
    48
     "dostep", "undostep", "redostep", "abortgoal", 
aspinall@21637
    49
     "askids", "showid", "askguise",
aspinall@21637
    50
     "parsescript",
aspinall@21637
    51
     "showproofstate", "showctxt", "searchtheorems", "setlinewidth", "viewdoc",
aspinall@21637
    52
     "doitem", "undoitem", "redoitem", "abortheory",
aspinall@21637
    53
     "retracttheory", "loadfile", "openfile", "closefile",
aspinall@21637
    54
     "abortfile", "retractfile", "changecwd", "systemcmd"];
aspinall@21637
    55
aspinall@21637
    56
    fun element_async p = 
aspinall@21637
    57
	false (* single threaded only *)
aspinall@21637
    58
aspinall@21637
    59
    fun supported_optional_attrs p = (case p of
aspinall@21637
    60
					  "undostep" => ["times"]
aspinall@21637
    61
					(* TODO: we could probably extend these too:
aspinall@21637
    62
					| "redostep" => ["times"]
aspinall@21637
    63
					| "undoitem" => ["times"]
aspinall@21637
    64
					| "redoitem" => ["times"] *)
aspinall@21637
    65
				        | _ => [])
aspinall@21637
    66
in
aspinall@21637
    67
val accepted_inputs = 
aspinall@21637
    68
    (map (fn p=> (p, element_async p, supported_optional_attrs p))
aspinall@21637
    69
         accepted_names);
aspinall@21637
    70
end
aspinall@21637
    71
aspinall@22165
    72
aspinall@22165
    73
(* Now we have to parse strings constructed elsewhere in Isabelle, which is silly!
aspinall@22165
    74
   This is another case where Isabelle should use structured types
aspinall@22165
    75
   from the ground up to help its interfaces, instead of just plain
aspinall@22165
    76
   strings.
aspinall@22165
    77
*)
aspinall@22165
    78
fun unquote s = case explode s of 
aspinall@22165
    79
		    "\""::xs => (case (rev xs) of
aspinall@22165
    80
				    "\""::_ => SOME (String.substring(s,1,(String.size s) - 2))
aspinall@22165
    81
			         | _ => NONE)
aspinall@22165
    82
		  | _ => NONE
aspinall@22165
    83
aspinall@22165
    84
fun location_of_position pos = 
aspinall@22165
    85
    let val line = Position.line_of pos
aspinall@22165
    86
	val (url,descr) = 
aspinall@22165
    87
	    (case Position.name_of pos of
aspinall@22165
    88
		 NONE => (NONE,NONE)
aspinall@22165
    89
	       | SOME possiblyfile => 
aspinall@22165
    90
		 (case unquote possiblyfile of
aspinall@22165
    91
		      SOME fname => let val path = (Path.explode fname) in
aspinall@22165
    92
					case ThyLoad.check_file NONE path of
aspinall@22165
    93
					    SOME _ => (SOME (PgipTypes.pgipurl_of_path path), NONE)
aspinall@22165
    94
					  | NONE => (NONE,SOME fname)
aspinall@22165
    95
				    end
aspinall@22165
    96
		    | _ => (NONE,SOME possiblyfile)))
aspinall@22165
    97
    in 
aspinall@22165
    98
	{ descr=descr, url=url, line=line, column=NONE, char=NONE, length=NONE }
aspinall@22165
    99
    end 
aspinall@22403
   100
aspinall@22403
   101
aspinall@22403
   102
val [ObjTheoryBody,
aspinall@22403
   103
     ObjTheoryDecl,
aspinall@22403
   104
     ObjTheoryBodySubsection,
aspinall@22403
   105
     ObjProofBody,
aspinall@22403
   106
     ObjFormalComment,
aspinall@22403
   107
     ObjClass,
aspinall@22403
   108
     ObjTheoremSet,
aspinall@22403
   109
     ObjOracle,
aspinall@22403
   110
     ObjLocale] =
aspinall@22403
   111
    map PgipTypes.ObjOther 
aspinall@22403
   112
	["theory body", 
aspinall@22403
   113
	 "theory declaration",
aspinall@22403
   114
	 "theory subsection",
aspinall@22403
   115
	 "proof body",
aspinall@22403
   116
	 "formal comment",
aspinall@22403
   117
	 "class",
aspinall@22403
   118
	 "theorem set declaration",
aspinall@22403
   119
	 "oracle",
aspinall@22403
   120
	 "locale"];
aspinall@22403
   121
aspinall@22165
   122
	
aspinall@21637
   123
end
aspinall@21637
   124