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