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