| author | nipkow |
| Fri, 28 Feb 2014 18:09:37 +0100 | |
| changeset 55807 | fd31d0e70eb8 |
| parent 54690 | cd88b44623bf |
| child 56276 | 9e2d5e3debd3 |
| 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 |
||
|
52444
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
4 |
View 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 |
||
|
52444
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
25 |
private def contents_lines(): List[String] = |
|
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))) |
|
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
31 |
} yield line |
|
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
32 |
|
| 52427 | 33 |
sealed abstract class Entry |
34 |
case class Section(text: String) extends Entry |
|
35 |
case class Doc(name: String, title: String) 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 |
|
| 53777 | 38 |
def text_file(name: String): Option[Text_File] = |
39 |
{
|
|
40 |
val path = Path.variable("ISABELLE_HOME") + Path.explode(name)
|
|
41 |
if (path.is_file) Some(Text_File(name, path)) |
|
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] = |
|
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
49 |
{
|
|
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
50 |
val names = |
|
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
51 |
List("ANNOUNCE", "README", "NEWS", "COPYRIGHT", "CONTRIBUTORS",
|
|
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
52 |
"contrib/README", "README_REPOSITORY") |
|
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
53 |
Section("Release notes") ::
|
|
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
54 |
(for (name <- names; entry <- text_file(name)) yield entry) |
|
19d674acb764
more release notes according to availability in proper release vs. repository clone;
wenzelm
parents:
52541
diff
changeset
|
55 |
} |
|
52541
97c950217d7f
quick access to release notes (imitating website/documentation.html);
wenzelm
parents:
52448
diff
changeset
|
56 |
|
| 53777 | 57 |
private def examples(): List[Entry] = |
58 |
{
|
|
59 |
val names = |
|
60 |
List( |
|
61 |
"src/HOL/ex/Seq.thy", |
|
| 53935 | 62 |
"src/HOL/ex/ML.thy", |
| 53777 | 63 |
"src/HOL/Unix/Unix.thy", |
64 |
"src/HOL/Isar_Examples/Drinker.thy") |
|
65 |
Section("Examples") :: names.map(name => text_file(name).get)
|
|
66 |
} |
|
67 |
||
|
52444
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
68 |
def contents(): List[Entry] = |
|
52541
97c950217d7f
quick access to release notes (imitating website/documentation.html);
wenzelm
parents:
52448
diff
changeset
|
69 |
(for {
|
|
52444
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
70 |
line <- contents_lines() |
| 52427 | 71 |
entry <- |
72 |
line match {
|
|
73 |
case Section_Entry(text) => Some(Section(text)) |
|
74 |
case Doc_Entry(name, title) => Some(Doc(name, title)) |
|
75 |
case _ => None |
|
76 |
} |
|
| 53777 | 77 |
} yield entry) ::: release_notes() ::: examples() |
| 52427 | 78 |
|
79 |
||
80 |
/* view */ |
|
81 |
||
82 |
def view(name: String) |
|
83 |
{
|
|
| 54690 | 84 |
val doc = Path.basic(name + ".pdf") |
85 |
dirs().find(dir => (dir + doc).is_file) match {
|
|
86 |
case Some(dir) => Isabelle_System.pdf_viewer(dir + doc) |
|
87 |
case None => error("Missing Isabelle documentation file: " + doc)
|
|
| 52427 | 88 |
} |
89 |
} |
|
|
52444
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
90 |
|
|
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
91 |
|
|
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
92 |
/* command line entry point */ |
|
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 |
def main(args: Array[String]) |
|
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 |
Command_Line.tool {
|
|
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
97 |
if (args.isEmpty) Console.println(cat_lines(contents_lines())) |
|
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
98 |
else args.foreach(view) |
|
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
99 |
0 |
|
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
100 |
} |
|
2cfe6656d6d6
slightly improved "isabelle doc" based on Isabelle/Scala;
wenzelm
parents:
52429
diff
changeset
|
101 |
} |
| 52427 | 102 |
} |
103 |