src/Pure/Thy/sessions.scala
changeset 76005 a9bbf075f431
parent 76002 64b05dc56656
child 76016 b07f2ff55144
equal deleted inserted replaced
76004:152c5c83c119 76005:a9bbf075f431
   416           val other_name = info.name + "_requirements(" + ancestor.get + ")"
   416           val other_name = info.name + "_requirements(" + ancestor.get + ")"
   417           Isabelle_System.isabelle_tmp_prefix()
   417           Isabelle_System.isabelle_tmp_prefix()
   418 
   418 
   419           (other_name,
   419           (other_name,
   420             List(
   420             List(
   421               make_info(info.options,
   421               make_info(
       
   422                 Chapter_Defs.empty,
       
   423                 info.options,
   422                 dir_selected = false,
   424                 dir_selected = false,
   423                 dir = Path.explode("$ISABELLE_TMP_PREFIX"),
   425                 dir = Path.explode("$ISABELLE_TMP_PREFIX"),
   424                 chapter = info.chapter,
   426                 chapter = info.chapter,
   425                 Session_Entry(
   427                 Session_Entry(
   426                   pos = info.pos,
   428                   pos = info.pos,
   458   /* cumulative session info */
   460   /* cumulative session info */
   459 
   461 
   460   sealed case class Chapter_Info(
   462   sealed case class Chapter_Info(
   461     name: String,
   463     name: String,
   462     pos: Position.T,
   464     pos: Position.T,
       
   465     groups: List[String],
   463     description: String,
   466     description: String,
   464     sessions: List[String]
   467     sessions: List[String]
   465   )
   468   )
   466 
   469 
   467   sealed case class Info(
   470   sealed case class Info(
   552     def is_afp: Boolean = chapter == AFP.chapter
   555     def is_afp: Boolean = chapter == AFP.chapter
   553     def is_afp_bulky: Boolean = is_afp && groups.exists(AFP.groups_bulky.contains)
   556     def is_afp_bulky: Boolean = is_afp && groups.exists(AFP.groups_bulky.contains)
   554   }
   557   }
   555 
   558 
   556   def make_info(
   559   def make_info(
       
   560     chapter_defs: Chapter_Defs,
   557     options: Options,
   561     options: Options,
   558     dir_selected: Boolean,
   562     dir_selected: Boolean,
   559     dir: Path,
   563     dir: Path,
   560     chapter: String,
   564     chapter: String,
   561     entry: Session_Entry
   565     entry: Session_Entry
   607           (name, chapter, entry.parent, entry.directories, entry.options, entry.imports,
   611           (name, chapter, entry.parent, entry.directories, entry.options, entry.imports,
   608             entry.theories_no_position, conditions, entry.document_theories_no_position,
   612             entry.theories_no_position, conditions, entry.document_theories_no_position,
   609             entry.document_files)
   613             entry.document_files)
   610           .toString)
   614           .toString)
   611 
   615 
   612       Info(name, chapter, dir_selected, entry.pos, entry.groups, session_path,
   616       val chapter_groups = chapter_defs(chapter).groups
       
   617       val groups = chapter_groups ::: entry.groups.filterNot(chapter_groups.contains)
       
   618 
       
   619       Info(name, chapter, dir_selected, entry.pos, groups, session_path,
   613         entry.parent, entry.description, directories, session_options,
   620         entry.parent, entry.description, directories, session_options,
   614         entry.imports, theories, global_theories, entry.document_theories, document_files,
   621         entry.imports, theories, global_theories, entry.document_theories, document_files,
   615         export_files, entry.export_classpath, meta_digest)
   622         export_files, entry.export_classpath, meta_digest)
   616     }
   623     }
   617     catch {
   624     catch {
   750           for ((_, (info, _)) <- build_graph.iterator)
   757           for ((_, (info, _)) <- build_graph.iterator)
   751             yield info.chapter -> info.name)
   758             yield info.chapter -> info.name)
   752       val chapters1 =
   759       val chapters1 =
   753         (for (entry <- chapter_defs.list.iterator) yield {
   760         (for (entry <- chapter_defs.list.iterator) yield {
   754           val sessions = chapter_sessions.get_list(entry.name)
   761           val sessions = chapter_sessions.get_list(entry.name)
   755           Chapter_Info(entry.name, entry.pos, entry.description, sessions.sorted)
   762           Chapter_Info(entry.name, entry.pos, entry.groups, entry.description, sessions.sorted)
   756         }).toList
   763         }).toList
   757       val chapters2 =
   764       val chapters2 =
   758         (for {
   765         (for {
   759           (name, sessions) <- chapter_sessions.iterator_list
   766           (name, sessions) <- chapter_sessions.iterator_list
   760           if !chapters1.exists(_.name == name)
   767           if !chapters1.exists(_.name == name)
   761         } yield Chapter_Info(name, Position.none, "", sessions.sorted)).toList.sortBy(_.name)
   768         } yield Chapter_Info(name, Position.none, Nil, "", sessions.sorted)).toList.sortBy(_.name)
   762       chapters1 ::: chapters2
   769       chapters1 ::: chapters2
   763     }
   770     }
   764 
   771 
   765     def relevant_chapters: List[Chapter_Info] = known_chapters.filter(_.sessions.nonEmpty)
   772     def relevant_chapters: List[Chapter_Info] = known_chapters.filter(_.sessions.nonEmpty)
   766 
   773 
   904       (DOCUMENT_FILES, Keyword.QUASI_COMMAND) +
   911       (DOCUMENT_FILES, Keyword.QUASI_COMMAND) +
   905       (EXPORT_FILES, Keyword.QUASI_COMMAND) +
   912       (EXPORT_FILES, Keyword.QUASI_COMMAND) +
   906       (EXPORT_CLASSPATH, Keyword.QUASI_COMMAND)
   913       (EXPORT_CLASSPATH, Keyword.QUASI_COMMAND)
   907 
   914 
   908   abstract class Entry
   915   abstract class Entry
   909   sealed case class Chapter_Def(pos: Position.T, name: String, description: String) extends Entry
   916   object Chapter_Def {
       
   917     def empty(chapter: String): Chapter_Def = Chapter_Def(Position.none, chapter, Nil, "")
       
   918   }
       
   919   sealed case class Chapter_Def(
       
   920     pos: Position.T,
       
   921     name: String,
       
   922     groups: List[String],
       
   923     description: String
       
   924   ) extends Entry
   910   sealed case class Chapter_Entry(name: String) extends Entry
   925   sealed case class Chapter_Entry(name: String) extends Entry
   911   sealed case class Session_Entry(
   926   sealed case class Session_Entry(
   912     pos: Position.T,
   927     pos: Position.T,
   913     name: String,
   928     name: String,
   914     groups: List[String],
   929     groups: List[String],
   941       list.map(_.name).mkString("Chapter_Defs(", ", ", ")")
   956       list.map(_.name).mkString("Chapter_Defs(", ", ", ")")
   942 
   957 
   943     def get(chapter: String): Option[Chapter_Def] =
   958     def get(chapter: String): Option[Chapter_Def] =
   944       rev_list.find(_.name == chapter)
   959       rev_list.find(_.name == chapter)
   945 
   960 
       
   961     def apply(chapter: String): Chapter_Def =
       
   962       get(chapter) getOrElse Chapter_Def.empty(chapter)
       
   963 
   946     def + (entry: Chapter_Def): Chapter_Defs =
   964     def + (entry: Chapter_Def): Chapter_Defs =
   947       get(entry.name) match {
   965       get(entry.name) match {
   948         case None => new Chapter_Defs(entry :: rev_list)
   966         case None => new Chapter_Defs(entry :: rev_list)
   949         case Some(old_entry) =>
   967         case Some(old_entry) =>
   950           error("Duplicate chapter definition " + quote(entry.name) +
   968           error("Duplicate chapter definition " + quote(entry.name) +
   951             Position.here(old_entry.pos) + Position.here(entry.pos))
   969             Position.here(old_entry.pos) + Position.here(entry.pos))
   952       }
   970       }
   953   }
   971   }
   954 
   972 
   955   private object Parsers extends Options.Parsers {
   973   private object Parsers extends Options.Parsers {
       
   974     private val groups: Parser[List[String]] =
       
   975       ($$$("(") ~! (rep1(name) <~ $$$(")")) ^^ { case _ ~ x => x }) | success(Nil)
       
   976 
   956     private val description: Parser[String] =
   977     private val description: Parser[String] =
   957       ($$$(DESCRIPTION) ~! text ^^ { case _ ~ x => x }) | success("")
   978       ($$$(DESCRIPTION) ~! text ^^ { case _ ~ x => x }) | success("")
   958 
   979 
   959     private val chapter_def: Parser[Chapter_Def] =
   980     private val chapter_def: Parser[Chapter_Def] =
   960       command(CHAPTER_DEFINITION) ~! (position(chapter_name) ~ description) ^^
   981       command(CHAPTER_DEFINITION) ~! (position(chapter_name) ~ groups ~ description) ^^
   961         { case _ ~ ((a, pos) ~ b) => Chapter_Def(pos, a, b) }
   982         { case _ ~ ((a, pos) ~ b ~ c) => Chapter_Def(pos, a, b, c) }
   962 
   983 
   963     private val chapter_entry: Parser[Chapter_Entry] =
   984     private val chapter_entry: Parser[Chapter_Entry] =
   964       command(CHAPTER) ~! chapter_name ^^ { case _ ~ a => Chapter_Entry(a) }
   985       command(CHAPTER) ~! chapter_name ^^ { case _ ~ a => Chapter_Entry(a) }
   965 
   986 
   966     private val session_entry: Parser[Session_Entry] = {
   987     private val session_entry: Parser[Session_Entry] = {
   995       val export_classpath =
  1016       val export_classpath =
   996         $$$(EXPORT_CLASSPATH) ~! (rep1(embedded) | success(List("*:classpath/*.jar"))) ^^
  1017         $$$(EXPORT_CLASSPATH) ~! (rep1(embedded) | success(List("*:classpath/*.jar"))) ^^
   997           { case _ ~ x => x }
  1018           { case _ ~ x => x }
   998 
  1019 
   999       command(SESSION) ~!
  1020       command(SESSION) ~!
  1000         (position(session_name) ~
  1021         (position(session_name) ~ groups ~
  1001           (($$$("(") ~! (rep1(name) <~ $$$(")")) ^^ { case _ ~ x => x }) | success(Nil)) ~
       
  1002           (($$$(IN) ~! path ^^ { case _ ~ x => x }) | success(".")) ~
  1022           (($$$(IN) ~! path ^^ { case _ ~ x => x }) | success(".")) ~
  1003           ($$$("=") ~!
  1023           ($$$("=") ~!
  1004             (opt(session_name ~! $$$("+") ^^ { case x ~ _ => x }) ~ description ~
  1024             (opt(session_name ~! $$$("+") ^^ { case x ~ _ => x }) ~ description ~
  1005               (($$$(OPTIONS) ~! options ^^ { case _ ~ x => x }) | success(Nil)) ~
  1025               (($$$(OPTIONS) ~! options ^^ { case _ ~ x => x }) | success(Nil)) ~
  1006               (($$$(SESSIONS) ~! rep1(session_name)  ^^ { case _ ~ x => x }) | success(Nil)) ~
  1026               (($$$(SESSIONS) ~! rep1(session_name)  ^^ { case _ ~ x => x }) | success(Nil)) ~
  1101           }
  1121           }
  1102       }.toList.map(_._2)
  1122       }.toList.map(_._2)
  1103 
  1123 
  1104     val (chapter_defs, info_roots) = {
  1124     val (chapter_defs, info_roots) = {
  1105       var chapter_defs = Chapter_Defs.empty
  1125       var chapter_defs = Chapter_Defs.empty
  1106       val info_roots = new mutable.ListBuffer[Info]
  1126       val mk_infos = new mutable.ListBuffer[() => Info]
  1107 
  1127 
  1108       for ((select, path) <- unique_roots) {
  1128       for ((select, path) <- unique_roots) {
  1109         var entry_chapter = UNSORTED
  1129         var entry_chapter = UNSORTED
  1110         parse_root(path).foreach {
  1130         parse_root(path).foreach {
  1111           case entry: Chapter_Def => chapter_defs += entry
  1131           case entry: Chapter_Def => chapter_defs += entry
  1112           case entry: Chapter_Entry => entry_chapter = entry.name
  1132           case entry: Chapter_Entry => entry_chapter = entry.name
  1113           case entry: Session_Entry =>
  1133           case entry: Session_Entry =>
  1114             info_roots += make_info(options, select, path.dir, entry_chapter, entry)
  1134             def mk(): Info = make_info(chapter_defs, options, select, path.dir, entry_chapter, entry)
       
  1135             mk_infos += mk
  1115         }
  1136         }
  1116       }
  1137       }
  1117       (chapter_defs, info_roots.toList)
  1138       (chapter_defs, mk_infos.toList.map(_()))
  1118     }
  1139     }
  1119 
  1140 
  1120     Structure.make(chapter_defs, info_roots ::: infos)
  1141     Structure.make(chapter_defs, info_roots ::: infos)
  1121   }
  1142   }
  1122 
  1143