src/Pure/Thy/present.ML
author berghofe
Wed, 07 Jun 2000 12:14:29 +0200
changeset 9044 28ee037278a6
parent 8808 204f4ebbba64
child 9136 8196955b02ec
permissions -rw-r--r--
Reorganized graph stuff.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6203
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Thy/present.ML
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
     3
    Author:     Stefan Berghofer and Markus Wenzel, TU Muenchen
8808
wenzelm
parents: 8660
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
6203
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
     5
8196
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
     6
Theory presentation (HTML, graph files, (PDF)LaTeX documents).
6203
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
     7
*)
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
     8
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
     9
signature BASIC_PRESENT =
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
    10
sig
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    11
  val section: string -> unit
6203
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
    12
end;
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
    13
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
    14
signature PRESENT =
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
    15
sig
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    16
  include BASIC_PRESENT
8196
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
    17
  val init: bool -> string -> string list -> string -> Path.T option -> Url.T option * bool -> unit
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    18
  val finish: unit -> unit
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    19
  val init_theory: string -> unit
8192
45a7027136e3 added old_symbol_source;
wenzelm
parents: 8088
diff changeset
    20
  val verbatim_source: string -> (unit -> Symbol.symbol list) -> unit
7757
b2538dccc21e Latex.token;
wenzelm
parents: 7752
diff changeset
    21
  type token
b2538dccc21e Latex.token;
wenzelm
parents: 7752
diff changeset
    22
  val basic_token: OuterLex.token -> token
b2538dccc21e Latex.token;
wenzelm
parents: 7752
diff changeset
    23
  val markup_token: string * string -> token
8660
e5048a26e1d8 support markup environments;
wenzelm
parents: 8646
diff changeset
    24
  val markup_env_token: string * string -> token
7789
57d20133224e verbatim markup tokens;
wenzelm
parents: 7769
diff changeset
    25
  val verbatim_token: string -> token
8192
45a7027136e3 added old_symbol_source;
wenzelm
parents: 8088
diff changeset
    26
  val old_symbol_source: string -> (unit -> Symbol.symbol list) -> unit
7757
b2538dccc21e Latex.token;
wenzelm
parents: 7752
diff changeset
    27
  val token_source: string -> (unit -> token list) -> unit
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    28
  val begin_theory: string -> string list -> (Path.T * bool) list -> theory -> theory
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    29
  val result: string -> string -> thm -> unit
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    30
  val results: string -> string -> thm list -> unit
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    31
  val theorem: string -> thm -> unit
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    32
  val theorems: string -> thm list -> unit
8088
6ae943d080de chapter;
wenzelm
parents: 7853
diff changeset
    33
  val chapter: string -> unit
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    34
  val subsection: string -> unit
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    35
  val subsubsection: string -> unit
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    36
  val setup: (theory -> theory) list
7763
fdf7c941a22b Exported function get_info.
berghofe
parents: 7757
diff changeset
    37
  val get_info: theory -> {session: string list, is_local: bool}
6203
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
    38
end;
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
    39
7685
3edd32d588a6 improved theory_source presentation (hook);
wenzelm
parents: 6325
diff changeset
    40
structure Present: PRESENT =
3edd32d588a6 improved theory_source presentation (hook);
wenzelm
parents: 6325
diff changeset
    41
struct
3edd32d588a6 improved theory_source presentation (hook);
wenzelm
parents: 6325
diff changeset
    42
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    43
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    44
(** paths **)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    45
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    46
val output_path = Path.variable "ISABELLE_BROWSER_INFO";
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    47
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    48
val tex_ext = Path.ext "tex";
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    49
val tex_path = tex_ext o Path.basic;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    50
val html_ext = Path.ext "html";
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    51
val html_path = html_ext o Path.basic;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    52
val graph_path = Path.ext "graph" o Path.basic;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    53
val index_path = Path.basic "index.html";
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    54
val doc_path = Path.basic "document";
8196
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
    55
val doc_indexN = "session";
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    56
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    57
val session_path = Path.basic ".session";
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    58
val session_entries_path = Path.unpack ".session/entries";
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    59
val pre_index_path = Path.unpack ".session/pre-index";
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    60
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
    61
fun mk_rel_path [] ys = Path.make ys
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
    62
  | mk_rel_path xs [] = Path.appends (replicate (length xs) Path.parent)
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
    63
  | mk_rel_path (ps as x::xs) (qs as y::ys) = if x=y then mk_rel_path xs ys else
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
    64
      Path.appends (replicate (length ps) Path.parent @ [Path.make qs]);
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    65
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    66
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    67
(** additional theory data **)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    68
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    69
structure BrowserInfoArgs =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    70
struct
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    71
  val name = "Pure/browser_info";
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    72
  type T = {session: string list, is_local: bool};
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    73
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    74
  val empty = {session = [], is_local = false};
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    75
  val copy = I;
7763
fdf7c941a22b Exported function get_info.
berghofe
parents: 7757
diff changeset
    76
  fun prep_ext _ = empty;
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    77
  fun merge _ = empty;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    78
  fun print _ _ = ();
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    79
end;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    80
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    81
structure BrowserInfoData = TheoryDataFun(BrowserInfoArgs);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    82
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    83
fun get_info thy =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    84
  if Theory.eq_thy (thy, ProtoPure.thy) then BrowserInfoArgs.empty
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    85
  else BrowserInfoData.get thy;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    86
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    87
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    88
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    89
(** graphs **)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    90
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    91
type graph_node =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    92
  {name: string, ID: string, dir: string, unfold: bool,
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    93
   path: string, parents: string list};
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    94
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    95
fun get_graph path = map (fn (a :: b :: c :: d :: e :: r) =>
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    96
  {name = unenclose a, ID = unenclose b,
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    97
   dir = unenclose c, unfold = (d = "+"),
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    98
   path = unenclose (if d = "+" then e else d),
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
    99
   parents = map unenclose (fst (split_last (if d = "+" then tl r else r)))})
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   100
     (map (filter_out (equal "") o space_explode " ") (split_lines (File.read path)));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   101
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   102
fun put_graph gr path =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   103
    File.write path (cat_lines (map (fn {name, ID, dir, unfold, path, parents} =>
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   104
      "\"" ^ name ^ "\" \"" ^ ID ^ "\" \"" ^ dir ^ (if unfold then "\" + \"" else "\" \"") ^
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   105
      path ^ "\" > " ^ space_implode " " (map quote parents) ^ " ;") gr));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   106
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   107
fun dir_of sess = space_implode "/" (case sess of
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   108
  [] => ["Pure"] | [x] => [x, "base"] | xs => xs);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   109
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   110
fun ID_of sess s = dir_of sess ^ "/" ^ s;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   111
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   112
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   113
(* retrieve graph data from theory loader database *)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   114
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   115
fun make_graph remote_path unfold curr_sess = map (fn name =>
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   116
  let
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   117
    val {session, is_local} = get_info (ThyInfo.theory name);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   118
    val path' = Path.append (Path.make session) (html_path name)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   119
  in
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   120
    {name = name, ID = ID_of session name, dir = dir_of session,
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   121
     path = if null session then "" else
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   122
            if is_some remote_path andalso not is_local then
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   123
              Url.pack (Url.append (the remote_path) (Url.file
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   124
                (Path.append (Path.make session) (html_path name))))
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   125
            else Path.pack (Path.append
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   126
              (mk_rel_path curr_sess session) (html_path name)),
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   127
     unfold = unfold andalso (length session = 1),
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   128
     parents = map (fn s => ID_of (#session (get_info (ThyInfo.theory s))) s)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   129
       (ThyInfo.get_preds name)}
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   130
  end) (ThyInfo.names ());
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   131
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   132
fun add_graph_entry' (entry as {ID, ...}) (gr : graph_node list) =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   133
  filter_out (fn entry' => #ID entry' = ID) gr @ [entry];
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   134
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   135
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   136
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   137
(** global browser info state **)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   138
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   139
(* type theory_info *)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   140
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   141
type theory_info = {tex_source: Buffer.T, html_source: Buffer.T, html: Buffer.T};
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   142
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   143
fun make_theory_info (tex_source, html_source, html) =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   144
  {tex_source = tex_source, html_source = html_source, html = html}: theory_info;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   145
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   146
val empty_theory_info = make_theory_info (Buffer.empty, Buffer.empty, Buffer.empty);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   147
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   148
fun map_theory_info f {tex_source, html_source, html} =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   149
  make_theory_info (f (tex_source, html_source, html));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   150
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   151
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   152
(* type browser_info *)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   153
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   154
type browser_info = {theories: theory_info Symtab.table, tex_index: Buffer.T,
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   155
  html_index: Buffer.T, graph: graph_node list, all_graph: graph_node list};
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   156
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   157
fun make_browser_info (theories, tex_index, html_index, graph, all_graph) =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   158
  {theories = theories, tex_index = tex_index, html_index = html_index,
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   159
    graph = graph, all_graph = all_graph}: browser_info;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   160
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   161
val empty_browser_info = make_browser_info (Symtab.empty, Buffer.empty, Buffer.empty, [], []);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   162
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   163
fun initial_browser_info remote_path graph_path curr_sess = make_browser_info
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   164
  (Symtab.empty, Buffer.empty, Buffer.empty, make_graph remote_path false curr_sess,
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   165
   if_none (try get_graph graph_path) (make_graph remote_path true [hd curr_sess]));
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   166
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   167
fun map_browser_info f {theories, tex_index, html_index, graph, all_graph} =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   168
  make_browser_info (f (theories, tex_index, html_index, graph, all_graph));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   169
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   170
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   171
(* state *)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   172
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   173
val browser_info = ref empty_browser_info;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   174
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   175
fun change_browser_info f = browser_info := map_browser_info f (! browser_info);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   176
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   177
fun init_theory_info name info =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   178
  change_browser_info (fn (theories, tex_index, html_index, graph, all_graph) =>
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   179
    (Symtab.update ((name, info), theories), tex_index, html_index, graph, all_graph));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   180
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   181
fun change_theory_info name f =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   182
  change_browser_info (fn (info as (theories, tex_index, html_index, graph, all_graph)) =>
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   183
    (case Symtab.lookup (theories, name) of
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   184
      None => (warning ("Browser info: cannot access theory document " ^ quote name); info)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   185
    | Some info => (Symtab.update ((name, map_theory_info f info), theories),
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   186
        tex_index, html_index, graph, all_graph)));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   187
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   188
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   189
fun add_tex_index txt =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   190
  change_browser_info (fn (theories, tex_index, html_index, graph, all_graph) =>
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   191
    (theories, Buffer.add txt tex_index, html_index, graph, all_graph));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   192
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   193
fun add_html_index txt =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   194
  change_browser_info (fn (theories, tex_index, html_index, graph, all_graph) =>
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   195
    (theories, tex_index, Buffer.add txt html_index, graph, all_graph));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   196
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   197
(*add entry to graph for current session*)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   198
fun add_graph_entry e =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   199
  change_browser_info (fn (theories, tex_index, html_index, graph, all_graph) =>
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   200
    (theories, tex_index, html_index, add_graph_entry' e graph, all_graph));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   201
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   202
(*add entry to graph for all sessions*)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   203
fun add_all_graph_entry e =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   204
  change_browser_info (fn (theories, tex_index, html_index, graph, all_graph) =>
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   205
    (theories, tex_index, html_index, graph, add_graph_entry' e all_graph));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   206
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   207
fun add_tex_source name txt = change_theory_info name (fn (tex_source, html_source, html) =>
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   208
  (Buffer.add txt tex_source, html_source, html));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   209
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   210
fun add_html_source name txt = change_theory_info name (fn (tex_source, html_source, html) =>
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   211
  (tex_source, Buffer.add txt html_source, html));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   212
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   213
fun add_html name txt = change_theory_info name (fn (tex_source, html_source, html) =>
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   214
  (tex_source, html_source, Buffer.add txt html));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   215
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   216
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   217
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   218
(** global session state **)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   219
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   220
(* session_info *)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   221
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   222
type session_info =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   223
  {name: string, parent: string, session: string, path: string list, html_prefix: Path.T,
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   224
    doc_format: string, doc_prefixes: (Path.T * Path.T option) option,
8196
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   225
    all_graph_path: Path.T, remote_path: Url.T option};
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   226
8196
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   227
fun make_session_info (name, parent, session, path, html_prefix, doc_format, doc_prefixes,
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   228
    all_graph_path, remote_path) =
7802
fba7a36e8556 isatool_document;
wenzelm
parents: 7789
diff changeset
   229
  {name = name, parent = parent, session = session, path = path, html_prefix = html_prefix,
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   230
    doc_format = doc_format, doc_prefixes = doc_prefixes,
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   231
    all_graph_path = all_graph_path, remote_path = remote_path}: session_info;
7685
3edd32d588a6 improved theory_source presentation (hook);
wenzelm
parents: 6325
diff changeset
   232
3edd32d588a6 improved theory_source presentation (hook);
wenzelm
parents: 6325
diff changeset
   233
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   234
(* state *)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   235
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   236
val session_info = ref (None: session_info option);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   237
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   238
fun with_session x f = (case ! session_info of None => x | Some info => f info);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   239
fun with_context f = f (PureThy.get_name (Context.the_context ()));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   240
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   241
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   242
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   243
(** HTML output **)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   244
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   245
(* maintain index *)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   246
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   247
val session_entries =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   248
  HTML.session_entries o
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   249
    map (fn name => (Url.file (Path.append (Path.basic name) index_path), name));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   250
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   251
fun get_entries dir =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   252
  split_lines (File.read (Path.append dir session_entries_path));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   253
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   254
fun put_entries entries dir =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   255
  File.write (Path.append dir session_entries_path) (cat_lines entries);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   256
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   257
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   258
fun create_index dir =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   259
  File.read (Path.append dir pre_index_path) ^
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   260
    session_entries (get_entries dir) ^ HTML.end_index
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   261
  |> File.write (Path.append dir index_path);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   262
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   263
fun update_index dir name =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   264
  (case try get_entries dir of
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   265
    None => warning ("Browser info: cannot access session index of " ^ quote (Path.pack dir))
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   266
  | Some es => (put_entries ((es \ name) @ [name]) dir; create_index dir));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   267
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   268
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   269
(* init session *)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   270
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   271
fun name_of_session elems = space_implode "/" ("Isabelle" :: elems);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   272
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   273
fun could_copy inpath outpath =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   274
  if File.exists inpath then (File.copy inpath outpath; true)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   275
  else false;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   276
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   277
fun copy_files path1 path2 =
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   278
  (File.mkdir path2;
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   279
   File.system_command
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   280
     ("cp " ^ File.sysify_path path1 ^ " " ^ File.sysify_path path2));
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   281
8196
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   282
fun init false _ _ _ _ _ = (browser_info := empty_browser_info; session_info := None)
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   283
  | init true doc path name dump_path (remote_path, first_time) =
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   284
      let
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   285
        val parent_name = name_of_session (take (length path - 1, path));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   286
        val session_name = name_of_session path;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   287
        val sess_prefix = Path.make path;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   288
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   289
        val out_path = Path.expand output_path;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   290
        val html_prefix = Path.append out_path sess_prefix;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   291
8196
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   292
        val (doc_prefixes, document_path) =
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   293
          if doc = "" then (None, None)
8196
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   294
          else (Some (Path.append html_prefix doc_path, dump_path), Some (Path.ext doc doc_path));
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   295
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   296
        val graph_up_lnk = (Url.file index_path, session_name);
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   297
        val all_graph_path = Path.appends [out_path,
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   298
          Path.basic (hd path), graph_path "all_sessions"];
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   299
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   300
        val _ =
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   301
          (copy_files (Path.unpack "~~/lib/browser/awtUtilities/*.class")
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   302
             (Path.append html_prefix (Path.basic "awtUtilities"));
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   303
           copy_files (Path.unpack "~~/lib/browser/GraphBrowser/*.class")
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   304
             (Path.append html_prefix (Path.basic "GraphBrowser")));
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   305
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   306
        fun prep_readme readme =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   307
          let val readme_path = Path.basic readme in
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   308
            if could_copy readme_path (Path.append html_prefix readme_path) then Some readme_path
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   309
            else None
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   310
          end;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   311
        val opt_readme =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   312
          (case prep_readme "README.html" of None => prep_readme "README" | some => some);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   313
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   314
        val parent_index_path = Path.append Path.parent index_path;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   315
        val index_up_lnk = if first_time then
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   316
            Url.append (the remote_path) (Url.file (Path.append sess_prefix parent_index_path))
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   317
          else Url.file parent_index_path;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   318
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   319
        val index_text = HTML.begin_index (index_up_lnk, parent_name)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   320
          (Url.file index_path, session_name) (apsome Url.file opt_readme)
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   321
            (apsome Url.file document_path) (Url.unpack "medium.html");
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   322
      in
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   323
        File.mkdir (Path.append html_prefix session_path);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   324
        File.write (Path.append html_prefix session_entries_path) "";
8196
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   325
        if is_some doc_prefixes then File.copy_all doc_path html_prefix else ();
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   326
        seq (fn (name, txt) => File.write (Path.append html_prefix (Path.basic name)) txt)
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   327
          (HTML.applet_pages session_name graph_up_lnk (length path = 1));
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   328
        session_info := Some (make_session_info (name, parent_name, session_name, path,
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   329
          html_prefix, doc, doc_prefixes, all_graph_path, remote_path));
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   330
        browser_info := initial_browser_info remote_path all_graph_path path;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   331
        add_html_index index_text
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   332
      end;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   333
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   334
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   335
(* finish session *)
7685
3edd32d588a6 improved theory_source presentation (hook);
wenzelm
parents: 6325
diff changeset
   336
7802
fba7a36e8556 isatool_document;
wenzelm
parents: 7789
diff changeset
   337
fun isatool_document doc_format doc_prefix =
8646
1a2c5ccebfdb isatool document: check output file (workaround PolyML problem with RC);
wenzelm
parents: 8499
diff changeset
   338
  let
1a2c5ccebfdb isatool document: check output file (workaround PolyML problem with RC);
wenzelm
parents: 8499
diff changeset
   339
    val cmd = "$ISATOOL document -c -o '" ^ doc_format ^ "' '" ^ File.sysify_path doc_prefix ^ "'";
1a2c5ccebfdb isatool document: check output file (workaround PolyML problem with RC);
wenzelm
parents: 8499
diff changeset
   340
  in
1a2c5ccebfdb isatool document: check output file (workaround PolyML problem with RC);
wenzelm
parents: 8499
diff changeset
   341
    writeln cmd;
1a2c5ccebfdb isatool document: check output file (workaround PolyML problem with RC);
wenzelm
parents: 8499
diff changeset
   342
    if system cmd <> 0 orelse not (File.exists (Path.ext doc_format doc_prefix)) then
1a2c5ccebfdb isatool document: check output file (workaround PolyML problem with RC);
wenzelm
parents: 8499
diff changeset
   343
      error "Failed to build document"
1a2c5ccebfdb isatool document: check output file (workaround PolyML problem with RC);
wenzelm
parents: 8499
diff changeset
   344
    else ()
1a2c5ccebfdb isatool document: check output file (workaround PolyML problem with RC);
wenzelm
parents: 8499
diff changeset
   345
  end;
7802
fba7a36e8556 isatool_document;
wenzelm
parents: 7789
diff changeset
   346
8196
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   347
fun write_tex src name path = Buffer.write (Path.append path (tex_path name)) src;
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   348
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   349
fun write_texes src name (path, None) = write_tex src name path
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   350
  | write_texes src name (path, Some path') = (write_tex src name path; write_tex src name path');
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   351
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   352
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   353
fun finish () = with_session ()
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   354
    (fn {name, html_prefix, doc_format, doc_prefixes, all_graph_path, path, ...} =>
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   355
  let
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   356
    val {theories, tex_index, html_index, graph, all_graph} = ! browser_info;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   357
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   358
    fun finish_node (a, {tex_source, html_source = _, html}) =
8196
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   359
     (doc_prefixes |> apsome (write_texes tex_source a);
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   360
      Buffer.write (Path.append html_prefix (html_path a)) (Buffer.add HTML.end_theory html));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   361
  in
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   362
    seq finish_node (Symtab.dest theories);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   363
    Buffer.write (Path.append html_prefix pre_index_path) html_index;
8196
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   364
    doc_prefixes |> apsome (write_texes tex_index doc_indexN);
ecb9decd38ac additional tex dump;
wenzelm
parents: 8192
diff changeset
   365
    doc_prefixes |> apsome (isatool_document doc_format o #1);
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   366
    put_graph graph (Path.append html_prefix (graph_path "session"));
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   367
    put_graph all_graph all_graph_path;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   368
    create_index html_prefix;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   369
    update_index (Path.append html_prefix Path.parent) name;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   370
    browser_info := empty_browser_info;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   371
    session_info := None
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   372
  end);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   373
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   374
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   375
(* theory elements *)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   376
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   377
fun init_theory name = with_session () (fn _ => init_theory_info name empty_theory_info);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   378
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   379
fun verbatim_source name mk_text =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   380
  with_session () (fn _ => add_html_source name (HTML.verbatim_source (mk_text ())));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   381
7757
b2538dccc21e Latex.token;
wenzelm
parents: 7752
diff changeset
   382
b2538dccc21e Latex.token;
wenzelm
parents: 7752
diff changeset
   383
type token = Latex.token;
b2538dccc21e Latex.token;
wenzelm
parents: 7752
diff changeset
   384
val basic_token = Latex.Basic;
b2538dccc21e Latex.token;
wenzelm
parents: 7752
diff changeset
   385
val markup_token = Latex.Markup;
8660
e5048a26e1d8 support markup environments;
wenzelm
parents: 8646
diff changeset
   386
val markup_env_token = Latex.MarkupEnv;
7789
57d20133224e verbatim markup tokens;
wenzelm
parents: 7769
diff changeset
   387
val verbatim_token = Latex.Verbatim;
7757
b2538dccc21e Latex.token;
wenzelm
parents: 7752
diff changeset
   388
8192
45a7027136e3 added old_symbol_source;
wenzelm
parents: 8088
diff changeset
   389
fun old_symbol_source name mk_text =
8499
8958ece3bbdf old_symbol_source: include header;
wenzelm
parents: 8219
diff changeset
   390
  with_session () (fn _ => add_tex_source name (Latex.old_symbol_source name (mk_text ())));
8192
45a7027136e3 added old_symbol_source;
wenzelm
parents: 8088
diff changeset
   391
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   392
fun token_source name mk_toks =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   393
  with_session () (fn _ => add_tex_source name (Latex.token_source (mk_toks ())));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   394
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   395
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   396
fun parent_link remote_path curr_session name =
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   397
  let val {session, is_local} = get_info (ThyInfo.theory name)
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   398
  in (if null session then None else
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   399
     Some (if is_some remote_path andalso not is_local then
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   400
       Url.append (the remote_path) (Url.file
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   401
         (Path.append (Path.make session) (html_path name)))
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   402
     else Url.file (Path.append (mk_rel_path curr_session session)
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   403
       (html_path name))), name)
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   404
  end;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   405
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   406
fun begin_theory name raw_parents orig_files thy =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   407
  with_session thy (fn {session, path, html_prefix, remote_path, ...} =>
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   408
  let
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   409
    val parents = map (parent_link remote_path path) raw_parents;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   410
    val ml_path = ThyLoad.ml_path name;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   411
    val files = map (apsnd Some) orig_files @
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   412
      (if is_some (ThyLoad.check_file ml_path) then [(ml_path, None)] else []);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   413
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   414
    fun prep_file (raw_path, loadit) =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   415
      (case ThyLoad.check_file raw_path of
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   416
        Some (path, _) =>
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   417
          let
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   418
            val base = Path.base path;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   419
            val base_html = html_ext base;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   420
          in
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   421
            File.write (Path.append html_prefix base_html)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   422
              (HTML.ml_file (Url.file base) (File.read path));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   423
            (Some (Url.file base_html), Url.file raw_path, loadit)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   424
          end
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   425
      | None => (warning ("Browser info: expected to find ML file" ^ quote (Path.pack raw_path));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   426
          (None, Url.file raw_path, loadit)));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   427
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   428
    val files_html = map prep_file files;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   429
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   430
    fun prep_html_source (tex_source, html_source, html) =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   431
      let
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   432
        val txt = HTML.begin_theory (Url.file index_path, session)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   433
          name parents files_html (Buffer.content html_source)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   434
      in (tex_source, Buffer.empty, Buffer.add txt html) end;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   435
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   436
    fun make_entry unfold all =
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   437
      {name = name, ID = ID_of path name, dir = dir_of path, unfold = unfold,
9044
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   438
       path = Path.pack (Path.append
28ee037278a6 Reorganized graph stuff.
berghofe
parents: 8808
diff changeset
   439
         (mk_rel_path (if all then [hd path] else path) path) (html_path name)),
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   440
       parents = map (fn s => ID_of (#session (get_info (ThyInfo.theory s))) s) raw_parents};
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   441
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   442
  in
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   443
    change_theory_info name prep_html_source;
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   444
    add_all_graph_entry (make_entry (length path = 1) true);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   445
    add_graph_entry (make_entry true false);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   446
    add_html_index (HTML.theory_entry (Url.file (html_path name), name));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   447
    add_tex_index (Latex.theory_entry name);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   448
    BrowserInfoData.put {session = path, is_local = is_some remote_path} thy
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   449
  end);
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   450
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   451
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   452
fun result k a thm = with_session () (fn _ => with_context add_html (HTML.result k a thm));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   453
fun results k a thms = with_session () (fn _ => with_context add_html (HTML.results k a thms));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   454
fun theorem a thm = with_session () (fn _ => with_context add_html (HTML.theorem a thm));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   455
fun theorems a thms = with_session () (fn _ => with_context add_html (HTML.theorems a thms));
8088
6ae943d080de chapter;
wenzelm
parents: 7853
diff changeset
   456
fun chapter s = with_session () (fn _ => with_context add_html (HTML.chapter s));
7727
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   457
fun section s = with_session () (fn _ => with_context add_html (HTML.section s));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   458
fun subsection s = with_session () (fn _ => with_context add_html (HTML.subsection s));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   459
fun subsubsection s = with_session () (fn _ => with_context add_html (HTML.subsubsection s));
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   460
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   461
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   462
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   463
(** theory setup **)
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   464
b52c7d773121 include browser_info stuff;
wenzelm
parents: 7685
diff changeset
   465
val setup = [BrowserInfoData.init];
7685
3edd32d588a6 improved theory_source presentation (hook);
wenzelm
parents: 6325
diff changeset
   466
3edd32d588a6 improved theory_source presentation (hook);
wenzelm
parents: 6325
diff changeset
   467
3edd32d588a6 improved theory_source presentation (hook);
wenzelm
parents: 6325
diff changeset
   468
end;
3edd32d588a6 improved theory_source presentation (hook);
wenzelm
parents: 6325
diff changeset
   469
6203
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
   470
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
   471
structure BasicPresent: BASIC_PRESENT = Present;
328b4377755c Theory presentation (fake implementation);
wenzelm
parents:
diff changeset
   472
open BasicPresent;