26 catalog = dir + Path.basic("Contents") |
25 catalog = dir + Path.basic("Contents") |
27 if catalog.is_file |
26 if catalog.is_file |
28 line <- Library.trim_split_lines(File.read(catalog)) |
27 line <- Library.trim_split_lines(File.read(catalog)) |
29 } yield (dir, line) |
28 } yield (dir, line) |
30 |
29 |
31 object Contents |
30 object Contents { |
32 { |
|
33 def apply(sections: List[Section]): Contents = new Contents(sections) |
31 def apply(sections: List[Section]): Contents = new Contents(sections) |
34 |
32 |
35 def section(title: String, important: Boolean, entries: List[Entry]): Contents = |
33 def section(title: String, important: Boolean, entries: List[Entry]): Contents = |
36 apply(List(Section(title, important, entries))) |
34 apply(List(Section(title, important, entries))) |
37 } |
35 } |
38 class Contents private(val sections: List[Section]) |
36 class Contents private(val sections: List[Section]) { |
39 { |
|
40 def ++ (other: Contents): Contents = new Contents(sections ::: other.sections) |
37 def ++ (other: Contents): Contents = new Contents(sections ::: other.sections) |
41 def entries: List[Entry] = sections.flatMap(_.entries) |
38 def entries: List[Entry] = sections.flatMap(_.entries) |
42 def docs: List[Doc] = entries.collect({ case doc: Doc => doc }) |
39 def docs: List[Doc] = entries.collect({ case doc: Doc => doc }) |
43 } |
40 } |
44 |
41 |
45 case class Section(title: String, important: Boolean, entries: List[Entry]) |
42 case class Section(title: String, important: Boolean, entries: List[Entry]) |
46 sealed abstract class Entry |
43 sealed abstract class Entry { |
47 { |
|
48 def name: String |
44 def name: String |
49 def path: Path |
45 def path: Path |
50 } |
46 } |
51 case class Doc(name: String, title: String, path: Path) extends Entry |
47 case class Doc(name: String, title: String, path: Path) extends Entry |
52 case class Text_File(name: String, path: Path) extends Entry |
48 case class Text_File(name: String, path: Path) extends Entry |
69 text_file(file) match { |
65 text_file(file) match { |
70 case Some(entry) => entry |
66 case Some(entry) => entry |
71 case None => error("Bad entry in ISABELLE_DOCS_EXAMPLES: " + file) |
67 case None => error("Bad entry in ISABELLE_DOCS_EXAMPLES: " + file) |
72 })) |
68 })) |
73 |
69 |
74 def main_contents(): Contents = |
70 def main_contents(): Contents = { |
75 { |
|
76 val result = new mutable.ListBuffer[Section] |
71 val result = new mutable.ListBuffer[Section] |
77 val entries = new mutable.ListBuffer[Entry] |
72 val entries = new mutable.ListBuffer[Entry] |
78 var section: Option[Section] = None |
73 var section: Option[Section] = None |
79 |
74 |
80 def flush(): Unit = |
75 def flush(): Unit = |
108 |
102 |
109 flush() |
103 flush() |
110 Contents(result.toList) |
104 Contents(result.toList) |
111 } |
105 } |
112 |
106 |
113 def contents(): Contents = |
107 def contents(): Contents = { |
114 { |
|
115 examples() ++ release_notes() ++ main_contents() |
108 examples() ++ release_notes() ++ main_contents() |
116 } |
109 } |
117 |
110 |
118 object Doc_Names extends Scala.Fun_String("doc_names") |
111 object Doc_Names extends Scala.Fun_String("doc_names") { |
119 { |
|
120 val here = Scala_Project.here |
112 val here = Scala_Project.here |
121 def apply(arg: String): String = |
113 def apply(arg: String): String = |
122 if (arg.nonEmpty) error("Bad argument: " + quote(arg)) |
114 if (arg.nonEmpty) error("Bad argument: " + quote(arg)) |
123 else cat_lines((for (doc <- contents().docs) yield doc.name).sorted) |
115 else cat_lines((for (doc <- contents().docs) yield doc.name).sorted) |
124 } |
116 } |
125 |
117 |
126 |
118 |
127 /* view */ |
119 /* view */ |
128 |
120 |
129 def view(path: Path): Unit = |
121 def view(path: Path): Unit = { |
130 { |
|
131 if (!path.is_file) error("Bad Isabelle documentation file: " + path) |
122 if (!path.is_file) error("Bad Isabelle documentation file: " + path) |
132 else if (path.is_pdf) Isabelle_System.pdf_viewer(path) |
123 else if (path.is_pdf) Isabelle_System.pdf_viewer(path) |
133 else Output.writeln(Library.trim_line(File.read(path)), stdout = true) |
124 else Output.writeln(Library.trim_line(File.read(path)), stdout = true) |
134 } |
125 } |
135 |
126 |
136 |
127 |
137 /* Isabelle tool wrapper */ |
128 /* Isabelle tool wrapper */ |
138 |
129 |
139 val isabelle_tool = Isabelle_Tool("doc", "view Isabelle PDF documentation", |
130 val isabelle_tool = Isabelle_Tool("doc", "view Isabelle PDF documentation", |
140 Scala_Project.here, args => |
131 Scala_Project.here, args => { |
141 { |
|
142 val getopts = Getopts(""" |
132 val getopts = Getopts(""" |
143 Usage: isabelle doc [DOC ...] |
133 Usage: isabelle doc [DOC ...] |
144 |
134 |
145 View Isabelle PDF documentation. |
135 View Isabelle PDF documentation. |
146 """) |
136 """) |