5 *) |
5 *) |
6 |
6 |
7 signature THY_LOAD = |
7 signature THY_LOAD = |
8 sig |
8 sig |
9 val master_directory: theory -> Path.T |
9 val master_directory: theory -> Path.T |
10 val imports_of: theory -> string list |
10 val imports_of: theory -> (string * Position.T) list |
11 val thy_path: Path.T -> Path.T |
11 val thy_path: Path.T -> Path.T |
12 val parse_files: string -> (theory -> Token.file list) parser |
12 val parse_files: string -> (theory -> Token.file list) parser |
13 val check_thy: Path.T -> string -> |
13 val check_thy: Path.T -> string -> |
14 {master: Path.T * SHA1.digest, text: string, imports: string list, |
14 {master: Path.T * SHA1.digest, text: string, imports: (string * Position.T) list, |
15 uses: (Path.T * bool) list, keywords: Thy_Header.keywords} |
15 uses: (Path.T * bool) list, keywords: Thy_Header.keywords} |
16 val provide: Path.T * SHA1.digest -> theory -> theory |
16 val provide: Path.T * SHA1.digest -> theory -> theory |
17 val provide_parse_files: string -> (theory -> Token.file list * theory) parser |
17 val provide_parse_files: string -> (theory -> Token.file list * theory) parser |
18 val load_file: theory -> Path.T -> (Path.T * SHA1.digest) * string |
18 val load_file: theory -> Path.T -> (Path.T * SHA1.digest) * string |
19 val use_file: Path.T -> theory -> string * theory |
19 val use_file: Path.T -> theory -> string * theory |
33 |
33 |
34 (* manage source files *) |
34 (* manage source files *) |
35 |
35 |
36 type files = |
36 type files = |
37 {master_dir: Path.T, (*master directory of theory source*) |
37 {master_dir: Path.T, (*master directory of theory source*) |
38 imports: string list, (*source specification of imports*) |
38 imports: (string * Position.T) list, (*source specification of imports*) |
39 provided: (Path.T * SHA1.digest) list}; (*source path, digest*) |
39 provided: (Path.T * SHA1.digest) list}; (*source path, digest*) |
40 |
40 |
41 fun make_files (master_dir, imports, provided): files = |
41 fun make_files (master_dir, imports, provided): files = |
42 {master_dir = master_dir, imports = imports, provided = provided}; |
42 {master_dir = master_dir, imports = imports, provided = provided}; |
43 |
43 |
130 let |
130 let |
131 val path = thy_path (Path.basic thy_name); |
131 val path = thy_path (Path.basic thy_name); |
132 val master_file = check_file dir path; |
132 val master_file = check_file dir path; |
133 val text = File.read master_file; |
133 val text = File.read master_file; |
134 |
134 |
135 val {name, imports, uses, keywords} = Thy_Header.read (Path.position master_file) text; |
135 val {name = (name, pos), imports, uses, keywords} = |
|
136 Thy_Header.read (Path.position master_file) text; |
136 val _ = thy_name <> name andalso |
137 val _ = thy_name <> name andalso |
137 error ("Bad file name " ^ Path.print path ^ " for theory " ^ quote name); |
138 error ("Bad file name " ^ Path.print path ^ " for theory " ^ quote name ^ Position.str_of pos); |
138 in |
139 in |
139 {master = (master_file, SHA1.digest text), text = text, |
140 {master = (master_file, SHA1.digest text), text = text, |
140 imports = imports, uses = uses, keywords = keywords} |
141 imports = imports, uses = uses, keywords = keywords} |
141 end; |
142 end; |
142 |
143 |
231 fold_map element_result elements (Toplevel.toplevel, Position.none); |
232 fold_map element_result elements (Toplevel.toplevel, Position.none); |
232 |
233 |
233 val thy = Toplevel.end_theory end_pos end_state; |
234 val thy = Toplevel.end_theory end_pos end_state; |
234 in (flat results, thy) end; |
235 in (flat results, thy) end; |
235 |
236 |
236 fun load_thy update_time master_dir header pos text parents = |
237 fun load_thy update_time master_dir header text_pos text parents = |
237 let |
238 let |
238 val time = ! Toplevel.timing; |
239 val time = ! Toplevel.timing; |
239 |
240 |
240 val {name, uses, ...} = header; |
241 val {name = (name, _), uses, ...} = header; |
241 val _ = Thy_Header.define_keywords header; |
242 val _ = Thy_Header.define_keywords header; |
242 val _ = Present.init_theory name; |
243 val _ = Present.init_theory name; |
243 fun init () = |
244 fun init () = |
244 begin_theory master_dir header parents |
245 begin_theory master_dir header parents |
245 |> Present.begin_theory update_time master_dir uses; |
246 |> Present.begin_theory update_time master_dir uses; |
246 |
247 |
247 val lexs = Keyword.get_lexicons (); |
248 val lexs = Keyword.get_lexicons (); |
248 |
249 |
249 val toks = Thy_Syntax.parse_tokens lexs pos text; |
250 val toks = Thy_Syntax.parse_tokens lexs text_pos text; |
250 val spans = map (resolve_files master_dir) (Thy_Syntax.parse_spans toks); |
251 val spans = map (resolve_files master_dir) (Thy_Syntax.parse_spans toks); |
251 val elements = Thy_Syntax.parse_elements spans; |
252 val elements = Thy_Syntax.parse_elements spans; |
252 |
253 |
253 val _ = Present.theory_source name |
254 val _ = Present.theory_source name |
254 (fn () => HTML.html_mode (implode o map Thy_Syntax.present_span) spans); |
255 (fn () => HTML.html_mode (implode o map Thy_Syntax.present_span) spans); |