src/Pure/ProofGeneral/pgip_isabelle.ML
author wenzelm
Mon, 31 May 2010 21:06:57 +0200
changeset 37216 3165bc303f66
parent 29606 fedb8be05f24
child 38188 965537d86fcc
permissions -rw-r--r--
modernized some structure names, keeping a few legacy aliases;
aspinall@21637
     1
(*  Title:      Pure/ProofGeneral/pgip_isabelle.ML
aspinall@21637
     2
    Author:     David Aspinall
aspinall@21637
     3
aspinall@22165
     4
Prover-side PGIP abstraction: Isabelle configuration and mapping to Isabelle types.
aspinall@21637
     5
*)
aspinall@21637
     6
aspinall@21637
     7
signature PGIP_ISABELLE =
aspinall@21637
     8
sig
aspinall@21637
     9
    val isabelle_pgml_version_supported : string
aspinall@21637
    10
    val isabelle_pgip_version_supported : string
aspinall@23603
    11
    val systemid : string
wenzelm@23799
    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
wenzelm@23799
    27
aspinall@21637
    28
end
aspinall@21637
    29
aspinall@21637
    30
structure PgipIsabelle : PGIP_ISABELLE =
aspinall@21637
    31
struct
aspinall@21637
    32
aspinall@23603
    33
val isabelle_pgml_version_supported = "2.0";
aspinall@21637
    34
val isabelle_pgip_version_supported = "2.0"
aspinall@23603
    35
val systemid = "Isabelle"
aspinall@21637
    36
wenzelm@23799
    37
aspinall@21637
    38
(** Accepted commands **)
aspinall@21637
    39
aspinall@21637
    40
local
aspinall@21637
    41
aspinall@21637
    42
    (* These element names are a subset of those in pgip_input.ML.
aspinall@21637
    43
       They must be handled in proof_general_pgip.ML/process_pgip_element. *)
wenzelm@23799
    44
aspinall@21637
    45
    val accepted_names =
aspinall@21637
    46
    (* not implemented: "askconfig", "forget", "restoregoal" *)
aspinall@21637
    47
    ["askpgip","askpgml","askprefs","getpref","setpref",
aspinall@21637
    48
     "proverinit","proverexit","startquiet","stopquiet",
aspinall@21637
    49
     "pgmlsymbolson", "pgmlsymbolsoff",
wenzelm@23799
    50
     "dostep", "undostep", "redostep", "abortgoal",
aspinall@21637
    51
     "askids", "showid", "askguise",
aspinall@21637
    52
     "parsescript",
aspinall@21637
    53
     "showproofstate", "showctxt", "searchtheorems", "setlinewidth", "viewdoc",
aspinall@21637
    54
     "doitem", "undoitem", "redoitem", "abortheory",
aspinall@21637
    55
     "retracttheory", "loadfile", "openfile", "closefile",
aspinall@21637
    56
     "abortfile", "retractfile", "changecwd", "systemcmd"];
aspinall@21637
    57
wenzelm@23799
    58
    fun element_async p =
wenzelm@23799
    59
        false (* single threaded only *)
aspinall@21637
    60
aspinall@21637
    61
    fun supported_optional_attrs p = (case p of
wenzelm@23799
    62
                                          "undostep" => ["times"]
wenzelm@23799
    63
                                        (* TODO: we could probably extend these too:
wenzelm@23799
    64
                                        | "redostep" => ["times"]
wenzelm@23799
    65
                                        | "undoitem" => ["times"]
wenzelm@23799
    66
                                        | "redoitem" => ["times"] *)
wenzelm@23799
    67
                                        | _ => [])
aspinall@21637
    68
in
wenzelm@23799
    69
val accepted_inputs =
aspinall@21637
    70
    (map (fn p=> (p, element_async p, supported_optional_attrs p))
aspinall@21637
    71
         accepted_names);
aspinall@21637
    72
end
aspinall@21637
    73
aspinall@22165
    74
wenzelm@23799
    75
fun location_of_position pos =
aspinall@22165
    76
    let val line = Position.line_of pos
wenzelm@26005
    77
        val column = Position.column_of pos
wenzelm@23799
    78
        val (url,descr) =
wenzelm@23799
    79
            (case Position.file_of pos of
wenzelm@23799
    80
               NONE => (NONE, NONE)
wenzelm@23799
    81
             | SOME fname =>
wenzelm@23799
    82
               let val path = Path.explode fname in
wenzelm@37216
    83
                 case Thy_Load.check_file Path.current path of
wenzelm@23799
    84
                   SOME _ => (SOME (PgipTypes.pgipurl_of_path path), NONE)
wenzelm@23799
    85
                 | NONE => (NONE, SOME fname)
wenzelm@23799
    86
               end);
wenzelm@23680
    87
    in
wenzelm@26005
    88
        { descr=descr, url=url, line=line, column=column, char=NONE, length=NONE }
wenzelm@23680
    89
    end
aspinall@22403
    90
aspinall@22403
    91
aspinall@22403
    92
val [ObjTheoryBody,
aspinall@22403
    93
     ObjTheoryDecl,
aspinall@22403
    94
     ObjTheoryBodySubsection,
aspinall@22403
    95
     ObjProofBody,
aspinall@22403
    96
     ObjFormalComment,
aspinall@22403
    97
     ObjClass,
aspinall@22403
    98
     ObjTheoremSet,
aspinall@22403
    99
     ObjOracle,
aspinall@22403
   100
     ObjLocale] =
wenzelm@23799
   101
    map PgipTypes.ObjOther
wenzelm@23799
   102
        ["theory body",
wenzelm@23799
   103
         "theory declaration",
wenzelm@23799
   104
         "theory subsection",
wenzelm@23799
   105
         "proof body",
wenzelm@23799
   106
         "formal comment",
wenzelm@23799
   107
         "class",
wenzelm@23799
   108
         "theorem set declaration",
wenzelm@23799
   109
         "oracle",
wenzelm@23799
   110
         "locale"];
aspinall@22403
   111
aspinall@21637
   112
end