author | wenzelm |
Fri, 26 Aug 2022 11:41:59 +0200 | |
changeset 75977 | 59aa034220bf |
parent 75679 | aa89255b704c |
child 75986 | 27d98da31985 |
permissions | -rw-r--r-- |
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 |
||
72841 | 22 |
val theory_entry = Parse.input Parse.theory_name --| Parse.opt_keyword "global"; |
67215 | 23 |
|
24 |
val theories = |
|
25 |
Parse.$$$ "theories" |-- Parse.!!! (Scan.optional Parse.options [] -- Scan.repeat1 theory_entry); |
|
26 |
||
68292 | 27 |
val in_path = |
72841 | 28 |
Parse.$$$ "(" |-- Parse.!!! (Parse.$$$ "in" |-- Parse.path_input --| Parse.$$$ ")"); |
68292 | 29 |
|
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
70683
diff
changeset
|
30 |
val document_theories = |
72841 | 31 |
Parse.$$$ "document_theories" |-- Scan.repeat1 (Parse.input Parse.theory_name); |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
70683
diff
changeset
|
32 |
|
67215 | 33 |
val document_files = |
34 |
Parse.$$$ "document_files" |-- |
|
72841 | 35 |
Parse.!!! (Scan.optional in_path (Input.string "document") -- Scan.repeat1 Parse.path_input); |
67215 | 36 |
|
69671 | 37 |
val prune = |
38 |
Scan.optional (Parse.$$$ "[" |-- Parse.!!! (Parse.nat --| Parse.$$$ "]")) 0; |
|
39 |
||
68292 | 40 |
val export_files = |
41 |
Parse.$$$ "export_files" |-- |
|
72841 | 42 |
Parse.!!! (Scan.optional in_path (Input.string "export") -- prune -- Scan.repeat1 Parse.embedded); |
43 |
||
75679
aa89255b704c
support for classpath artifacts within session structure:
wenzelm
parents:
74887
diff
changeset
|
44 |
val export_classpath = |
aa89255b704c
support for classpath artifacts within session structure:
wenzelm
parents:
74887
diff
changeset
|
45 |
Parse.$$$ "export_classpath" |-- Scan.repeat Parse.embedded; |
aa89255b704c
support for classpath artifacts within session structure:
wenzelm
parents:
74887
diff
changeset
|
46 |
|
72841 | 47 |
fun path_source source path = |
48 |
Input.source (Input.is_delimited source) (Path.implode path) (Input.range_of source); |
|
68292 | 49 |
|
67215 | 50 |
in |
51 |
||
52 |
val command_parser = |
|
53 |
Parse.session_name -- |
|
54 |
Scan.optional (Parse.$$$ "(" |-- Parse.!!! (Scan.repeat1 Parse.name --| Parse.$$$ ")")) [] -- |
|
72841 | 55 |
Scan.optional (Parse.$$$ "in" |-- Parse.!!! Parse.path_input) (Input.string ".") -- |
67220 | 56 |
(Parse.$$$ "=" |-- |
69349
7cef9e386ffe
more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents:
68808
diff
changeset
|
57 |
Parse.!!! (Scan.option (Parse.session_name --| Parse.!!! (Parse.$$$ "+")) -- |
74887 | 58 |
Scan.optional (Parse.$$$ "description" |-- Parse.!!! (Parse.input Parse.embedded)) Input.empty -- |
67220 | 59 |
Scan.optional (Parse.$$$ "options" |-- Parse.!!! Parse.options) [] -- |
60 |
Scan.optional (Parse.$$$ "sessions" |-- |
|
69349
7cef9e386ffe
more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents:
68808
diff
changeset
|
61 |
Parse.!!! (Scan.repeat1 Parse.session_name)) [] -- |
72841 | 62 |
Scan.optional (Parse.$$$ "directories" |-- Parse.!!! (Scan.repeat1 Parse.path_input)) [] -- |
67220 | 63 |
Scan.repeat theories -- |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
70683
diff
changeset
|
64 |
Scan.optional document_theories [] -- |
68292 | 65 |
Scan.repeat document_files -- |
75679
aa89255b704c
support for classpath artifacts within session structure:
wenzelm
parents:
74887
diff
changeset
|
66 |
Scan.repeat export_files -- |
aa89255b704c
support for classpath artifacts within session structure:
wenzelm
parents:
74887
diff
changeset
|
67 |
Scan.optional export_classpath [])) |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
70683
diff
changeset
|
68 |
>> (fn (((((session, _), _), dir), |
75679
aa89255b704c
support for classpath artifacts within session structure:
wenzelm
parents:
74887
diff
changeset
|
69 |
((((((((((parent, descr), options), sessions), directories), theories), |
aa89255b704c
support for classpath artifacts within session structure:
wenzelm
parents:
74887
diff
changeset
|
70 |
document_theories), document_files), export_files), _)))) => |
67215 | 71 |
Toplevel.keep (fn state => |
72 |
let |
|
73 |
val ctxt = Toplevel.context_of state; |
|
70049 | 74 |
val session_dir = Resources.check_dir ctxt NONE dir; |
67215 | 75 |
|
76 |
val _ = |
|
67220 | 77 |
(the_list parent @ sessions) |> List.app (fn arg => |
78 |
ignore (Resources.check_session ctxt arg) |
|
79 |
handle ERROR msg => Output.error_message msg); |
|
80 |
||
81 |
val _ = |
|
67215 | 82 |
Context_Position.report ctxt |
83 |
(Position.range_position (Symbol_Pos.range (Input.source_explode descr))) |
|
84 |
Markup.comment; |
|
85 |
||
86 |
val _ = |
|
87 |
(options @ maps #1 theories) |> List.app (fn (x, y) => |
|
67220 | 88 |
ignore (Completion.check_option_value ctxt x y (Options.default ())) |
89 |
handle ERROR msg => Output.error_message msg); |
|
67215 | 90 |
|
72841 | 91 |
fun check_thy source = |
92 |
ignore (Resources.check_file ctxt (SOME Path.current) source) |
|
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
70683
diff
changeset
|
93 |
handle ERROR msg => Output.error_message msg; |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
70683
diff
changeset
|
94 |
|
67215 | 95 |
val _ = |
72841 | 96 |
maps #2 theories |> List.app (fn source => |
67215 | 97 |
let |
72841 | 98 |
val s = Input.string_of source; |
99 |
val pos = Input.pos_of source; |
|
67215 | 100 |
val {node_name, theory_name, ...} = |
101 |
Resources.import_name session session_dir s |
|
102 |
handle ERROR msg => error (msg ^ Position.here pos); |
|
72841 | 103 |
val thy_path = the_default node_name (Resources.find_theory_file theory_name); |
104 |
in check_thy (path_source source thy_path) end); |
|
67215 | 105 |
|
106 |
val _ = |
|
70681 | 107 |
directories |> List.app (ignore o Resources.check_dir ctxt (SOME session_dir)); |
70668 | 108 |
|
109 |
val _ = |
|
72841 | 110 |
document_theories |> List.app (fn source => |
111 |
let |
|
112 |
val thy = Input.string_of source; |
|
113 |
val pos = Input.pos_of source; |
|
114 |
in |
|
115 |
(case Resources.find_theory_file thy of |
|
116 |
NONE => Output.error_message ("Unknown theory " ^ quote thy ^ Position.here pos) |
|
117 |
| SOME path => check_thy (path_source source path)) |
|
118 |
end); |
|
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
70683
diff
changeset
|
119 |
|
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
70683
diff
changeset
|
120 |
val _ = |
67215 | 121 |
document_files |> List.app (fn (doc_dir, doc_files) => |
122 |
let |
|
70049 | 123 |
val dir = Resources.check_dir ctxt (SOME session_dir) doc_dir; |
124 |
val _ = List.app (ignore o Resources.check_file ctxt (SOME dir)) doc_files; |
|
67215 | 125 |
in () end); |
68292 | 126 |
|
127 |
val _ = |
|
69671 | 128 |
export_files |> List.app (fn ((export_dir, _), _) => |
70049 | 129 |
ignore (Resources.check_path ctxt (SOME session_dir) export_dir)); |
67215 | 130 |
in () end)); |
131 |
||
132 |
end; |
|
133 |
||
134 |
end; |