16 val global_theory: string -> string option |
16 val global_theory: string -> string option |
17 val loaded_theory: string -> string option |
17 val loaded_theory: string -> string option |
18 val known_theory: string -> Path.T option |
18 val known_theory: string -> Path.T option |
19 val master_directory: theory -> Path.T |
19 val master_directory: theory -> Path.T |
20 val imports_of: theory -> (string * Position.T) list |
20 val imports_of: theory -> (string * Position.T) list |
|
21 val begin_theory: Path.T -> Thy_Header.header -> theory list -> theory |
21 val thy_path: Path.T -> Path.T |
22 val thy_path: Path.T -> Path.T |
22 val theory_qualifier: string -> string |
23 val theory_qualifier: string -> string |
23 val import_name: string -> Path.T -> string -> |
24 val import_name: string -> Path.T -> string -> |
24 {node_name: Path.T, master_dir: Path.T, theory_name: string} |
25 {node_name: Path.T, master_dir: Path.T, theory_name: string} |
25 val check_thy: Path.T -> string -> |
26 val check_thy: Path.T -> string -> |
27 imports: (string * Position.T) list, keywords: Thy_Header.keywords} |
28 imports: (string * Position.T) list, keywords: Thy_Header.keywords} |
28 val parse_files: string -> (theory -> Token.file list) parser |
29 val parse_files: string -> (theory -> Token.file list) parser |
29 val provide: Path.T * SHA1.digest -> theory -> theory |
30 val provide: Path.T * SHA1.digest -> theory -> theory |
30 val provide_parse_files: string -> (theory -> Token.file list * theory) parser |
31 val provide_parse_files: string -> (theory -> Token.file list * theory) parser |
31 val loaded_files_current: theory -> bool |
32 val loaded_files_current: theory -> bool |
32 val begin_theory: Path.T -> Thy_Header.header -> theory list -> theory |
|
33 val load_thy: bool -> HTML.symbols -> (Toplevel.transition -> Time.time) -> int -> |
|
34 Path.T -> Thy_Header.header -> Position.T -> string -> theory list -> |
|
35 theory * (unit -> unit) * int |
|
36 end; |
33 end; |
37 |
34 |
38 structure Resources: RESOURCES = |
35 structure Resources: RESOURCES = |
39 struct |
36 struct |
40 |
37 |
99 |
96 |
100 |
97 |
101 val master_directory = #master_dir o Files.get; |
98 val master_directory = #master_dir o Files.get; |
102 val imports_of = #imports o Files.get; |
99 val imports_of = #imports o Files.get; |
103 |
100 |
104 fun put_deps master_dir imports = map_files (fn _ => (master_dir, imports, [])); |
101 fun begin_theory master_dir {name, imports, keywords} parents = |
|
102 Theory.begin_theory name parents |
|
103 |> map_files (fn _ => (master_dir, imports, [])) |
|
104 |> Thy_Header.add_keywords keywords; |
105 |
105 |
106 |
106 |
107 (* theory files *) |
107 (* theory files *) |
108 |
108 |
109 val thy_path = Path.ext "thy"; |
109 val thy_path = Path.ext "thy"; |
195 #provided (Files.get thy) |> |
195 #provided (Files.get thy) |> |
196 forall (fn (src_path, id) => |
196 forall (fn (src_path, id) => |
197 (case try (load_file thy) src_path of |
197 (case try (load_file thy) src_path of |
198 NONE => false |
198 NONE => false |
199 | SOME ((_, id'), _) => id = id')); |
199 | SOME ((_, id'), _) => id = id')); |
200 |
|
201 |
|
202 (* load theory *) |
|
203 |
|
204 fun begin_theory master_dir {name, imports, keywords} parents = |
|
205 Theory.begin_theory name parents |
|
206 |> put_deps master_dir imports |
|
207 |> Thy_Header.add_keywords keywords; |
|
208 |
|
209 fun excursion keywords master_dir last_timing init elements = |
|
210 let |
|
211 fun prepare_span st span = |
|
212 Command_Span.content span |
|
213 |> Command.read keywords (Command.read_thy st) master_dir init ([], ~1) |
|
214 |> (fn tr => Toplevel.put_timing (last_timing tr) tr); |
|
215 |
|
216 fun element_result span_elem (st, _) = |
|
217 let |
|
218 val elem = Thy_Syntax.map_element (prepare_span st) span_elem; |
|
219 val (results, st') = Toplevel.element_result keywords elem st; |
|
220 val pos' = Toplevel.pos_of (Thy_Syntax.last_element elem); |
|
221 in (results, (st', pos')) end; |
|
222 |
|
223 val (results, (end_state, end_pos)) = |
|
224 fold_map element_result elements (Toplevel.toplevel, Position.none); |
|
225 |
|
226 val thy = Toplevel.end_theory end_pos end_state; |
|
227 in (results, thy) end; |
|
228 |
|
229 fun load_thy document symbols last_timing update_time master_dir header text_pos text parents = |
|
230 let |
|
231 val (name, _) = #name header; |
|
232 val keywords = |
|
233 fold (curry Keyword.merge_keywords o Thy_Header.get_keywords) parents |
|
234 (Keyword.add_keywords (#keywords header) Keyword.empty_keywords); |
|
235 |
|
236 val toks = Token.explode keywords text_pos text; |
|
237 val spans = Outer_Syntax.parse_spans toks; |
|
238 val elements = Thy_Syntax.parse_elements keywords spans; |
|
239 |
|
240 fun init () = |
|
241 begin_theory master_dir header parents |
|
242 |> Present.begin_theory update_time |
|
243 (fn () => implode (map (HTML.present_span symbols keywords) spans)); |
|
244 |
|
245 val (results, thy) = |
|
246 cond_timeit true ("theory " ^ quote name) |
|
247 (fn () => excursion keywords master_dir last_timing init elements); |
|
248 |
|
249 fun present () = |
|
250 let |
|
251 val res = filter_out (Toplevel.is_ignored o #1) (maps Toplevel.join_results results); |
|
252 in |
|
253 if exists (Toplevel.is_skipped_proof o #2) res then |
|
254 warning ("Cannot present theory with skipped proofs: " ^ quote name) |
|
255 else |
|
256 let val tex_source = Thy_Output.present_thy thy res toks |> Buffer.content; |
|
257 in if document then Present.theory_output (Long_Name.base_name name) tex_source else () end |
|
258 end; |
|
259 |
|
260 in (thy, present, size text) end; |
|
261 |
200 |
262 |
201 |
263 (* antiquotations *) |
202 (* antiquotations *) |
264 |
203 |
265 local |
204 local |