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