| author | wenzelm | 
| Sun, 03 Nov 2019 18:55:35 +0100 | |
| changeset 71015 | bb49abc2ecbb | 
| parent 70683 | 8c7706b053c7 | 
| child 72600 | 2fa4f25d9d07 | 
| 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 | ||
| 70668 | 22 | val theory_entry = 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 = | 
| 28 |   Parse.$$$ "(" |-- Parse.!!! (Parse.$$$ "in" |-- Parse.position Parse.path --| Parse.$$$ ")");
 | |
| 29 | ||
| 67215 | 30 | val document_files = | 
| 31 | Parse.$$$ "document_files" |-- | |
| 68292 | 32 |     Parse.!!! (Scan.optional in_path ("document", Position.none)
 | 
| 67215 | 33 | -- Scan.repeat1 (Parse.position Parse.path)); | 
| 34 | ||
| 69671 | 35 | val prune = | 
| 36 | Scan.optional (Parse.$$$ "[" |-- Parse.!!! (Parse.nat --| Parse.$$$ "]")) 0; | |
| 37 | ||
| 68292 | 38 | val export_files = | 
| 39 | Parse.$$$ "export_files" |-- | |
| 69671 | 40 | Parse.!!! | 
| 41 |       (Scan.optional in_path ("export", Position.none) -- prune -- Scan.repeat1 Parse.embedded);
 | |
| 68292 | 42 | |
| 67215 | 43 | in | 
| 44 | ||
| 45 | val command_parser = | |
| 46 | Parse.session_name -- | |
| 47 |   Scan.optional (Parse.$$$ "(" |-- Parse.!!! (Scan.repeat1 Parse.name --| Parse.$$$ ")")) [] --
 | |
| 48 |   Scan.optional (Parse.$$$ "in" |-- Parse.!!! (Parse.position Parse.path)) (".", Position.none) --
 | |
| 67220 | 49 | (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: 
68808diff
changeset | 50 | Parse.!!! (Scan.option (Parse.session_name --| Parse.!!! (Parse.$$$ "+")) -- | 
| 67220 | 51 | Scan.optional (Parse.$$$ "description" |-- Parse.!!! (Parse.input Parse.text)) Input.empty -- | 
| 52 | Scan.optional (Parse.$$$ "options" |-- Parse.!!! Parse.options) [] -- | |
| 53 | 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 | 54 | Parse.!!! (Scan.repeat1 Parse.session_name)) [] -- | 
| 70681 | 55 | Scan.optional | 
| 56 | (Parse.$$$ "directories" |-- Parse.!!! (Scan.repeat1 (Parse.position Parse.path))) [] -- | |
| 67220 | 57 | Scan.repeat theories -- | 
| 68292 | 58 | Scan.repeat document_files -- | 
| 59 | Scan.repeat export_files)) | |
| 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 | 60 | >> (fn ((((session, _), _), dir), | 
| 70678 
36c8c32346cb
clarified syntax: 'directories' and 'theories' belong together;
 wenzelm parents: 
70668diff
changeset | 61 | ((((((((parent, descr), options), sessions), directories), theories), | 
| 70668 | 62 | document_files), export_files))) => | 
| 67215 | 63 | Toplevel.keep (fn state => | 
| 64 | let | |
| 65 | val ctxt = Toplevel.context_of state; | |
| 70049 | 66 | val session_dir = Resources.check_dir ctxt NONE dir; | 
| 67215 | 67 | |
| 68 | val _ = | |
| 67220 | 69 | (the_list parent @ sessions) |> List.app (fn arg => | 
| 70 | ignore (Resources.check_session ctxt arg) | |
| 71 | handle ERROR msg => Output.error_message msg); | |
| 72 | ||
| 73 | val _ = | |
| 67215 | 74 | Context_Position.report ctxt | 
| 75 | (Position.range_position (Symbol_Pos.range (Input.source_explode descr))) | |
| 76 | Markup.comment; | |
| 77 | ||
| 78 | val _ = | |
| 79 | (options @ maps #1 theories) |> List.app (fn (x, y) => | |
| 67220 | 80 | ignore (Completion.check_option_value ctxt x y (Options.default ())) | 
| 81 | handle ERROR msg => Output.error_message msg); | |
| 67215 | 82 | |
| 83 | val _ = | |
| 84 | maps #2 theories |> List.app (fn (s, pos) => | |
| 85 | let | |
| 86 |               val {node_name, theory_name, ...} =
 | |
| 87 | Resources.import_name session session_dir s | |
| 88 | handle ERROR msg => error (msg ^ Position.here pos); | |
| 70683 
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
 wenzelm parents: 
70681diff
changeset | 89 | val theory_path = the_default node_name (Resources.find_theory_file theory_name); | 
| 70049 | 90 | val _ = Resources.check_file ctxt (SOME Path.current) (Path.implode theory_path, pos); | 
| 67215 | 91 | in () end); | 
| 92 | ||
| 93 | val _ = | |
| 70681 | 94 | directories |> List.app (ignore o Resources.check_dir ctxt (SOME session_dir)); | 
| 70668 | 95 | |
| 96 | val _ = | |
| 67215 | 97 | document_files |> List.app (fn (doc_dir, doc_files) => | 
| 98 | let | |
| 70049 | 99 | val dir = Resources.check_dir ctxt (SOME session_dir) doc_dir; | 
| 100 | val _ = List.app (ignore o Resources.check_file ctxt (SOME dir)) doc_files; | |
| 67215 | 101 | in () end); | 
| 68292 | 102 | |
| 103 | val _ = | |
| 69671 | 104 | export_files |> List.app (fn ((export_dir, _), _) => | 
| 70049 | 105 | ignore (Resources.check_path ctxt (SOME session_dir) export_dir)); | 
| 67215 | 106 | in () end)); | 
| 107 | ||
| 108 | end; | |
| 109 | ||
| 110 | end; |