| author | wenzelm | 
| Tue, 20 Oct 2015 23:53:40 +0200 | |
| changeset 61493 | 0debd22f0c0e | 
| parent 61157 | 13f4056c42d7 | 
| child 62438 | 42e13a4f52f5 | 
| permissions | -rw-r--r-- | 
| 
52444
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
1  | 
/* Title: Pure/Tools/doc.scala  | 
| 52427 | 2  | 
Author: Makarius  | 
3  | 
||
| 
56424
 
7032378cc097
proper settings instead of hard-wired information;
 
wenzelm 
parents: 
56423 
diff
changeset
 | 
4  | 
Access to Isabelle documentation.  | 
| 52427 | 5  | 
*/  | 
6  | 
||
7  | 
package isabelle  | 
|
8  | 
||
9  | 
||
10  | 
import scala.util.matching.Regex  | 
|
11  | 
||
12  | 
||
13  | 
object Doc  | 
|
14  | 
{
 | 
|
15  | 
/* dirs */  | 
|
16  | 
||
17  | 
def dirs(): List[Path] =  | 
|
18  | 
    Path.split(Isabelle_System.getenv("ISABELLE_DOCS")).map(dir =>
 | 
|
19  | 
if (dir.is_dir) dir  | 
|
20  | 
      else error("Bad documentation directory: " + dir))
 | 
|
| 52740 | 21  | 
|
| 52427 | 22  | 
|
23  | 
/* contents */  | 
|
24  | 
||
| 56422 | 25  | 
private def contents_lines(): List[(Path, String)] =  | 
| 
52444
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
26  | 
    for {
 | 
| 
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
27  | 
dir <- dirs()  | 
| 
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
28  | 
      catalog = dir + Path.basic("Contents")
 | 
| 
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
29  | 
if catalog.is_file  | 
| 
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
30  | 
line <- split_lines(Library.trim_line(File.read(catalog)))  | 
| 56422 | 31  | 
} yield (dir, line)  | 
| 
52444
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
32  | 
|
| 52427 | 33  | 
sealed abstract class Entry  | 
| 
56423
 
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
 
wenzelm 
parents: 
56422 
diff
changeset
 | 
34  | 
case class Section(text: String, important: Boolean) extends Entry  | 
| 56422 | 35  | 
case class Doc(name: String, title: String, path: Path) extends Entry  | 
| 
52542
 
19d674acb764
more release notes according to availability in proper release vs. repository clone;
 
wenzelm 
parents: 
52541 
diff
changeset
 | 
36  | 
case class Text_File(name: String, path: Path) extends Entry  | 
| 52427 | 37  | 
|
| 
56424
 
7032378cc097
proper settings instead of hard-wired information;
 
wenzelm 
parents: 
56423 
diff
changeset
 | 
38  | 
def text_file(name: Path): Option[Text_File] =  | 
| 53777 | 39  | 
  {
 | 
| 
56424
 
7032378cc097
proper settings instead of hard-wired information;
 
wenzelm 
parents: 
56423 
diff
changeset
 | 
40  | 
    val path = Path.variable("ISABELLE_HOME") + name
 | 
| 
 
7032378cc097
proper settings instead of hard-wired information;
 
wenzelm 
parents: 
56423 
diff
changeset
 | 
41  | 
if (path.is_file) Some(Text_File(name.implode, path))  | 
| 53777 | 42  | 
else None  | 
43  | 
}  | 
|
44  | 
||
| 
52444
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
45  | 
  private val Section_Entry = new Regex("""^(\S.*)\s*$""")
 | 
| 
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
46  | 
  private val Doc_Entry = new Regex("""^\s+(\S+)\s+(.+)\s*$""")
 | 
| 52427 | 47  | 
|
| 
52542
 
19d674acb764
more release notes according to availability in proper release vs. repository clone;
 
wenzelm 
parents: 
52541 
diff
changeset
 | 
48  | 
private def release_notes(): List[Entry] =  | 
| 
56423
 
c2f52824dbb2
explicit indication of important doc sections ("!"), which are expanded in the tree view;
 
wenzelm 
parents: 
56422 
diff
changeset
 | 
49  | 
    Section("Release notes", true) ::
 | 
| 
56424
 
7032378cc097
proper settings instead of hard-wired information;
 
wenzelm 
parents: 
56423 
diff
changeset
 | 
50  | 
      Path.split(Isabelle_System.getenv_strict("ISABELLE_DOCS_RELEASE_NOTES")).flatMap(text_file(_))
 | 
| 
52541
 
97c950217d7f
quick access to release notes (imitating website/documentation.html);
 
wenzelm 
parents: 
52448 
diff
changeset
 | 
51  | 
|
| 53777 | 52  | 
private def examples(): List[Entry] =  | 
| 
56424
 
7032378cc097
proper settings instead of hard-wired information;
 
wenzelm 
parents: 
56423 
diff
changeset
 | 
53  | 
    Section("Examples", true) ::
 | 
| 
 
7032378cc097
proper settings instead of hard-wired information;
 
wenzelm 
parents: 
56423 
diff
changeset
 | 
54  | 
      Path.split(Isabelle_System.getenv_strict("ISABELLE_DOCS_EXAMPLES")).map(file =>
 | 
| 
 
7032378cc097
proper settings instead of hard-wired information;
 
wenzelm 
parents: 
56423 
diff
changeset
 | 
55  | 
        text_file(file) match {
 | 
| 
 
7032378cc097
proper settings instead of hard-wired information;
 
wenzelm 
parents: 
56423 
diff
changeset
 | 
56  | 
case Some(entry) => entry  | 
| 56425 | 57  | 
          case None => error("Bad entry in ISABELLE_DOCS_EXAMPLES: " + file)
 | 
| 
56424
 
7032378cc097
proper settings instead of hard-wired information;
 
wenzelm 
parents: 
56423 
diff
changeset
 | 
58  | 
})  | 
| 53777 | 59  | 
|
| 
52444
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
60  | 
def contents(): List[Entry] =  | 
| 61157 | 61  | 
  {
 | 
62  | 
val main_contents =  | 
|
63  | 
      for {
 | 
|
64  | 
(dir, line) <- contents_lines()  | 
|
65  | 
entry <-  | 
|
66  | 
          line match {
 | 
|
67  | 
case Section_Entry(text) =>  | 
|
68  | 
              Library.try_unsuffix("!", text) match {
 | 
|
69  | 
case None => Some(Section(text, false))  | 
|
70  | 
case Some(txt) => Some(Section(txt, true))  | 
|
71  | 
}  | 
|
72  | 
case Doc_Entry(name, title) => Some(Doc(name, title, dir + Path.basic(name)))  | 
|
73  | 
case _ => None  | 
|
74  | 
}  | 
|
75  | 
} yield entry  | 
|
76  | 
||
77  | 
examples() ::: release_notes() ::: main_contents  | 
|
78  | 
}  | 
|
| 52427 | 79  | 
|
80  | 
||
81  | 
/* view */  | 
|
82  | 
||
| 56422 | 83  | 
def view(path: Path)  | 
| 52427 | 84  | 
  {
 | 
| 
56831
 
e3ccf0809d51
prefer scala.Console with its support for thread-local redirection;
 
wenzelm 
parents: 
56784 
diff
changeset
 | 
85  | 
if (path.is_file) Console.println(Library.trim_line(File.read(path)))  | 
| 56422 | 86  | 
    else {
 | 
87  | 
      val pdf = path.ext("pdf")
 | 
|
88  | 
if (pdf.is_file) Isabelle_System.pdf_viewer(pdf)  | 
|
89  | 
      else error("Bad Isabelle documentation file: " + pdf)
 | 
|
| 52427 | 90  | 
}  | 
91  | 
}  | 
|
| 
52444
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
92  | 
|
| 
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
93  | 
|
| 
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
94  | 
/* command line entry point */  | 
| 
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
95  | 
|
| 
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
96  | 
def main(args: Array[String])  | 
| 
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
97  | 
  {
 | 
| 56631 | 98  | 
    Command_Line.tool0 {
 | 
| 56425 | 99  | 
val entries = contents()  | 
| 
56831
 
e3ccf0809d51
prefer scala.Console with its support for thread-local redirection;
 
wenzelm 
parents: 
56784 
diff
changeset
 | 
100  | 
if (args.isEmpty) Console.println(cat_lines(contents_lines().map(_._2)))  | 
| 56422 | 101  | 
      else {
 | 
102  | 
args.foreach(arg =>  | 
|
103  | 
          entries.collectFirst { case Doc(name, _, path) if arg == name => path } match {
 | 
|
104  | 
case Some(path) => view(path)  | 
|
105  | 
            case None => error("No Isabelle documentation entry: " + quote(arg))
 | 
|
106  | 
}  | 
|
107  | 
)  | 
|
108  | 
}  | 
|
| 
52444
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
109  | 
}  | 
| 
 
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
 
wenzelm 
parents: 
52429 
diff
changeset
 | 
110  | 
}  | 
| 52427 | 111  | 
}  |