src/Pure/ProofGeneral/pgip_types.ML
author wenzelm
Wed, 21 Jan 2009 23:21:44 +0100
changeset 29606 fedb8be05f24
parent 28397 389c5e494605
child 38228 ada3ab6b9085
permissions -rw-r--r--
removed Ids;
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_types.ML
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     2
    Author:     David Aspinall
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     3
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
     4
PGIP abstraction: types and conversions.
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     5
*)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     6
22402
a1cce5b241be Comment
aspinall
parents: 22162
diff changeset
     7
(* TODO: PGML, proverflag *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     8
signature PGIPTYPES =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     9
sig
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    10
    (* Object types: the types of values which can be manipulated externally.
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    11
       Ideally a list of other types would be configured as a parameter. *)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    12
    datatype objtype = ObjFile | ObjTheory | ObjTheorem | ObjComment  
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    13
                     | ObjTerm | ObjType | ObjOther of string
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    14
  
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    15
    (* Names for values of objtypes (i.e. prover identifiers). Could be a parameter.
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    16
       Names for ObjFiles are URIs. *)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    17
    type objname = string
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    18
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    19
    type idtable = { context: objname option,    (* container's objname *)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    20
                     objtype: objtype, 
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    21
                     ids: objname list }
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    22
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    23
    (* Types and values (used for preferences and dialogs) *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    24
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    25
    datatype pgiptype = Pgipnull | Pgipbool | Pgipint of int option * int option | Pgipnat
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    26
                      | Pgipstring | Pgipconst of string | Pgipchoice of pgipdtype list
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    27
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    28
    and pgipdtype = Pgipdtype of string option * pgiptype  (* type with opt. description *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    29
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    30
    type pgipval   (* typed value *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    31
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    32
    (* URLs we can cope with *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    33
    type pgipurl
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    34
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    35
    (* Representation error in reading/writing PGIP *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    36
    exception PGIP of string
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    37
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    38
    (* Interface areas for message output *)
23753
d74a16b84e05 Track schema changes: merge messagecategory with area attributes
aspinall
parents: 22402
diff changeset
    39
    datatype displayarea = Status | Message | Display | Tracing | Internal | Other of string
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    40
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    41
    (* Error levels *)
22041
c874c3f13c45 Add info fatality for error messages.
aspinall
parents: 22009
diff changeset
    42
    datatype fatality = Info | Warning | Nonfatal | Fatal | Panic | Log | Debug
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    43
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    44
    (* File location *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    45
    type location = { descr: string option,
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    46
                      url: pgipurl option,
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    47
                      line: int option,
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    48
                      column: int option,
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    49
                      char: int option,
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    50
                      length: int option }
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    51
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    52
    (* Prover preference *)   
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    53
    type preference = { name: string,
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    54
                        descr: string option,
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    55
                        default: string option,
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    56
                        pgiptype: pgiptype }
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    57
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    58
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    59
signature PGIPTYPES_OPNS = 
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    60
sig
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    61
    include PGIPTYPES
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    62
 
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    63
    (* Object types *)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    64
    val name_of_objtype  : objtype -> string
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    65
    val attrs_of_objtype : objtype -> XML.attributes
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    66
    val objtype_of_attrs : XML.attributes -> objtype                    (* raises PGIP *)
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    67
    val idtable_to_xml   : idtable -> XML.tree
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    68
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    69
    (* Values as XML strings *)
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    70
    val read_pgipint       : (int option * int option) -> string -> int (* raises PGIP *)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    71
    val read_pgipnat       : string -> int                              (* raises PGIP *)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    72
    val read_pgipbool      : string -> bool                             (* raises PGIP *)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    73
    val read_pgipstring    : string -> string                           (* raises PGIP *)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    74
    val int_to_pgstring    : int -> string
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    75
    val bool_to_pgstring   : bool -> string
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    76
    val string_to_pgstring : string -> string
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    77
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    78
    (* PGIP datatypes *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    79
    val pgiptype_to_xml   : pgiptype -> XML.tree
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    80
    val read_pgval        : pgiptype -> string -> pgipval              (* raises PGIP *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    81
    val pgval_to_string   : pgipval -> string
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    82
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    83
    val attrs_of_displayarea : displayarea -> XML.attributes
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    84
    val attrs_of_fatality : fatality -> XML.attributes
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    85
    val attrs_of_location : location -> XML.attributes
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    86
    val location_of_attrs : XML.attributes -> location (* raises PGIP *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    87
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    88
    val haspref : preference -> XML.tree
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    89
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    90
    val pgipurl_of_url : Url.T -> pgipurl              (* raises PGIP *)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    91
    val pgipurl_of_string : string -> pgipurl          (* raises PGIP *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    92
    val pgipurl_of_path : Path.T -> pgipurl
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    93
    val path_of_pgipurl : pgipurl -> Path.T
22003
34e190b24399 Be more chatty in PGIP file operations.proof_general_pgip.ML
aspinall
parents: 22000
diff changeset
    94
    val string_of_pgipurl : pgipurl -> string
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    95
    val attrs_of_pgipurl : pgipurl -> XML.attributes
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    96
    val pgipurl_of_attrs : XML.attributes -> pgipurl   (* raises PGIP *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    97
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    98
    (* XML utils, only for PGIP code *)
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    99
    val has_attr       : string -> XML.attributes -> bool
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   100
    val attr           : string -> string -> XML.attributes
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   101
    val opt_attr       : string -> string option -> XML.attributes
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   102
    val opt_attr_map   : ('a -> string) -> string -> 'a option -> XML.attributes
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   103
    val get_attr       : string -> XML.attributes -> string           (* raises PGIP *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   104
    val get_attr_opt   : string -> XML.attributes -> string option
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   105
    val get_attr_dflt  : string -> string -> XML.attributes -> string
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   106
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   107
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   108
structure PgipTypes : PGIPTYPES_OPNS =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   109
struct
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   110
exception PGIP of string
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   111
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   112
(** XML utils **)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   113
28017
4919bd124a58 type Properties.T;
wenzelm
parents: 24133
diff changeset
   114
fun has_attr attr attrs = Properties.defined attrs attr
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   115
28017
4919bd124a58 type Properties.T;
wenzelm
parents: 24133
diff changeset
   116
fun get_attr_opt attr attrs = Properties.get attrs attr
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   117
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   118
fun get_attr attr attrs =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   119
    (case get_attr_opt attr attrs of
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   120
         SOME value => value
21973
e7c9b0d3ce82 Quote arguments in PGIP exceptions. Tune comment.
aspinall
parents: 21944
diff changeset
   121
       | NONE => raise PGIP ("Missing attribute: " ^ quote attr))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   122
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   123
fun get_attr_dflt attr dflt attrs = the_default dflt (get_attr_opt attr attrs)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   124
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   125
fun attr x y = [(x,y)] : XML.attributes
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   126
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   127
fun opt_attr_map f attr_name opt_val = 
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   128
    case opt_val of NONE => [] | SOME v => [(attr_name,f v)]
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   129
 (* or, if you've got function-itis: 
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   130
    the_default [] (Option.map (single o (pair attr_name) o f) opt_val)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   131
  *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   132
21902
8e5e2571c716 made SML/NJ happy
haftmann
parents: 21867
diff changeset
   133
fun opt_attr attr_name = opt_attr_map I attr_name
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   134
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   135
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   136
(** Objtypes **)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   137
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   138
datatype objtype = ObjFile | ObjTheory | ObjTheorem | ObjComment  
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   139
                 | ObjTerm | ObjType | ObjOther of string
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   140
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   141
fun name_of_objtype obj = 
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   142
    case obj of 
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   143
        ObjFile    => "file"
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   144
      | ObjTheory  => "theory"
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   145
      | ObjTheorem => "theorem"
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   146
      | ObjComment => "comment"
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   147
      | ObjTerm    => "term"
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   148
      | ObjType    => "type"
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   149
      | ObjOther s => s
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   150
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   151
val attrs_of_objtype = attr "objtype" o name_of_objtype
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   152
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   153
fun objtype_of_attrs attrs = case get_attr "objtype" attrs of
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   154
       "file" => ObjFile
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   155
     | "theory" => ObjTheory
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   156
     | "theorem" => ObjTheorem
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   157
     | "comment" => ObjComment
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   158
     | "term" => ObjTerm
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   159
     | "type" => ObjType
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   160
     | s => ObjOther s    (* where s mem other_objtypes_parameter *)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   161
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   162
type objname = string
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   163
type idtable = { context: objname option,    (* container's objname *)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   164
                 objtype: objtype, 
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   165
                 ids: objname list }
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   166
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   167
fun idtable_to_xml {context, objtype, ids} = 
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   168
    let 
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   169
        val objtype_attrs = attrs_of_objtype objtype
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   170
        val context_attrs = opt_attr "context" context
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   171
        val ids_content = map (fn x => XML.Elem("identifier",[],[XML.Text x])) ids
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   172
    in 
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   173
        XML.Elem ("idtable",
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   174
                  objtype_attrs @ context_attrs,
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   175
                  ids_content)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   176
    end
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   177
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   178
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   179
(** Types and values **)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   180
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   181
(* readers and writers for values represented in XML strings *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   182
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   183
fun read_pgipbool s =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   184
    (case s of 
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   185
         "false" => false 
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   186
       | "true" => true 
21973
e7c9b0d3ce82 Quote arguments in PGIP exceptions. Tune comment.
aspinall
parents: 21944
diff changeset
   187
       | _ => raise PGIP ("Invalid boolean value: " ^ quote s))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   188
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   189
local
24133
75063f96618f added int type constraints to accomodate hacked SML/NJ;
wenzelm
parents: 23753
diff changeset
   190
    fun int_in_range (NONE,NONE) (_: int) = true
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   191
      | int_in_range (SOME min,NONE) i = min<= i
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   192
      | int_in_range (NONE,SOME max) i = i<=max
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   193
      | int_in_range (SOME min,SOME max) i = min<= i andalso i<=max
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   194
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   195
fun read_pgipint range s =
22009
b0c966b30066 approximate Syntax.read_int/nat by Int.fromString -- avoids dependency on Syntax module;
wenzelm
parents: 22003
diff changeset
   196
    (case Int.fromString s of 
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   197
         SOME i => if int_in_range range i then i
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   198
                   else raise PGIP ("Out of range integer value: " ^ quote s)
21973
e7c9b0d3ce82 Quote arguments in PGIP exceptions. Tune comment.
aspinall
parents: 21944
diff changeset
   199
       | NONE => raise PGIP ("Invalid integer value: " ^ quote s))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   200
end;
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   201
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   202
fun read_pgipnat s =
22009
b0c966b30066 approximate Syntax.read_int/nat by Int.fromString -- avoids dependency on Syntax module;
wenzelm
parents: 22003
diff changeset
   203
    (case Int.fromString s of 
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   204
         SOME i => if i >= 0 then i
22009
b0c966b30066 approximate Syntax.read_int/nat by Int.fromString -- avoids dependency on Syntax module;
wenzelm
parents: 22003
diff changeset
   205
                   else raise PGIP ("Invalid natural number: " ^ quote s)
21973
e7c9b0d3ce82 Quote arguments in PGIP exceptions. Tune comment.
aspinall
parents: 21944
diff changeset
   206
       | NONE => raise PGIP ("Invalid natural number: " ^ quote s))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   207
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   208
(* NB: we can maybe do without xml decode/encode here. *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   209
fun read_pgipstring s =  (* non-empty strings, XML escapes decoded *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   210
    (case XML.parse_string s of
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   211
         SOME s => s
21973
e7c9b0d3ce82 Quote arguments in PGIP exceptions. Tune comment.
aspinall
parents: 21944
diff changeset
   212
       | NONE => raise PGIP ("Expected a non-empty string: " ^ quote s))
28397
389c5e494605 handle _ should be avoided (spurious Interrupt will spoil the game);
wenzelm
parents: 28020
diff changeset
   213
    handle _ => raise PGIP ("Invalid XML string syntax: " ^ quote s)  (* FIXME avoid handle _ *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   214
21944
e877a5a78522 signed_string_of_int;
wenzelm
parents: 21940
diff changeset
   215
val int_to_pgstring = signed_string_of_int
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   216
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   217
fun string_to_pgstring s = XML.text s
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   218
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   219
fun bool_to_pgstring b = if b then "true" else "false"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   220
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   221
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   222
(* PGIP datatypes.
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   223
   
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   224
   This is a reflection of the type structure of PGIP configuration,
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   225
   which is meant for setting up user dialogs and preference settings.
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   226
   These are configured declaratively in XML, using a syntax for types
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   227
   and values which is like a (vastly cut down) form of XML Schema
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   228
   Datatypes.
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   229
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   230
   The prover needs to interpret the strings representing the typed
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   231
   values, at least for the types it expects from the dialogs it
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   232
   configures.  Here we go further and construct a type-safe
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   233
   encapsulation of these values, which would be useful for more
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   234
   advanced cases (e.g. generating and processing forms).  
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   235
*)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   236
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   237
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   238
datatype pgiptype = 
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   239
         Pgipnull                            (* unit type: unique element is empty string *)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   240
       | Pgipbool                            (* booleans: "true" or "false" *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   241
       | Pgipint of int option * int option  (* ranged integers, should be XSD canonical *)
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   242
       | Pgipnat                             (* naturals: non-negative integers (convenience) *)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   243
       | Pgipstring                          (* non-empty strings *)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   244
       | Pgipconst of string                 (* singleton type *)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   245
       | Pgipchoice of pgipdtype list        (* union type *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   246
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   247
(* Compared with the PGIP schema, we push descriptions of types inside choices. *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   248
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   249
and pgipdtype = Pgipdtype of string option * pgiptype
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   250
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   251
datatype pgipuval = Pgvalnull | Pgvalbool of bool | Pgvalint of int | Pgvalnat of int 
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   252
                  | Pgvalstring of string | Pgvalconst of string
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   253
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   254
type pgipval = pgiptype * pgipuval      (* type-safe values *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   255
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   256
fun pgipdtype_to_xml (desco,ty) = 
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   257
    let
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   258
        val desc_attr = opt_attr "descr" desco
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   259
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   260
        val elt = case ty of
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   261
                      Pgipnull => "pgipnull"
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   262
                    | Pgipbool => "pgipbool"
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   263
                    | Pgipint _ => "pgipint"
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   264
                    | Pgipnat => "pgipint"
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   265
                    | Pgipstring => "pgipstring"
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   266
                    | Pgipconst _ => "pgipconst"
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   267
                    | Pgipchoice _ => "pgipchoice"
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   268
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   269
        fun range_attr r v = attr r (int_to_pgstring v)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   270
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   271
        val attrs = case ty of 
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   272
                        Pgipint (SOME min,SOME max) => (range_attr "min" min)@(range_attr "max" max)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   273
                      | Pgipint (SOME min,NONE) => (range_attr "min" min)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   274
                      | Pgipint (NONE,SOME max) => (range_attr "max" max)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   275
                      | Pgipnat => (range_attr "min" 0)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   276
                      | Pgipconst nm => attr "name" nm
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   277
                      | _ => []
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   278
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   279
        fun destpgipdtype (Pgipdtype x) = x
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   280
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   281
        val typargs = case ty of
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   282
                          Pgipchoice ds => map destpgipdtype ds
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   283
                        | _ => []
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   284
    in 
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   285
        XML.Elem (elt, (desc_attr @ attrs), (map pgipdtype_to_xml typargs))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   286
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   287
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   288
val pgiptype_to_xml = pgipdtype_to_xml o pair NONE
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   289
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   290
fun read_pguval Pgipnull s = 
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   291
    if s="" then Pgvalnull
21973
e7c9b0d3ce82 Quote arguments in PGIP exceptions. Tune comment.
aspinall
parents: 21944
diff changeset
   292
    else raise PGIP ("Expecting empty string for null type, not: " ^ quote s)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   293
  | read_pguval Pgipbool s = Pgvalbool (read_pgipbool s)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   294
  | read_pguval (Pgipint range) s = Pgvalint (read_pgipint range s)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   295
  | read_pguval Pgipnat s = Pgvalnat (read_pgipnat s)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   296
  | read_pguval (Pgipconst c) s = 
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   297
    if c=s then Pgvalconst c 
21973
e7c9b0d3ce82 Quote arguments in PGIP exceptions. Tune comment.
aspinall
parents: 21944
diff changeset
   298
    else raise PGIP ("Given string: "^quote s^" doesn't match expected string: "^quote c)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   299
  | read_pguval Pgipstring s = 
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   300
    if s<>"" then Pgvalstring s
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   301
    else raise PGIP ("Expecting non-empty string, empty string illegal.")
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   302
  | read_pguval (Pgipchoice tydescs) s = 
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   303
    let 
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   304
        (* Union type: match first in list *)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   305
        fun getty (Pgipdtype(_, ty)) = ty
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   306
        val uval = get_first 
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   307
                       (fn ty => SOME (read_pguval ty s) handle PGIP _ => NONE)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   308
                       (map getty tydescs)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   309
    in
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   310
        case uval of SOME pgv => pgv | NONE => raise PGIP ("Can't match string: "^quote s^
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   311
                                                           " against any allowed types.")
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   312
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   313
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   314
fun read_pgval ty s = (ty, read_pguval ty s)
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   315
            
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   316
fun pgval_to_string (_, Pgvalnull) = ""
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   317
  | pgval_to_string (_, Pgvalbool b) = bool_to_pgstring b
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   318
  | pgval_to_string (_, Pgvalnat n) = int_to_pgstring n
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   319
  | pgval_to_string (_, Pgvalint i) = int_to_pgstring i
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   320
  | pgval_to_string (_, Pgvalconst c) = string_to_pgstring c
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   321
  | pgval_to_string (_, Pgvalstring s) = string_to_pgstring s
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   322
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   323
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   324
type pgipurl = Path.T    (* URLs: only local files *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   325
23753
d74a16b84e05 Track schema changes: merge messagecategory with area attributes
aspinall
parents: 22402
diff changeset
   326
datatype displayarea = Status | Message | Display | Tracing | Internal | Other of string
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   327
22041
c874c3f13c45 Add info fatality for error messages.
aspinall
parents: 22009
diff changeset
   328
datatype fatality = Info | Warning | Nonfatal | Fatal | Panic | Log | Debug
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   329
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   330
type location = { descr: string option,
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   331
                  url: pgipurl option,
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   332
                  line: int option,
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   333
                  column: int option,
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   334
                  char: int option,
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   335
                  length: int option }
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   336
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   337
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   338
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   339
(** Url operations **)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   340
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   341
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   342
fun pgipurl_of_string url = (* only handle file:/// or file://localhost/ *)
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   343
        case Url.explode url of
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   344
            (Url.File path) => path
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   345
          | _ => raise PGIP ("Cannot access non-local URL " ^ quote url)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   346
                       
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   347
fun pgipurl_of_path p = p
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   348
21973
e7c9b0d3ce82 Quote arguments in PGIP exceptions. Tune comment.
aspinall
parents: 21944
diff changeset
   349
fun path_of_pgipurl p = p  (* potentially raises PGIP, but not with this implementation *)
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
   350
22003
34e190b24399 Be more chatty in PGIP file operations.proof_general_pgip.ML
aspinall
parents: 22000
diff changeset
   351
fun string_of_pgipurl p = Path.implode p
34e190b24399 Be more chatty in PGIP file operations.proof_general_pgip.ML
aspinall
parents: 22000
diff changeset
   352
22162
63dbc68eb527 Sync location with pgip.rnc, fixing attribute names
aspinall
parents: 22041
diff changeset
   353
fun attrval_of_pgipurl purl = "file:" ^ (XML.text (File.platform_path (File.full_path purl)))
63dbc68eb527 Sync location with pgip.rnc, fixing attribute names
aspinall
parents: 22041
diff changeset
   354
fun attrs_of_pgipurl purl = [("url", attrval_of_pgipurl purl)]
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   355
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   356
val pgipurl_of_attrs = pgipurl_of_string o get_attr "url"
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   357
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   358
fun pgipurl_of_url (Url.File p) = p
21973
e7c9b0d3ce82 Quote arguments in PGIP exceptions. Tune comment.
aspinall
parents: 21944
diff changeset
   359
  | pgipurl_of_url url = 
e7c9b0d3ce82 Quote arguments in PGIP exceptions. Tune comment.
aspinall
parents: 21944
diff changeset
   360
    raise PGIP ("Cannot access non-local/non-file URL " ^ quote (Url.implode url))
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   361
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   362
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   363
(** Messages and errors **)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   364
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   365
local
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   366
  fun string_of_area Status = "status"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   367
    | string_of_area Message = "message"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   368
    | string_of_area Display = "display"
23753
d74a16b84e05 Track schema changes: merge messagecategory with area attributes
aspinall
parents: 22402
diff changeset
   369
    | string_of_area Tracing = "tracing"
d74a16b84e05 Track schema changes: merge messagecategory with area attributes
aspinall
parents: 22402
diff changeset
   370
    | string_of_area Internal = "internal"
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   371
    | string_of_area (Other s) = s
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   372
22041
c874c3f13c45 Add info fatality for error messages.
aspinall
parents: 22009
diff changeset
   373
  fun string_of_fatality Info = "info"
c874c3f13c45 Add info fatality for error messages.
aspinall
parents: 22009
diff changeset
   374
    | string_of_fatality Warning = "warning"
22000
358525557580 Add warning fatality
aspinall
parents: 21973
diff changeset
   375
    | string_of_fatality Nonfatal = "nonfatal"
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   376
    | string_of_fatality Fatal = "fatal"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   377
    | string_of_fatality Panic = "panic"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   378
    | string_of_fatality Log = "log"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   379
    | string_of_fatality Debug = "debug"
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   380
in
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   381
  fun attrs_of_displayarea area = [("area", string_of_area area)]
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   382
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   383
  fun attrs_of_fatality fatality = [("fatality", string_of_fatality fatality)]
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   384
22162
63dbc68eb527 Sync location with pgip.rnc, fixing attribute names
aspinall
parents: 22041
diff changeset
   385
  fun attrs_of_location ({ descr, url, line, column, char, length }:location) =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   386
      let 
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   387
          val descr = opt_attr "location_descr" descr
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   388
          val url = opt_attr_map attrval_of_pgipurl "location_url" url
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   389
          val line = opt_attr_map int_to_pgstring "locationline" line
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   390
          val column = opt_attr_map int_to_pgstring "locationcolumn"  column
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   391
          val char = opt_attr_map int_to_pgstring "locationcharacter" char
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   392
          val length = opt_attr_map int_to_pgstring "locationlength" length
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   393
      in 
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   394
          descr @ url @ line @ column @ char @ length
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   395
      end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   396
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   397
    fun pgipint_of_string err s = 
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   398
        case Int.fromString s of 
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   399
            SOME i => i
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   400
          | NONE => raise PGIP ("Type error in " ^ quote err ^ ": expected integer.")
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   401
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   402
  fun location_of_attrs attrs = 
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   403
      let
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   404
          val descr = get_attr_opt "location_descr" attrs
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   405
          val url = Option.map  pgipurl_of_string (get_attr_opt "location_url" attrs)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   406
          val line = Option.map (pgipint_of_string "location element line attribute")
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   407
                                (get_attr_opt "locationline" attrs)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   408
          val column = Option.map (pgipint_of_string "location element column attribute")
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   409
                                  (get_attr_opt "locationcolumn" attrs)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   410
          val char = Option.map (pgipint_of_string "location element char attribute")
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   411
                                (get_attr_opt "locationcharacter" attrs)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   412
          val length = Option.map (pgipint_of_string "location element length attribute")
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   413
                                  (get_attr_opt "locationlength" attrs)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   414
      in 
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   415
          {descr=descr, url=url, line=line, column=column, char=char, length=length}
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   416
      end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   417
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   418
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   419
(** Preferences **)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   420
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   421
type preference = { name: string,
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   422
                    descr: string option,
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   423
                    default: string option,
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   424
                    pgiptype: pgiptype }
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   425
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   426
fun haspref ({ name, descr, default, pgiptype}:preference) = 
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   427
    XML.Elem ("haspref",
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   428
              attr "name" name @
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   429
              opt_attr "descr" descr @
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   430
              opt_attr "default" default,
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   431
              [pgiptype_to_xml pgiptype])
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   432
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   433
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   434