| author | wenzelm | 
| Sun, 22 Sep 2024 16:12:15 +0200 | |
| changeset 80923 | 6c9628a116cc | 
| parent 80462 | 7a1f9e571046 | 
| child 82720 | 956ecf2c07a0 | 
| permissions | -rw-r--r-- | 
| 79502 | 1 | /* Title: Pure/Build/resources.scala | 
| 43651 
511df47bcadc
some support for theory files within Isabelle/Scala session;
 wenzelm parents: diff
changeset | 2 | Author: Makarius | 
| 
511df47bcadc
some support for theory files within Isabelle/Scala session;
 wenzelm parents: diff
changeset | 3 | |
| 56208 | 4 | Resources for theories and auxiliary files. | 
| 43651 
511df47bcadc
some support for theory files within Isabelle/Scala session;
 wenzelm parents: diff
changeset | 5 | */ | 
| 
511df47bcadc
some support for theory files within Isabelle/Scala session;
 wenzelm parents: diff
changeset | 6 | |
| 
511df47bcadc
some support for theory files within Isabelle/Scala session;
 wenzelm parents: diff
changeset | 7 | package isabelle | 
| 
511df47bcadc
some support for theory files within Isabelle/Scala session;
 wenzelm parents: diff
changeset | 8 | |
| 44953 | 9 | |
| 56823 
37be55461dbe
more frugal access to theory text via Reader, reduced costs for I/O text decoding;
 wenzelm parents: 
56801diff
changeset | 10 | import scala.util.parsing.input.Reader | 
| 48885 | 11 | |
| 48409 | 12 | import java.io.{File => JFile}
 | 
| 44953 | 13 | |
| 14 | ||
| 75393 | 15 | object Resources {
 | 
| 76657 | 16 | def bootstrap: Resources = new Resources(Sessions.Background(base = Sessions.Base.bootstrap)) | 
| 74755 
510296c0d8d1
clarified signature: avoid potential misunderstanding of Resources.empty as proper Resources;
 wenzelm parents: 
74696diff
changeset | 17 | |
| 74756 | 18 | def hidden_node(name: Document.Node.Name): Boolean = | 
| 19 | !name.is_theory || name.theory == Sessions.root_name || File_Format.registry.is_theory(name) | |
| 20 | ||
| 75941 | 21 | def html_document(snapshot: Document.Snapshot): Option[Browser_Info.HTML_Document] = | 
| 74756 | 22 | File_Format.registry.get(snapshot.node_name).flatMap(_.html_document(snapshot)) | 
| 72962 | 23 | } | 
| 24 | ||
| 65359 | 25 | class Resources( | 
| 76657 | 26 | val session_background: Sessions.Background, | 
| 79777 | 27 | val log: Logger = new Logger, | 
| 75393 | 28 | command_timings: List[Properties.T] = Nil | 
| 29 | ) {
 | |
| 66959 | 30 | resources => | 
| 64839 | 31 | |
| 76657 | 32 | def sessions_structure: Sessions.Structure = session_background.sessions_structure | 
| 33 | def session_base: Sessions.Base = session_background.base | |
| 69255 
800b1ce96fce
more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
 wenzelm parents: 
69008diff
changeset | 34 | |
| 76661 | 35 |   override def toString: String = "Resources(" + session_base.print_body + ")"
 | 
| 75768 | 36 | |
| 37 | ||
| 72637 | 38 | /* init session */ | 
| 39 | ||
| 80462 
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
 wenzelm parents: 
80238diff
changeset | 40 |   def init_session_xml: XML.Body = {
 | 
| 72637 | 41 | import XML.Encode._ | 
| 42 | ||
| 80462 
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
 wenzelm parents: 
80238diff
changeset | 43 | pair(list(pair(string, properties)), | 
| 
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
 wenzelm parents: 
80238diff
changeset | 44 | pair(list(pair(string, string)), | 
| 
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
 wenzelm parents: 
80238diff
changeset | 45 | pair(list(properties), | 
| 
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
 wenzelm parents: 
80238diff
changeset | 46 | pair(list(pair(string, properties)), | 
| 
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
 wenzelm parents: 
80238diff
changeset | 47 | pair(list(Scala.encode_fun), | 
| 
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
 wenzelm parents: 
80238diff
changeset | 48 | pair(list(pair(string, string)), list(string)))))))( | 
| 
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
 wenzelm parents: 
80238diff
changeset | 49 | (sessions_structure.session_positions, | 
| 
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
 wenzelm parents: 
80238diff
changeset | 50 | (sessions_structure.dest_session_directories, | 
| 
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
 wenzelm parents: 
80238diff
changeset | 51 | (command_timings, | 
| 
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
 wenzelm parents: 
80238diff
changeset | 52 | (Command_Span.load_commands.map(cmd => (cmd.name, cmd.position)), | 
| 
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
 wenzelm parents: 
80238diff
changeset | 53 | (Scala.functions, | 
| 
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
 wenzelm parents: 
80238diff
changeset | 54 | (sessions_structure.global_theories.toList, | 
| 
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
 wenzelm parents: 
80238diff
changeset | 55 | session_base.loaded_theories.keys))))))) | 
| 72637 | 56 | } | 
| 57 | ||
| 58 | ||
| 69255 
800b1ce96fce
more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
 wenzelm parents: 
69008diff
changeset | 59 | /* file formats */ | 
| 
800b1ce96fce
more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
 wenzelm parents: 
69008diff
changeset | 60 | |
| 
800b1ce96fce
more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
 wenzelm parents: 
69008diff
changeset | 61 | def make_theory_name(name: Document.Node.Name): Option[Document.Node.Name] = | 
| 71733 | 62 | File_Format.registry.get(name).flatMap(_.make_theory_name(resources, name)) | 
| 69255 
800b1ce96fce
more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
 wenzelm parents: 
69008diff
changeset | 63 | |
| 
800b1ce96fce
more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
 wenzelm parents: 
69008diff
changeset | 64 | def make_theory_content(thy_name: Document.Node.Name): Option[String] = | 
| 71733 | 65 | File_Format.registry.get_theory(thy_name).flatMap(_.make_theory_content(resources, thy_name)) | 
| 69255 
800b1ce96fce
more general support for Isabelle/PIDE file formats -- less hardwired Bibtex operations;
 wenzelm parents: 
69008diff
changeset | 66 | |
| 64839 | 67 | |
| 44953 | 68 | /* file-system operations */ | 
| 69 | ||
| 76739 
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
 wenzelm parents: 
76666diff
changeset | 70 | def migrate_name(name: Document.Node.Name): Document.Node.Name = name | 
| 
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
 wenzelm parents: 
76666diff
changeset | 71 | |
| 76864 | 72 | def append_path(prefix: String, source_path: Path): String = | 
| 76883 | 73 | File.standard_path(Path.explode(prefix) + source_path) | 
| 44953 | 74 | |
| 76890 
d924a69e7d2b
more robust operations: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76889diff
changeset | 75 | def read_dir(dir: String): List[String] = File.read_dir(Path.explode(dir)) | 
| 
d924a69e7d2b
more robust operations: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76889diff
changeset | 76 | |
| 
d924a69e7d2b
more robust operations: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76889diff
changeset | 77 |   def list_thys(dir: String): List[String] = {
 | 
| 
d924a69e7d2b
more robust operations: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76889diff
changeset | 78 |     val entries = try { read_dir(dir) } catch { case ERROR(_) => Nil }
 | 
| 
d924a69e7d2b
more robust operations: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76889diff
changeset | 79 | entries.flatMap(Thy_Header.get_thy_name) | 
| 
d924a69e7d2b
more robust operations: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76889diff
changeset | 80 | } | 
| 
d924a69e7d2b
more robust operations: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76889diff
changeset | 81 | |
| 46737 | 82 | |
| 64657 | 83 | /* source files of Isabelle/ML bootstrap */ | 
| 84 | ||
| 75393 | 85 |   def source_file(raw_name: String): Option[String] = {
 | 
| 64657 | 86 |     if (Path.is_wellformed(raw_name)) {
 | 
| 87 |       if (Path.is_valid(raw_name)) {
 | |
| 88 | def check(p: Path): Option[Path] = if (p.is_file) Some(p) else None | |
| 89 | ||
| 90 | val path = Path.explode(raw_name) | |
| 91 | val path1 = | |
| 92 | if (path.is_absolute || path.is_current) check(path) | |
| 93 |           else {
 | |
| 94 |             check(Path.explode("~~/src/Pure") + path) orElse
 | |
| 95 |               (if (Isabelle_System.getenv("ML_SOURCES") == "") None
 | |
| 96 |                else check(Path.explode("$ML_SOURCES") + path))
 | |
| 97 | } | |
| 98 | Some(File.platform_path(path1 getOrElse path)) | |
| 99 | } | |
| 100 | else None | |
| 101 | } | |
| 102 | else Some(raw_name) | |
| 103 | } | |
| 104 | ||
| 105 | ||
| 46737 | 106 | /* theory files */ | 
| 107 | ||
| 75393 | 108 | def load_commands( | 
| 109 | syntax: Outer_Syntax, | |
| 110 | name: Document.Node.Name | |
| 111 |   ) : () => List[Command_Span.Span] = {
 | |
| 66918 
ec2b50aeb0dd
more robust treatment of UTF8 in raw byte sources;
 wenzelm parents: 
66917diff
changeset | 112 | val (is_utf8, raw_text) = | 
| 
ec2b50aeb0dd
more robust treatment of UTF8 in raw byte sources;
 wenzelm parents: 
66917diff
changeset | 113 | with_thy_reader(name, reader => (Scan.reader_is_utf8(reader), reader.source.toString)) | 
| 72816 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 114 | () => | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 115 |       {
 | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 116 |         if (syntax.has_load_commands(raw_text)) {
 | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 117 | val text = Symbol.decode(Scan.reader_decode_utf8(is_utf8, raw_text)) | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 118 | syntax.parse_spans(text).filter(_.is_load_command(syntax)) | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 119 | } | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 120 | else Nil | 
| 66698 
5b9dc3f7bcde
prefer sequential file-system access, but parallel parse;
 wenzelm parents: 
66697diff
changeset | 121 | } | 
| 72816 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 122 | } | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 123 | |
| 75393 | 124 | def loaded_files( | 
| 125 | syntax: Outer_Syntax, | |
| 126 | name: Document.Node.Name, | |
| 127 | spans: List[Command_Span.Span] | |
| 76886 
f405fcc3db33
clarified signature: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76885diff
changeset | 128 |   ) : List[Document.Node.Name] = {
 | 
| 
f405fcc3db33
clarified signature: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76885diff
changeset | 129 | for (span <- spans; file <- span.loaded_files(syntax).files) | 
| 
f405fcc3db33
clarified signature: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76885diff
changeset | 130 | yield Document.Node.Name(append_path(name.master_dir, Path.explode(file))) | 
| 66695 | 131 | } | 
| 132 | ||
| 76886 
f405fcc3db33
clarified signature: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76885diff
changeset | 133 | def pure_files(syntax: Outer_Syntax): List[Document.Node.Name] = | 
| 76885 | 134 |     (for {
 | 
| 76886 
f405fcc3db33
clarified signature: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76885diff
changeset | 135 | (file, theory) <- Thy_Header.ml_roots.iterator | 
| 
f405fcc3db33
clarified signature: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76885diff
changeset | 136 |       node = append_path("~~/src/Pure", Path.explode(file))
 | 
| 76885 | 137 | node_name = Document.Node.Name(node, theory = theory) | 
| 76886 
f405fcc3db33
clarified signature: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76885diff
changeset | 138 | name <- loaded_files(syntax, node_name, load_commands(syntax, node_name)()).iterator | 
| 
f405fcc3db33
clarified signature: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76885diff
changeset | 139 | } yield name).toList | 
| 66696 
8f863dae78a0
clarified pure_files, based on uniform loaded_files;
 wenzelm parents: 
66695diff
changeset | 140 | |
| 75885 
8342cba8eae8
clarified signature: avoid constants from Sessions.Structure within Session.Base;
 wenzelm parents: 
75884diff
changeset | 141 | def global_theory(theory: String): Boolean = | 
| 
8342cba8eae8
clarified signature: avoid constants from Sessions.Structure within Session.Base;
 wenzelm parents: 
75884diff
changeset | 142 | sessions_structure.global_theories.isDefinedAt(theory) | 
| 
8342cba8eae8
clarified signature: avoid constants from Sessions.Structure within Session.Base;
 wenzelm parents: 
75884diff
changeset | 143 | |
| 76049 | 144 | def literal_theory(theory: String): Boolean = | 
| 145 | Long_Name.is_qualified(theory) || global_theory(theory) | |
| 146 | ||
| 67104 
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
 wenzelm parents: 
67060diff
changeset | 147 | def theory_name(qualifier: String, theory: String): String = | 
| 76049 | 148 | if (literal_theory(theory)) theory | 
| 67104 
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
 wenzelm parents: 
67060diff
changeset | 149 | else Long_Name.qualify(qualifier, theory) | 
| 65471 
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
 wenzelm parents: 
65467diff
changeset | 150 | |
| 75393 | 151 |   def find_theory_node(theory: String): Option[Document.Node.Name] = {
 | 
| 72776 | 152 | val thy_file = Path.basic(Long_Name.base_name(theory)).thy | 
| 75884 
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
 wenzelm parents: 
75768diff
changeset | 153 | val session = sessions_structure.theory_qualifier(theory) | 
| 70712 
a3cfe859d915
find theories via session directories only -- ignore known_theories;
 wenzelm parents: 
70683diff
changeset | 154 | val dirs = | 
| 
a3cfe859d915
find theories via session directories only -- ignore known_theories;
 wenzelm parents: 
70683diff
changeset | 155 |       sessions_structure.get(session) match {
 | 
| 
a3cfe859d915
find theories via session directories only -- ignore known_theories;
 wenzelm parents: 
70683diff
changeset | 156 | case Some(info) => info.dirs | 
| 
a3cfe859d915
find theories via session directories only -- ignore known_theories;
 wenzelm parents: 
70683diff
changeset | 157 | case None => Nil | 
| 
a3cfe859d915
find theories via session directories only -- ignore known_theories;
 wenzelm parents: 
70683diff
changeset | 158 | } | 
| 76862 | 159 |     dirs.collectFirst { case dir if (dir + thy_file).is_file =>
 | 
| 160 |       Document.Node.Name(append_path("", dir + thy_file), theory = theory) }
 | |
| 70712 
a3cfe859d915
find theories via session directories only -- ignore known_theories;
 wenzelm parents: 
70683diff
changeset | 161 | } | 
| 70683 
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
 wenzelm parents: 
70682diff
changeset | 162 | |
| 76864 | 163 |   def import_name(qualifier: String, prefix: String, s: String): Document.Node.Name = {
 | 
| 67104 
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
 wenzelm parents: 
67060diff
changeset | 164 | val theory = theory_name(qualifier, Thy_Header.import_name(s)) | 
| 76050 
f1dc3d9d5164
check imports more strictly, e.g. reject ".../Pure" or ".../HOL-Library.Multiset";
 wenzelm parents: 
76049diff
changeset | 165 | val literal_import = | 
| 
f1dc3d9d5164
check imports more strictly, e.g. reject ".../Pure" or ".../HOL-Library.Multiset";
 wenzelm parents: 
76049diff
changeset | 166 | literal_theory(theory) && qualifier != sessions_structure.theory_qualifier(theory) | 
| 76828 | 167 |     if (literal_import && !Url.is_base_name(s)) {
 | 
| 76050 
f1dc3d9d5164
check imports more strictly, e.g. reject ".../Pure" or ".../HOL-Library.Multiset";
 wenzelm parents: 
76049diff
changeset | 168 |       error("Bad import of theory from other session via file-path: " + quote(s))
 | 
| 
f1dc3d9d5164
check imports more strictly, e.g. reject ".../Pure" or ".../HOL-Library.Multiset";
 wenzelm parents: 
76049diff
changeset | 169 | } | 
| 76845 | 170 | if (session_base.loaded_theory(theory)) Document.Node.Name.loaded_theory(theory) | 
| 67104 
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
 wenzelm parents: 
67060diff
changeset | 171 |     else {
 | 
| 70683 
8c7706b053c7
find theory files via session structure: much faster Prover IDE startup;
 wenzelm parents: 
70682diff
changeset | 172 |       find_theory_node(theory) match {
 | 
| 67104 
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
 wenzelm parents: 
67060diff
changeset | 173 | case Some(node_name) => node_name | 
| 76046 
507c65cc4332
back to more traditional import_name (reverting cceb10dcc9f9), e.g. relevant for "isabelle jedit -l CTT src/CTT/ex/Elimination.thy" to produce proper error "Cannot update finished theory CTT.Elimination";
 wenzelm parents: 
75941diff
changeset | 174 | case None => | 
| 76845 | 175 | if (Url.is_base_name(s) && literal_theory(s)) Document.Node.Name.loaded_theory(theory) | 
| 76864 | 176 | else Document.Node.Name(append_path(prefix, Path.explode(s).thy), theory = theory) | 
| 67104 
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
 wenzelm parents: 
67060diff
changeset | 177 | } | 
| 65472 | 178 | } | 
| 67104 
a2fa0c6a7aff
clarified theory_name vs. loaded_theory: proper import_name for already loaded theories from other sessions (amending 4c98c929a12a);
 wenzelm parents: 
67060diff
changeset | 179 | } | 
| 51634 
553953ad8165
more general Thy_Load.import_name, e.g. relevant for Isabelle/eclipse -- NB: Thy_Load serves as main hub for funny overriding to adapt to provers and editors;
 wenzelm parents: 
51293diff
changeset | 180 | |
| 65529 | 181 | def import_name(name: Document.Node.Name, s: String): Document.Node.Name = | 
| 75884 
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
 wenzelm parents: 
75768diff
changeset | 182 | import_name(sessions_structure.theory_qualifier(name), name.master_dir, s) | 
| 65489 | 183 | |
| 70633 | 184 | def import_name(info: Sessions.Info, s: String): Document.Node.Name = | 
| 185 | import_name(info.name, info.dir.implode, s) | |
| 186 | ||
| 75393 | 187 |   def find_theory(file: JFile): Option[Document.Node.Name] = {
 | 
| 70718 
5bb025e24224
clarified inversion of file name to theory name, notably for Windows;
 wenzelm parents: 
70717diff
changeset | 188 |     for {
 | 
| 75885 
8342cba8eae8
clarified signature: avoid constants from Sessions.Structure within Session.Base;
 wenzelm parents: 
75884diff
changeset | 189 | qualifier <- sessions_structure.session_directories.get(File.canonical(file).getParentFile) | 
| 70718 
5bb025e24224
clarified inversion of file name to theory name, notably for Windows;
 wenzelm parents: 
70717diff
changeset | 190 | theory_base <- proper_string(Thy_Header.theory_name(file.getName)) | 
| 
5bb025e24224
clarified inversion of file name to theory name, notably for Windows;
 wenzelm parents: 
70717diff
changeset | 191 | theory = theory_name(qualifier, theory_base) | 
| 
5bb025e24224
clarified inversion of file name to theory name, notably for Windows;
 wenzelm parents: 
70717diff
changeset | 192 | theory_node <- find_theory_node(theory) | 
| 
5bb025e24224
clarified inversion of file name to theory name, notably for Windows;
 wenzelm parents: 
70717diff
changeset | 193 | if File.eq(theory_node.path.file, file) | 
| 
5bb025e24224
clarified inversion of file name to theory name, notably for Windows;
 wenzelm parents: 
70717diff
changeset | 194 | } yield theory_node | 
| 70673 
b0172698d0d3
theory_name based on session_directories: no need for expensive all_known;
 wenzelm parents: 
70652diff
changeset | 195 | } | 
| 
b0172698d0d3
theory_name based on session_directories: no need for expensive all_known;
 wenzelm parents: 
70652diff
changeset | 196 | |
| 75393 | 197 |   def complete_import_name(context_name: Document.Node.Name, s: String): List[String] = {
 | 
| 75884 
3d8b37b1d798
clarified signature: avoid object-oriented HTML_Context;
 wenzelm parents: 
75768diff
changeset | 198 | val context_session = sessions_structure.theory_qualifier(context_name) | 
| 76890 
d924a69e7d2b
more robust operations: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76889diff
changeset | 199 | def context_dir(): List[String] = list_thys(context_name.master_dir) | 
| 
d924a69e7d2b
more robust operations: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76889diff
changeset | 200 | def session_dir(info: Sessions.Info): List[String] = info.dirs.flatMap(Thy_Header.list_thys) | 
| 70713 
fd188463066e
clarified theory imports completion, based on session directories and current master directory (no support for local session-subdirectories);
 wenzelm parents: 
70712diff
changeset | 201 |     (for {
 | 
| 76889 | 202 | (session, (info, _)) <- sessions_structure.imports_graph.iterator | 
| 76890 
d924a69e7d2b
more robust operations: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76889diff
changeset | 203 | theory <- (if (session == context_session) context_dir() else session_dir(info)).iterator | 
| 70713 
fd188463066e
clarified theory imports completion, based on session directories and current master directory (no support for local session-subdirectories);
 wenzelm parents: 
70712diff
changeset | 204 | if Completion.completed(s)(theory) | 
| 
fd188463066e
clarified theory imports completion, based on session directories and current master directory (no support for local session-subdirectories);
 wenzelm parents: 
70712diff
changeset | 205 |     } yield {
 | 
| 75885 
8342cba8eae8
clarified signature: avoid constants from Sessions.Structure within Session.Base;
 wenzelm parents: 
75884diff
changeset | 206 | if (session == context_session || global_theory(theory)) theory | 
| 70713 
fd188463066e
clarified theory imports completion, based on session directories and current master directory (no support for local session-subdirectories);
 wenzelm parents: 
70712diff
changeset | 207 | else Long_Name.qualify(session, theory) | 
| 
fd188463066e
clarified theory imports completion, based on session directories and current master directory (no support for local session-subdirectories);
 wenzelm parents: 
70712diff
changeset | 208 | }).toList.sorted | 
| 66767 | 209 | } | 
| 210 | ||
| 75393 | 211 |   def with_thy_reader[A](name: Document.Node.Name, f: Reader[Char] => A): A = {
 | 
| 66771 
925d10a7a610
clarified error for bad session-qualified imports;
 wenzelm parents: 
66767diff
changeset | 212 | val path = name.path | 
| 69393 
ed0824ef337e
static type for Library.using: avoid Java 11 warnings on "Illegal reflective access";
 wenzelm parents: 
69255diff
changeset | 213 | if (path.is_file) using(Scan.byte_reader(path.file))(f) | 
| 66771 
925d10a7a610
clarified error for bad session-qualified imports;
 wenzelm parents: 
66767diff
changeset | 214 | else if (name.node == name.theory) | 
| 
925d10a7a610
clarified error for bad session-qualified imports;
 wenzelm parents: 
66767diff
changeset | 215 |       error("Cannot load theory " + quote(name.theory))
 | 
| 
925d10a7a610
clarified error for bad session-qualified imports;
 wenzelm parents: 
66767diff
changeset | 216 |     else error ("Cannot load theory file " + path)
 | 
| 64656 | 217 | } | 
| 218 | ||
| 75393 | 219 | def check_thy( | 
| 220 | node_name: Document.Node.Name, | |
| 221 | reader: Reader[Char], | |
| 222 | command: Boolean = true, | |
| 223 | strict: Boolean = true | |
| 224 |   ): Document.Node.Header = {
 | |
| 64826 
c97296294f6d
clarified check_thy_reader: check node_name here;
 wenzelm parents: 
64825diff
changeset | 225 |     if (node_name.is_theory && reader.source.length > 0) {
 | 
| 57615 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 wenzelm parents: 
56913diff
changeset | 226 |       try {
 | 
| 72777 
164cb0806d0a
proper positions for inlined command messages, e.g. for completion within theory header;
 wenzelm parents: 
72776diff
changeset | 227 | val header = Thy_Header.read(node_name, reader, command = command, strict = strict) | 
| 72778 | 228 | val imports = | 
| 229 |           header.imports.map({ case (s, pos) =>
 | |
| 67296 
888aa91f0556
clarified check, notably for bibtex theory (amending 5f082b1fa9fa);
 wenzelm parents: 
67294diff
changeset | 230 | val name = import_name(node_name, s) | 
| 75922 | 231 |             if (Sessions.illegal_theory(name.theory_base_name)) {
 | 
| 232 |               error("Illegal theory name " + quote(name.theory_base_name) + Position.here(pos))
 | |
| 75919 | 233 | } | 
| 234 | else (name, pos) | |
| 67296 
888aa91f0556
clarified check, notably for bibtex theory (amending 5f082b1fa9fa);
 wenzelm parents: 
67294diff
changeset | 235 | }) | 
| 72778 | 236 | Document.Node.Header(imports, header.keywords, header.abbrevs) | 
| 57615 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 wenzelm parents: 
56913diff
changeset | 237 | } | 
| 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 wenzelm parents: 
56913diff
changeset | 238 |       catch { case exn: Throwable => Document.Node.bad_header(Exn.message(exn)) }
 | 
| 50414 
e17a1f179bb0
explore theory_body_files via future, for improved performance;
 wenzelm parents: 
50291diff
changeset | 239 | } | 
| 57615 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 wenzelm parents: 
56913diff
changeset | 240 | else Document.Node.no_header | 
| 46737 | 241 | } | 
| 46748 
8f3ae4d04a2d
refined node_header -- more direct buffer access (again);
 wenzelm parents: 
46737diff
changeset | 242 | |
| 50566 
b43c4f660320
tuned signature: use thy_load to adapt to prover/editor specific view on sources;
 wenzelm parents: 
50415diff
changeset | 243 | |
| 64673 
b5965890e54d
more uniform treatment of file name vs. theory name and special header;
 wenzelm parents: 
64657diff
changeset | 244 | /* special header */ | 
| 
b5965890e54d
more uniform treatment of file name vs. theory name and special header;
 wenzelm parents: 
64657diff
changeset | 245 | |
| 75393 | 246 |   def special_header(name: Document.Node.Name): Option[Document.Node.Header] = {
 | 
| 65445 
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
 wenzelm parents: 
65441diff
changeset | 247 | val imports = | 
| 75406 | 248 | if (name.theory == Sessions.root_name) List(import_name(name, Sessions.theory_import)) | 
| 67215 | 249 | else if (Thy_Header.is_ml_root(name.theory)) List(import_name(name, Thy_Header.ML_BOOTSTRAP)) | 
| 65489 | 250 | else if (Thy_Header.is_bootstrap(name.theory)) List(import_name(name, Thy_Header.PURE)) | 
| 65445 
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
 wenzelm parents: 
65441diff
changeset | 251 | else Nil | 
| 
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
 wenzelm parents: 
65441diff
changeset | 252 | if (imports.isEmpty) None | 
| 
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
 wenzelm parents: 
65441diff
changeset | 253 | else Some(Document.Node.Header(imports.map((_, Position.none)))) | 
| 
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
 wenzelm parents: 
65441diff
changeset | 254 | } | 
| 64673 
b5965890e54d
more uniform treatment of file name vs. theory name and special header;
 wenzelm parents: 
64657diff
changeset | 255 | |
| 
b5965890e54d
more uniform treatment of file name vs. theory name and special header;
 wenzelm parents: 
64657diff
changeset | 256 | |
| 64797 | 257 | /* blobs */ | 
| 258 | ||
| 76590 | 259 | def undefined_blobs(version: Document.Version): List[Document.Node.Name] = | 
| 64797 | 260 |     (for {
 | 
| 76590 | 261 | (node_name, node) <- version.nodes.iterator | 
| 65361 | 262 | if !session_base.loaded_theory(node_name) | 
| 64797 | 263 | cmd <- node.load_commands.iterator | 
| 264 | name <- cmd.blobs_undefined.iterator | |
| 265 | } yield name).toList | |
| 266 | ||
| 267 | ||
| 56316 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 wenzelm parents: 
56315diff
changeset | 268 | /* document changes */ | 
| 50566 
b43c4f660320
tuned signature: use thy_load to adapt to prover/editor specific view on sources;
 wenzelm parents: 
50415diff
changeset | 269 | |
| 56316 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 wenzelm parents: 
56315diff
changeset | 270 | def parse_change( | 
| 56315 | 271 | reparse_limit: Int, | 
| 272 | previous: Document.Version, | |
| 273 | doc_blobs: Document.Blobs, | |
| 68336 
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
 wenzelm parents: 
68317diff
changeset | 274 | edits: List[Document.Edit_Text], | 
| 70796 
2739631ac368
discontinued pointless dump_checkpoint and share_common_data -- superseded by base logic image in Isabelle/MMT;
 wenzelm parents: 
70740diff
changeset | 275 | consolidate: List[Document.Node.Name]): Session.Change = | 
| 
2739631ac368
discontinued pointless dump_checkpoint and share_common_data -- superseded by base logic image in Isabelle/MMT;
 wenzelm parents: 
70740diff
changeset | 276 | Thy_Syntax.parse_change(resources, reparse_limit, previous, doc_blobs, edits, consolidate) | 
| 55134 
1b67b17cdad5
propagate update of outer syntax keywords: global propertiesChanged, buffer TokenMarker.markTokens, text area repainting;
 wenzelm parents: 
54521diff
changeset | 277 | |
| 73340 | 278 |   def commit(change: Session.Change): Unit = {}
 | 
| 66959 | 279 | |
| 280 | ||
| 281 | /* theory and file dependencies */ | |
| 282 | ||
| 69007 | 283 | def dependencies( | 
| 284 | thys: List[(Document.Node.Name, Position.T)], | |
| 71726 
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
 wenzelm parents: 
70796diff
changeset | 285 | progress: Progress = new Progress): Dependencies[Unit] = | 
| 69008 
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
 wenzelm parents: 
69007diff
changeset | 286 | Dependencies.empty[Unit].require_thys((), thys, progress = progress) | 
| 
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
 wenzelm parents: 
69007diff
changeset | 287 | |
| 75393 | 288 | def session_dependencies( | 
| 289 | info: Sessions.Info, | |
| 290 | progress: Progress = new Progress | |
| 291 |   ) : Dependencies[Options] = {
 | |
| 73359 | 292 |     info.theories.foldLeft(Dependencies.empty[Options]) {
 | 
| 293 | case (dependencies, (options, thys)) => | |
| 294 | dependencies.require_thys(options, | |
| 295 |           for { (thy, pos) <- thys } yield (import_name(info, thy), pos),
 | |
| 296 | progress = progress) | |
| 297 | } | |
| 69008 
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
 wenzelm parents: 
69007diff
changeset | 298 | } | 
| 69007 | 299 | |
| 75393 | 300 |   object Dependencies {
 | 
| 69008 
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
 wenzelm parents: 
69007diff
changeset | 301 | def empty[A]: Dependencies[A] = new Dependencies[A](Nil, Map.empty) | 
| 69007 | 302 | |
| 303 | private def show_path(names: List[Document.Node.Name]): String = | |
| 304 |       names.map(name => quote(name.theory)).mkString(" via ")
 | |
| 305 | ||
| 306 | private def cycle_msg(names: List[Document.Node.Name]): String = | |
| 307 | "Cyclic dependency of " + show_path(names) | |
| 308 | ||
| 309 | private def required_by(initiators: List[Document.Node.Name]): String = | |
| 77368 | 310 | if_proper(initiators, "\n(required by " + show_path(initiators.reverse) + ")") | 
| 66959 | 311 | } | 
| 312 | ||
| 69008 
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
 wenzelm parents: 
69007diff
changeset | 313 | final class Dependencies[A] private( | 
| 66959 | 314 | rev_entries: List[Document.Node.Entry], | 
| 75393 | 315 | seen: Map[Document.Node.Name, A] | 
| 316 |   ) {
 | |
| 69008 
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
 wenzelm parents: 
69007diff
changeset | 317 | private def cons(entry: Document.Node.Entry): Dependencies[A] = | 
| 
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
 wenzelm parents: 
69007diff
changeset | 318 | new Dependencies[A](entry :: rev_entries, seen) | 
| 66959 | 319 | |
| 69008 
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
 wenzelm parents: 
69007diff
changeset | 320 | def require_thy(adjunct: A, | 
| 69007 | 321 | thy: (Document.Node.Name, Position.T), | 
| 322 | initiators: List[Document.Node.Name] = Nil, | |
| 80238 | 323 | progress: Progress = new Progress | 
| 324 |     ): Dependencies[A] = {
 | |
| 69007 | 325 | val (name, pos) = thy | 
| 326 | ||
| 327 | def message: String = | |
| 328 | "The error(s) above occurred for theory " + quote(name.theory) + | |
| 329 | Dependencies.required_by(initiators) + Position.here(pos) | |
| 330 | ||
| 69008 
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
 wenzelm parents: 
69007diff
changeset | 331 | if (seen.isDefinedAt(name)) this | 
| 69007 | 332 |       else {
 | 
| 69008 
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
 wenzelm parents: 
69007diff
changeset | 333 | val dependencies1 = new Dependencies[A](rev_entries, seen + (name -> adjunct)) | 
| 69007 | 334 | if (session_base.loaded_theory(name)) dependencies1 | 
| 335 |         else {
 | |
| 336 |           try {
 | |
| 337 | if (initiators.contains(name)) error(Dependencies.cycle_msg(initiators)) | |
| 338 | ||
| 339 | progress.expose_interrupt() | |
| 340 | val header = | |
| 72772 | 341 |               try {
 | 
| 72777 
164cb0806d0a
proper positions for inlined command messages, e.g. for completion within theory header;
 wenzelm parents: 
72776diff
changeset | 342 | with_thy_reader(name, check_thy(name, _, command = false)).cat_errors(message) | 
| 72772 | 343 | } | 
| 69007 | 344 |               catch { case ERROR(msg) => cat_error(msg, message) }
 | 
| 345 | val entry = Document.Node.Entry(name, header) | |
| 70638 
f164cec7ac22
clarified signature: prefer operations without position;
 wenzelm parents: 
70634diff
changeset | 346 | dependencies1.require_thys(adjunct, header.imports_pos, | 
| 69008 
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
 wenzelm parents: 
69007diff
changeset | 347 | initiators = name :: initiators, progress = progress).cons(entry) | 
| 69007 | 348 | } | 
| 349 |           catch {
 | |
| 350 | case e: Throwable => | |
| 351 | dependencies1.cons(Document.Node.Entry(name, Document.Node.bad_header(Exn.message(e)))) | |
| 352 | } | |
| 353 | } | |
| 354 | } | |
| 355 | } | |
| 356 | ||
| 69008 
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
 wenzelm parents: 
69007diff
changeset | 357 | def require_thys(adjunct: A, | 
| 69007 | 358 | thys: List[(Document.Node.Name, Position.T)], | 
| 71726 
a5fda30edae2
clarified signature: more uniform treatment of stopped/interrupted state;
 wenzelm parents: 
70796diff
changeset | 359 | progress: Progress = new Progress, | 
| 80238 | 360 | initiators: List[Document.Node.Name] = Nil | 
| 361 |     ): Dependencies[A] = {
 | |
| 73359 | 362 | thys.foldLeft(this)(_.require_thy(adjunct, _, progress = progress, initiators = initiators)) | 
| 80238 | 363 | } | 
| 66959 | 364 | |
| 365 | def entries: List[Document.Node.Entry] = rev_entries.reverse | |
| 69008 
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
 wenzelm parents: 
69007diff
changeset | 366 | |
| 67059 | 367 | def theories: List[Document.Node.Name] = entries.map(_.name) | 
| 72062 | 368 | def theories_adjunct: List[(Document.Node.Name, A)] = theories.map(name => (name, seen(name))) | 
| 66959 | 369 | |
| 370 | def errors: List[String] = entries.flatMap(_.header.errors) | |
| 371 | ||
| 69008 
d55783ea6cf6
more detailed session dependencies, with conditions for theories;
 wenzelm parents: 
69007diff
changeset | 372 | def check_errors: Dependencies[A] = | 
| 67056 | 373 |       errors match {
 | 
| 374 | case Nil => this | |
| 375 | case errs => error(cat_lines(errs)) | |
| 376 | } | |
| 377 | ||
| 75393 | 378 |     lazy val theory_graph: Document.Node.Name.Graph[Unit] = {
 | 
| 70652 | 379 | val regular = theories.toSet | 
| 380 | val irregular = | |
| 381 |         (for {
 | |
| 382 | entry <- entries.iterator | |
| 383 | imp <- entry.header.imports | |
| 384 | if !regular(imp) | |
| 385 | } yield imp).toSet | |
| 386 | ||
| 70674 
29bb1ebb188f
clarified signature: proper Document.Node.Ordering conforming to equality (e.g. required in situations where theory names are ambiguous due to overlapping session directories);
 wenzelm parents: 
70673diff
changeset | 387 | Document.Node.Name.make_graph( | 
| 70652 | 388 | irregular.toList.map(name => ((name, ()), Nil)) ::: | 
| 389 | entries.map(entry => ((entry.name, ()), entry.header.imports))) | |
| 390 | } | |
| 70650 | 391 | |
| 66959 | 392 | lazy val loaded_theories: Graph[String, Outer_Syntax] = | 
| 73359 | 393 |       entries.foldLeft(session_base.loaded_theories) {
 | 
| 394 | case (graph, entry) => | |
| 395 | val name = entry.name.theory | |
| 396 | val imports = entry.header.imports.map(_.theory) | |
| 66959 | 397 | |
| 73359 | 398 | val graph1 = (name :: imports).foldLeft(graph)(_.default_node(_, Outer_Syntax.empty)) | 
| 399 | val graph2 = imports.foldLeft(graph1)(_.add_edge(_, name)) | |
| 66959 | 400 | |
| 73359 | 401 | val syntax0 = if (name == Thy_Header.PURE) List(Thy_Header.bootstrap_syntax) else Nil | 
| 402 | val syntax1 = (name :: graph2.imm_preds(name).toList).map(graph2.get_node) | |
| 403 | val syntax = Outer_Syntax.merge(syntax0 ::: syntax1) + entry.header | |
| 404 | ||
| 405 | graph2.map_node(name, _ => syntax) | |
| 406 | } | |
| 66959 | 407 | |
| 72816 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 408 | def get_syntax(name: Document.Node.Name): Outer_Syntax = | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 409 | loaded_theories.get_node(name.theory) | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 410 | |
| 75745 | 411 | lazy val load_commands: List[(Document.Node.Name, List[Command_Span.Span])] = | 
| 72799 | 412 | theories.zip( | 
| 72816 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 413 | Par_List.map((e: () => List[Command_Span.Span]) => e(), | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 414 | theories.map(name => resources.load_commands(get_syntax(name), name)))) | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 415 | .filter(p => p._2.nonEmpty) | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 416 | |
| 75393 | 417 | def loaded_files( | 
| 418 | name: Document.Node.Name, | |
| 419 | spans: List[Command_Span.Span] | |
| 76886 
f405fcc3db33
clarified signature: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76885diff
changeset | 420 |     ) : (String, List[Document.Node.Name]) = {
 | 
| 72816 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 421 | val theory = name.theory | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 422 | val syntax = get_syntax(name) | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 423 | val files1 = resources.loaded_files(syntax, name, spans) | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 424 | val files2 = if (theory == Thy_Header.PURE) pure_files(syntax) else Nil | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 425 | (theory, files1 ::: files2) | 
| 66959 | 426 | } | 
| 427 | ||
| 76886 
f405fcc3db33
clarified signature: avoid somewhat fragile Document.Node.Name.master_dir_path;
 wenzelm parents: 
76885diff
changeset | 428 | def loaded_files: List[Document.Node.Name] = | 
| 72816 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 429 |       for {
 | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 430 | (name, spans) <- load_commands | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 431 | file <- loaded_files(name, spans)._2 | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 432 | } yield file | 
| 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 433 | |
| 75393 | 434 |     def imported_files: List[Path] = {
 | 
| 66959 | 435 | val base_theories = | 
| 67059 | 436 | loaded_theories.all_preds(theories.map(_.theory)). | 
| 72063 | 437 | filter(session_base.loaded_theories.defined) | 
| 66959 | 438 | |
| 70740 | 439 | base_theories.map(theory => session_base.known_theories(theory).name.path) ::: | 
| 72816 
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
 wenzelm parents: 
72799diff
changeset | 440 | base_theories.flatMap(session_base.known_loaded_files.withDefaultValue(Nil)) | 
| 66959 | 441 | } | 
| 442 | ||
| 443 | lazy val overall_syntax: Outer_Syntax = | |
| 72063 | 444 | Outer_Syntax.merge(loaded_theories.maximals.map(loaded_theories.get_node)) | 
| 66959 | 445 | |
| 446 | override def toString: String = entries.toString | |
| 447 | } | |
| 76587 | 448 | |
| 449 | ||
| 450 | /* resolve implicit theory dependencies */ | |
| 451 | ||
| 452 | def resolve_dependencies[A]( | |
| 76766 | 453 | models: Iterable[Document.Model], | 
| 76767 | 454 | theories: List[Document.Node.Name] | 
| 76587 | 455 |   ): List[Document.Node.Name] = {
 | 
| 456 | val model_theories = | |
| 76766 | 457 | (for (model <- models.iterator if model.is_theory) | 
| 76587 | 458 | yield (model.node_name, Position.none)).toList | 
| 459 | ||
| 76767 | 460 | val thy_files1 = | 
| 461 | dependencies(model_theories ::: theories.map((_, Position.none))).theories | |
| 76587 | 462 | |
| 463 | val thy_files2 = | |
| 464 |       (for {
 | |
| 76766 | 465 | model <- models.iterator if !model.is_theory | 
| 76587 | 466 | thy_name <- make_theory_name(model.node_name) | 
| 467 | } yield thy_name).toList | |
| 468 | ||
| 469 | thy_files1 ::: thy_files2 | |
| 470 | } | |
| 43651 
511df47bcadc
some support for theory files within Isabelle/Scala session;
 wenzelm parents: diff
changeset | 471 | } |