src/Pure/Thy/thy_document_model.scala
author wenzelm
Sun, 12 Nov 2017 16:56:39 +0100
changeset 67057 0d8e4e777973
parent 67056 e35ae3eeec93
permissions -rw-r--r--
theory nodes are never visible: avoid prints, which are not covered by node_consolidated;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
67016
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Thy/thy_document_model.scala
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
     3
67055
383b902fe2b9 tuned signature;
wenzelm
parents: 67016
diff changeset
     4
Document model for theory files: no blobs, no edits, no overlays.
67016
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
     5
*/
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
     6
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
     7
package isabelle
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
     8
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
     9
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    10
object Thy_Document_Model
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    11
{
67057
0d8e4e777973 theory nodes are never visible: avoid prints, which are not covered by node_consolidated;
wenzelm
parents: 67056
diff changeset
    12
  def read_file(session: Session, node_name: Document.Node.Name): Thy_Document_Model =
67016
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    13
  {
67055
383b902fe2b9 tuned signature;
wenzelm
parents: 67016
diff changeset
    14
    val path = node_name.path
67016
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    15
    if (!node_name.is_theory) error("Not a theory file: " + path)
67057
0d8e4e777973 theory nodes are never visible: avoid prints, which are not covered by node_consolidated;
wenzelm
parents: 67056
diff changeset
    16
    new Thy_Document_Model(session, node_name, File.read(path))
67016
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    17
  }
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    18
}
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    19
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    20
final class Thy_Document_Model private(
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    21
  val session: Session,
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    22
  val node_name: Document.Node.Name,
67057
0d8e4e777973 theory nodes are never visible: avoid prints, which are not covered by node_consolidated;
wenzelm
parents: 67056
diff changeset
    23
  val text: String) extends Document.Model
67016
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    24
{
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    25
  /* content */
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    26
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    27
  def get_text(range: Text.Range): Option[String] =
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    28
    if (0 <= range.start && range.stop <= text.length) Some(range.substring(text)) else None
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    29
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    30
  def get_blob: Option[Document.Blob] = None
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    31
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    32
  def bibtex_entries: List[Text.Info[String]] = Nil
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    33
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    34
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    35
  /* header */
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    36
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    37
  def node_header: Document.Node.Header =
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    38
    resources.check_thy_reader(node_name, Scan.char_reader(text))
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    39
67056
e35ae3eeec93 load theories via PIDE document update;
wenzelm
parents: 67055
diff changeset
    40
  def node_required: Boolean = true
e35ae3eeec93 load theories via PIDE document update;
wenzelm
parents: 67055
diff changeset
    41
67016
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    42
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    43
  /* perspective */
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    44
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    45
  def node_perspective: Document.Node.Perspective_Text =
67057
0d8e4e777973 theory nodes are never visible: avoid prints, which are not covered by node_consolidated;
wenzelm
parents: 67056
diff changeset
    46
    Document.Node.Perspective(node_required, Text.Perspective.full, Document.Node.Overlays.empty)
67016
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    47
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    48
67056
e35ae3eeec93 load theories via PIDE document update;
wenzelm
parents: 67055
diff changeset
    49
  /* edits */
e35ae3eeec93 load theories via PIDE document update;
wenzelm
parents: 67055
diff changeset
    50
e35ae3eeec93 load theories via PIDE document update;
wenzelm
parents: 67055
diff changeset
    51
  def node_edits(old: Option[Thy_Document_Model]): List[Document.Edit_Text] =
e35ae3eeec93 load theories via PIDE document update;
wenzelm
parents: 67055
diff changeset
    52
  {
e35ae3eeec93 load theories via PIDE document update;
wenzelm
parents: 67055
diff changeset
    53
    val text_edits =
e35ae3eeec93 load theories via PIDE document update;
wenzelm
parents: 67055
diff changeset
    54
      if (old.isEmpty) Text.Edit.inserts(0, text)
e35ae3eeec93 load theories via PIDE document update;
wenzelm
parents: 67055
diff changeset
    55
      else Text.Edit.replace(0, old.get.text, text)
e35ae3eeec93 load theories via PIDE document update;
wenzelm
parents: 67055
diff changeset
    56
67057
0d8e4e777973 theory nodes are never visible: avoid prints, which are not covered by node_consolidated;
wenzelm
parents: 67056
diff changeset
    57
    if (text_edits.isEmpty) Nil
67056
e35ae3eeec93 load theories via PIDE document update;
wenzelm
parents: 67055
diff changeset
    58
    else node_edits(node_header, text_edits, node_perspective)
e35ae3eeec93 load theories via PIDE document update;
wenzelm
parents: 67055
diff changeset
    59
  }
e35ae3eeec93 load theories via PIDE document update;
wenzelm
parents: 67055
diff changeset
    60
e35ae3eeec93 load theories via PIDE document update;
wenzelm
parents: 67055
diff changeset
    61
67016
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    62
  /* prover session */
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    63
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    64
  def resources: Resources = session.resources
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    65
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    66
  def is_stable: Boolean = true
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    67
  def snapshot(): Document.Snapshot = session.snapshot(node_name, pending_edits = Nil)
57d58c3cf16b minimal document model for theory files;
wenzelm
parents:
diff changeset
    68
}