src/Pure/Thy/browser_info.ML
changeset 6665 bf421d724db7
parent 6649 2156012be986
child 7236 e077484d50d8
equal deleted inserted replaced
6664:f679ddd1ddd8 6665:bf421d724db7
    23 end;
    23 end;
    24 
    24 
    25 structure BrowserInfo: BROWSER_INFO =
    25 structure BrowserInfo: BROWSER_INFO =
    26 struct
    26 struct
    27 
    27 
       
    28 
    28 (** paths **)
    29 (** paths **)
    29 
    30 
    30 val output_path = Path.variable "ISABELLE_BROWSER_INFO";
    31 val output_path = Path.variable "ISABELLE_BROWSER_INFO";
    31 
    32 
    32 fun top_path sess_path offset = Path.append (Path.appends (replicate (offset + length sess_path) Path.parent));
    33 fun top_path sess_path offset = Path.append (Path.appends (replicate (offset + length sess_path) Path.parent));
    37 val index_path = Path.basic "index.html";
    38 val index_path = Path.basic "index.html";
    38 
    39 
    39 val session_path = Path.basic ".session";
    40 val session_path = Path.basic ".session";
    40 val session_entries_path = Path.unpack ".session/entries";
    41 val session_entries_path = Path.unpack ".session/entries";
    41 val pre_index_path = Path.unpack ".session/pre-index";
    42 val pre_index_path = Path.unpack ".session/pre-index";
       
    43 
    42 
    44 
    43 
    45 
    44 (** additional theory data **)
    46 (** additional theory data **)
    45 
    47 
    46 structure BrowserInfoArgs =
    48 structure BrowserInfoArgs =
    54   fun merge _ = empty;
    56   fun merge _ = empty;
    55   fun print _ _ = ();
    57   fun print _ _ = ();
    56 end;
    58 end;
    57 
    59 
    58 structure BrowserInfoData = TheoryDataFun(BrowserInfoArgs);
    60 structure BrowserInfoData = TheoryDataFun(BrowserInfoArgs);
    59 val setup = [BrowserInfoData.init];
    61 
    60 fun get_info thy = if PureThy.get_name thy = "ProtoPure" then BrowserInfoArgs.empty
    62 fun get_info thy =
    61   else BrowserInfoData.get thy;  (** FIXME!? **)
    63   if Theory.eq_thy (thy, ProtoPure.thy) then BrowserInfoArgs.empty
       
    64   else BrowserInfoData.get thy;
       
    65 
       
    66 
    62 
    67 
    63 (** graphs **)
    68 (** graphs **)
    64 
    69 
    65 type graph_node =
    70 type graph_node =
    66   {name: string, ID: string, dir: string, unfold: bool,
    71   {name: string, ID: string, dir: string, unfold: bool,
   101 
   106 
   102 fun add_graph_entry' (entry as {ID, ...}) (gr : graph_node list) =
   107 fun add_graph_entry' (entry as {ID, ...}) (gr : graph_node list) =
   103   filter_out (fn entry' => #ID entry' = ID) gr @ [entry];
   108   filter_out (fn entry' => #ID entry' = ID) gr @ [entry];
   104 
   109 
   105 
   110 
       
   111 
   106 (** global browser info state **)
   112 (** global browser info state **)
   107 
   113 
   108 (* type theory_info *)
   114 (* type theory_info *)
   109 
   115 
   110 type theory_info = {source: Buffer.T, html: Buffer.T};
   116 type theory_info = {source: Buffer.T, html: Buffer.T};
   151 
   157 
   152 
   158 
   153 fun add_index txt = change_browser_info (fn (theories, index, graph, all_graph) =>
   159 fun add_index txt = change_browser_info (fn (theories, index, graph, all_graph) =>
   154   (theories, Buffer.add txt index, graph, all_graph));
   160   (theories, Buffer.add txt index, graph, all_graph));
   155 
   161 
   156 (** add entry to graph for current session **)
   162 (*add entry to graph for current session*)
   157 fun add_graph_entry e = change_browser_info (fn (theories, index, graph, all_graph) =>
   163 fun add_graph_entry e = change_browser_info (fn (theories, index, graph, all_graph) =>
   158   (theories, index, add_graph_entry' e graph, all_graph));
   164   (theories, index, add_graph_entry' e graph, all_graph));
   159 
   165 
   160 (** add entry to graph for all sessions **)
   166 (*add entry to graph for all sessions*)
   161 fun add_all_graph_entry e = change_browser_info (fn (theories, index, graph, all_graph) =>
   167 fun add_all_graph_entry e = change_browser_info (fn (theories, index, graph, all_graph) =>
   162   (theories, index, graph, add_graph_entry' e all_graph));
   168   (theories, index, graph, add_graph_entry' e all_graph));
   163 
   169 
   164 fun add_source name txt = change_theory_info name (fn (source, html) =>
   170 fun add_source name txt = change_theory_info name (fn (source, html) =>
   165   (Buffer.add txt source, html));
   171   (Buffer.add txt source, html));
   166 
   172 
   167 fun add_html name txt = change_theory_info name (fn (source, html) =>
   173 fun add_html name txt = change_theory_info name (fn (source, html) =>
   168   (source, Buffer.add txt html));
   174   (source, Buffer.add txt html));
       
   175 
   169 
   176 
   170 
   177 
   171 (** global session state **)
   178 (** global session state **)
   172 
   179 
   173 (* session_info *)
   180 (* session_info *)
   186 
   193 
   187 val session_info = ref (None: session_info option);
   194 val session_info = ref (None: session_info option);
   188 
   195 
   189 fun with_session x f = (case ! session_info of None => x | Some info => f info);
   196 fun with_session x f = (case ! session_info of None => x | Some info => f info);
   190 fun with_context f = f (PureThy.get_name (Context.the_context ()));
   197 fun with_context f = f (PureThy.get_name (Context.the_context ()));
       
   198 
   191 
   199 
   192 
   200 
   193 (** HTML output **)
   201 (** HTML output **)
   194 
   202 
   195 (* maintain index *)
   203 (* maintain index *)
   346 
   354 
   347 fun theorem name thm = with_session () (fn _ => with_context add_html (HTML.theorem name thm));
   355 fun theorem name thm = with_session () (fn _ => with_context add_html (HTML.theorem name thm));
   348 fun section s = with_session () (fn _ => with_context add_html (HTML.section s));
   356 fun section s = with_session () (fn _ => with_context add_html (HTML.section s));
   349 
   357 
   350 
   358 
       
   359 
       
   360 (** theory setup **)
       
   361 
       
   362 val setup = [BrowserInfoData.init];
       
   363 
       
   364 
   351 end;
   365 end;
   352