author | wenzelm |
Sat, 16 Nov 2013 21:18:31 +0100 | |
changeset 54456 | f4b1440d9880 |
parent 54455 | 1d977436c1bf |
child 54458 | 96ccc8972fc7 |
permissions | -rw-r--r-- |
6168 | 1 |
(* Title: Pure/Thy/thy_load.ML |
42002 | 2 |
Author: Makarius |
6168 | 3 |
|
54454 | 4 |
Loading files that contribute to a theory. |
6168 | 5 |
*) |
6 |
||
7 |
signature THY_LOAD = |
|
8 |
sig |
|
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
9 |
val master_directory: theory -> Path.T |
48927
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents:
48924
diff
changeset
|
10 |
val imports_of: theory -> (string * Position.T) list |
46737 | 11 |
val thy_path: Path.T -> Path.T |
54451 | 12 |
val read_files: Path.T -> string -> Path.T * Position.T -> Token.file list |
48906 | 13 |
val parse_files: string -> (theory -> Token.file list) parser |
48898
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
14 |
val check_thy: Path.T -> string -> |
48928 | 15 |
{master: Path.T * SHA1.digest, text: string, theory_pos: Position.T, |
51293
05b1bbae748d
discontinued obsolete 'uses' within theory header;
wenzelm
parents:
51273
diff
changeset
|
16 |
imports: (string * Position.T) list, keywords: Thy_Header.keywords} |
48906 | 17 |
val provide: Path.T * SHA1.digest -> theory -> theory |
18 |
val provide_parse_files: string -> (theory -> Token.file list * theory) parser |
|
43702
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
19 |
val load_file: theory -> Path.T -> (Path.T * SHA1.digest) * string |
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
20 |
val loaded_files: theory -> Path.T list |
54446 | 21 |
val loaded_files_current: theory -> bool |
46938
cda018294515
some support for outer syntax keyword declarations within theory header;
wenzelm
parents:
46811
diff
changeset
|
22 |
val begin_theory: Path.T -> Thy_Header.header -> theory list -> theory |
51423
e5f9a6d9ca82
clarified parallel_subproofs_saturation (blind guess) vs. parallel_subproofs_threshold (precient timing estimate);
wenzelm
parents:
51332
diff
changeset
|
23 |
val load_thy: (Toplevel.transition -> Time.time option) -> int -> Path.T -> Thy_Header.header -> |
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51326
diff
changeset
|
24 |
Position.T -> string -> theory list -> theory * (unit -> unit) * int |
6168 | 25 |
end; |
26 |
||
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
33221
diff
changeset
|
27 |
structure Thy_Load: THY_LOAD = |
6168 | 28 |
struct |
29 |
||
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
30 |
(* manage source files *) |
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
31 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
32 |
type files = |
40741
17d6293a1e26
moved file identification to thy_load.ML (where it is actually used);
wenzelm
parents:
40625
diff
changeset
|
33 |
{master_dir: Path.T, (*master directory of theory source*) |
48927
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents:
48924
diff
changeset
|
34 |
imports: (string * Position.T) list, (*source specification of imports*) |
48896
bb1f461a7815
simplified Thy_Load.provide: do not store full path;
wenzelm
parents:
48888
diff
changeset
|
35 |
provided: (Path.T * SHA1.digest) list}; (*source path, digest*) |
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
36 |
|
48886
9604c6563226
discontinued separate list of required files -- maintain only provided files as they occur at runtime;
wenzelm
parents:
48881
diff
changeset
|
37 |
fun make_files (master_dir, imports, provided): files = |
9604c6563226
discontinued separate list of required files -- maintain only provided files as they occur at runtime;
wenzelm
parents:
48881
diff
changeset
|
38 |
{master_dir = master_dir, imports = imports, provided = provided}; |
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
39 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
40 |
structure Files = Theory_Data |
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
41 |
( |
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
42 |
type T = files; |
48886
9604c6563226
discontinued separate list of required files -- maintain only provided files as they occur at runtime;
wenzelm
parents:
48881
diff
changeset
|
43 |
val empty = make_files (Path.current, [], []); |
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
44 |
fun extend _ = empty; |
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
45 |
fun merge _ = empty; |
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
46 |
); |
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
47 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
48 |
fun map_files f = |
48886
9604c6563226
discontinued separate list of required files -- maintain only provided files as they occur at runtime;
wenzelm
parents:
48881
diff
changeset
|
49 |
Files.map (fn {master_dir, imports, provided} => |
9604c6563226
discontinued separate list of required files -- maintain only provided files as they occur at runtime;
wenzelm
parents:
48881
diff
changeset
|
50 |
make_files (f (master_dir, imports, provided))); |
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
51 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
52 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
53 |
val master_directory = #master_dir o Files.get; |
41548
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents:
41414
diff
changeset
|
54 |
val imports_of = #imports o Files.get; |
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
55 |
|
48888 | 56 |
fun put_deps master_dir imports = map_files (fn _ => (master_dir, imports, [])); |
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
57 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
58 |
|
54451 | 59 |
(* auxiliary files *) |
48869 | 60 |
|
48878 | 61 |
fun check_file dir file = File.check_file (File.full_path dir file); |
62 |
||
54451 | 63 |
fun read_files dir cmd (path, pos) = |
48898
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
64 |
let |
48919 | 65 |
fun make_file file = |
66 |
let |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49244
diff
changeset
|
67 |
val _ = Position.report pos (Markup.path (Path.implode file)); |
48919 | 68 |
val full_path = check_file dir file; |
69 |
in {src_path = file, text = File.read full_path, pos = Path.position full_path} end; |
|
48898
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
70 |
val paths = |
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
71 |
(case Keyword.command_files cmd of |
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
72 |
[] => [path] |
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
73 |
| exts => map (fn ext => Path.ext ext path) exts); |
48919 | 74 |
in map make_file paths end; |
48898
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
75 |
|
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
76 |
fun parse_files cmd = |
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
77 |
Scan.ahead Parse.not_eof -- Parse.path >> (fn (tok, name) => fn thy => |
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
78 |
(case Token.get_files tok of |
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
79 |
SOME files => files |
54451 | 80 |
| NONE => read_files (master_directory thy) cmd (Path.explode name, Token.position_of tok))); |
48869 | 81 |
|
82 |
||
54451 | 83 |
(* theory files *) |
6232 | 84 |
|
46737 | 85 |
val thy_path = Path.ext "thy"; |
86 |
||
48898
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
87 |
fun check_thy dir thy_name = |
23872 | 88 |
let |
48876
157dd47032e0
more standard Thy_Load.check_thy for Pure.thy, relying on its header;
wenzelm
parents:
48874
diff
changeset
|
89 |
val path = thy_path (Path.basic thy_name); |
46737 | 90 |
val master_file = check_file dir path; |
42003
6e45dc518ebb
replaced File.check by specific File.check_file, File.check_dir;
wenzelm
parents:
42002
diff
changeset
|
91 |
val text = File.read master_file; |
48876
157dd47032e0
more standard Thy_Load.check_thy for Pure.thy, relying on its header;
wenzelm
parents:
48874
diff
changeset
|
92 |
|
51294
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents:
51293
diff
changeset
|
93 |
val {name = (name, pos), imports, keywords} = |
48927
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents:
48924
diff
changeset
|
94 |
Thy_Header.read (Path.position master_file) text; |
48876
157dd47032e0
more standard Thy_Load.check_thy for Pure.thy, relying on its header;
wenzelm
parents:
48874
diff
changeset
|
95 |
val _ = thy_name <> name andalso |
48992 | 96 |
error ("Bad file name " ^ Path.print path ^ " for theory " ^ quote name ^ Position.here pos); |
48874
ff9cd47be39b
refined Thy_Load.check_thy: find more uses in body text, based on keywords;
wenzelm
parents:
48869
diff
changeset
|
97 |
in |
48928 | 98 |
{master = (master_file, SHA1.digest text), text = text, theory_pos = pos, |
51293
05b1bbae748d
discontinued obsolete 'uses' within theory header;
wenzelm
parents:
51273
diff
changeset
|
99 |
imports = imports, keywords = keywords} |
48874
ff9cd47be39b
refined Thy_Load.check_thy: find more uses in body text, based on keywords;
wenzelm
parents:
48869
diff
changeset
|
100 |
end; |
6168 | 101 |
|
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
102 |
|
43702
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
103 |
(* load files *) |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
104 |
|
48906 | 105 |
fun provide (src_path, id) = |
106 |
map_files (fn (master_dir, imports, provided) => |
|
107 |
if AList.defined (op =) provided src_path then |
|
108 |
error ("Duplicate use of source file: " ^ Path.print src_path) |
|
109 |
else (master_dir, imports, (src_path, id) :: provided)); |
|
110 |
||
111 |
fun provide_parse_files cmd = |
|
112 |
parse_files cmd >> (fn files => fn thy => |
|
113 |
let |
|
114 |
val fs = files thy; |
|
115 |
val thy' = fold (fn {src_path, text, ...} => provide (src_path, SHA1.digest text)) fs thy; |
|
116 |
in (fs, thy') end); |
|
117 |
||
43702
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
118 |
fun load_file thy src_path = |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
119 |
let |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
120 |
val full_path = check_file (master_directory thy) src_path; |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
121 |
val text = File.read full_path; |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
122 |
val id = SHA1.digest text; |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
123 |
in ((full_path, id), text) end; |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
124 |
|
54446 | 125 |
fun loaded_files_current thy = |
48886
9604c6563226
discontinued separate list of required files -- maintain only provided files as they occur at runtime;
wenzelm
parents:
48881
diff
changeset
|
126 |
#provided (Files.get thy) |> |
48896
bb1f461a7815
simplified Thy_Load.provide: do not store full path;
wenzelm
parents:
48888
diff
changeset
|
127 |
forall (fn (src_path, id) => |
43702
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
128 |
(case try (load_file thy) src_path of |
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
129 |
NONE => false |
48886
9604c6563226
discontinued separate list of required files -- maintain only provided files as they occur at runtime;
wenzelm
parents:
48881
diff
changeset
|
130 |
| SOME ((_, id'), _) => id = id')); |
37952 | 131 |
|
54454 | 132 |
(*Proof General legacy*) |
133 |
fun loaded_files thy = |
|
134 |
let val {master_dir, provided, ...} = Files.get thy |
|
135 |
in map (File.full_path master_dir o #1) provided end; |
|
136 |
||
37949
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
137 |
|
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
138 |
(* load_thy *) |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37952
diff
changeset
|
139 |
|
51294
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents:
51293
diff
changeset
|
140 |
fun begin_theory master_dir {name, imports, keywords} parents = |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37952
diff
changeset
|
141 |
Theory.begin_theory name parents |
48888 | 142 |
|> put_deps master_dir imports |
52788 | 143 |
|> fold Thy_Header.declare_keyword keywords; |
37977
3ceccd415145
simplified/clarified theory loader: more explicit task management, kill old versions at start, commit results only in the very end, non-optional master dependency, do not store text in deps;
wenzelm
parents:
37952
diff
changeset
|
144 |
|
51217
65ab2c4f4c32
support for prescient timing information within command transactions;
wenzelm
parents:
50201
diff
changeset
|
145 |
fun excursion last_timing init elements = |
46959
cdc791910460
defer actual parsing of command spans and thus allow new commands to be used in the same theory where defined;
wenzelm
parents:
46958
diff
changeset
|
146 |
let |
51268
fcc4b89a600d
simplified Outer_Syntax.read_span: internalized Toplevel.is_ignored;
wenzelm
parents:
51228
diff
changeset
|
147 |
fun prepare_span span = |
fcc4b89a600d
simplified Outer_Syntax.read_span: internalized Toplevel.is_ignored;
wenzelm
parents:
51228
diff
changeset
|
148 |
Thy_Syntax.span_content span |
52534 | 149 |
|> Command.read init |
51268
fcc4b89a600d
simplified Outer_Syntax.read_span: internalized Toplevel.is_ignored;
wenzelm
parents:
51228
diff
changeset
|
150 |
|> (fn tr => Toplevel.put_timing (last_timing tr) tr); |
51217
65ab2c4f4c32
support for prescient timing information within command transactions;
wenzelm
parents:
50201
diff
changeset
|
151 |
|
51268
fcc4b89a600d
simplified Outer_Syntax.read_span: internalized Toplevel.is_ignored;
wenzelm
parents:
51228
diff
changeset
|
152 |
fun element_result span_elem (st, _) = |
46959
cdc791910460
defer actual parsing of command spans and thus allow new commands to be used in the same theory where defined;
wenzelm
parents:
46958
diff
changeset
|
153 |
let |
51273
d54ee0cad2ab
clarified Toplevel.element_result: scheduling policies happen here;
wenzelm
parents:
51268
diff
changeset
|
154 |
val elem = Thy_Syntax.map_element prepare_span span_elem; |
d54ee0cad2ab
clarified Toplevel.element_result: scheduling policies happen here;
wenzelm
parents:
51268
diff
changeset
|
155 |
val (results, st') = Toplevel.element_result elem st; |
d54ee0cad2ab
clarified Toplevel.element_result: scheduling policies happen here;
wenzelm
parents:
51268
diff
changeset
|
156 |
val pos' = Toplevel.pos_of (Thy_Syntax.last_element elem); |
51268
fcc4b89a600d
simplified Outer_Syntax.read_span: internalized Toplevel.is_ignored;
wenzelm
parents:
51228
diff
changeset
|
157 |
in (results, (st', pos')) end; |
46959
cdc791910460
defer actual parsing of command spans and thus allow new commands to be used in the same theory where defined;
wenzelm
parents:
46958
diff
changeset
|
158 |
|
cdc791910460
defer actual parsing of command spans and thus allow new commands to be used in the same theory where defined;
wenzelm
parents:
46958
diff
changeset
|
159 |
val (results, (end_state, end_pos)) = |
cdc791910460
defer actual parsing of command spans and thus allow new commands to be used in the same theory where defined;
wenzelm
parents:
46958
diff
changeset
|
160 |
fold_map element_result elements (Toplevel.toplevel, Position.none); |
cdc791910460
defer actual parsing of command spans and thus allow new commands to be used in the same theory where defined;
wenzelm
parents:
46958
diff
changeset
|
161 |
|
cdc791910460
defer actual parsing of command spans and thus allow new commands to be used in the same theory where defined;
wenzelm
parents:
46958
diff
changeset
|
162 |
val thy = Toplevel.end_theory end_pos end_state; |
51273
d54ee0cad2ab
clarified Toplevel.element_result: scheduling policies happen here;
wenzelm
parents:
51268
diff
changeset
|
163 |
in (results, thy) end; |
46959
cdc791910460
defer actual parsing of command spans and thus allow new commands to be used in the same theory where defined;
wenzelm
parents:
46958
diff
changeset
|
164 |
|
51217
65ab2c4f4c32
support for prescient timing information within command transactions;
wenzelm
parents:
50201
diff
changeset
|
165 |
fun load_thy last_timing update_time master_dir header text_pos text parents = |
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
166 |
let |
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
167 |
val time = ! Toplevel.timing; |
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
168 |
|
51294
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents:
51293
diff
changeset
|
169 |
val {name = (name, _), ...} = header; |
46958
0ec8f04e753a
define keywords early when processing the theory header, before running the body commands;
wenzelm
parents:
46938
diff
changeset
|
170 |
val _ = Thy_Header.define_keywords header; |
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
171 |
|
46959
cdc791910460
defer actual parsing of command spans and thus allow new commands to be used in the same theory where defined;
wenzelm
parents:
46958
diff
changeset
|
172 |
val lexs = Keyword.get_lexicons (); |
48927
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents:
48924
diff
changeset
|
173 |
val toks = Thy_Syntax.parse_tokens lexs text_pos text; |
54451 | 174 |
val spans = map (Thy_Syntax.resolve_files (read_files master_dir)) (Thy_Syntax.parse_spans toks); |
46959
cdc791910460
defer actual parsing of command spans and thus allow new commands to be used in the same theory where defined;
wenzelm
parents:
46958
diff
changeset
|
175 |
val elements = Thy_Syntax.parse_elements spans; |
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
176 |
|
54456 | 177 |
fun init () = |
178 |
begin_theory master_dir header parents |
|
179 |
|> Present.begin_theory update_time |
|
180 |
(fn () => HTML.html_mode (implode o map Thy_Syntax.present_span) spans); |
|
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
181 |
|
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
182 |
val _ = if time then writeln ("\n**** Starting theory " ^ quote name ^ " ****") else (); |
51217
65ab2c4f4c32
support for prescient timing information within command transactions;
wenzelm
parents:
50201
diff
changeset
|
183 |
val (results, thy) = cond_timeit time "" (fn () => excursion last_timing init elements); |
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
184 |
val _ = if time then writeln ("**** Finished theory " ^ quote name ^ " ****\n") else (); |
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
185 |
|
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51326
diff
changeset
|
186 |
fun present () = |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51326
diff
changeset
|
187 |
let |
51332
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51331
diff
changeset
|
188 |
val res = filter_out (Toplevel.is_ignored o #1) (maps Toplevel.join_results results); |
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51326
diff
changeset
|
189 |
val ((minor, _), outer_syntax) = Outer_Syntax.get_syntax (); |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51326
diff
changeset
|
190 |
in |
51556 | 191 |
if exists (Toplevel.is_skipped_proof o #2) res then |
192 |
warning ("Cannot present theory with skipped proofs: " ^ quote name) |
|
193 |
else |
|
194 |
Thy_Output.present_thy minor Keyword.command_tags |
|
195 |
(Outer_Syntax.is_markup outer_syntax) res toks |
|
196 |
|> Buffer.content |
|
197 |
|> Present.theory_output name |
|
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51326
diff
changeset
|
198 |
end; |
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
199 |
|
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51326
diff
changeset
|
200 |
in (thy, present, size text) end; |
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
201 |
|
42002 | 202 |
|
49244
fb669aff821e
formal markup for @{file} (for hyperlinks etc.) -- interpret path wrt. master directory as usual;
wenzelm
parents:
48992
diff
changeset
|
203 |
(* document antiquotation *) |
fb669aff821e
formal markup for @{file} (for hyperlinks etc.) -- interpret path wrt. master directory as usual;
wenzelm
parents:
48992
diff
changeset
|
204 |
|
53171 | 205 |
val _ = Theory.setup |
206 |
(Thy_Output.antiquotation (Binding.name "file") (Scan.lift (Parse.position Parse.path)) |
|
49244
fb669aff821e
formal markup for @{file} (for hyperlinks etc.) -- interpret path wrt. master directory as usual;
wenzelm
parents:
48992
diff
changeset
|
207 |
(fn {context = ctxt, ...} => fn (name, pos) => |
fb669aff821e
formal markup for @{file} (for hyperlinks etc.) -- interpret path wrt. master directory as usual;
wenzelm
parents:
48992
diff
changeset
|
208 |
let |
fb669aff821e
formal markup for @{file} (for hyperlinks etc.) -- interpret path wrt. master directory as usual;
wenzelm
parents:
48992
diff
changeset
|
209 |
val dir = master_directory (Proof_Context.theory_of ctxt); |
fb669aff821e
formal markup for @{file} (for hyperlinks etc.) -- interpret path wrt. master directory as usual;
wenzelm
parents:
48992
diff
changeset
|
210 |
val path = Path.append dir (Path.explode name); |
fb669aff821e
formal markup for @{file} (for hyperlinks etc.) -- interpret path wrt. master directory as usual;
wenzelm
parents:
48992
diff
changeset
|
211 |
val _ = |
fb669aff821e
formal markup for @{file} (for hyperlinks etc.) -- interpret path wrt. master directory as usual;
wenzelm
parents:
48992
diff
changeset
|
212 |
if File.exists path then () |
fb669aff821e
formal markup for @{file} (for hyperlinks etc.) -- interpret path wrt. master directory as usual;
wenzelm
parents:
48992
diff
changeset
|
213 |
else error ("Bad file: " ^ Path.print (Path.expand path) ^ Position.here pos); |
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49244
diff
changeset
|
214 |
val _ = Position.report pos (Markup.path name); |
52752 | 215 |
in |
216 |
space_explode "/" name |
|
217 |
|> map Thy_Output.verb_text |
|
218 |
|> space_implode (Thy_Output.verb_text "/" ^ "\\discretionary{}{}{}") |
|
53171 | 219 |
end)); |
49244
fb669aff821e
formal markup for @{file} (for hyperlinks etc.) -- interpret path wrt. master directory as usual;
wenzelm
parents:
48992
diff
changeset
|
220 |
|
6168 | 221 |
end; |