equal
deleted
inserted
replaced
1 (* Title: Pure/ProofGeneral/pgip_types.ML |
1 (* Title: Pure/ProofGeneral/pgip_types.ML |
2 ID: $Id$ |
2 ID: $Id$ |
3 Author: David Aspinall |
3 Author: David Aspinall |
4 |
4 |
5 PGIP abstraction: types and conversions |
5 PGIP abstraction: types and conversions. |
6 *) |
6 *) |
7 |
7 |
8 (* TODO: PGML *) |
8 (* TODO: PGML *) |
9 signature PGIPTYPES = |
9 signature PGIPTYPES = |
10 sig |
10 sig |
150 | ObjComment => "comment" |
150 | ObjComment => "comment" |
151 | ObjTerm => "term" |
151 | ObjTerm => "term" |
152 | ObjType => "type" |
152 | ObjType => "type" |
153 | ObjOther s => s |
153 | ObjOther s => s |
154 |
154 |
155 val attrs_of_objtype = (attr "objtype") o name_of_objtype |
155 val attrs_of_objtype = attr "objtype" o name_of_objtype |
156 |
156 |
157 fun objtype_of_attrs attrs = case get_attr "objtype" attrs of |
157 fun objtype_of_attrs attrs = case get_attr "objtype" attrs of |
158 "file" => ObjFile |
158 "file" => ObjFile |
159 | "theory" => ObjTheory |
159 | "theory" => ObjTheory |
160 | "theorem" => ObjTheorem |
160 | "theorem" => ObjTheorem |
287 | _ => [] |
287 | _ => [] |
288 in |
288 in |
289 XML.Elem (elt, (desc_attr @ attrs), (map pgipdtype_to_xml typargs)) |
289 XML.Elem (elt, (desc_attr @ attrs), (map pgipdtype_to_xml typargs)) |
290 end |
290 end |
291 |
291 |
292 val pgiptype_to_xml = pgipdtype_to_xml o (pair NONE) |
292 val pgiptype_to_xml = pgipdtype_to_xml o pair NONE |
293 |
293 |
294 fun read_pguval Pgipnull s = |
294 fun read_pguval Pgipnull s = |
295 if s="" then Pgvalnull |
295 if s="" then Pgvalnull |
296 else raise PGIP ("Expecting empty string for null type, not: "^s) |
296 else raise PGIP ("Expecting empty string for null type, not: "^s) |
297 | read_pguval Pgipbool s = Pgvalbool (read_pgipbool s) |
297 | read_pguval Pgipbool s = Pgvalbool (read_pgipbool s) |
304 if s<>"" then Pgvalstring s |
304 if s<>"" then Pgvalstring s |
305 else raise PGIP ("Expecting non-empty string, empty string illegal.") |
305 else raise PGIP ("Expecting non-empty string, empty string illegal.") |
306 | read_pguval (Pgipchoice tydescs) s = |
306 | read_pguval (Pgipchoice tydescs) s = |
307 let |
307 let |
308 (* Union type: match first in list *) |
308 (* Union type: match first in list *) |
309 fun getty (Pgipdtype(_,ty)) = ty |
309 fun getty (Pgipdtype(_, ty)) = ty |
310 val uval = get_first |
310 val uval = get_first |
311 (fn ty => SOME (read_pguval ty s) handle PGIP _ => NONE) |
311 (fn ty => SOME (read_pguval ty s) handle PGIP _ => NONE) |
312 (map getty tydescs) |
312 (map getty tydescs) |
313 in |
313 in |
314 case uval of SOME pgv => pgv | NONE => raise PGIP ("Can't match string: "^s^ |
314 case uval of SOME pgv => pgv | NONE => raise PGIP ("Can't match string: "^s^ |
316 end |
316 end |
317 |
317 |
318 fun read_pgval ty s = (ty, read_pguval ty s) |
318 fun read_pgval ty s = (ty, read_pguval ty s) |
319 |
319 |
320 fun pgval_to_string (_, Pgvalnull) = "" |
320 fun pgval_to_string (_, Pgvalnull) = "" |
321 | pgval_to_string (_,(Pgvalbool b)) = bool_to_pgstring b |
321 | pgval_to_string (_, Pgvalbool b) = bool_to_pgstring b |
322 | pgval_to_string (_,(Pgvalnat n)) = int_to_pgstring n |
322 | pgval_to_string (_, Pgvalnat n) = int_to_pgstring n |
323 | pgval_to_string (_,(Pgvalint i)) = int_to_pgstring i |
323 | pgval_to_string (_, Pgvalint i) = int_to_pgstring i |
324 | pgval_to_string (_,(Pgvalconst c)) = string_to_pgstring c |
324 | pgval_to_string (_, Pgvalconst c) = string_to_pgstring c |
325 | pgval_to_string (_,(Pgvalstring s)) = string_to_pgstring s |
325 | pgval_to_string (_, Pgvalstring s) = string_to_pgstring s |
326 |
326 |
327 |
327 |
328 type pgipurl = Path.T (* URLs: only local files *) |
328 type pgipurl = Path.T (* URLs: only local files *) |
329 |
329 |
330 datatype displayarea = Status | Message | Display | Other of string |
330 datatype displayarea = Status | Message | Display | Other of string |
354 fun path_of_pgipurl p = p (* potentially raises PGIP *) |
354 fun path_of_pgipurl p = p (* potentially raises PGIP *) |
355 |
355 |
356 fun attrs_of_pgipurl purl = |
356 fun attrs_of_pgipurl purl = |
357 [("url", "file:" ^ (XML.text (File.platform_path (File.full_path purl))))] |
357 [("url", "file:" ^ (XML.text (File.platform_path (File.full_path purl))))] |
358 |
358 |
359 val pgipurl_of_attrs = pgipurl_of_string o (get_attr "url") |
359 val pgipurl_of_attrs = pgipurl_of_string o get_attr "url" |
360 |
360 |
361 fun pgipurl_of_url (Url.File p) = p |
361 fun pgipurl_of_url (Url.File p) = p |
362 | pgipurl_of_url url = raise PGIP ("Cannot access non-local/non-file URL " ^ (Url.implode url)) |
362 | pgipurl_of_url url = raise PGIP ("Cannot access non-local/non-file URL " ^ (Url.implode url)) |
363 |
363 |
364 |
364 |
390 |
390 |
391 fun attrs_of_fatality fatality = [("fatality", string_of_fatality fatality)] |
391 fun attrs_of_fatality fatality = [("fatality", string_of_fatality fatality)] |
392 |
392 |
393 fun attrs_of_location ({ descr, url, line, column, char }:location) = |
393 fun attrs_of_location ({ descr, url, line, column, char }:location) = |
394 let |
394 let |
395 val descr = opt_attr "descr"descr |
395 val descr = opt_attr "descr" descr |
396 val url = the_default [] (Option.map attrs_of_pgipurl url) |
396 val url = these (Option.map attrs_of_pgipurl url) |
397 val line = opt_attr_map int_to_pgstring "line" line |
397 val line = opt_attr_map int_to_pgstring "line" line |
398 val column = opt_attr_map int_to_pgstring "column" column |
398 val column = opt_attr_map int_to_pgstring "column" column |
399 val char = opt_attr_map int_to_pgstring "char" char |
399 val char = opt_attr_map int_to_pgstring "char" char |
400 in |
400 in |
401 descr @ url @ line @ column @ char |
401 descr @ url @ line @ column @ char |