src/Pure/Tools/dump.scala
changeset 68365 f9379279f98c
parent 68355 67a4db47e4f6
child 68416 33114721ac9a
equal deleted inserted replaced
68364:5c579bb9adb1 68365:f9379279f98c
    12   /* aspects */
    12   /* aspects */
    13 
    13 
    14   sealed case class Aspect_Args(
    14   sealed case class Aspect_Args(
    15     options: Options,
    15     options: Options,
    16     progress: Progress,
    16     progress: Progress,
       
    17     deps: Sessions.Deps,
    17     output_dir: Path,
    18     output_dir: Path,
    18     deps: Sessions.Deps,
    19     node_name: Document.Node.Name,
    19     result: Thy_Resources.Theories_Result)
    20     node_status: Protocol.Node_Status,
       
    21     snapshot: Document.Snapshot)
    20   {
    22   {
    21     def write(node_name: Document.Node.Name, file_name: Path, bytes: Bytes)
    23     def write(file_name: Path, bytes: Bytes)
    22     {
    24     {
    23       val path = output_dir + Path.basic(node_name.theory) + file_name
    25       val path = output_dir + Path.basic(node_name.theory) + file_name
    24       Isabelle_System.mkdirs(path.dir)
    26       Isabelle_System.mkdirs(path.dir)
    25       Bytes.write(path, bytes)
    27       Bytes.write(path, bytes)
    26     }
    28     }
    27 
    29 
    28     def write(node_name: Document.Node.Name, file_name: Path, text: String): Unit =
    30     def write(file_name: Path, text: String): Unit =
    29       write(node_name, file_name, Bytes(text))
    31       write(file_name, Bytes(text))
    30 
    32 
    31     def write(node_name: Document.Node.Name, file_name: Path, body: XML.Body): Unit =
    33     def write(file_name: Path, body: XML.Body): Unit =
    32       write(node_name, file_name, Symbol.encode(YXML.string_of_body(body)))
    34       write(file_name, Symbol.encode(YXML.string_of_body(body)))
    33   }
    35   }
    34 
    36 
    35   sealed case class Aspect(name: String, description: String, operation: Aspect_Args => Unit,
    37   sealed case class Aspect(name: String, description: String, operation: Aspect_Args => Unit,
    36     options: List[String] = Nil)
    38     options: List[String] = Nil)
    37   {
    39   {
    38     override def toString: String = name
    40     override def toString: String = name
    39   }
    41   }
    40 
    42 
    41   val known_aspects =
    43   val known_aspects =
    42     List(
    44     List(
       
    45       Aspect("markup", "PIDE markup (YXML format)",
       
    46         { case args =>
       
    47             args.write(Path.explode("markup.yxml"),
       
    48               args.snapshot.markup_to_XML(Text.Range.full, Markup.Elements.full))
       
    49         }),
    43       Aspect("messages", "output messages (YXML format)",
    50       Aspect("messages", "output messages (YXML format)",
    44         { case args =>
    51         { case args =>
    45             for (node_name <- args.result.node_names) {
    52             args.write(Path.explode("messages.yxml"),
    46               args.write(node_name, Path.explode("messages.yxml"),
    53               args.snapshot.messages.iterator.map(_._1).toList)
    47                 args.result.messages(node_name).iterator.map(_._1).toList)
       
    48             }
       
    49         }),
       
    50       Aspect("markup", "PIDE markup (YXML format)",
       
    51         { case args =>
       
    52             for (node_name <- args.result.node_names) {
       
    53               args.write(node_name, Path.explode("markup.yxml"),
       
    54                 args.result.markup_to_XML(node_name))
       
    55             }
       
    56         }),
    54         }),
    57       Aspect("latex", "generated LaTeX source",
    55       Aspect("latex", "generated LaTeX source",
    58         { case args =>
    56         { case args =>
    59             for {
    57             for (entry <- args.snapshot.exports if entry.name == "document.tex")
    60               node_name <- args.result.node_names
    58               args.write(Path.explode(entry.name), entry.uncompressed())
    61               entry <- args.result.exports(node_name)
       
    62               if entry.name == "document.tex"
       
    63             } args.write(node_name, Path.explode(entry.name), entry.uncompressed())
       
    64         }, options = List("editor_presentation")),
    59         }, options = List("editor_presentation")),
    65       Aspect("theory", "foundational theory content",
    60       Aspect("theory", "foundational theory content",
    66         { case args =>
    61         { case args =>
    67             for {
    62             for {
    68               node_name <- args.result.node_names
    63               entry <- args.snapshot.exports
    69               entry <- args.result.exports(node_name)
       
    70               if entry.name.startsWith(Export_Theory.export_prefix)
    64               if entry.name.startsWith(Export_Theory.export_prefix)
    71             } args.write(node_name, Path.explode(entry.name), entry.uncompressed())
    65             } args.write(Path.explode(entry.name), entry.uncompressed())
    72         }, options = List("editor_presentation", "export_theory"))
    66         }, options = List("editor_presentation", "export_theory"))
    73     ).sortBy(_.name)
    67     ).sortBy(_.name)
    74 
    68 
    75   def show_aspects: String =
    69   def show_aspects: String =
    76     cat_lines(known_aspects.map(aspect => aspect.name + " - " + aspect.description))
    70     cat_lines(known_aspects.map(aspect => aspect.name + " - " + aspect.description))
   127     val session_result = session.stop()
   121     val session_result = session.stop()
   128 
   122 
   129 
   123 
   130     /* dump aspects */
   124     /* dump aspects */
   131 
   125 
   132     val aspect_args = Aspect_Args(dump_options, progress, output_dir, deps, theories_result)
   126     for ((node_name, node_status) <- theories_result.nodes) {
   133     aspects.foreach(_.operation(aspect_args))
   127       val snapshot = theories_result.snapshot(node_name)
       
   128       val aspect_args =
       
   129         Aspect_Args(dump_options, progress, deps, output_dir, node_name, node_status, snapshot)
       
   130       aspects.foreach(_.operation(aspect_args))
       
   131     }
   134 
   132 
   135     session_result
   133     session_result
   136   }
   134   }
   137 
   135 
   138 
   136