src/Pure/PIDE/isar_document.scala
author wenzelm
Wed, 31 Aug 2011 22:10:07 +0200
changeset 44613 a3255c85327b
parent 44612 990ac978854c
child 44615 a4ff8a787202
permissions -rw-r--r--
crude display of node status; tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38483
3d16bebee1d3 moved Isar_Document to Pure/PIDE;
wenzelm
parents: 38448
diff changeset
     1
/*  Title:      Pure/PIDE/isar_document.scala
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     3
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
     4
Protocol message formats for interactive Isar documents.
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     5
*/
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     6
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     7
package isabelle
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     8
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
     9
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    10
object Isar_Document
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    11
{
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    12
  /* document editing */
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    13
44476
e8a87398f35d propagate information about last command with exec state assignment through document model;
wenzelm
parents: 44474
diff changeset
    14
  object Assign
e8a87398f35d propagate information about last command with exec state assignment through document model;
wenzelm
parents: 44474
diff changeset
    15
  {
e8a87398f35d propagate information about last command with exec state assignment through document model;
wenzelm
parents: 44474
diff changeset
    16
    def unapply(msg: XML.Tree): Option[(Document.Version_ID, Document.Assign)] =
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    17
      msg match {
44476
e8a87398f35d propagate information about last command with exec state assignment through document model;
wenzelm
parents: 44474
diff changeset
    18
        case XML.Elem(Markup(Markup.ASSIGN, List((Markup.VERSION, Document.ID(id)))), body) =>
e8a87398f35d propagate information about last command with exec state assignment through document model;
wenzelm
parents: 44474
diff changeset
    19
          try {
e8a87398f35d propagate information about last command with exec state assignment through document model;
wenzelm
parents: 44474
diff changeset
    20
            import XML.Decode._
44479
9a04e7502e22 refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents: 44476
diff changeset
    21
            val a = pair(list(pair(long, option(long))), list(pair(string, option(long))))(body)
44476
e8a87398f35d propagate information about last command with exec state assignment through document model;
wenzelm
parents: 44474
diff changeset
    22
            Some(id, a)
e8a87398f35d propagate information about last command with exec state assignment through document model;
wenzelm
parents: 44474
diff changeset
    23
          }
e8a87398f35d propagate information about last command with exec state assignment through document model;
wenzelm
parents: 44474
diff changeset
    24
          catch {
e8a87398f35d propagate information about last command with exec state assignment through document model;
wenzelm
parents: 44474
diff changeset
    25
            case _: XML.XML_Atom => None
e8a87398f35d propagate information about last command with exec state assignment through document model;
wenzelm
parents: 44474
diff changeset
    26
            case _: XML.XML_Body => None
e8a87398f35d propagate information about last command with exec state assignment through document model;
wenzelm
parents: 44474
diff changeset
    27
          }
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    28
        case _ => None
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    29
      }
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    30
  }
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    31
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    32
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    33
  /* toplevel transactions */
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    34
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    35
  sealed abstract class Status
44613
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    36
  case object Unprocessed extends Status
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    37
  case class Forked(forks: Int) extends Status
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    38
  case object Finished extends Status
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    39
  case object Failed extends Status
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    40
38581
d503a0912e14 simplified Command.status again, reverting most of e5eed57913d0 (note that more complex information can be represented with full markup reports);
wenzelm
parents: 38567
diff changeset
    41
  def command_status(markup: List[Markup]): Status =
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    42
  {
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    43
    val forks = (0 /: markup) {
38581
d503a0912e14 simplified Command.status again, reverting most of e5eed57913d0 (note that more complex information can be represented with full markup reports);
wenzelm
parents: 38567
diff changeset
    44
      case (i, Markup(Markup.FORKED, _)) => i + 1
d503a0912e14 simplified Command.status again, reverting most of e5eed57913d0 (note that more complex information can be represented with full markup reports);
wenzelm
parents: 38567
diff changeset
    45
      case (i, Markup(Markup.JOINED, _)) => i - 1
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    46
      case (i, _) => i
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    47
    }
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    48
    if (forks != 0) Forked(forks)
38581
d503a0912e14 simplified Command.status again, reverting most of e5eed57913d0 (note that more complex information can be represented with full markup reports);
wenzelm
parents: 38567
diff changeset
    49
    else if (markup.exists(_.name == Markup.FAILED)) Failed
d503a0912e14 simplified Command.status again, reverting most of e5eed57913d0 (note that more complex information can be represented with full markup reports);
wenzelm
parents: 38567
diff changeset
    50
    else if (markup.exists(_.name == Markup.FINISHED)) Finished
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    51
    else Unprocessed
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    52
  }
38887
1261481ef5e5 Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents: 38581
diff changeset
    53
44613
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    54
  sealed case class Node_Status(unprocessed: Int, running: Int, finished: Int, failed: Int)
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    55
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    56
  def node_status(
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    57
    state: Document.State, version: Document.Version, node: Document.Node): Node_Status =
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    58
  {
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    59
    var unprocessed = 0
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    60
    var running = 0
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    61
    var finished = 0
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    62
    var failed = 0
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    63
    node.commands.foreach(command =>
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    64
      command_status(state.command_state(version, command).status) match {
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    65
        case Unprocessed => unprocessed += 1
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    66
        case Forked(_) => running += 1
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    67
        case Finished => finished += 1
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    68
        case Failed => failed += 1
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    69
      })
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    70
    Node_Status(unprocessed, running, finished, failed)
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    71
  }
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
    72
38887
1261481ef5e5 Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents: 38581
diff changeset
    73
39441
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
    74
  /* result messages */
39439
1c294d150ded eliminated markup "location" in favour of more explicit "no_report", which is actually deleted from messages;
wenzelm
parents: 39181
diff changeset
    75
1c294d150ded eliminated markup "location" in favour of more explicit "no_report", which is actually deleted from messages;
wenzelm
parents: 39181
diff changeset
    76
  def clean_message(body: XML.Body): XML.Body =
1c294d150ded eliminated markup "location" in favour of more explicit "no_report", which is actually deleted from messages;
wenzelm
parents: 39181
diff changeset
    77
    body filter { case XML.Elem(Markup(Markup.NO_REPORT, _), _) => false case _ => true } map
1c294d150ded eliminated markup "location" in favour of more explicit "no_report", which is actually deleted from messages;
wenzelm
parents: 39181
diff changeset
    78
      { case XML.Elem(markup, ts) => XML.Elem(markup, clean_message(ts)) case t => t }
1c294d150ded eliminated markup "location" in favour of more explicit "no_report", which is actually deleted from messages;
wenzelm
parents: 39181
diff changeset
    79
39441
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
    80
  def message_reports(msg: XML.Tree): List[XML.Elem] =
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
    81
    msg match {
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
    82
      case elem @ XML.Elem(Markup(Markup.REPORT, _), _) => List(elem)
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
    83
      case XML.Elem(_, body) => body.flatMap(message_reports)
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
    84
      case XML.Text(_) => Nil
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
    85
    }
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
    86
39439
1c294d150ded eliminated markup "location" in favour of more explicit "no_report", which is actually deleted from messages;
wenzelm
parents: 39181
diff changeset
    87
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
    88
  /* specific messages */
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
    89
39625
fb0c851e4f9d tuned prover message categorization;
wenzelm
parents: 39622
diff changeset
    90
  def is_ready(msg: XML.Tree): Boolean =
fb0c851e4f9d tuned prover message categorization;
wenzelm
parents: 39622
diff changeset
    91
    msg match {
fb0c851e4f9d tuned prover message categorization;
wenzelm
parents: 39622
diff changeset
    92
      case XML.Elem(Markup(Markup.STATUS, _),
fb0c851e4f9d tuned prover message categorization;
wenzelm
parents: 39622
diff changeset
    93
        List(XML.Elem(Markup(Markup.READY, _), _))) => true
fb0c851e4f9d tuned prover message categorization;
wenzelm
parents: 39622
diff changeset
    94
      case _ => false
fb0c851e4f9d tuned prover message categorization;
wenzelm
parents: 39622
diff changeset
    95
    }
fb0c851e4f9d tuned prover message categorization;
wenzelm
parents: 39622
diff changeset
    96
fb0c851e4f9d tuned prover message categorization;
wenzelm
parents: 39622
diff changeset
    97
 def is_tracing(msg: XML.Tree): Boolean =
39622
53365ba766ac Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents: 39511
diff changeset
    98
    msg match {
53365ba766ac Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents: 39511
diff changeset
    99
      case XML.Elem(Markup(Markup.TRACING, _), _) => true
53365ba766ac Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents: 39511
diff changeset
   100
      case _ => false
53365ba766ac Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents: 39511
diff changeset
   101
    }
53365ba766ac Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents: 39511
diff changeset
   102
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   103
  def is_warning(msg: XML.Tree): Boolean =
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   104
    msg match {
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   105
      case XML.Elem(Markup(Markup.WARNING, _), _) => true
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   106
      case _ => false
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   107
    }
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   108
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   109
  def is_error(msg: XML.Tree): Boolean =
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   110
    msg match {
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   111
      case XML.Elem(Markup(Markup.ERROR, _), _) => true
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   112
      case _ => false
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   113
    }
38887
1261481ef5e5 Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents: 38581
diff changeset
   114
39441
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
   115
  def is_state(msg: XML.Tree): Boolean =
39170
04ad0fed81f5 Isar_Document.reported_positions: exclude proof state output;
wenzelm
parents: 39042
diff changeset
   116
    msg match {
39627
wenzelm
parents: 39625
diff changeset
   117
      case XML.Elem(Markup(Markup.WRITELN, _),
wenzelm
parents: 39625
diff changeset
   118
        List(XML.Elem(Markup(Markup.STATE, _), _))) => true
39170
04ad0fed81f5 Isar_Document.reported_positions: exclude proof state output;
wenzelm
parents: 39042
diff changeset
   119
      case _ => false
04ad0fed81f5 Isar_Document.reported_positions: exclude proof state output;
wenzelm
parents: 39042
diff changeset
   120
    }
04ad0fed81f5 Isar_Document.reported_positions: exclude proof state output;
wenzelm
parents: 39042
diff changeset
   121
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   122
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   123
  /* reported positions */
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   124
39627
wenzelm
parents: 39625
diff changeset
   125
  private val include_pos =
wenzelm
parents: 39625
diff changeset
   126
    Set(Markup.BINDING, Markup.ENTITY, Markup.REPORT, Markup.POSITION)
39441
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
   127
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
   128
  def message_positions(command: Command, message: XML.Elem): Set[Text.Range] =
38887
1261481ef5e5 Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents: 38581
diff changeset
   129
  {
39441
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
   130
    def positions(set: Set[Text.Range], tree: XML.Tree): Set[Text.Range] =
38887
1261481ef5e5 Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents: 38581
diff changeset
   131
      tree match {
39172
31b95e0da7b7 Isar_Document.reported_positions: slightly more robust treatment of positions outside the command range, notably parsing beyond EOF;
wenzelm
parents: 39170
diff changeset
   132
        case XML.Elem(Markup(name, Position.Id_Range(id, raw_range)), body)
31b95e0da7b7 Isar_Document.reported_positions: slightly more robust treatment of positions outside the command range, notably parsing beyond EOF;
wenzelm
parents: 39170
diff changeset
   133
        if include_pos(name) && id == command.id =>
31b95e0da7b7 Isar_Document.reported_positions: slightly more robust treatment of positions outside the command range, notably parsing beyond EOF;
wenzelm
parents: 39170
diff changeset
   134
          val range = command.decode(raw_range).restrict(command.range)
39441
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
   135
          body.foldLeft(if (range.is_singularity) set else set + range)(positions)
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
   136
        case XML.Elem(Markup(name, _), body) => body.foldLeft(set)(positions)
39042
470fd769ae53 Isar_Document.reported_positions: more precise include/exclude, include root as last resort only;
wenzelm
parents: 38887
diff changeset
   137
        case _ => set
38887
1261481ef5e5 Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents: 38581
diff changeset
   138
      }
39441
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
   139
    val set = positions(Set.empty, message)
39170
04ad0fed81f5 Isar_Document.reported_positions: exclude proof state output;
wenzelm
parents: 39042
diff changeset
   140
    if (set.isEmpty && !is_state(message))
39172
31b95e0da7b7 Isar_Document.reported_positions: slightly more robust treatment of positions outside the command range, notably parsing beyond EOF;
wenzelm
parents: 39170
diff changeset
   141
      set ++ Position.Range.unapply(message.markup.properties).map(command.decode(_))
39042
470fd769ae53 Isar_Document.reported_positions: more precise include/exclude, include root as last resort only;
wenzelm
parents: 38887
diff changeset
   142
    else set
38887
1261481ef5e5 Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents: 38581
diff changeset
   143
  }
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   144
}
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   145
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   146
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   147
trait Isar_Document extends Isabelle_Process
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   148
{
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   149
  /* commands */
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   150
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   151
  def define_command(id: Document.Command_ID, text: String): Unit =
38414
49f1f657adc2 more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
wenzelm
parents: 38412
diff changeset
   152
    input("Isar_Document.define_command", Document.ID(id), text)
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   153
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   154
38417
b8922ae21111 renamed class Document to Document.Version etc.;
wenzelm
parents: 38414
diff changeset
   155
  /* document versions */
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   156
44612
990ac978854c explicit cancel_execution before queueing new edits -- potential performance improvement for machines with few cores;
wenzelm
parents: 44481
diff changeset
   157
  def cancel_execution()
990ac978854c explicit cancel_execution before queueing new edits -- potential performance improvement for machines with few cores;
wenzelm
parents: 44481
diff changeset
   158
  {
990ac978854c explicit cancel_execution before queueing new edits -- potential performance improvement for machines with few cores;
wenzelm
parents: 44481
diff changeset
   159
    input("Isar_Document.cancel_execution")
990ac978854c explicit cancel_execution before queueing new edits -- potential performance improvement for machines with few cores;
wenzelm
parents: 44481
diff changeset
   160
  }
990ac978854c explicit cancel_execution before queueing new edits -- potential performance improvement for machines with few cores;
wenzelm
parents: 44481
diff changeset
   161
44436
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44384
diff changeset
   162
  def update_perspective(old_id: Document.Version_ID, new_id: Document.Version_ID,
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44384
diff changeset
   163
    name: String, perspective: Command.Perspective)
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44384
diff changeset
   164
  {
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44384
diff changeset
   165
    val ids =
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44384
diff changeset
   166
    { import XML.Encode._
44474
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44436
diff changeset
   167
      list(long)(perspective.commands.map(_.id)) }
44436
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44384
diff changeset
   168
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44384
diff changeset
   169
    input("Isar_Document.update_perspective", Document.ID(old_id), Document.ID(new_id), name,
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44384
diff changeset
   170
      YXML.string_of_body(ids))
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44384
diff changeset
   171
  }
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44384
diff changeset
   172
44481
bb42bc831570 tuned signature;
wenzelm
parents: 44479
diff changeset
   173
  def update(old_id: Document.Version_ID, new_id: Document.Version_ID,
44383
f99906c2a1d3 discontinued redundant Edit_Command_ID;
wenzelm
parents: 44185
diff changeset
   174
    edits: List[Document.Edit_Command])
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   175
  {
44157
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
   176
    val edits_yxml =
43767
e0219ef7f84c tuned XML modules;
wenzelm
parents: 43748
diff changeset
   177
    { import XML.Encode._
44383
f99906c2a1d3 discontinued redundant Edit_Command_ID;
wenzelm
parents: 44185
diff changeset
   178
      def id: T[Command] = (cmd => long(cmd.id))
f99906c2a1d3 discontinued redundant Edit_Command_ID;
wenzelm
parents: 44185
diff changeset
   179
      def encode: T[List[Document.Edit_Command]] =
44156
6aa25b80e1a5 explicit datatypes for document node edits;
wenzelm
parents: 43767
diff changeset
   180
        list(pair(string,
6aa25b80e1a5 explicit datatypes for document node edits;
wenzelm
parents: 43767
diff changeset
   181
          variant(List(
44185
05641edb5d30 provide node header via Scala layer;
wenzelm
parents: 44182
diff changeset
   182
            { case Document.Node.Clear() => (Nil, Nil) },
44383
f99906c2a1d3 discontinued redundant Edit_Command_ID;
wenzelm
parents: 44185
diff changeset
   183
            { case Document.Node.Edits(a) => (Nil, list(pair(option(id), option(id)))(a)) },
44182
ecb51b457064 clarified node header -- exclude master_dir;
wenzelm
parents: 44159
diff changeset
   184
            { case Document.Node.Header(Exn.Res(Thy_Header(a, b, c))) =>
44185
05641edb5d30 provide node header via Scala layer;
wenzelm
parents: 44182
diff changeset
   185
                (Nil, triple(string, list(string), list(pair(string, bool)))(a, b, c)) },
44384
8f6054a63f96 some support for editor perspective;
wenzelm
parents: 44383
diff changeset
   186
            { case Document.Node.Header(Exn.Exn(e)) => (List(Exn.message(e)), Nil) },
44474
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44436
diff changeset
   187
            { case Document.Node.Perspective(a) => (a.commands.map(c => long_atom(c.id)), Nil) }))))
44157
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
   188
      YXML.string_of_body(encode(edits)) }
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   189
44481
bb42bc831570 tuned signature;
wenzelm
parents: 44479
diff changeset
   190
    input("Isar_Document.update", Document.ID(old_id), Document.ID(new_id), edits_yxml)
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   191
  }
43748
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   192
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   193
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   194
  /* method invocation service */
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   195
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   196
  def invoke_scala(id: String, tag: Invoke_Scala.Tag.Value, res: String)
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   197
  {
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   198
    input("Isar_Document.invoke_scala", id, tag.toString, res)
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   199
  }
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   200
}