src/Pure/ProofGeneral/pgip_types.ML
author wenzelm
Tue, 14 May 2013 21:02:49 +0200
changeset 51991 5b814dd90f7f
parent 51990 cc66addbba6d
child 51992 5c179451c445
permissions -rw-r--r--
prefer Markup.parse/print operations -- slight change of exception behaviour; removed obsolete PGIP material;
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
51985
wenzelm
parents: 51973
diff changeset
     4
Some PGIP types and conversions.
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     5
*)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     6
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     7
signature PGIPTYPES =
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
     8
sig
51985
wenzelm
parents: 51973
diff changeset
     9
  val attr: string -> string -> XML.attributes
wenzelm
parents: 51973
diff changeset
    10
  val opt_attr: string -> string option -> XML.attributes
wenzelm
parents: 51973
diff changeset
    11
  val get_attr: XML.attributes -> string -> string           (* raises PGIP *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    12
51985
wenzelm
parents: 51973
diff changeset
    13
  datatype pgiptype =
wenzelm
parents: 51973
diff changeset
    14
      Pgipnull | Pgipbool | Pgipint of int option * int option | Pgipnat | Pgipreal
wenzelm
parents: 51973
diff changeset
    15
    | Pgipstring | Pgipconst of string | Pgipchoice of pgipdtype list
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    16
51985
wenzelm
parents: 51973
diff changeset
    17
  and pgipdtype = Pgipdtype of string option * pgiptype  (* type with opt. description *)
wenzelm
parents: 51973
diff changeset
    18
wenzelm
parents: 51973
diff changeset
    19
  exception PGIP of string
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    20
51985
wenzelm
parents: 51973
diff changeset
    21
  val pgiptype_to_xml   : pgiptype -> XML.tree
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    22
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    23
51973
e116eb9e5e17 removed obsolete PGIP material;
wenzelm
parents: 51972
diff changeset
    24
structure PgipTypes : PGIPTYPES =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    25
struct
51973
e116eb9e5e17 removed obsolete PGIP material;
wenzelm
parents: 51972
diff changeset
    26
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    27
exception PGIP of string
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    28
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    29
(** XML utils **)
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    30
51985
wenzelm
parents: 51973
diff changeset
    31
fun get_attr attrs name =
wenzelm
parents: 51973
diff changeset
    32
  (case Properties.get attrs name of
wenzelm
parents: 51973
diff changeset
    33
    SOME value => value
wenzelm
parents: 51973
diff changeset
    34
  | NONE => raise PGIP ("Missing attribute: " ^ quote name));
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    35
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    36
fun attr x y = [(x,y)] : XML.attributes
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    37
51985
wenzelm
parents: 51973
diff changeset
    38
fun opt_attr _ NONE = []
wenzelm
parents: 51973
diff changeset
    39
  | opt_attr name (SOME value) = attr name value;
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    40
21867
8750fbc28d5c Add abstraction for objtypes and documents.
aspinall
parents: 21858
diff changeset
    41
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    42
(* PGIP datatypes.
51985
wenzelm
parents: 51973
diff changeset
    43
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    44
   This is a reflection of the type structure of PGIP configuration,
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    45
   which is meant for setting up user dialogs and preference settings.
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    46
   These are configured declaratively in XML, using a syntax for types
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    47
   and values which is like a (vastly cut down) form of XML Schema
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    48
   Datatypes.
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    49
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    50
   The prover needs to interpret the strings representing the typed
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    51
   values, at least for the types it expects from the dialogs it
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    52
   configures.  Here we go further and construct a type-safe
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    53
   encapsulation of these values, which would be useful for more
51985
wenzelm
parents: 51973
diff changeset
    54
   advanced cases (e.g. generating and processing forms).
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    55
*)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    56
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    57
51985
wenzelm
parents: 51973
diff changeset
    58
datatype pgiptype =
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    59
         Pgipnull                            (* unit type: unique element is empty string *)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    60
       | Pgipbool                            (* booleans: "true" or "false" *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    61
       | Pgipint of int option * int option  (* ranged integers, should be XSD canonical *)
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    62
       | Pgipnat                             (* naturals: non-negative integers (convenience) *)
40292
ba13793594f0 support for real valued preferences;
wenzelm
parents: 38228
diff changeset
    63
       | Pgipreal                            (* floating-point numbers *)
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    64
       | Pgipstring                          (* non-empty strings *)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    65
       | Pgipconst of string                 (* singleton type *)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    66
       | Pgipchoice of pgipdtype list        (* union type *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    67
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    68
(* Compared with the PGIP schema, we push descriptions of types inside choices. *)
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    69
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    70
and pgipdtype = Pgipdtype of string option * pgiptype
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    71
40292
ba13793594f0 support for real valued preferences;
wenzelm
parents: 38228
diff changeset
    72
datatype pgipuval =
ba13793594f0 support for real valued preferences;
wenzelm
parents: 38228
diff changeset
    73
    Pgvalnull | Pgvalbool of bool | Pgvalint of int | Pgvalnat of int | Pgvalreal of real
ba13793594f0 support for real valued preferences;
wenzelm
parents: 38228
diff changeset
    74
  | Pgvalstring of string | Pgvalconst of string
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    75
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    76
type pgipval = pgiptype * pgipuval      (* type-safe values *)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    77
51985
wenzelm
parents: 51973
diff changeset
    78
fun pgipdtype_to_xml (desco,ty) =
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    79
    let
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    80
        val desc_attr = opt_attr "descr" desco
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    81
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    82
        val elt = case ty of
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    83
                      Pgipnull => "pgipnull"
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    84
                    | Pgipbool => "pgipbool"
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    85
                    | Pgipint _ => "pgipint"
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    86
                    | Pgipnat => "pgipint"
41733
775da08dae1b clarified comment -- ancienct PG 3.7.x is still in use;
wenzelm
parents: 41516
diff changeset
    87
                    | Pgipreal => "pgipint"  (*sic!*)  (*required for PG 4.0 and 3.7.x*)
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    88
                    | Pgipstring => "pgipstring"
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    89
                    | Pgipconst _ => "pgipconst"
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    90
                    | Pgipchoice _ => "pgipchoice"
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    91
51991
5b814dd90f7f prefer Markup.parse/print operations -- slight change of exception behaviour;
wenzelm
parents: 51990
diff changeset
    92
        fun range_attr r v = attr r (Markup.print_int v)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
    93
51985
wenzelm
parents: 51973
diff changeset
    94
        val attrs = case ty of
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    95
                        Pgipint (SOME min,SOME max) => (range_attr "min" min)@(range_attr "max" max)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    96
                      | Pgipint (SOME min,NONE) => (range_attr "min" min)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    97
                      | Pgipint (NONE,SOME max) => (range_attr "max" max)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    98
                      | Pgipnat => (range_attr "min" 0)
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
    99
                      | Pgipconst nm => attr "name" nm
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   100
                      | _ => []
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   101
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   102
        fun destpgipdtype (Pgipdtype x) = x
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   103
28020
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   104
        val typargs = case ty of
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   105
                          Pgipchoice ds => map destpgipdtype ds
1ff5167592ba get rid of tabs;
wenzelm
parents: 28017
diff changeset
   106
                        | _ => []
51985
wenzelm
parents: 51973
diff changeset
   107
    in
38228
ada3ab6b9085 simplified type XML.tree: embed Markup.T directly, avoid slightly odd triple;
wenzelm
parents: 29606
diff changeset
   108
        XML.Elem ((elt, desc_attr @ attrs), map pgipdtype_to_xml typargs)
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   109
    end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   110
21940
fbd068dd4d29 minor tuning;
wenzelm
parents: 21902
diff changeset
   111
val pgiptype_to_xml = pgipdtype_to_xml o pair NONE
21637
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   112
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   113
end
a7b156c404e2 Revamped Proof General interface.
aspinall
parents:
diff changeset
   114