src/Pure/Thy/export.ML
changeset 68105 577072a0ceed
parent 68102 813b5d0904c6
child 68113 c925f53fd1f6
equal deleted inserted replaced
68104:3795f67716e6 68105:577072a0ceed
    11 end;
    11 end;
    12 
    12 
    13 structure Export: EXPORT =
    13 structure Export: EXPORT =
    14 struct
    14 struct
    15 
    15 
       
    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 
    16 fun gen_export compress thy name body =
    28 fun gen_export compress thy name body =
    17   (Output.try_protocol_message o Markup.export)
    29   (Output.try_protocol_message o Markup.export)
    18    {id = Position.get_id (Position.thread_data ()),
    30    {id = Position.get_id (Position.thread_data ()),
    19     serial = serial (),
    31     serial = serial (),
    20     theory_name = Context.theory_long_name thy,
    32     theory_name = Context.theory_long_name thy,
    21     name = name,
    33     name = check_name name,
    22     compress = compress} body;
    34     compress = compress} body;
    23 
    35 
    24 fun export thy name body = gen_export (size body > 60) thy name [body];
    36 fun export thy name body = gen_export (size body > 60) thy name [body];
    25 fun export_raw thy name body = gen_export false thy name body;
    37 fun export_raw thy name body = gen_export false thy name body;
    26 
    38