67215
|
1 |
(* Title: Pure/Thy/sessions.ML
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Support for session ROOT syntax.
|
|
5 |
*)
|
|
6 |
|
|
7 |
signature SESSIONS =
|
|
8 |
sig
|
|
9 |
val root_name: string
|
|
10 |
val theory_name: string
|
|
11 |
val command_parser: (Toplevel.transition -> Toplevel.transition) parser
|
|
12 |
end;
|
|
13 |
|
|
14 |
structure Sessions: SESSIONS =
|
|
15 |
struct
|
|
16 |
|
|
17 |
val root_name = "ROOT";
|
|
18 |
val theory_name = "Pure.Sessions";
|
|
19 |
|
|
20 |
local
|
|
21 |
|
|
22 |
val global =
|
|
23 |
Parse.$$$ "(" -- Parse.!!! (Parse.$$$ "global" -- Parse.$$$ ")") >> K true || Scan.succeed false;
|
|
24 |
|
|
25 |
val theory_entry = Parse.position Parse.theory_name --| global;
|
|
26 |
|
|
27 |
val theories =
|
|
28 |
Parse.$$$ "theories" |-- Parse.!!! (Scan.optional Parse.options [] -- Scan.repeat1 theory_entry);
|
|
29 |
|
|
30 |
val document_files =
|
|
31 |
Parse.$$$ "document_files" |--
|
|
32 |
Parse.!!!
|
|
33 |
(Scan.optional
|
|
34 |
(Parse.$$$ "(" |--
|
|
35 |
Parse.!!! (Parse.$$$ "in" |-- Parse.position Parse.path --| Parse.$$$ ")"))
|
|
36 |
("document", Position.none)
|
|
37 |
-- Scan.repeat1 (Parse.position Parse.path));
|
|
38 |
|
|
39 |
in
|
|
40 |
|
|
41 |
val command_parser =
|
|
42 |
Parse.session_name --
|
|
43 |
Scan.optional (Parse.$$$ "(" |-- Parse.!!! (Scan.repeat1 Parse.name --| Parse.$$$ ")")) [] --
|
|
44 |
Scan.optional (Parse.$$$ "in" |-- Parse.!!! (Parse.position Parse.path)) (".", Position.none) --
|
|
45 |
(Parse.$$$ "=" |-- Parse.!!! (Scan.option (Parse.session_name --| Parse.!!! (Parse.$$$ "+")) --
|
|
46 |
Scan.optional (Parse.$$$ "description" |-- Parse.!!! (Parse.input Parse.text)) Input.empty --
|
|
47 |
Scan.optional (Parse.$$$ "options" |-- Parse.!!! Parse.options) [] --
|
|
48 |
Scan.optional (Parse.$$$ "sessions" |-- Parse.!!! (Scan.repeat1 Parse.session_name)) [] --
|
|
49 |
Scan.repeat theories --
|
|
50 |
Scan.repeat document_files))
|
|
51 |
>> (fn (((session, _), dir), ((((((_, descr), options), _), theories), document_files))) =>
|
|
52 |
Toplevel.keep (fn state =>
|
|
53 |
let
|
|
54 |
val ctxt = Toplevel.context_of state;
|
|
55 |
val thy = Toplevel.theory_of state;
|
|
56 |
val session_dir = Resources.check_dir ctxt (Resources.master_directory thy) dir;
|
|
57 |
|
|
58 |
val _ =
|
|
59 |
Context_Position.report ctxt
|
|
60 |
(Position.range_position (Symbol_Pos.range (Input.source_explode descr)))
|
|
61 |
Markup.comment;
|
|
62 |
|
|
63 |
val _ =
|
|
64 |
(options @ maps #1 theories) |> List.app (fn (x, y) =>
|
|
65 |
ignore (Completion.check_option_value ctxt x y (Options.default ())));
|
|
66 |
|
|
67 |
val _ =
|
|
68 |
maps #2 theories |> List.app (fn (s, pos) =>
|
|
69 |
let
|
|
70 |
val {node_name, theory_name, ...} =
|
|
71 |
Resources.import_name session session_dir s
|
|
72 |
handle ERROR msg => error (msg ^ Position.here pos);
|
|
73 |
val theory_path = the_default node_name (Resources.known_theory theory_name);
|
|
74 |
val _ = Resources.check_file ctxt Path.current (Path.implode theory_path, pos);
|
|
75 |
in () end);
|
|
76 |
|
|
77 |
val _ =
|
|
78 |
document_files |> List.app (fn (doc_dir, doc_files) =>
|
|
79 |
let
|
|
80 |
val dir = Resources.check_dir ctxt session_dir doc_dir;
|
|
81 |
val _ = List.app (ignore o Resources.check_file ctxt dir) doc_files;
|
|
82 |
in () end);
|
|
83 |
in () end));
|
|
84 |
|
|
85 |
end;
|
|
86 |
|
|
87 |
end;
|