src/Pure/PIDE/protocol.scala
author wenzelm
Wed, 12 Apr 2017 21:13:43 +0200
changeset 65470 a0f49174dbeb
parent 65445 e9e7f5f5794c
child 65471 05e5bffcf1d8
permissions -rw-r--r--
global session_base for PIDE interaction;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45709
87017fcbad83 clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents: 45672
diff changeset
     1
/*  Title:      Pure/PIDE/protocol.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
45709
87017fcbad83 clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents: 45672
diff changeset
     4
Protocol message formats for interactive proof 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
45709
87017fcbad83 clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents: 45672
diff changeset
    10
object Protocol
38412
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
52563
f9a20c2c3b70 tuned protocol terminology;
wenzelm
parents: 52531
diff changeset
    14
  object Assign_Update
44476
e8a87398f35d propagate information about last command with exec state assignment through document model;
wenzelm
parents: 44474
diff changeset
    15
  {
52563
f9a20c2c3b70 tuned protocol terminology;
wenzelm
parents: 52531
diff changeset
    16
    def unapply(text: String): Option[(Document_ID.Version, Document.Assign_Update)] =
44661
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    17
      try {
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    18
        import XML.Decode._
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
    19
        Some(pair(long, list(pair(long, list(long))))(Symbol.decode_yxml(text)))
44661
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    20
      }
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    21
      catch {
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    22
        case ERROR(_) => None
51987
7d8e0e3c553b tuned signature;
wenzelm
parents: 51818
diff changeset
    23
        case _: XML.Error => None
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    24
      }
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    25
  }
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    26
44676
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    27
  object Removed
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    28
  {
52530
99dd8b4ef3fe explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents: 52527
diff changeset
    29
    def unapply(text: String): Option[List[Document_ID.Version]] =
44676
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    30
      try {
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    31
        import XML.Decode._
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
    32
        Some(list(long)(Symbol.decode_yxml(text)))
44676
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    33
      }
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    34
      catch {
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    35
        case ERROR(_) => None
51987
7d8e0e3c553b tuned signature;
wenzelm
parents: 51818
diff changeset
    36
        case _: XML.Error => None
44676
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    37
      }
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    38
  }
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    39
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    40
46209
aad604f74be0 tuned comments;
wenzelm
parents: 46207
diff changeset
    41
  /* command status */
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    42
56359
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    43
  object Status
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    44
  {
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    45
    def make(markup_iterator: Iterator[Markup]): Status =
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    46
    {
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    47
      var touched = false
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    48
      var accepted = false
56395
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56387
diff changeset
    49
      var warned = false
56359
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    50
      var failed = false
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    51
      var forks = 0
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    52
      var runs = 0
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    53
      for (markup <- markup_iterator) {
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    54
        markup.name match {
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    55
          case Markup.ACCEPTED => accepted = true
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    56
          case Markup.FORKED => touched = true; forks += 1
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    57
          case Markup.JOINED => forks -= 1
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    58
          case Markup.RUNNING => touched = true; runs += 1
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    59
          case Markup.FINISHED => runs -= 1
59203
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
    60
          case Markup.WARNING | Markup.LEGACY => warned = true
56395
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56387
diff changeset
    61
          case Markup.FAILED | Markup.ERROR => failed = true
56359
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    62
          case _ =>
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    63
        }
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    64
      }
56395
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56387
diff changeset
    65
      Status(touched, accepted, warned, failed, forks, runs)
56359
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    66
    }
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    67
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    68
    val empty = make(Iterator.empty)
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    69
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    70
    def merge(status_iterator: Iterator[Status]): Status =
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    71
      if (status_iterator.hasNext) {
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    72
        val status0 = status_iterator.next
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    73
        (status0 /: status_iterator)(_ + _)
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    74
      }
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    75
      else empty
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    76
  }
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    77
46166
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
    78
  sealed case class Status(
56352
abdc524db8b4 more frugal command_status, which is often used in a tight loop;
wenzelm
parents: 56335
diff changeset
    79
    private val touched: Boolean,
abdc524db8b4 more frugal command_status, which is often used in a tight loop;
wenzelm
parents: 56335
diff changeset
    80
    private val accepted: Boolean,
56395
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56387
diff changeset
    81
    private val warned: Boolean,
56352
abdc524db8b4 more frugal command_status, which is often used in a tight loop;
wenzelm
parents: 56335
diff changeset
    82
    private val failed: Boolean,
abdc524db8b4 more frugal command_status, which is often used in a tight loop;
wenzelm
parents: 56335
diff changeset
    83
    forks: Int,
abdc524db8b4 more frugal command_status, which is often used in a tight loop;
wenzelm
parents: 56335
diff changeset
    84
    runs: Int)
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    85
  {
56359
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    86
    def + (that: Status): Status =
56395
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56387
diff changeset
    87
      Status(
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56387
diff changeset
    88
        touched || that.touched,
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56387
diff changeset
    89
        accepted || that.accepted,
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56387
diff changeset
    90
        warned || that.warned,
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56387
diff changeset
    91
        failed || that.failed,
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56387
diff changeset
    92
        forks + that.forks,
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56387
diff changeset
    93
        runs + that.runs)
56359
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
    94
49036
4680c4046814 further refinement of command status, to accomodate forked proofs;
wenzelm
parents: 49009
diff changeset
    95
    def is_unprocessed: Boolean = accepted && !failed && (!touched || (forks != 0 && runs == 0))
4680c4046814 further refinement of command status, to accomodate forked proofs;
wenzelm
parents: 49009
diff changeset
    96
    def is_running: Boolean = runs != 0
56474
4df2727a0b5f more direct interpretation of "warned" status, like "failed" and independently of "finished", e.g. relevant for Rendering.overview_color of aux. files where main command status is unavailable (amending 0546e036d1c0);
wenzelm
parents: 56470
diff changeset
    97
    def is_warned: Boolean = warned
4df2727a0b5f more direct interpretation of "warned" status, like "failed" and independently of "finished", e.g. relevant for Rendering.overview_color of aux. files where main command status is unavailable (amending 0546e036d1c0);
wenzelm
parents: 56470
diff changeset
    98
    def is_failed: Boolean = failed
49039
e780d1bf767e clarified command status (again);
wenzelm
parents: 49036
diff changeset
    99
    def is_finished: Boolean = !failed && touched && forks == 0 && runs == 0
46166
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
   100
  }
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
   101
56395
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56387
diff changeset
   102
  val proper_status_elements =
56743
81370dfadb1d tuned signature;
wenzelm
parents: 56616
diff changeset
   103
    Markup.Elements(Markup.ACCEPTED, Markup.FORKED, Markup.JOINED, Markup.RUNNING,
55646
ec4651c697e3 tuned signature;
wenzelm
parents: 55548
diff changeset
   104
      Markup.FINISHED, Markup.FAILED)
ec4651c697e3 tuned signature;
wenzelm
parents: 55548
diff changeset
   105
56395
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56387
diff changeset
   106
  val liberal_status_elements =
59203
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   107
    proper_status_elements + Markup.WARNING + Markup.LEGACY + Markup.ERROR
55646
ec4651c697e3 tuned signature;
wenzelm
parents: 55548
diff changeset
   108
46209
aad604f74be0 tuned comments;
wenzelm
parents: 46207
diff changeset
   109
51818
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   110
  /* command timing */
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   111
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   112
  object Command_Timing
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   113
  {
52531
21f8e0e151f5 tuned signature;
wenzelm
parents: 52530
diff changeset
   114
    def unapply(props: Properties.T): Option[(Document_ID.Generic, isabelle.Timing)] =
51818
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   115
      props match {
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   116
        case (Markup.FUNCTION, Markup.COMMAND_TIMING) :: args =>
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   117
          (args, args) match {
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   118
            case (Position.Id(id), Markup.Timing_Properties(timing)) => Some((id, timing))
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   119
            case _ => None
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   120
          }
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   121
        case _ => None
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   122
      }
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   123
  }
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   124
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   125
46209
aad604f74be0 tuned comments;
wenzelm
parents: 46207
diff changeset
   126
  /* node status */
aad604f74be0 tuned comments;
wenzelm
parents: 46207
diff changeset
   127
46688
134982ee4ecb include warning messages in node status;
wenzelm
parents: 46227
diff changeset
   128
  sealed case class Node_Status(
56474
4df2727a0b5f more direct interpretation of "warned" status, like "failed" and independently of "finished", e.g. relevant for Rendering.overview_color of aux. files where main command status is unavailable (amending 0546e036d1c0);
wenzelm
parents: 56470
diff changeset
   129
    unprocessed: Int, running: Int, warned: Int, failed: Int, finished: Int)
44866
0eb8284a64bd some color scheme for theory status;
wenzelm
parents: 44676
diff changeset
   130
  {
56474
4df2727a0b5f more direct interpretation of "warned" status, like "failed" and independently of "finished", e.g. relevant for Rendering.overview_color of aux. files where main command status is unavailable (amending 0546e036d1c0);
wenzelm
parents: 56470
diff changeset
   131
    def total: Int = unprocessed + running + warned + failed + finished
44866
0eb8284a64bd some color scheme for theory status;
wenzelm
parents: 44676
diff changeset
   132
  }
44613
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   133
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   134
  def node_status(
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   135
    state: Document.State, version: Document.Version, node: Document.Node): Node_Status =
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   136
  {
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   137
    var unprocessed = 0
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   138
    var running = 0
46688
134982ee4ecb include warning messages in node status;
wenzelm
parents: 46227
diff changeset
   139
    var warned = 0
44613
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   140
    var failed = 0
56474
4df2727a0b5f more direct interpretation of "warned" status, like "failed" and independently of "finished", e.g. relevant for Rendering.overview_color of aux. files where main command status is unavailable (amending 0546e036d1c0);
wenzelm
parents: 56470
diff changeset
   141
    var finished = 0
56356
c3dbaa155ece tuned for-comprehensions -- less structure mapping;
wenzelm
parents: 56355
diff changeset
   142
    for (command <- node.commands.iterator) {
56355
1a9f569b5b7e some rephrasing to ensure that this becomes cheap "foreach" and not expensive "map" (cf. 0fc032898b05);
wenzelm
parents: 56353
diff changeset
   143
      val states = state.command_states(version, command)
56359
bca016a9a18d persistent protocol_status, to improve performance of node_status a little;
wenzelm
parents: 56356
diff changeset
   144
      val status = Status.merge(states.iterator.map(_.protocol_status))
56355
1a9f569b5b7e some rephrasing to ensure that this becomes cheap "foreach" and not expensive "map" (cf. 0fc032898b05);
wenzelm
parents: 56353
diff changeset
   145
56299
8201790fdeb9 more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents: 56295
diff changeset
   146
      if (status.is_running) running += 1
57843
d8966c09025c proper priority for error over warning also for node_status (see 9c5220e05e04);
wenzelm
parents: 56801
diff changeset
   147
      else if (status.is_failed) failed += 1
56395
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56387
diff changeset
   148
      else if (status.is_warned) warned += 1
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56387
diff changeset
   149
      else if (status.is_finished) finished += 1
56299
8201790fdeb9 more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents: 56295
diff changeset
   150
      else unprocessed += 1
8201790fdeb9 more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents: 56295
diff changeset
   151
    }
56474
4df2727a0b5f more direct interpretation of "warned" status, like "failed" and independently of "finished", e.g. relevant for Rendering.overview_color of aux. files where main command status is unavailable (amending 0546e036d1c0);
wenzelm
parents: 56470
diff changeset
   152
    Node_Status(unprocessed, running, warned, failed, finished)
44613
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   153
  }
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   154
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
   155
51533
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   156
  /* node timing */
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   157
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   158
  sealed case class Node_Timing(total: Double, commands: Map[Command, Double])
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   159
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   160
  val empty_node_timing = Node_Timing(0.0, Map.empty)
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   161
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   162
  def node_timing(
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   163
    state: Document.State,
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   164
    version: Document.Version,
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   165
    node: Document.Node,
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   166
    threshold: Double): Node_Timing =
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   167
  {
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   168
    var total = 0.0
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   169
    var commands = Map.empty[Command, Double]
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   170
    for {
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   171
      command <- node.commands.iterator
56299
8201790fdeb9 more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents: 56295
diff changeset
   172
      st <- state.command_states(version, command)
56356
c3dbaa155ece tuned for-comprehensions -- less structure mapping;
wenzelm
parents: 56355
diff changeset
   173
    } {
c3dbaa155ece tuned for-comprehensions -- less structure mapping;
wenzelm
parents: 56355
diff changeset
   174
      val command_timing =
51533
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   175
        (0.0 /: st.status)({
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   176
          case (timing, Markup.Timing(t)) => timing + t.elapsed.seconds
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   177
          case (timing, _) => timing
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   178
        })
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   179
      total += command_timing
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   180
      if (command_timing >= threshold) commands += (command -> command_timing)
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   181
    }
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   182
    Node_Timing(total, commands)
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   183
  }
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   184
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   185
39441
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
   186
  /* 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
   187
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   188
  def is_result(msg: XML.Tree): Boolean =
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   189
    msg match {
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   190
      case XML.Elem(Markup(Markup.RESULT, _), _) => true
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   191
      case _ => false
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   192
    }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   193
50157
76efdb6daab2 tuned whitespace;
wenzelm
parents: 50128
diff changeset
   194
  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
   195
    msg match {
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
   196
      case XML.Elem(Markup(Markup.TRACING, _), _) => true
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
   197
      case XML.Elem(Markup(Markup.TRACING_MESSAGE, _), _) => true
39622
53365ba766ac Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents: 39511
diff changeset
   198
      case _ => false
53365ba766ac Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents: 39511
diff changeset
   199
    }
53365ba766ac Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents: 39511
diff changeset
   200
59184
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   201
  def is_state(msg: XML.Tree): Boolean =
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   202
    msg match {
59184
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   203
      case XML.Elem(Markup(Markup.STATE, _), _) => true
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   204
      case XML.Elem(Markup(Markup.STATE_MESSAGE, _), _) => true
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   205
      case _ => false
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   206
    }
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   207
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   208
  def is_information(msg: XML.Tree): Boolean =
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   209
    msg match {
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   210
      case XML.Elem(Markup(Markup.INFORMATION, _), _) => true
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   211
      case XML.Elem(Markup(Markup.INFORMATION_MESSAGE, _), _) => true
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   212
      case _ => false
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   213
    }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   214
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   215
  def is_warning(msg: XML.Tree): Boolean =
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   216
    msg match {
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
   217
      case XML.Elem(Markup(Markup.WARNING, _), _) => true
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
   218
      case XML.Elem(Markup(Markup.WARNING_MESSAGE, _), _) => true
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   219
      case _ => false
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   220
    }
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   221
59203
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   222
  def is_legacy(msg: XML.Tree): Boolean =
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   223
    msg match {
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   224
      case XML.Elem(Markup(Markup.LEGACY, _), _) => true
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   225
      case XML.Elem(Markup(Markup.LEGACY_MESSAGE, _), _) => true
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   226
      case _ => false
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   227
    }
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   228
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   229
  def is_error(msg: XML.Tree): Boolean =
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   230
    msg match {
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
   231
      case XML.Elem(Markup(Markup.ERROR, _), _) => true
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
   232
      case XML.Elem(Markup(Markup.ERROR_MESSAGE, _), _) => true
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   233
      case _ => false
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   234
    }
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
   235
56495
0b9334adcf05 more explicit message discrimination;
wenzelm
parents: 56474
diff changeset
   236
  def is_inlined(msg: XML.Tree): Boolean =
0b9334adcf05 more explicit message discrimination;
wenzelm
parents: 56474
diff changeset
   237
    !(is_result(msg) || is_tracing(msg) || is_state(msg))
0b9334adcf05 more explicit message discrimination;
wenzelm
parents: 56474
diff changeset
   238
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   239
60882
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   240
  /* breakpoints */
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   241
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   242
  object ML_Breakpoint
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   243
  {
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   244
    def unapply(tree: XML.Tree): Option[Long] =
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   245
    tree match {
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   246
      case XML.Elem(Markup(Markup.ML_BREAKPOINT, Markup.Serial(breakpoint)), _) => Some(breakpoint)
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   247
      case _ => None
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   248
    }
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   249
  }
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   250
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   251
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   252
  /* dialogs */
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   253
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   254
  object Dialog_Args
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   255
  {
52531
21f8e0e151f5 tuned signature;
wenzelm
parents: 52530
diff changeset
   256
    def unapply(props: Properties.T): Option[(Document_ID.Generic, Long, String)] =
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   257
      (props, props, props) match {
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   258
        case (Position.Id(id), Markup.Serial(serial), Markup.Result(result)) =>
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   259
          Some((id, serial, result))
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   260
        case _ => None
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   261
      }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   262
  }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   263
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   264
  object Dialog
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   265
  {
52531
21f8e0e151f5 tuned signature;
wenzelm
parents: 52530
diff changeset
   266
    def unapply(tree: XML.Tree): Option[(Document_ID.Generic, Long, String)] =
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   267
      tree match {
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   268
        case XML.Elem(Markup(Markup.DIALOG, Dialog_Args(id, serial, result)), _) =>
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   269
          Some((id, serial, result))
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   270
        case _ => None
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   271
      }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   272
  }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   273
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   274
  object Dialog_Result
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   275
  {
52531
21f8e0e151f5 tuned signature;
wenzelm
parents: 52530
diff changeset
   276
    def apply(id: Document_ID.Generic, serial: Long, result: String): XML.Elem =
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   277
    {
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   278
      val props = Position.Id(id) ::: Markup.Serial(serial)
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   279
      XML.Elem(Markup(Markup.RESULT, props), List(XML.Text(result)))
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   280
    }
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   281
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   282
    def unapply(tree: XML.Tree): Option[String] =
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   283
      tree match {
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   284
        case XML.Elem(Markup(Markup.RESULT, _), List(XML.Text(result))) => Some(result)
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   285
        case _ => None
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   286
      }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   287
  }
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   288
}
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   289
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   290
57916
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57911
diff changeset
   291
trait Protocol
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   292
{
57916
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57911
diff changeset
   293
  /* protocol commands */
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57911
diff changeset
   294
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57911
diff changeset
   295
  def protocol_command_bytes(name: String, args: Bytes*): Unit
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57911
diff changeset
   296
  def protocol_command(name: String, args: String*): Unit
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57911
diff changeset
   297
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57911
diff changeset
   298
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56372
diff changeset
   299
  /* options */
d92eb5c3960d more general prover operations;
wenzelm
parents: 56372
diff changeset
   300
d92eb5c3960d more general prover operations;
wenzelm
parents: 56372
diff changeset
   301
  def options(opts: Options): Unit =
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   302
    protocol_command("Prover.options", Symbol.encode_yxml(opts.encode))
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56372
diff changeset
   303
d92eb5c3960d more general prover operations;
wenzelm
parents: 56372
diff changeset
   304
65470
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   305
  /* session base */
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   306
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   307
  private def encode_table(table: List[(String, String)]): String =
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   308
  {
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   309
    import XML.Encode._
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   310
    Symbol.encode_yxml(list(pair(string, string))(table))
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   311
  }
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   312
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   313
  def session_base(resources: Resources): Unit =
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   314
    protocol_command("Prover.session_base",
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   315
      Symbol.encode(resources.default_qualifier),
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   316
      encode_table(resources.session_base.global_theories.toList),
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   317
      encode_table(resources.session_base.dest_loaded_theories),
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   318
      encode_table(resources.session_base.dest_known_theories))
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   319
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   320
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56372
diff changeset
   321
  /* interned items */
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54515
diff changeset
   322
56335
8953d4cc060a store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents: 56306
diff changeset
   323
  def define_blob(digest: SHA1.Digest, bytes: Bytes): Unit =
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56372
diff changeset
   324
    protocol_command_bytes("Document.define_blob", Bytes(digest.toString), bytes)
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   325
59671
9715eb8e9408 more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
wenzelm
parents: 59364
diff changeset
   326
  def define_command(command: Command)
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54515
diff changeset
   327
  {
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54515
diff changeset
   328
    val blobs_yxml =
61376
93224745477f output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents: 60992
diff changeset
   329
    {
93224745477f output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents: 60992
diff changeset
   330
      import XML.Encode._
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54515
diff changeset
   331
      val encode_blob: T[Command.Blob] =
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54515
diff changeset
   332
        variant(List(
54526
92961f196d9e load files that are not provided by PIDE blobs;
wenzelm
parents: 54524
diff changeset
   333
          { case Exn.Res((a, b)) =>
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   334
              (Nil, pair(string, option(string))((a.node, b.map(p => p._1.toString)))) },
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   335
          { case Exn.Exn(e) => (Nil, string(Exn.message(e))) }))
59085
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 58015
diff changeset
   336
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   337
      Symbol.encode_yxml(pair(list(encode_blob), int)(command.blobs, command.blobs_index))
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54515
diff changeset
   338
    }
59085
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 58015
diff changeset
   339
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 58015
diff changeset
   340
    val toks = command.span.content
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 58015
diff changeset
   341
    val toks_yxml =
61376
93224745477f output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents: 60992
diff changeset
   342
    {
93224745477f output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents: 60992
diff changeset
   343
      import XML.Encode._
64616
wenzelm
parents: 63805
diff changeset
   344
      val encode_tok: T[Token] = (tok => pair(int, int)((tok.kind.id, Symbol.length(tok.source))))
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   345
      Symbol.encode_yxml(list(encode_tok)(toks))
59085
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 58015
diff changeset
   346
    }
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 58015
diff changeset
   347
52582
31467a4b1466 tuned signature;
wenzelm
parents: 52563
diff changeset
   348
    protocol_command("Document.define_command",
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   349
      (Document_ID(command.id) :: Symbol.encode(command.span.name) :: blobs_yxml :: toks_yxml ::
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   350
        toks.map(tok => Symbol.encode(tok.source))): _*)
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54515
diff changeset
   351
  }
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   352
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   353
52931
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   354
  /* execution */
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   355
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   356
  def discontinue_execution(): Unit =
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   357
    protocol_command("Document.discontinue_execution")
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   358
52931
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   359
  def cancel_exec(id: Document_ID.Exec): Unit =
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   360
    protocol_command("Document.cancel_exec", Document_ID(id))
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   361
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   362
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   363
  /* document versions */
47343
b8aeab386414 less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
wenzelm
parents: 46938
diff changeset
   364
52530
99dd8b4ef3fe explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents: 52527
diff changeset
   365
  def update(old_id: Document_ID.Version, new_id: Document_ID.Version,
44383
f99906c2a1d3 discontinued redundant Edit_Command_ID;
wenzelm
parents: 44185
diff changeset
   366
    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
   367
  {
44157
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
   368
    val edits_yxml =
61376
93224745477f output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents: 60992
diff changeset
   369
    {
93224745477f output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents: 60992
diff changeset
   370
      import XML.Encode._
44383
f99906c2a1d3 discontinued redundant Edit_Command_ID;
wenzelm
parents: 44185
diff changeset
   371
      def id: T[Command] = (cmd => long(cmd.id))
46737
09ab89658a5d clarified module Thy_Load;
wenzelm
parents: 46688
diff changeset
   372
      def encode_edit(name: Document.Node.Name)
52849
199e9fa5a5c2 maintain overlays within node perspective;
wenzelm
parents: 52808
diff changeset
   373
          : T[Document.Node.Edit[Command.Edit, Command.Perspective]] =
44979
68b990e950b1 explicit master_dir as part of header -- still required (for Cygwin) since Scala layer does not pass file content yet;
wenzelm
parents: 44866
diff changeset
   374
        variant(List(
68b990e950b1 explicit master_dir as part of header -- still required (for Cygwin) since Scala layer does not pass file content yet;
wenzelm
parents: 44866
diff changeset
   375
          { case Document.Node.Edits(a) => (Nil, list(pair(option(id), option(id)))(a)) },
48707
ba531af91148 simplified Document.Node.Header -- internalized errors;
wenzelm
parents: 48705
diff changeset
   376
          { case Document.Node.Deps(header) =>
60992
89effcb342df clarified modules, like ML version;
wenzelm
parents: 60882
diff changeset
   377
              val master_dir = File.standard_url(name.master_dir)
59695
a03e0561bdbf clarified positions of theory imports;
wenzelm
parents: 59685
diff changeset
   378
              val imports = header.imports.map({ case (a, _) => a.node })
65384
36255c43c64c more explicit types;
wenzelm
parents: 65345
diff changeset
   379
              val keywords =
36255c43c64c more explicit types;
wenzelm
parents: 65345
diff changeset
   380
                header.keywords.map({ case (a, Keyword.Spec(b, c, d)) => (a, ((b, c), d)) })
44979
68b990e950b1 explicit master_dir as part of header -- still required (for Cygwin) since Scala layer does not pass file content yet;
wenzelm
parents: 44866
diff changeset
   381
              (Nil,
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   382
                pair(string, pair(string, pair(list(string), pair(list(pair(string,
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   383
                    pair(pair(string, list(string)), list(string)))), list(string)))))(
65445
e9e7f5f5794c more qualifier treatment, but in the end it is still ignored;
wenzelm
parents: 65439
diff changeset
   384
                (master_dir, (name.theory, (imports, (keywords, header.errors)))))) },
52849
199e9fa5a5c2 maintain overlays within node perspective;
wenzelm
parents: 52808
diff changeset
   385
          { case Document.Node.Perspective(a, b, c) =>
199e9fa5a5c2 maintain overlays within node perspective;
wenzelm
parents: 52808
diff changeset
   386
              (bool_atom(a) :: b.commands.map(cmd => long_atom(cmd.id)),
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   387
                list(pair(id, pair(string, list(string))))(c.dest)) }))
48705
dd32321d6eef tuned signature -- slightly more abstract text representation of prover process;
wenzelm
parents: 47542
diff changeset
   388
      def encode_edits: T[List[Document.Edit_Command]] = list((node_edit: Document.Edit_Command) =>
44979
68b990e950b1 explicit master_dir as part of header -- still required (for Cygwin) since Scala layer does not pass file content yet;
wenzelm
parents: 44866
diff changeset
   389
      {
68b990e950b1 explicit master_dir as part of header -- still required (for Cygwin) since Scala layer does not pass file content yet;
wenzelm
parents: 44866
diff changeset
   390
        val (name, edit) = node_edit
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   391
        pair(string, encode_edit(name))(name.node, edit)
44979
68b990e950b1 explicit master_dir as part of header -- still required (for Cygwin) since Scala layer does not pass file content yet;
wenzelm
parents: 44866
diff changeset
   392
      })
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   393
      Symbol.encode_yxml(encode_edits(edits)) }
52582
31467a4b1466 tuned signature;
wenzelm
parents: 52563
diff changeset
   394
    protocol_command("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
   395
  }
43748
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   396
44673
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   397
  def remove_versions(versions: List[Document.Version])
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   398
  {
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   399
    val versions_yxml =
59364
3b5da177ae6b clarified build_theories;
wenzelm
parents: 59362
diff changeset
   400
    { import XML.Encode._
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   401
      Symbol.encode_yxml(list(long)(versions.map(_.id))) }
52582
31467a4b1466 tuned signature;
wenzelm
parents: 52563
diff changeset
   402
    protocol_command("Document.remove_versions", versions_yxml)
44673
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   403
  }
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   404
43748
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   405
50498
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50450
diff changeset
   406
  /* dialog via document content */
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50450
diff changeset
   407
52931
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   408
  def dialog_result(serial: Long, result: String): Unit =
63805
c272680df665 clarified modules;
wenzelm
parents: 63579
diff changeset
   409
    protocol_command("Document.dialog_result", Value.Long(serial), result)
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   410
}