author | wenzelm |
Tue, 23 Jan 2018 19:25:39 +0100 | |
changeset 67493 | c4e9e0c50487 |
parent 67473 | aad088768872 |
child 68088 | 0763d4eb3ebc |
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 |
65532 | 9 |
val default_qualifier: string |
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
|
10 |
val init_session_base: |
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
11 |
{sessions: (string * Properties.T) list, |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
12 |
docs: string list, |
67219 | 13 |
global_theories: (string * string) list, |
66712 | 14 |
loaded_theories: string list, |
65441 | 15 |
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
|
16 |
val finish_session_base: unit -> unit |
65457 | 17 |
val global_theory: string -> string option |
66712 | 18 |
val loaded_theory: string -> bool |
65431
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
19 |
val known_theory: string -> Path.T option |
67219 | 20 |
val check_session: Proof.context -> string * Position.T -> string |
67471 | 21 |
val check_doc: Proof.context -> string * Position.T -> 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
|
22 |
val master_directory: theory -> Path.T |
48927
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents:
48924
diff
changeset
|
23 |
val imports_of: theory -> (string * Position.T) list |
65505 | 24 |
val begin_theory: Path.T -> Thy_Header.header -> theory list -> theory |
46737 | 25 |
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
|
26 |
val theory_qualifier: string -> string |
67215 | 27 |
val import_name: string -> Path.T -> string -> |
28 |
{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
|
29 |
val check_thy: Path.T -> string -> |
48928 | 30 |
{master: Path.T * SHA1.digest, text: string, theory_pos: Position.T, |
51293
05b1bbae748d
discontinued obsolete 'uses' within theory header;
wenzelm
parents:
51273
diff
changeset
|
31 |
imports: (string * Position.T) list, keywords: Thy_Header.keywords} |
54525 | 32 |
val parse_files: string -> (theory -> Token.file list) parser |
48906 | 33 |
val provide: Path.T * SHA1.digest -> theory -> theory |
34 |
val provide_parse_files: string -> (theory -> Token.file list * theory) parser |
|
54446 | 35 |
val loaded_files_current: theory -> bool |
67209 | 36 |
val check_path: Proof.context -> Path.T -> string * Position.T -> Path.T |
37 |
val check_file: Proof.context -> Path.T -> string * Position.T -> Path.T |
|
38 |
val check_dir: Proof.context -> Path.T -> string * Position.T -> Path.T |
|
6168 | 39 |
end; |
40 |
||
56208 | 41 |
structure Resources: RESOURCES = |
6168 | 42 |
struct |
43 |
||
65431
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
44 |
(* session base *) |
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
45 |
|
65532 | 46 |
val default_qualifier = "Draft"; |
47 |
||
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
48 |
type entry = {pos: Position.T, serial: serial}; |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
49 |
|
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
50 |
fun make_entry props : entry = |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
51 |
{pos = Position.of_properties props, serial = serial ()}; |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
52 |
|
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
|
53 |
val empty_session_base = |
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
54 |
{sessions = []: (string * entry) list, |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
55 |
docs = []: (string * entry) list, |
67219 | 56 |
global_theories = Symtab.empty: string Symtab.table, |
66712 | 57 |
loaded_theories = Symtab.empty: unit Symtab.table, |
65441 | 58 |
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
|
59 |
|
65441 | 60 |
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
|
61 |
Synchronized.var "Sessions.base" empty_session_base; |
65441 | 62 |
|
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
63 |
fun init_session_base {sessions, docs, global_theories, loaded_theories, known_theories} = |
65431
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
64 |
Synchronized.change global_session_base |
65441 | 65 |
(fn _ => |
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
66 |
{sessions = sort_by #1 (map (apsnd make_entry) sessions), |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
67 |
docs = sort_by #1 (map (apsnd make_entry o rpair []) docs), |
67219 | 68 |
global_theories = Symtab.make global_theories, |
66712 | 69 |
loaded_theories = Symtab.make_set loaded_theories, |
65441 | 70 |
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
|
71 |
|
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
|
72 |
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
|
73 |
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
|
74 |
(fn {global_theories, loaded_theories, ...} => |
67219 | 75 |
{sessions = [], |
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
76 |
docs = [], |
67219 | 77 |
global_theories = global_theories, |
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
|
78 |
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
|
79 |
known_theories = #known_theories empty_session_base}); |
65441 | 80 |
|
81 |
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
|
82 |
|
65457 | 83 |
fun global_theory a = Symtab.lookup (get_session_base #global_theories) a; |
66712 | 84 |
fun loaded_theory a = Symtab.defined (get_session_base #loaded_theories) a; |
65441 | 85 |
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
|
86 |
|
67471 | 87 |
fun check_name which kind markup ctxt (name, pos) = |
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
88 |
let val entries = get_session_base which in |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
89 |
(case AList.lookup (op =) entries name of |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
90 |
SOME entry => (Context_Position.report ctxt pos (markup name entry); name) |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
91 |
| NONE => |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
92 |
let |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
93 |
val completion = |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
94 |
Completion.make (name, pos) (fn completed => |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
95 |
entries |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
96 |
|> map #1 |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
97 |
|> filter completed |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
98 |
|> sort_strings |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
99 |
|> map (fn a => (a, (kind, a)))); |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
100 |
val report = Markup.markup_report (Completion.reported_text completion); |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
101 |
in error ("Bad " ^ kind ^ " " ^ quote name ^ Position.here pos ^ report) end) |
67219 | 102 |
end; |
103 |
||
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
104 |
fun markup_session name {pos, serial} = |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
105 |
Markup.properties |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
106 |
(Position.entity_properties_of false serial pos) (Markup.entity Markup.sessionN name); |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
107 |
|
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
108 |
val check_session = check_name #sessions "session" markup_session; |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67473
diff
changeset
|
109 |
val check_doc = check_name #docs "documentation" (fn name => fn _ => Markup.doc name); |
67471 | 110 |
|
111 |
||
65431
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
112 |
|
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
|
113 |
(* 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
|
114 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
115 |
type files = |
40741
17d6293a1e26
moved file identification to thy_load.ML (where it is actually used);
wenzelm
parents:
40625
diff
changeset
|
116 |
{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
|
117 |
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
|
118 |
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
|
119 |
|
48886
9604c6563226
discontinued separate list of required files -- maintain only provided files as they occur at runtime;
wenzelm
parents:
48881
diff
changeset
|
120 |
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
|
121 |
{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
|
122 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
123 |
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
|
124 |
( |
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
); |
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
130 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
135 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
136 |
val master_directory = #master_dir o Files.get; |
41548
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents:
41414
diff
changeset
|
137 |
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
|
138 |
|
65505 | 139 |
fun begin_theory master_dir {name, imports, keywords} parents = |
140 |
Theory.begin_theory name parents |
|
141 |
|> map_files (fn _ => (master_dir, imports, [])) |
|
142 |
|> Thy_Header.add_keywords keywords; |
|
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
|
143 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
144 |
|
54525 | 145 |
(* theory files *) |
146 |
||
147 |
val thy_path = Path.ext "thy"; |
|
48869 | 148 |
|
65445
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65443
diff
changeset
|
149 |
fun theory_qualifier theory = |
65457 | 150 |
(case global_theory theory of |
151 |
SOME qualifier => qualifier |
|
152 |
| NONE => Long_Name.qualifier theory); |
|
65445
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65443
diff
changeset
|
153 |
|
66712 | 154 |
fun theory_name qualifier theory = |
67104
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
wenzelm
parents:
66771
diff
changeset
|
155 |
if Long_Name.is_qualified theory orelse is_some (global_theory theory) |
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
wenzelm
parents:
66771
diff
changeset
|
156 |
then theory |
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
wenzelm
parents:
66771
diff
changeset
|
157 |
else Long_Name.qualify qualifier theory; |
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
158 |
|
65454 | 159 |
fun import_name qualifier dir s = |
67104
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
wenzelm
parents:
66771
diff
changeset
|
160 |
let val theory = theory_name qualifier (Thy_Header.import_name s) in |
67215 | 161 |
if loaded_theory theory |
162 |
then {node_name = Path.basic theory, master_dir = Path.current, theory_name = theory} |
|
67104
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
wenzelm
parents:
66771
diff
changeset
|
163 |
else |
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
wenzelm
parents:
66771
diff
changeset
|
164 |
let |
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
wenzelm
parents:
66771
diff
changeset
|
165 |
val node_name = |
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
wenzelm
parents:
66771
diff
changeset
|
166 |
(case known_theory theory of |
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
wenzelm
parents:
66771
diff
changeset
|
167 |
SOME node_name => node_name |
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
wenzelm
parents:
66771
diff
changeset
|
168 |
| NONE => |
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
wenzelm
parents:
66771
diff
changeset
|
169 |
if Thy_Header.is_base_name s andalso Long_Name.is_qualified s |
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
wenzelm
parents:
66771
diff
changeset
|
170 |
then Path.explode s |
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
wenzelm
parents:
66771
diff
changeset
|
171 |
else File.full_path dir (thy_path (Path.expand (Path.explode s)))); |
67215 | 172 |
in {node_name = node_name, master_dir = Path.dir node_name, theory_name = theory} end |
67104
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
wenzelm
parents:
66771
diff
changeset
|
173 |
end; |
65443
dccbfc715904
provide Resources.import_name in ML, similar to Scala version;
wenzelm
parents:
65442
diff
changeset
|
174 |
|
48878 | 175 |
fun check_file dir file = File.check_file (File.full_path dir file); |
176 |
||
54525 | 177 |
fun check_thy dir thy_name = |
178 |
let |
|
65433 | 179 |
val thy_base_name = Long_Name.base_name thy_name; |
180 |
val master_file = |
|
181 |
(case known_theory thy_name of |
|
65442 | 182 |
SOME known_path => check_file Path.current known_path |
183 |
| NONE => check_file dir (thy_path (Path.basic thy_base_name))); |
|
54525 | 184 |
val text = File.read master_file; |
185 |
||
186 |
val {name = (name, pos), imports, keywords} = |
|
187 |
Thy_Header.read (Path.position master_file) text; |
|
65433 | 188 |
val _ = |
189 |
thy_base_name <> name andalso |
|
190 |
error ("Bad theory name " ^ quote name ^ |
|
65442 | 191 |
" for file " ^ Path.print (Path.base master_file) ^ Position.here pos); |
54525 | 192 |
in |
193 |
{master = (master_file, SHA1.digest text), text = text, theory_pos = pos, |
|
194 |
imports = imports, keywords = keywords} |
|
195 |
end; |
|
196 |
||
197 |
||
54526 | 198 |
(* 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
|
199 |
|
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
200 |
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
|
201 |
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
|
202 |
(case Token.get_files tok of |
54526 | 203 |
[] => |
204 |
let |
|
58928
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents:
58923
diff
changeset
|
205 |
val keywords = Thy_Header.get_keywords thy; |
54526 | 206 |
val master_dir = master_directory thy; |
55708 | 207 |
val pos = Token.pos_of tok; |
58923 | 208 |
val src_paths = Keyword.command_files keywords cmd (Path.explode name); |
54526 | 209 |
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
|
210 |
| files => map Exn.release files)); |
48869 | 211 |
|
48906 | 212 |
fun provide (src_path, id) = |
213 |
map_files (fn (master_dir, imports, provided) => |
|
214 |
if AList.defined (op =) provided src_path then |
|
215 |
error ("Duplicate use of source file: " ^ Path.print src_path) |
|
216 |
else (master_dir, imports, (src_path, id) :: provided)); |
|
217 |
||
218 |
fun provide_parse_files cmd = |
|
219 |
parse_files cmd >> (fn files => fn thy => |
|
220 |
let |
|
221 |
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
|
222 |
val thy' = fold (fn {src_path, digest, ...} => provide (src_path, digest)) fs thy; |
48906 | 223 |
in (fs, thy') end); |
224 |
||
43702
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
225 |
fun load_file thy src_path = |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
226 |
let |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
227 |
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
|
228 |
val text = File.read full_path; |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
229 |
val id = SHA1.digest text; |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
230 |
in ((full_path, id), text) end; |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
231 |
|
54446 | 232 |
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
|
233 |
#provided (Files.get thy) |> |
48896
bb1f461a7815
simplified Thy_Load.provide: do not store full path;
wenzelm
parents:
48888
diff
changeset
|
234 |
forall (fn (src_path, id) => |
43702
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
235 |
(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
|
236 |
NONE => false |
48886
9604c6563226
discontinued separate list of required files -- maintain only provided files as they occur at runtime;
wenzelm
parents:
48881
diff
changeset
|
237 |
| SOME ((_, id'), _) => id = id')); |
37952 | 238 |
|
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
|
239 |
|
67217 | 240 |
(* formal check *) |
49244
fb669aff821e
formal markup for @{file} (for hyperlinks etc.) -- interpret path wrt. master directory as usual;
wenzelm
parents:
48992
diff
changeset
|
241 |
|
67217 | 242 |
fun formal_check check_file ctxt dir (name, pos) = |
54705 | 243 |
let |
67214 | 244 |
fun err msg = error (msg ^ Position.here pos); |
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
|
245 |
|
67214 | 246 |
val _ = Context_Position.report ctxt pos Markup.language_path; |
247 |
val path = Path.append dir (Path.explode name) handle ERROR msg => err msg; |
|
248 |
val _ = Path.expand path handle ERROR msg => err msg; |
|
56134 | 249 |
val _ = Context_Position.report ctxt pos (Markup.path (Path.smart_implode path)); |
67214 | 250 |
val _ = check_file path handle ERROR msg => err msg; |
63675 | 251 |
in path end; |
252 |
||
67217 | 253 |
val check_path = formal_check I; |
254 |
val check_file = formal_check File.check_file; |
|
255 |
val check_dir = formal_check File.check_dir; |
|
256 |
||
257 |
||
258 |
(* antiquotations *) |
|
259 |
||
260 |
local |
|
261 |
||
67209 | 262 |
fun document_antiq check ctxt (name, pos) = |
63675 | 263 |
let |
264 |
val dir = master_directory (Proof_Context.theory_of ctxt); |
|
67209 | 265 |
val _ = check ctxt dir (name, pos); |
67463 | 266 |
val latex = |
267 |
space_explode "/" name |
|
268 |
|> map Latex.output_ascii |
|
269 |
|> space_implode (Latex.output_ascii "/" ^ "\\discretionary{}{}{}"); |
|
270 |
in Latex.enclose_block "\\isatt{" "}" [Latex.string latex] end; |
|
54705 | 271 |
|
67209 | 272 |
fun ML_antiq check ctxt (name, pos) = |
273 |
let val path = check ctxt Path.current (name, pos); |
|
63675 | 274 |
in "Path.explode " ^ ML_Syntax.print_string (Path.implode path) end; |
275 |
||
56135 | 276 |
in |
277 |
||
53171 | 278 |
val _ = Theory.setup |
67463 | 279 |
(Thy_Output.antiquotation_verbatim \<^binding>\<open>session\<close> |
280 |
(Scan.lift (Parse.position Parse.embedded)) check_session #> |
|
67471 | 281 |
Thy_Output.antiquotation_verbatim \<^binding>\<open>doc\<close> |
282 |
(Scan.lift (Parse.position Parse.embedded)) check_doc #> |
|
67463 | 283 |
Thy_Output.antiquotation_raw \<^binding>\<open>path\<close> |
284 |
(Scan.lift (Parse.position Parse.path)) (document_antiq check_path) #> |
|
285 |
Thy_Output.antiquotation_raw \<^binding>\<open>file\<close> |
|
286 |
(Scan.lift (Parse.position Parse.path)) (document_antiq check_file) #> |
|
287 |
Thy_Output.antiquotation_raw \<^binding>\<open>dir\<close> |
|
288 |
(Scan.lift (Parse.position Parse.path)) (document_antiq check_dir) #> |
|
67147 | 289 |
ML_Antiquotation.value \<^binding>\<open>path\<close> |
67209 | 290 |
(Args.context -- Scan.lift (Parse.position Parse.path) >> uncurry (ML_antiq check_path)) #> |
67147 | 291 |
ML_Antiquotation.value \<^binding>\<open>file\<close> |
67209 | 292 |
(Args.context -- Scan.lift (Parse.position Parse.path) >> uncurry (ML_antiq check_file)) #> |
67147 | 293 |
ML_Antiquotation.value \<^binding>\<open>dir\<close> |
67209 | 294 |
(Args.context -- Scan.lift (Parse.position Parse.path) >> uncurry (ML_antiq check_dir))); |
49244
fb669aff821e
formal markup for @{file} (for hyperlinks etc.) -- interpret path wrt. master directory as usual;
wenzelm
parents:
48992
diff
changeset
|
295 |
|
6168 | 296 |
end; |
56135 | 297 |
|
298 |
end; |