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