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