src/Pure/Thy/export.ML
author wenzelm
Mon, 14 Jan 2019 13:58:12 +0100
changeset 69650 c95edf19133b
parent 69648 97ddaec3e2ae
child 69784 24bbc4e30e5b
permissions -rw-r--r--
clarified message;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Thy/export.ML
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     3
68102
813b5d0904c6 clarified signature;
wenzelm
parents: 68101
diff changeset
     4
Manage theory exports: compressed blobs.
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     5
*)
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     6
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     7
signature EXPORT =
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
     8
sig
68146
d23af2dbb4e7 more scalable API;
wenzelm
parents: 68113
diff changeset
     9
  val export: theory -> string -> string list -> unit
d23af2dbb4e7 more scalable API;
wenzelm
parents: 68113
diff changeset
    10
  val export_raw: theory -> string -> string list -> unit
69650
c95edf19133b clarified message;
wenzelm
parents: 69648
diff changeset
    11
  val markup: theory -> string -> Markup.T
c95edf19133b clarified message;
wenzelm
parents: 69648
diff changeset
    12
  val message: theory -> string -> string
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    13
end;
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    14
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    15
structure Export: EXPORT =
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    16
struct
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    17
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    18
(* export *)
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    19
68105
577072a0ceed more checks;
wenzelm
parents: 68102
diff changeset
    20
fun check_name name =
577072a0ceed more checks;
wenzelm
parents: 68102
diff changeset
    21
  let
69627
3e26471d6d01 clarified Path.check_elem;
wenzelm
parents: 68167
diff changeset
    22
    val _ =
3e26471d6d01 clarified Path.check_elem;
wenzelm
parents: 68167
diff changeset
    23
      (case space_explode "/" name of
3e26471d6d01 clarified Path.check_elem;
wenzelm
parents: 68167
diff changeset
    24
        [] => error "Empty export name"
3e26471d6d01 clarified Path.check_elem;
wenzelm
parents: 68167
diff changeset
    25
      | elems => List.app Path.check_elem elems);
68105
577072a0ceed more checks;
wenzelm
parents: 68102
diff changeset
    26
  in name end;
577072a0ceed more checks;
wenzelm
parents: 68102
diff changeset
    27
68102
813b5d0904c6 clarified signature;
wenzelm
parents: 68101
diff changeset
    28
fun gen_export compress thy name body =
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    29
  (Output.try_protocol_message o Markup.export)
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    30
   {id = Position.get_id (Position.thread_data ()),
68101
0699a0bacc50 store exports within PIDE command state;
wenzelm
parents: 68090
diff changeset
    31
    serial = serial (),
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    32
    theory_name = Context.theory_long_name thy,
68105
577072a0ceed more checks;
wenzelm
parents: 68102
diff changeset
    33
    name = check_name name,
68146
d23af2dbb4e7 more scalable API;
wenzelm
parents: 68113
diff changeset
    34
    compress = compress} body;
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    35
68167
327bb0f5f768 clarified implicit compression;
wenzelm
parents: 68146
diff changeset
    36
val export = gen_export true;
68113
c925f53fd1f6 tuned signature;
wenzelm
parents: 68105
diff changeset
    37
val export_raw = gen_export false;
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    38
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    39
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    40
(* information message *)
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    41
69650
c95edf19133b clarified message;
wenzelm
parents: 69648
diff changeset
    42
fun markup thy s =
c95edf19133b clarified message;
wenzelm
parents: 69648
diff changeset
    43
  let val name = (Markup.nameN, Context.theory_long_name thy ^ (if s = "" then "" else "/" ^ s))
c95edf19133b clarified message;
wenzelm
parents: 69648
diff changeset
    44
  in Active.make_markup Markup.theory_exportsN {implicit = false, properties = [name]} end;
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    45
69650
c95edf19133b clarified message;
wenzelm
parents: 69648
diff changeset
    46
fun message thy s =
c95edf19133b clarified message;
wenzelm
parents: 69648
diff changeset
    47
  "See " ^ Markup.markup (markup thy s) "theory exports";
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    48
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    49
end;