src/Pure/Thy/export.ML
author wenzelm
Fri, 29 Mar 2019 13:42:17 +0100
changeset 70011 9dde788b0128
parent 70009 435fb018e8ee
child 70013 6de8b7a5cd44
permissions -rw-r--r--
clarified 'file_prefix';
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
70011
9dde788b0128 clarified 'file_prefix';
wenzelm
parents: 70009
diff changeset
     9
  val check_name: Path.T -> string
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    10
  type params = {theory: theory, path: Path.T, executable: bool, compress: bool}
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    11
  val export_params: params -> string list -> unit
69784
24bbc4e30e5b clarified signature: Path.T as in Generated_Files;
wenzelm
parents: 69650
diff changeset
    12
  val export: theory -> Path.T -> string list -> unit
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    13
  val export_executable: theory -> Path.T -> string list -> unit
70009
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    14
  val markup: theory -> Path.T -> Markup.T
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    15
  val message: theory -> Path.T -> string
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    16
end;
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    17
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    18
structure Export: EXPORT =
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    19
struct
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    20
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    21
(* export *)
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    22
69784
24bbc4e30e5b clarified signature: Path.T as in Generated_Files;
wenzelm
parents: 69650
diff changeset
    23
fun check_name path =
68105
577072a0ceed more checks;
wenzelm
parents: 68102
diff changeset
    24
  let
69784
24bbc4e30e5b clarified signature: Path.T as in Generated_Files;
wenzelm
parents: 69650
diff changeset
    25
    val name = Path.implode path;
69627
3e26471d6d01 clarified Path.check_elem;
wenzelm
parents: 68167
diff changeset
    26
    val _ =
69784
24bbc4e30e5b clarified signature: Path.T as in Generated_Files;
wenzelm
parents: 69650
diff changeset
    27
      if not (Path.is_current path) andalso Path.all_basic path then ()
24bbc4e30e5b clarified signature: Path.T as in Generated_Files;
wenzelm
parents: 69650
diff changeset
    28
      else error ("Bad export name: " ^ quote name);
68105
577072a0ceed more checks;
wenzelm
parents: 68102
diff changeset
    29
  in name end;
577072a0ceed more checks;
wenzelm
parents: 68102
diff changeset
    30
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    31
type params = {theory: theory, path: Path.T, executable: bool, compress: bool};
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    32
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    33
fun export_params ({theory, path, executable, compress}: params) blob =
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    34
  (Output.try_protocol_message o Markup.export)
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    35
   {id = Position.get_id (Position.thread_data ()),
68101
0699a0bacc50 store exports within PIDE command state;
wenzelm
parents: 68090
diff changeset
    36
    serial = serial (),
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    37
    theory_name = Context.theory_long_name theory,
69784
24bbc4e30e5b clarified signature: Path.T as in Generated_Files;
wenzelm
parents: 69650
diff changeset
    38
    name = check_name path,
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    39
    executable = executable,
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    40
    compress = compress} blob;
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    41
69788
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    42
fun export theory path blob =
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    43
  export_params {theory = theory, path = path, executable = false, compress = true} blob;
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    44
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    45
fun export_executable theory path blob =
c175499a7537 added executable flag for exports;
wenzelm
parents: 69784
diff changeset
    46
  export_params {theory = theory, path = path, executable = true, compress = true} blob;
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    47
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    48
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    49
(* information message *)
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    50
70009
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    51
fun markup thy path =
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    52
  let
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    53
    val thy_path = Path.append (Path.basic (Context.theory_long_name thy)) path;
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    54
    val name = (Markup.nameN, Path.implode thy_path);
69650
c95edf19133b clarified message;
wenzelm
parents: 69648
diff changeset
    55
  in Active.make_markup Markup.theory_exportsN {implicit = false, properties = [name]} end;
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    56
70009
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    57
fun message thy path =
435fb018e8ee "export_code ... file_prefix ..." is the preferred way to produce output within the logical file-system within the theory context, as well as session exports;
wenzelm
parents: 69788
diff changeset
    58
  "See " ^ Markup.markup (markup thy path) "theory exports";
69648
97ddaec3e2ae support hyperlink to theory exports;
wenzelm
parents: 69627
diff changeset
    59
68090
7c8ed28dd40a tuned signature;
wenzelm
parents:
diff changeset
    60
end;