author | wenzelm |
Sat, 27 Aug 2022 17:46:58 +0200 | |
changeset 76005 | a9bbf075f431 |
parent 75998 | c36e5c6f3069 |
child 76614 | ac08b6e3b9e3 |
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 |
|
75986
27d98da31985
support 'chapter_definition' with description for presentation purposes;
wenzelm
parents:
75679
diff
changeset
|
11 |
val chapter_definition_parser: (Toplevel.transition -> Toplevel.transition) parser |
27d98da31985
support 'chapter_definition' with description for presentation purposes;
wenzelm
parents:
75679
diff
changeset
|
12 |
val session_parser: (Toplevel.transition -> Toplevel.transition) parser |
67215 | 13 |
end; |
14 |
||
15 |
structure Sessions: SESSIONS = |
|
16 |
struct |
|
17 |
||
18 |
val root_name = "ROOT"; |
|
19 |
val theory_name = "Pure.Sessions"; |
|
20 |
||
21 |
local |
|
22 |
||
76005
a9bbf075f431
include groups from 'chapter_definition' in session info, based on the state of chapter_defs after processing all ROOT files (thus the declaration order does not matter);
wenzelm
parents:
75998
diff
changeset
|
23 |
val groups = |
a9bbf075f431
include groups from 'chapter_definition' in session info, based on the state of chapter_defs after processing all ROOT files (thus the declaration order does not matter);
wenzelm
parents:
75998
diff
changeset
|
24 |
Scan.optional (Parse.$$$ "(" |-- Parse.!!! (Scan.repeat1 Parse.name --| Parse.$$$ ")")) []; |
a9bbf075f431
include groups from 'chapter_definition' in session info, based on the state of chapter_defs after processing all ROOT files (thus the declaration order does not matter);
wenzelm
parents:
75998
diff
changeset
|
25 |
|
75998 | 26 |
val description = |
27 |
Scan.optional (Parse.$$$ "description" |-- Parse.!!! (Parse.input Parse.embedded)) Input.empty; |
|
28 |
||
72841 | 29 |
val theory_entry = Parse.input Parse.theory_name --| Parse.opt_keyword "global"; |
67215 | 30 |
|
31 |
val theories = |
|
32 |
Parse.$$$ "theories" |-- Parse.!!! (Scan.optional Parse.options [] -- Scan.repeat1 theory_entry); |
|
33 |
||
68292 | 34 |
val in_path = |
72841 | 35 |
Parse.$$$ "(" |-- Parse.!!! (Parse.$$$ "in" |-- Parse.path_input --| Parse.$$$ ")"); |
68292 | 36 |
|
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
70683
diff
changeset
|
37 |
val document_theories = |
72841 | 38 |
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
|
39 |
|
67215 | 40 |
val document_files = |
41 |
Parse.$$$ "document_files" |-- |
|
72841 | 42 |
Parse.!!! (Scan.optional in_path (Input.string "document") -- Scan.repeat1 Parse.path_input); |
67215 | 43 |
|
69671 | 44 |
val prune = |
45 |
Scan.optional (Parse.$$$ "[" |-- Parse.!!! (Parse.nat --| Parse.$$$ "]")) 0; |
|
46 |
||
68292 | 47 |
val export_files = |
48 |
Parse.$$$ "export_files" |-- |
|
72841 | 49 |
Parse.!!! (Scan.optional in_path (Input.string "export") -- prune -- Scan.repeat1 Parse.embedded); |
50 |
||
75679
aa89255b704c
support for classpath artifacts within session structure:
wenzelm
parents:
74887
diff
changeset
|
51 |
val export_classpath = |
aa89255b704c
support for classpath artifacts within session structure:
wenzelm
parents:
74887
diff
changeset
|
52 |
Parse.$$$ "export_classpath" |-- Scan.repeat Parse.embedded; |
aa89255b704c
support for classpath artifacts within session structure:
wenzelm
parents:
74887
diff
changeset
|
53 |
|
72841 | 54 |
fun path_source source path = |
55 |
Input.source (Input.is_delimited source) (Path.implode path) (Input.range_of source); |
|
68292 | 56 |
|
67215 | 57 |
in |
58 |
||
75986
27d98da31985
support 'chapter_definition' with description for presentation purposes;
wenzelm
parents:
75679
diff
changeset
|
59 |
val chapter_definition_parser = |
76005
a9bbf075f431
include groups from 'chapter_definition' in session info, based on the state of chapter_defs after processing all ROOT files (thus the declaration order does not matter);
wenzelm
parents:
75998
diff
changeset
|
60 |
Parse.chapter_name -- groups -- description >> (fn (_, descr) => |
75998 | 61 |
Toplevel.keep (fn state => |
62 |
let |
|
63 |
val ctxt = Toplevel.context_of state; |
|
64 |
val _ = |
|
65 |
Context_Position.report ctxt |
|
66 |
(Position.range_position (Symbol_Pos.range (Input.source_explode descr))) |
|
67 |
Markup.comment; |
|
68 |
in () end)); |
|
75986
27d98da31985
support 'chapter_definition' with description for presentation purposes;
wenzelm
parents:
75679
diff
changeset
|
69 |
|
27d98da31985
support 'chapter_definition' with description for presentation purposes;
wenzelm
parents:
75679
diff
changeset
|
70 |
val session_parser = |
76005
a9bbf075f431
include groups from 'chapter_definition' in session info, based on the state of chapter_defs after processing all ROOT files (thus the declaration order does not matter);
wenzelm
parents:
75998
diff
changeset
|
71 |
Parse.session_name -- groups -- |
72841 | 72 |
Scan.optional (Parse.$$$ "in" |-- Parse.!!! Parse.path_input) (Input.string ".") -- |
67220 | 73 |
(Parse.$$$ "=" |-- |
75998 | 74 |
Parse.!!! (Scan.option (Parse.session_name --| Parse.!!! (Parse.$$$ "+")) -- description -- |
67220 | 75 |
Scan.optional (Parse.$$$ "options" |-- Parse.!!! Parse.options) [] -- |
76 |
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
|
77 |
Parse.!!! (Scan.repeat1 Parse.session_name)) [] -- |
72841 | 78 |
Scan.optional (Parse.$$$ "directories" |-- Parse.!!! (Scan.repeat1 Parse.path_input)) [] -- |
67220 | 79 |
Scan.repeat theories -- |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
70683
diff
changeset
|
80 |
Scan.optional document_theories [] -- |
68292 | 81 |
Scan.repeat document_files -- |
75679
aa89255b704c
support for classpath artifacts within session structure:
wenzelm
parents:
74887
diff
changeset
|
82 |
Scan.repeat export_files -- |
aa89255b704c
support for classpath artifacts within session structure:
wenzelm
parents:
74887
diff
changeset
|
83 |
Scan.optional export_classpath [])) |
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
70683
diff
changeset
|
84 |
>> (fn (((((session, _), _), dir), |
75679
aa89255b704c
support for classpath artifacts within session structure:
wenzelm
parents:
74887
diff
changeset
|
85 |
((((((((((parent, descr), options), sessions), directories), theories), |
aa89255b704c
support for classpath artifacts within session structure:
wenzelm
parents:
74887
diff
changeset
|
86 |
document_theories), document_files), export_files), _)))) => |
67215 | 87 |
Toplevel.keep (fn state => |
88 |
let |
|
89 |
val ctxt = Toplevel.context_of state; |
|
70049 | 90 |
val session_dir = Resources.check_dir ctxt NONE dir; |
67215 | 91 |
|
92 |
val _ = |
|
67220 | 93 |
(the_list parent @ sessions) |> List.app (fn arg => |
94 |
ignore (Resources.check_session ctxt arg) |
|
95 |
handle ERROR msg => Output.error_message msg); |
|
96 |
||
97 |
val _ = |
|
67215 | 98 |
Context_Position.report ctxt |
99 |
(Position.range_position (Symbol_Pos.range (Input.source_explode descr))) |
|
100 |
Markup.comment; |
|
101 |
||
102 |
val _ = |
|
103 |
(options @ maps #1 theories) |> List.app (fn (x, y) => |
|
67220 | 104 |
ignore (Completion.check_option_value ctxt x y (Options.default ())) |
105 |
handle ERROR msg => Output.error_message msg); |
|
67215 | 106 |
|
72841 | 107 |
fun check_thy source = |
108 |
ignore (Resources.check_file ctxt (SOME Path.current) source) |
|
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
70683
diff
changeset
|
109 |
handle ERROR msg => Output.error_message msg; |
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
70683
diff
changeset
|
110 |
|
67215 | 111 |
val _ = |
72841 | 112 |
maps #2 theories |> List.app (fn source => |
67215 | 113 |
let |
72841 | 114 |
val s = Input.string_of source; |
115 |
val pos = Input.pos_of source; |
|
67215 | 116 |
val {node_name, theory_name, ...} = |
117 |
Resources.import_name session session_dir s |
|
118 |
handle ERROR msg => error (msg ^ Position.here pos); |
|
72841 | 119 |
val thy_path = the_default node_name (Resources.find_theory_file theory_name); |
120 |
in check_thy (path_source source thy_path) end); |
|
67215 | 121 |
|
122 |
val _ = |
|
70681 | 123 |
directories |> List.app (ignore o Resources.check_dir ctxt (SOME session_dir)); |
70668 | 124 |
|
125 |
val _ = |
|
72841 | 126 |
document_theories |> List.app (fn source => |
127 |
let |
|
128 |
val thy = Input.string_of source; |
|
129 |
val pos = Input.pos_of source; |
|
130 |
in |
|
131 |
(case Resources.find_theory_file thy of |
|
132 |
NONE => Output.error_message ("Unknown theory " ^ quote thy ^ Position.here pos) |
|
133 |
| SOME path => check_thy (path_source source path)) |
|
134 |
end); |
|
72600
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
70683
diff
changeset
|
135 |
|
2fa4f25d9d07
official support for document theories from other sessions;
wenzelm
parents:
70683
diff
changeset
|
136 |
val _ = |
67215 | 137 |
document_files |> List.app (fn (doc_dir, doc_files) => |
138 |
let |
|
70049 | 139 |
val dir = Resources.check_dir ctxt (SOME session_dir) doc_dir; |
140 |
val _ = List.app (ignore o Resources.check_file ctxt (SOME dir)) doc_files; |
|
67215 | 141 |
in () end); |
68292 | 142 |
|
143 |
val _ = |
|
69671 | 144 |
export_files |> List.app (fn ((export_dir, _), _) => |
70049 | 145 |
ignore (Resources.check_path ctxt (SOME session_dir) export_dir)); |
67215 | 146 |
in () end)); |
147 |
||
148 |
end; |
|
149 |
||
150 |
end; |