| 68090 |      1 | (*  Title:      Pure/Thy/export.ML
 | 
|  |      2 |     Author:     Makarius
 | 
|  |      3 | 
 | 
| 68102 |      4 | Manage theory exports: compressed blobs.
 | 
| 68090 |      5 | *)
 | 
|  |      6 | 
 | 
|  |      7 | signature EXPORT =
 | 
|  |      8 | sig
 | 
| 68146 |      9 |   val export: theory -> string -> string list -> unit
 | 
|  |     10 |   val export_raw: theory -> string -> string list -> unit
 | 
| 68090 |     11 | end;
 | 
|  |     12 | 
 | 
|  |     13 | structure Export: EXPORT =
 | 
|  |     14 | struct
 | 
|  |     15 | 
 | 
| 68105 |     16 | fun check_name name =
 | 
|  |     17 |   let
 | 
|  |     18 |     fun err () = error ("Bad export name " ^ quote name);
 | 
|  |     19 |     fun check_elem elem =
 | 
|  |     20 |       if member (op =) ["", ".", ".."] elem then err ()
 | 
|  |     21 |       else ignore (Path.basic elem handle ERROR _ => err ());
 | 
|  |     22 | 
 | 
|  |     23 |     val elems = space_explode "/" name;
 | 
|  |     24 |     val _ = null elems andalso err ();
 | 
|  |     25 |     val _ = List.app check_elem elems;
 | 
|  |     26 |   in name end;
 | 
|  |     27 | 
 | 
| 68102 |     28 | fun gen_export compress thy name body =
 | 
| 68090 |     29 |   (Output.try_protocol_message o Markup.export)
 | 
|  |     30 |    {id = Position.get_id (Position.thread_data ()),
 | 
| 68101 |     31 |     serial = serial (),
 | 
| 68090 |     32 |     theory_name = Context.theory_long_name thy,
 | 
| 68105 |     33 |     name = check_name name,
 | 
| 68146 |     34 |     compress = compress} body;
 | 
| 68090 |     35 | 
 | 
| 68167 |     36 | val export = gen_export true;
 | 
| 68113 |     37 | val export_raw = gen_export false;
 | 
| 68090 |     38 | 
 | 
|  |     39 | end;
 |