author | wenzelm |
Thu, 13 Apr 2017 12:39:36 +0200 | |
changeset 65478 | 7c40477e0a87 |
parent 65476 | a72ae9eb4462 |
child 65497 | 7966bd7c6461 |
permissions | -rw-r--r-- |
56208 | 1 |
(* Title: Pure/PIDE/resources.ML |
42002 | 2 |
Author: Makarius |
6168 | 3 |
|
56208 | 4 |
Resources for theories and auxiliary files. |
6168 | 5 |
*) |
6 |
||
56208 | 7 |
signature RESOURCES = |
6168 | 8 |
sig |
65478
7c40477e0a87
clarified init_session_base / finish_session_base: retain some information for plain "isabelle process", without rechecking dependencies as in "isabelle console";
wenzelm
parents:
65476
diff
changeset
|
9 |
val init_session_base: |
65441 | 10 |
{default_qualifier: string, |
65457 | 11 |
global_theories: (string * string) list, |
65441 | 12 |
loaded_theories: (string * string) list, |
13 |
known_theories: (string * string) list} -> unit |
|
65478
7c40477e0a87
clarified init_session_base / finish_session_base: retain some information for plain "isabelle process", without rechecking dependencies as in "isabelle console";
wenzelm
parents:
65476
diff
changeset
|
14 |
val finish_session_base: unit -> unit |
65441 | 15 |
val default_qualifier: unit -> string |
65457 | 16 |
val global_theory: string -> string option |
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
17 |
val loaded_theory: string -> string option |
65431
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
18 |
val known_theory: string -> Path.T option |
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
|
19 |
val master_directory: theory -> Path.T |
48927
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents:
48924
diff
changeset
|
20 |
val imports_of: theory -> (string * Position.T) list |
46737 | 21 |
val thy_path: Path.T -> Path.T |
65445
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65443
diff
changeset
|
22 |
val theory_qualifier: string -> string |
65454 | 23 |
val import_name: string -> Path.T -> string -> |
24 |
{node_name: Path.T, master_dir: Path.T, theory_name: string} |
|
48898
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
25 |
val check_thy: Path.T -> string -> |
48928 | 26 |
{master: Path.T * SHA1.digest, text: string, theory_pos: Position.T, |
51293
05b1bbae748d
discontinued obsolete 'uses' within theory header;
wenzelm
parents:
51273
diff
changeset
|
27 |
imports: (string * Position.T) list, keywords: Thy_Header.keywords} |
54525 | 28 |
val parse_files: string -> (theory -> Token.file list) parser |
48906 | 29 |
val provide: Path.T * SHA1.digest -> theory -> theory |
30 |
val provide_parse_files: string -> (theory -> Token.file list * theory) parser |
|
54446 | 31 |
val loaded_files_current: theory -> bool |
46938
cda018294515
some support for outer syntax keyword declarations within theory header;
wenzelm
parents:
46811
diff
changeset
|
32 |
val begin_theory: Path.T -> Thy_Header.header -> theory list -> theory |
65058
3e9f382fb67e
absent timing information means zero, according to 0070053570c4, f235646b1b73;
wenzelm
parents:
63675
diff
changeset
|
33 |
val load_thy: bool -> HTML.symbols -> (Toplevel.transition -> Time.time) -> int -> |
61381 | 34 |
Path.T -> Thy_Header.header -> Position.T -> string -> theory list -> |
35 |
theory * (unit -> unit) * int |
|
6168 | 36 |
end; |
37 |
||
56208 | 38 |
structure Resources: RESOURCES = |
6168 | 39 |
struct |
40 |
||
65431
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
41 |
(* session base *) |
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
42 |
|
65478
7c40477e0a87
clarified init_session_base / finish_session_base: retain some information for plain "isabelle process", without rechecking dependencies as in "isabelle console";
wenzelm
parents:
65476
diff
changeset
|
43 |
val empty_session_base = |
65445
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65443
diff
changeset
|
44 |
{default_qualifier = "Draft", |
65457 | 45 |
global_theories = Symtab.empty: string Symtab.table, |
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
46 |
loaded_theories = Symtab.empty: string Symtab.table, |
65441 | 47 |
known_theories = Symtab.empty: Path.T Symtab.table}; |
65431
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
48 |
|
65441 | 49 |
val global_session_base = |
65478
7c40477e0a87
clarified init_session_base / finish_session_base: retain some information for plain "isabelle process", without rechecking dependencies as in "isabelle console";
wenzelm
parents:
65476
diff
changeset
|
50 |
Synchronized.var "Sessions.base" empty_session_base; |
65441 | 51 |
|
65478
7c40477e0a87
clarified init_session_base / finish_session_base: retain some information for plain "isabelle process", without rechecking dependencies as in "isabelle console";
wenzelm
parents:
65476
diff
changeset
|
52 |
fun init_session_base {default_qualifier, global_theories, loaded_theories, known_theories} = |
65431
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
53 |
Synchronized.change global_session_base |
65441 | 54 |
(fn _ => |
65445
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65443
diff
changeset
|
55 |
{default_qualifier = |
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65443
diff
changeset
|
56 |
if default_qualifier <> "" then default_qualifier |
65478
7c40477e0a87
clarified init_session_base / finish_session_base: retain some information for plain "isabelle process", without rechecking dependencies as in "isabelle console";
wenzelm
parents:
65476
diff
changeset
|
57 |
else #default_qualifier empty_session_base, |
65457 | 58 |
global_theories = Symtab.make global_theories, |
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
59 |
loaded_theories = Symtab.make loaded_theories, |
65441 | 60 |
known_theories = Symtab.make (map (apsnd Path.explode) known_theories)}); |
65431
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
61 |
|
65478
7c40477e0a87
clarified init_session_base / finish_session_base: retain some information for plain "isabelle process", without rechecking dependencies as in "isabelle console";
wenzelm
parents:
65476
diff
changeset
|
62 |
fun finish_session_base () = |
7c40477e0a87
clarified init_session_base / finish_session_base: retain some information for plain "isabelle process", without rechecking dependencies as in "isabelle console";
wenzelm
parents:
65476
diff
changeset
|
63 |
Synchronized.change global_session_base |
7c40477e0a87
clarified init_session_base / finish_session_base: retain some information for plain "isabelle process", without rechecking dependencies as in "isabelle console";
wenzelm
parents:
65476
diff
changeset
|
64 |
(fn {global_theories, loaded_theories, ...} => |
7c40477e0a87
clarified init_session_base / finish_session_base: retain some information for plain "isabelle process", without rechecking dependencies as in "isabelle console";
wenzelm
parents:
65476
diff
changeset
|
65 |
{default_qualifier = #default_qualifier empty_session_base, |
7c40477e0a87
clarified init_session_base / finish_session_base: retain some information for plain "isabelle process", without rechecking dependencies as in "isabelle console";
wenzelm
parents:
65476
diff
changeset
|
66 |
global_theories = global_theories, |
7c40477e0a87
clarified init_session_base / finish_session_base: retain some information for plain "isabelle process", without rechecking dependencies as in "isabelle console";
wenzelm
parents:
65476
diff
changeset
|
67 |
loaded_theories = loaded_theories, |
7c40477e0a87
clarified init_session_base / finish_session_base: retain some information for plain "isabelle process", without rechecking dependencies as in "isabelle console";
wenzelm
parents:
65476
diff
changeset
|
68 |
known_theories = #known_theories empty_session_base}); |
65441 | 69 |
|
70 |
fun get_session_base f = f (Synchronized.value global_session_base); |
|
65431
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
71 |
|
65441 | 72 |
fun default_qualifier () = get_session_base #default_qualifier; |
65457 | 73 |
fun global_theory a = Symtab.lookup (get_session_base #global_theories) a; |
65441 | 74 |
fun loaded_theory a = Symtab.lookup (get_session_base #loaded_theories) a; |
75 |
fun known_theory a = Symtab.lookup (get_session_base #known_theories) a; |
|
65431
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
76 |
|
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
77 |
|
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
|
78 |
(* 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
|
79 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
80 |
type files = |
40741
17d6293a1e26
moved file identification to thy_load.ML (where it is actually used);
wenzelm
parents:
40625
diff
changeset
|
81 |
{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
|
82 |
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
|
83 |
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
|
84 |
|
48886
9604c6563226
discontinued separate list of required files -- maintain only provided files as they occur at runtime;
wenzelm
parents:
48881
diff
changeset
|
85 |
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
|
86 |
{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
|
87 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
88 |
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
|
89 |
( |
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
90 |
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
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
); |
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
95 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
100 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
101 |
val master_directory = #master_dir o Files.get; |
41548
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents:
41414
diff
changeset
|
102 |
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
|
103 |
|
48888 | 104 |
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
|
105 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
106 |
|
54525 | 107 |
(* theory files *) |
108 |
||
109 |
val thy_path = Path.ext "thy"; |
|
48869 | 110 |
|
65445
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65443
diff
changeset
|
111 |
fun theory_qualifier theory = |
65457 | 112 |
(case global_theory theory of |
113 |
SOME qualifier => qualifier |
|
114 |
| NONE => Long_Name.qualifier theory); |
|
65445
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65443
diff
changeset
|
115 |
|
65476 | 116 |
fun theory_name qualifier theory0 = |
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
117 |
(case loaded_theory theory0 of |
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
118 |
SOME theory => (true, theory) |
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
119 |
| NONE => |
65474 | 120 |
let val theory = |
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
121 |
if Long_Name.is_qualified theory0 orelse is_some (global_theory theory0) |
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
122 |
orelse true (* FIXME *) then theory0 |
65474 | 123 |
else Long_Name.qualify qualifier theory0 |
124 |
in (false, theory) end); |
|
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
125 |
|
65454 | 126 |
fun import_name qualifier dir s = |
65476 | 127 |
(case theory_name qualifier (Thy_Header.import_name s) of |
65474 | 128 |
(true, theory) => |
129 |
{node_name = Path.basic theory, master_dir = Path.current, theory_name = theory} |
|
130 |
| (false, theory) => |
|
131 |
let val node_name = |
|
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
132 |
(case known_theory theory of |
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
133 |
SOME node_name => node_name |
65474 | 134 |
| NONE => File.full_path dir (thy_path (Path.expand (Path.explode s)))) |
135 |
in {node_name = node_name, master_dir = Path.dir node_name, theory_name = theory} end); |
|
65443
dccbfc715904
provide Resources.import_name in ML, similar to Scala version;
wenzelm
parents:
65442
diff
changeset
|
136 |
|
48878 | 137 |
fun check_file dir file = File.check_file (File.full_path dir file); |
138 |
||
54525 | 139 |
fun check_thy dir thy_name = |
140 |
let |
|
65433 | 141 |
val thy_base_name = Long_Name.base_name thy_name; |
142 |
val master_file = |
|
143 |
(case known_theory thy_name of |
|
65442 | 144 |
SOME known_path => check_file Path.current known_path |
145 |
| NONE => check_file dir (thy_path (Path.basic thy_base_name))); |
|
54525 | 146 |
val text = File.read master_file; |
147 |
||
148 |
val {name = (name, pos), imports, keywords} = |
|
149 |
Thy_Header.read (Path.position master_file) text; |
|
65433 | 150 |
val _ = |
151 |
thy_base_name <> name andalso |
|
152 |
error ("Bad theory name " ^ quote name ^ |
|
65442 | 153 |
" for file " ^ Path.print (Path.base master_file) ^ Position.here pos); |
54525 | 154 |
in |
155 |
{master = (master_file, SHA1.digest text), text = text, theory_pos = pos, |
|
156 |
imports = imports, keywords = keywords} |
|
157 |
end; |
|
158 |
||
159 |
||
54526 | 160 |
(* load files *) |
48898
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
161 |
|
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
162 |
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
|
163 |
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
|
164 |
(case Token.get_files tok of |
54526 | 165 |
[] => |
166 |
let |
|
58928
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents:
58923
diff
changeset
|
167 |
val keywords = Thy_Header.get_keywords thy; |
54526 | 168 |
val master_dir = master_directory thy; |
55708 | 169 |
val pos = Token.pos_of tok; |
58923 | 170 |
val src_paths = Keyword.command_files keywords cmd (Path.explode name); |
54526 | 171 |
in map (Command.read_file master_dir pos) src_paths end |
54520
cee77d2e9582
release file errors at runtime: Command.eval instead of Command.read;
wenzelm
parents:
54519
diff
changeset
|
172 |
| files => map Exn.release files)); |
48869 | 173 |
|
48906 | 174 |
fun provide (src_path, id) = |
175 |
map_files (fn (master_dir, imports, provided) => |
|
176 |
if AList.defined (op =) provided src_path then |
|
177 |
error ("Duplicate use of source file: " ^ Path.print src_path) |
|
178 |
else (master_dir, imports, (src_path, id) :: provided)); |
|
179 |
||
180 |
fun provide_parse_files cmd = |
|
181 |
parse_files cmd >> (fn files => fn thy => |
|
182 |
let |
|
183 |
val fs = files thy; |
|
55788
67699e08e969
store blobs / inlined files as separate text lines: smaller values are more healthy for the Poly/ML RTS and allow implicit sharing;
wenzelm
parents:
55708
diff
changeset
|
184 |
val thy' = fold (fn {src_path, digest, ...} => provide (src_path, digest)) fs thy; |
48906 | 185 |
in (fs, thy') end); |
186 |
||
43702
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
187 |
fun load_file thy src_path = |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
188 |
let |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
189 |
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
|
190 |
val text = File.read full_path; |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
191 |
val id = SHA1.digest text; |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
192 |
in ((full_path, id), text) end; |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
193 |
|
54446 | 194 |
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
|
195 |
#provided (Files.get thy) |> |
48896
bb1f461a7815
simplified Thy_Load.provide: do not store full path;
wenzelm
parents:
48888
diff
changeset
|
196 |
forall (fn (src_path, id) => |
43702
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
197 |
(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
|
198 |
NONE => false |
48886
9604c6563226
discontinued separate list of required files -- maintain only provided files as they occur at runtime;
wenzelm
parents:
48881
diff
changeset
|
199 |
| SOME ((_, id'), _) => id = id')); |
37952 | 200 |
|
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
|
201 |
|
54525 | 202 |
(* load theory *) |
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
|
203 |
|
51294
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents:
51293
diff
changeset
|
204 |
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
|
205 |
Theory.begin_theory name parents |
48888 | 206 |
|> put_deps master_dir imports |
58928
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents:
58923
diff
changeset
|
207 |
|> Thy_Header.add_keywords 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
|
208 |
|
58923 | 209 |
fun excursion keywords master_dir 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
|
210 |
let |
58928
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents:
58923
diff
changeset
|
211 |
fun prepare_span st span = |
57905
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
56803
diff
changeset
|
212 |
Command_Span.content span |
59689
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
wenzelm
parents:
59123
diff
changeset
|
213 |
|> Command.read keywords (Command.read_thy st) master_dir init ([], ~1) |
51268
fcc4b89a600d
simplified Outer_Syntax.read_span: internalized Toplevel.is_ignored;
wenzelm
parents:
51228
diff
changeset
|
214 |
|> (fn tr => Toplevel.put_timing (last_timing tr) tr); |
51217
65ab2c4f4c32
support for prescient timing information within command transactions;
wenzelm
parents:
50201
diff
changeset
|
215 |
|
51268
fcc4b89a600d
simplified Outer_Syntax.read_span: internalized Toplevel.is_ignored;
wenzelm
parents:
51228
diff
changeset
|
216 |
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
|
217 |
let |
58928
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents:
58923
diff
changeset
|
218 |
val elem = Thy_Syntax.map_element (prepare_span st) span_elem; |
58923 | 219 |
val (results, st') = Toplevel.element_result keywords elem st; |
51273
d54ee0cad2ab
clarified Toplevel.element_result: scheduling policies happen here;
wenzelm
parents:
51268
diff
changeset
|
220 |
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
|
221 |
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
|
222 |
|
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
|
223 |
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
|
224 |
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
|
225 |
|
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
|
226 |
val thy = Toplevel.end_theory end_pos end_state; |
51273
d54ee0cad2ab
clarified Toplevel.element_result: scheduling policies happen here;
wenzelm
parents:
51268
diff
changeset
|
227 |
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
|
228 |
|
61381 | 229 |
fun load_thy document symbols 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
|
230 |
let |
58918 | 231 |
val (name, _) = #name header; |
58928
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents:
58923
diff
changeset
|
232 |
val keywords = |
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents:
58923
diff
changeset
|
233 |
fold (curry Keyword.merge_keywords o Thy_Header.get_keywords) parents |
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents:
58923
diff
changeset
|
234 |
(Keyword.add_keywords (#keywords header) Keyword.empty_keywords); |
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
235 |
|
59083 | 236 |
val toks = Token.explode keywords text_pos text; |
57905
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
56803
diff
changeset
|
237 |
val spans = Outer_Syntax.parse_spans toks; |
58923 | 238 |
val elements = Thy_Syntax.parse_elements keywords spans; |
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
239 |
|
54456 | 240 |
fun init () = |
241 |
begin_theory master_dir header parents |
|
242 |
|> Present.begin_theory update_time |
|
61381 | 243 |
(fn () => implode (map (HTML.present_span symbols keywords) spans)); |
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
244 |
|
54526 | 245 |
val (results, thy) = |
58849
ef7700ecce83
discontinued pointless option: timing is always on (overall theory only);
wenzelm
parents:
58741
diff
changeset
|
246 |
cond_timeit true ("theory " ^ quote name) |
58923 | 247 |
(fn () => excursion keywords master_dir last_timing init elements); |
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
248 |
|
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51326
diff
changeset
|
249 |
fun present () = |
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51326
diff
changeset
|
250 |
let |
51332
8707df0b0255
refined parallel_proofs = 2: fork whole Isar sub-proofs, not just terminal ones;
wenzelm
parents:
51331
diff
changeset
|
251 |
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
|
252 |
in |
51556 | 253 |
if exists (Toplevel.is_skipped_proof o #2) res then |
254 |
warning ("Cannot present theory with skipped proofs: " ^ quote name) |
|
255 |
else |
|
58928
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents:
58923
diff
changeset
|
256 |
let val tex_source = Thy_Output.present_thy thy res toks |> Buffer.content; |
54458
96ccc8972fc7
prefer explicit "document" flag -- eliminated stateful Present.no_document;
wenzelm
parents:
54456
diff
changeset
|
257 |
in if document then Present.theory_output name tex_source else () end |
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51326
diff
changeset
|
258 |
end; |
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
259 |
|
51331
e7fab0b5dbe7
join all proofs before scheduling present phase (ordered according to weight);
wenzelm
parents:
51326
diff
changeset
|
260 |
in (thy, present, size text) end; |
43712
3c2c912af2ef
moved Outer_Syntax.load_thy to Thy_Load.load_thy;
wenzelm
parents:
43702
diff
changeset
|
261 |
|
42002 | 262 |
|
56135 | 263 |
(* antiquotations *) |
49244
fb669aff821e
formal markup for @{file} (for hyperlinks etc.) -- interpret path wrt. master directory as usual;
wenzelm
parents:
48992
diff
changeset
|
264 |
|
56135 | 265 |
local |
266 |
||
63669 | 267 |
fun err msg pos = error (msg ^ Position.here pos); |
268 |
||
63675 | 269 |
fun check_path check_file ctxt dir (name, pos) = |
54705 | 270 |
let |
56034
1c59b555ac4a
some Markup.language_path to prevent completion of symbols (notably "~") -- always "delimited" for simplicity in contrast to 42ac3cfb89f6;
wenzelm
parents:
55882
diff
changeset
|
271 |
val _ = Context_Position.report ctxt pos Markup.language_path; |
1c59b555ac4a
some Markup.language_path to prevent completion of symbols (notably "~") -- always "delimited" for simplicity in contrast to 42ac3cfb89f6;
wenzelm
parents:
55882
diff
changeset
|
272 |
|
63669 | 273 |
val path = Path.append dir (Path.explode name) handle ERROR msg => err msg pos; |
274 |
val _ = Path.expand path handle ERROR msg => err msg pos; |
|
56134 | 275 |
val _ = Context_Position.report ctxt pos (Markup.path (Path.smart_implode path)); |
63669 | 276 |
val _ = |
277 |
(case check_file of |
|
278 |
NONE => path |
|
279 |
| SOME check => (check path handle ERROR msg => err msg pos)); |
|
63675 | 280 |
in path end; |
281 |
||
282 |
fun document_antiq check_file ctxt (name, pos) = |
|
283 |
let |
|
284 |
val dir = master_directory (Proof_Context.theory_of ctxt); |
|
285 |
val _ = check_path check_file ctxt dir (name, pos); |
|
54705 | 286 |
in |
287 |
space_explode "/" name |
|
58716
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
57918
diff
changeset
|
288 |
|> map Latex.output_ascii |
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
57918
diff
changeset
|
289 |
|> space_implode (Latex.output_ascii "/" ^ "\\discretionary{}{}{}") |
58741
6e7b009e6d94
clarified verbatim line breaks, e.g. relevant for Implementation mldecls;
wenzelm
parents:
58716
diff
changeset
|
290 |
|> enclose "\\isatt{" "}" |
54705 | 291 |
end; |
292 |
||
63675 | 293 |
fun ML_antiq check_file ctxt (name, pos) = |
294 |
let val path = check_path check_file ctxt Path.current (name, pos); |
|
295 |
in "Path.explode " ^ ML_Syntax.print_string (Path.implode path) end; |
|
296 |
||
56135 | 297 |
in |
298 |
||
53171 | 299 |
val _ = Theory.setup |
63669 | 300 |
(Thy_Output.antiquotation @{binding path} (Scan.lift (Parse.position Parse.path)) |
63675 | 301 |
(document_antiq NONE o #context) #> |
63669 | 302 |
Thy_Output.antiquotation @{binding file} (Scan.lift (Parse.position Parse.path)) |
63675 | 303 |
(document_antiq (SOME File.check_file) o #context) #> |
63669 | 304 |
Thy_Output.antiquotation @{binding dir} (Scan.lift (Parse.position Parse.path)) |
63675 | 305 |
(document_antiq (SOME File.check_dir) o #context) #> |
306 |
ML_Antiquotation.value @{binding path} |
|
307 |
(Args.context -- Scan.lift (Parse.position Parse.path) |
|
308 |
>> uncurry (ML_antiq NONE)) #> |
|
63669 | 309 |
ML_Antiquotation.value @{binding file} |
63675 | 310 |
(Args.context -- Scan.lift (Parse.position Parse.path) |
311 |
>> uncurry (ML_antiq (SOME File.check_file))) #> |
|
312 |
ML_Antiquotation.value @{binding dir} |
|
313 |
(Args.context -- Scan.lift (Parse.position Parse.path) |
|
314 |
>> uncurry (ML_antiq (SOME File.check_dir)))); |
|
49244
fb669aff821e
formal markup for @{file} (for hyperlinks etc.) -- interpret path wrt. master directory as usual;
wenzelm
parents:
48992
diff
changeset
|
315 |
|
6168 | 316 |
end; |
56135 | 317 |
|
318 |
end; |