Scala version of "isabelle doc";
authorwenzelm
Sun Jun 23 20:12:01 2013 +0200 (2013-06-23)
changeset 524279d1cc9a22177
parent 52426 81e27230a8b7
child 52428 fce1c133e1f8
Scala version of "isabelle doc";
discontinued slightly odd / unused ">>" comments within Contents (see also b077b79061b6);
lib/Tools/doc
src/Pure/System/doc.scala
src/Pure/build-jars
     1.1 --- a/lib/Tools/doc	Sun Jun 23 18:11:38 2013 +0200
     1.2 +++ b/lib/Tools/doc	Sun Jun 23 20:12:01 2013 +0200
     1.3 @@ -39,18 +39,18 @@
     1.4  if [ -z "$DOC" ]; then
     1.5    for DIR in "${DOCS[@]}"
     1.6    do
     1.7 -    [ -d "$DIR" ] || fail "Bad document directory: $DIR"
     1.8 -    [ -f "$DIR/Contents" ] && grep -v "^>>" "$DIR/Contents"
     1.9 +    [ -d "$DIR" ] || fail "Bad documentation directory: \"$DIR\""
    1.10 +    [ -f "$DIR/Contents" ] && cat "$DIR/Contents"
    1.11    done
    1.12  else
    1.13    for DIR in "${DOCS[@]}"
    1.14    do
    1.15 -    [ -d "$DIR" ] || fail "Bad document directory: $DIR"
    1.16 +    [ -d "$DIR" ] || fail "Bad documentation directory: \"$DIR\""
    1.17      for FMT in "$ISABELLE_DOC_FORMAT" dvi
    1.18      do
    1.19        [ -f "$DIR/$DOC.$FMT" ] && { cd "$DIR"; exec "$ISABELLE_TOOL" display "$DOC.$FMT"; }
    1.20      done
    1.21    done
    1.22 -  fail "Unknown Isabelle document: $DOC"  
    1.23 +  fail "Missing Isabelle documentation: \"$DOC\""
    1.24  fi
    1.25  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/Pure/System/doc.scala	Sun Jun 23 20:12:01 2013 +0200
     2.3 @@ -0,0 +1,68 @@
     2.4 +/*  Title:      Pure/System/doc.scala
     2.5 +    Author:     Makarius
     2.6 +
     2.7 +View Isabelle documentation (see also "isabelle doc").
     2.8 +*/
     2.9 +
    2.10 +package isabelle
    2.11 +
    2.12 +
    2.13 +import scala.util.matching.Regex
    2.14 +
    2.15 +
    2.16 +object Doc
    2.17 +{
    2.18 +  /* dirs */
    2.19 +
    2.20 +  def dirs(): List[Path] =
    2.21 +    Path.split(Isabelle_System.getenv("ISABELLE_DOCS")).map(dir =>
    2.22 +      if (dir.is_dir) dir
    2.23 +      else error("Bad documentation directory: " + dir))
    2.24 +
    2.25 +
    2.26 +  /* contents */
    2.27 +
    2.28 +  sealed abstract class Entry
    2.29 +  case class Section(text: String) extends Entry
    2.30 +  case class Doc(name: String, title: String) extends Entry
    2.31 +
    2.32 +  def contents(): List[Entry] =
    2.33 +  {
    2.34 +    val Section_Entry = new Regex("""^(\S.*)\s*$""")
    2.35 +    val Doc_Entry = new Regex("""^\s+(\S+)\s+(.+)\s*$""")
    2.36 +
    2.37 +    for {
    2.38 +      dir <- dirs()
    2.39 +      catalog = dir + Path.basic("Contents")
    2.40 +      if catalog.is_file
    2.41 +      line <- split_lines(File.read(catalog))
    2.42 +      entry <-
    2.43 +        line match {
    2.44 +          case Section_Entry(text) => Some(Section(text))
    2.45 +          case Doc_Entry(name, title) => Some(Doc(name, title))
    2.46 +          case _ => None
    2.47 +        }
    2.48 +    } yield entry
    2.49 +  }
    2.50 +
    2.51 +
    2.52 +  /* view */
    2.53 +
    2.54 +  def view(name: String)
    2.55 +  {
    2.56 +    val formats = List(Isabelle_System.getenv_strict("ISABELLE_DOC_FORMAT"), "dvi")
    2.57 +    val docs =
    2.58 +      for {
    2.59 +        dir <- dirs()
    2.60 +        fmt <- formats
    2.61 +        doc = name + "." + fmt
    2.62 +        if (dir + Path.basic(doc)).is_file
    2.63 +      } yield (dir, doc)
    2.64 +    docs match {
    2.65 +      case (dir, doc) :: _ =>
    2.66 +        Isabelle_System.bash_env(dir.file, null, "\"$ISABELLE_TOOL\" display " + quote(doc) + " &")
    2.67 +      case Nil => error("Missing Isabelle documentation: " + quote(name))
    2.68 +    }
    2.69 +  }
    2.70 +}
    2.71 +
     3.1 --- a/src/Pure/build-jars	Sun Jun 23 18:11:38 2013 +0200
     3.2 +++ b/src/Pure/build-jars	Sun Jun 23 20:12:01 2013 +0200
     3.3 @@ -41,6 +41,7 @@
     3.4    PIDE/yxml.scala
     3.5    System/color_value.scala
     3.6    System/command_line.scala
     3.7 +  System/doc.scala
     3.8    System/event_bus.scala
     3.9    System/gui.scala
    3.10    System/gui_setup.scala