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