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