author | wenzelm |
Thu, 28 Sep 2017 11:53:55 +0200 | |
changeset 66711 | 80fa1401cf76 |
parent 65532 | febfd9f78bd4 |
child 66712 | 4c98c929a12a |
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: |
65532 | 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 |
65457 | 15 |
val global_theory: string -> string option |
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
16 |
val loaded_theory: string -> string option |
65431
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
17 |
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
|
18 |
val master_directory: theory -> Path.T |
48927
ef462b5558eb
theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents:
48924
diff
changeset
|
19 |
val imports_of: theory -> (string * Position.T) list |
65505 | 20 |
val begin_theory: Path.T -> Thy_Header.header -> theory list -> theory |
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 |
66711
80fa1401cf76
discontinued extra checks (see ce676a750575 and 60c159d490a2) -- qualified theory names are meant to cover this;
wenzelm
parents:
65532
diff
changeset
|
23 |
val import_name: string -> Path.T -> string -> {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
|
24 |
val check_thy: Path.T -> string -> |
48928 | 25 |
{master: Path.T * SHA1.digest, text: string, theory_pos: Position.T, |
51293
05b1bbae748d
discontinued obsolete 'uses' within theory header;
wenzelm
parents:
51273
diff
changeset
|
26 |
imports: (string * Position.T) list, keywords: Thy_Header.keywords} |
54525 | 27 |
val parse_files: string -> (theory -> Token.file list) parser |
48906 | 28 |
val provide: Path.T * SHA1.digest -> theory -> theory |
29 |
val provide_parse_files: string -> (theory -> Token.file list * theory) parser |
|
54446 | 30 |
val loaded_files_current: theory -> bool |
6168 | 31 |
end; |
32 |
||
56208 | 33 |
structure Resources: RESOURCES = |
6168 | 34 |
struct |
35 |
||
65431
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
36 |
(* session base *) |
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
37 |
|
65532 | 38 |
val default_qualifier = "Draft"; |
39 |
||
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
|
40 |
val empty_session_base = |
65532 | 41 |
{global_theories = Symtab.empty: string Symtab.table, |
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
42 |
loaded_theories = Symtab.empty: string Symtab.table, |
65441 | 43 |
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
|
44 |
|
65441 | 45 |
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
|
46 |
Synchronized.var "Sessions.base" empty_session_base; |
65441 | 47 |
|
65532 | 48 |
fun init_session_base {global_theories, loaded_theories, known_theories} = |
65431
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
49 |
Synchronized.change global_session_base |
65441 | 50 |
(fn _ => |
65532 | 51 |
{global_theories = Symtab.make global_theories, |
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
52 |
loaded_theories = Symtab.make loaded_theories, |
65441 | 53 |
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
|
54 |
|
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
|
55 |
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
|
56 |
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
|
57 |
(fn {global_theories, loaded_theories, ...} => |
65532 | 58 |
{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
|
59 |
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
|
60 |
known_theories = #known_theories empty_session_base}); |
65441 | 61 |
|
62 |
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
|
63 |
|
65457 | 64 |
fun global_theory a = Symtab.lookup (get_session_base #global_theories) a; |
65441 | 65 |
fun loaded_theory a = Symtab.lookup (get_session_base #loaded_theories) a; |
66 |
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
|
67 |
|
4a3e6cda3b94
provide session base for "isabelle build" and "isabelle console" ML process;
wenzelm
parents:
65058
diff
changeset
|
68 |
|
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
|
69 |
(* 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
|
70 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
71 |
type files = |
40741
17d6293a1e26
moved file identification to thy_load.ML (where it is actually used);
wenzelm
parents:
40625
diff
changeset
|
72 |
{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
|
73 |
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
|
74 |
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
|
75 |
|
48886
9604c6563226
discontinued separate list of required files -- maintain only provided files as they occur at runtime;
wenzelm
parents:
48881
diff
changeset
|
76 |
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
|
77 |
{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
|
78 |
|
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 |
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
|
80 |
( |
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
81 |
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
|
82 |
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
|
83 |
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
|
84 |
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
|
85 |
); |
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
86 |
|
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 |
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
|
88 |
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
|
89 |
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
|
90 |
|
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
wenzelm
parents:
37943
diff
changeset
|
91 |
|
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 |
val master_directory = #master_dir o Files.get; |
41548
bd0bebf93fa6
Thy_Load.begin_theory: maintain source specification of imports;
wenzelm
parents:
41414
diff
changeset
|
93 |
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
|
94 |
|
65505 | 95 |
fun begin_theory master_dir {name, imports, keywords} parents = |
96 |
Theory.begin_theory name parents |
|
97 |
|> map_files (fn _ => (master_dir, imports, [])) |
|
98 |
|> 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
|
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 |
|
54525 | 101 |
(* theory files *) |
102 |
||
103 |
val thy_path = Path.ext "thy"; |
|
48869 | 104 |
|
65445
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65443
diff
changeset
|
105 |
fun theory_qualifier theory = |
65457 | 106 |
(case global_theory theory of |
107 |
SOME qualifier => qualifier |
|
108 |
| NONE => Long_Name.qualifier theory); |
|
65445
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65443
diff
changeset
|
109 |
|
65476 | 110 |
fun theory_name qualifier theory0 = |
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
111 |
(case loaded_theory theory0 of |
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
112 |
SOME theory => (true, theory) |
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
113 |
| NONE => |
65474 | 114 |
let val theory = |
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
115 |
if Long_Name.is_qualified theory0 orelse is_some (global_theory theory0) |
65503 | 116 |
then theory0 |
65474 | 117 |
else Long_Name.qualify qualifier theory0 |
118 |
in (false, theory) end); |
|
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
119 |
|
65454 | 120 |
fun import_name qualifier dir s = |
65476 | 121 |
(case theory_name qualifier (Thy_Header.import_name s) of |
66711
80fa1401cf76
discontinued extra checks (see ce676a750575 and 60c159d490a2) -- qualified theory names are meant to cover this;
wenzelm
parents:
65532
diff
changeset
|
122 |
(true, theory) => {master_dir = Path.current, theory_name = theory} |
65474 | 123 |
| (false, theory) => |
124 |
let val node_name = |
|
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
125 |
(case known_theory theory of |
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65457
diff
changeset
|
126 |
SOME node_name => node_name |
65474 | 127 |
| NONE => File.full_path dir (thy_path (Path.expand (Path.explode s)))) |
66711
80fa1401cf76
discontinued extra checks (see ce676a750575 and 60c159d490a2) -- qualified theory names are meant to cover this;
wenzelm
parents:
65532
diff
changeset
|
128 |
in {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
|
129 |
|
48878 | 130 |
fun check_file dir file = File.check_file (File.full_path dir file); |
131 |
||
54525 | 132 |
fun check_thy dir thy_name = |
133 |
let |
|
65433 | 134 |
val thy_base_name = Long_Name.base_name thy_name; |
135 |
val master_file = |
|
136 |
(case known_theory thy_name of |
|
65442 | 137 |
SOME known_path => check_file Path.current known_path |
138 |
| NONE => check_file dir (thy_path (Path.basic thy_base_name))); |
|
54525 | 139 |
val text = File.read master_file; |
140 |
||
141 |
val {name = (name, pos), imports, keywords} = |
|
142 |
Thy_Header.read (Path.position master_file) text; |
|
65433 | 143 |
val _ = |
144 |
thy_base_name <> name andalso |
|
145 |
error ("Bad theory name " ^ quote name ^ |
|
65442 | 146 |
" for file " ^ Path.print (Path.base master_file) ^ Position.here pos); |
54525 | 147 |
in |
148 |
{master = (master_file, SHA1.digest text), text = text, theory_pos = pos, |
|
149 |
imports = imports, keywords = keywords} |
|
150 |
end; |
|
151 |
||
152 |
||
54526 | 153 |
(* 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
|
154 |
|
9fc880720663
simplified Thy_Load.check_thy (again) -- no need to pass keywords nor find files in body text;
wenzelm
parents:
48897
diff
changeset
|
155 |
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
|
156 |
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
|
157 |
(case Token.get_files tok of |
54526 | 158 |
[] => |
159 |
let |
|
58928
23d0ffd48006
plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents:
58923
diff
changeset
|
160 |
val keywords = Thy_Header.get_keywords thy; |
54526 | 161 |
val master_dir = master_directory thy; |
55708 | 162 |
val pos = Token.pos_of tok; |
58923 | 163 |
val src_paths = Keyword.command_files keywords cmd (Path.explode name); |
54526 | 164 |
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
|
165 |
| files => map Exn.release files)); |
48869 | 166 |
|
48906 | 167 |
fun provide (src_path, id) = |
168 |
map_files (fn (master_dir, imports, provided) => |
|
169 |
if AList.defined (op =) provided src_path then |
|
170 |
error ("Duplicate use of source file: " ^ Path.print src_path) |
|
171 |
else (master_dir, imports, (src_path, id) :: provided)); |
|
172 |
||
173 |
fun provide_parse_files cmd = |
|
174 |
parse_files cmd >> (fn files => fn thy => |
|
175 |
let |
|
176 |
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
|
177 |
val thy' = fold (fn {src_path, digest, ...} => provide (src_path, digest)) fs thy; |
48906 | 178 |
in (fs, thy') end); |
179 |
||
43702
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
180 |
fun load_file thy src_path = |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
181 |
let |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
182 |
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
|
183 |
val text = File.read full_path; |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
184 |
val id = SHA1.digest text; |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
185 |
in ((full_path, id), text) end; |
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
186 |
|
54446 | 187 |
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
|
188 |
#provided (Files.get thy) |> |
48896
bb1f461a7815
simplified Thy_Load.provide: do not store full path;
wenzelm
parents:
48888
diff
changeset
|
189 |
forall (fn (src_path, id) => |
43702
24fb44c1086a
more abstract Thy_Load.load_file/use_file for external theory resources;
wenzelm
parents:
43700
diff
changeset
|
190 |
(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
|
191 |
NONE => false |
48886
9604c6563226
discontinued separate list of required files -- maintain only provided files as they occur at runtime;
wenzelm
parents:
48881
diff
changeset
|
192 |
| SOME ((_, id'), _) => id = id')); |
37952 | 193 |
|
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
|
194 |
|
56135 | 195 |
(* antiquotations *) |
49244
fb669aff821e
formal markup for @{file} (for hyperlinks etc.) -- interpret path wrt. master directory as usual;
wenzelm
parents:
48992
diff
changeset
|
196 |
|
56135 | 197 |
local |
198 |
||
63669 | 199 |
fun err msg pos = error (msg ^ Position.here pos); |
200 |
||
63675 | 201 |
fun check_path check_file ctxt dir (name, pos) = |
54705 | 202 |
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
|
203 |
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
|
204 |
|
63669 | 205 |
val path = Path.append dir (Path.explode name) handle ERROR msg => err msg pos; |
206 |
val _ = Path.expand path handle ERROR msg => err msg pos; |
|
56134 | 207 |
val _ = Context_Position.report ctxt pos (Markup.path (Path.smart_implode path)); |
63669 | 208 |
val _ = |
209 |
(case check_file of |
|
210 |
NONE => path |
|
211 |
| SOME check => (check path handle ERROR msg => err msg pos)); |
|
63675 | 212 |
in path end; |
213 |
||
214 |
fun document_antiq check_file ctxt (name, pos) = |
|
215 |
let |
|
216 |
val dir = master_directory (Proof_Context.theory_of ctxt); |
|
217 |
val _ = check_path check_file ctxt dir (name, pos); |
|
54705 | 218 |
in |
219 |
space_explode "/" name |
|
58716
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
57918
diff
changeset
|
220 |
|> map Latex.output_ascii |
23a380cc45f4
official support for "tt" style variants, avoid fragile \verb in LaTeX;
wenzelm
parents:
57918
diff
changeset
|
221 |
|> space_implode (Latex.output_ascii "/" ^ "\\discretionary{}{}{}") |
58741
6e7b009e6d94
clarified verbatim line breaks, e.g. relevant for Implementation mldecls;
wenzelm
parents:
58716
diff
changeset
|
222 |
|> enclose "\\isatt{" "}" |
54705 | 223 |
end; |
224 |
||
63675 | 225 |
fun ML_antiq check_file ctxt (name, pos) = |
226 |
let val path = check_path check_file ctxt Path.current (name, pos); |
|
227 |
in "Path.explode " ^ ML_Syntax.print_string (Path.implode path) end; |
|
228 |
||
56135 | 229 |
in |
230 |
||
53171 | 231 |
val _ = Theory.setup |
63669 | 232 |
(Thy_Output.antiquotation @{binding path} (Scan.lift (Parse.position Parse.path)) |
63675 | 233 |
(document_antiq NONE o #context) #> |
63669 | 234 |
Thy_Output.antiquotation @{binding file} (Scan.lift (Parse.position Parse.path)) |
63675 | 235 |
(document_antiq (SOME File.check_file) o #context) #> |
63669 | 236 |
Thy_Output.antiquotation @{binding dir} (Scan.lift (Parse.position Parse.path)) |
63675 | 237 |
(document_antiq (SOME File.check_dir) o #context) #> |
238 |
ML_Antiquotation.value @{binding path} |
|
239 |
(Args.context -- Scan.lift (Parse.position Parse.path) |
|
240 |
>> uncurry (ML_antiq NONE)) #> |
|
63669 | 241 |
ML_Antiquotation.value @{binding file} |
63675 | 242 |
(Args.context -- Scan.lift (Parse.position Parse.path) |
243 |
>> uncurry (ML_antiq (SOME File.check_file))) #> |
|
244 |
ML_Antiquotation.value @{binding dir} |
|
245 |
(Args.context -- Scan.lift (Parse.position Parse.path) |
|
246 |
>> 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
|
247 |
|
6168 | 248 |
end; |
56135 | 249 |
|
250 |
end; |