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