src/Pure/PIDE/protocol.scala
author wenzelm
Mon, 29 Apr 2013 15:47:42 +0200
changeset 51818 517f232e867d
parent 51533 3f6280aedbcc
child 51987 7d8e0e3c553b
permissions -rw-r--r--
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
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
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
  {
44661
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    16
    def unapply(text: String): Option[(Document.Version_ID, Document.Assign)] =
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._
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    19
        val body = YXML.parse_body(text)
47388
fe4b245af74c discontinued obsolete last_execs (cf. cd3ab7625519);
wenzelm
parents: 47346
diff changeset
    20
        Some(pair(long, list(pair(long, option(long))))(body))
44661
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    21
      }
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    22
      catch {
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    23
        case ERROR(_) => None
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    24
        case _: XML.XML_Atom => None
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    25
        case _: XML.XML_Body => None
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    26
      }
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    27
  }
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    28
44676
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    29
  object Removed
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    30
  {
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    31
    def unapply(text: String): Option[List[Document.Version_ID]] =
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    32
      try {
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    33
        import XML.Decode._
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    34
        Some(list(long)(YXML.parse_body(text)))
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    35
      }
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    36
      catch {
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    37
        case ERROR(_) => None
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    38
        case _: XML.XML_Atom => None
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    39
        case _: XML.XML_Body => None
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    40
      }
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    41
  }
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    42
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    43
46209
aad604f74be0 tuned comments;
wenzelm
parents: 46207
diff changeset
    44
  /* command status */
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    45
46227
4aa84f84d5e8 more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents: 46209
diff changeset
    46
  object Status
4aa84f84d5e8 more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents: 46209
diff changeset
    47
  {
4aa84f84d5e8 more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents: 46209
diff changeset
    48
    val init = Status()
4aa84f84d5e8 more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents: 46209
diff changeset
    49
  }
4aa84f84d5e8 more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents: 46209
diff changeset
    50
46166
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
    51
  sealed case class Status(
49036
4680c4046814 further refinement of command status, to accomodate forked proofs;
wenzelm
parents: 49009
diff changeset
    52
    private val touched: Boolean = false,
47395
e6261a493f04 added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
wenzelm
parents: 47388
diff changeset
    53
    private val accepted: Boolean = false,
46166
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
    54
    private val failed: Boolean = false,
49036
4680c4046814 further refinement of command status, to accomodate forked proofs;
wenzelm
parents: 49009
diff changeset
    55
    forks: Int = 0,
4680c4046814 further refinement of command status, to accomodate forked proofs;
wenzelm
parents: 49009
diff changeset
    56
    runs: Int = 0)
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    57
  {
46227
4aa84f84d5e8 more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents: 46209
diff changeset
    58
    def + (that: Status): Status =
49036
4680c4046814 further refinement of command status, to accomodate forked proofs;
wenzelm
parents: 49009
diff changeset
    59
      Status(touched || that.touched, accepted || that.accepted, failed || that.failed,
4680c4046814 further refinement of command status, to accomodate forked proofs;
wenzelm
parents: 49009
diff changeset
    60
        forks + that.forks, runs + that.runs)
4680c4046814 further refinement of command status, to accomodate forked proofs;
wenzelm
parents: 49009
diff changeset
    61
4680c4046814 further refinement of command status, to accomodate forked proofs;
wenzelm
parents: 49009
diff changeset
    62
    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
    63
    def is_running: Boolean = runs != 0
49039
e780d1bf767e clarified command status (again);
wenzelm
parents: 49036
diff changeset
    64
    def is_finished: Boolean = !failed && touched && forks == 0 && runs == 0
49036
4680c4046814 further refinement of command status, to accomodate forked proofs;
wenzelm
parents: 49009
diff changeset
    65
    def is_failed: Boolean = failed
46166
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
    66
  }
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
    67
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
    68
  val command_status_markup: Set[String] =
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
    69
    Set(Markup.ACCEPTED, Markup.FORKED, Markup.JOINED, Markup.RUNNING,
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
    70
      Markup.FINISHED, Markup.FAILED)
46166
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
    71
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
    72
  def command_status(status: Status, markup: Markup): Status =
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
    73
    markup match {
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
    74
      case Markup(Markup.ACCEPTED, _) => status.copy(accepted = true)
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
    75
      case Markup(Markup.FORKED, _) => status.copy(touched = true, forks = status.forks + 1)
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
    76
      case Markup(Markup.JOINED, _) => status.copy(forks = status.forks - 1)
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
    77
      case Markup(Markup.RUNNING, _) => status.copy(touched = true, runs = status.runs + 1)
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
    78
      case Markup(Markup.FINISHED, _) => status.copy(runs = status.runs - 1)
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
    79
      case Markup(Markup.FAILED, _) => status.copy(failed = true)
46166
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
    80
      case _ => status
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    81
    }
46166
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
    82
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
    83
  def command_status(markups: List[Markup]): Status =
46227
4aa84f84d5e8 more precise rendering of overview_color/gutter_message/squiggly_underline based on cumulation of command status and warning/error messages;
wenzelm
parents: 46209
diff changeset
    84
    (Status.init /: markups)(command_status(_, _))
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
    85
46209
aad604f74be0 tuned comments;
wenzelm
parents: 46207
diff changeset
    86
51818
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    87
  /* command timing */
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    88
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    89
  object Command_Timing
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    90
  {
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    91
    def unapply(props: Properties.T): Option[(Document.ID, isabelle.Timing)] =
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    92
      props match {
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    93
        case (Markup.FUNCTION, Markup.COMMAND_TIMING) :: args =>
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    94
          (args, args) match {
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    95
            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
    96
            case _ => None
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    97
          }
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    98
        case _ => None
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    99
      }
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   100
  }
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   101
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
   102
46209
aad604f74be0 tuned comments;
wenzelm
parents: 46207
diff changeset
   103
  /* node status */
aad604f74be0 tuned comments;
wenzelm
parents: 46207
diff changeset
   104
46688
134982ee4ecb include warning messages in node status;
wenzelm
parents: 46227
diff changeset
   105
  sealed case class Node_Status(
134982ee4ecb include warning messages in node status;
wenzelm
parents: 46227
diff changeset
   106
    unprocessed: Int, running: Int, finished: Int, warned: Int, failed: Int)
44866
0eb8284a64bd some color scheme for theory status;
wenzelm
parents: 44676
diff changeset
   107
  {
46688
134982ee4ecb include warning messages in node status;
wenzelm
parents: 46227
diff changeset
   108
    def total: Int = unprocessed + running + finished + warned + failed
44866
0eb8284a64bd some color scheme for theory status;
wenzelm
parents: 44676
diff changeset
   109
  }
44613
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   110
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   111
  def node_status(
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   112
    state: Document.State, version: Document.Version, node: Document.Node): Node_Status =
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   113
  {
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   114
    var unprocessed = 0
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   115
    var running = 0
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   116
    var finished = 0
46688
134982ee4ecb include warning messages in node status;
wenzelm
parents: 46227
diff changeset
   117
    var warned = 0
44613
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   118
    var failed = 0
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   119
    node.commands.foreach(command =>
46166
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
   120
      {
46688
134982ee4ecb include warning messages in node status;
wenzelm
parents: 46227
diff changeset
   121
        val st = state.command_state(version, command)
134982ee4ecb include warning messages in node status;
wenzelm
parents: 46227
diff changeset
   122
        val status = command_status(st.status)
46166
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
   123
        if (status.is_running) running += 1
46688
134982ee4ecb include warning messages in node status;
wenzelm
parents: 46227
diff changeset
   124
        else if (status.is_finished) {
50507
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
   125
          if (st.results.entries.exists(p => is_warning(p._2))) warned += 1
46688
134982ee4ecb include warning messages in node status;
wenzelm
parents: 46227
diff changeset
   126
          else finished += 1
134982ee4ecb include warning messages in node status;
wenzelm
parents: 46227
diff changeset
   127
        }
46166
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
   128
        else if (status.is_failed) failed += 1
4beb2f41ed93 command status color via regular markup;
wenzelm
parents: 46121
diff changeset
   129
        else unprocessed += 1
44613
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   130
      })
46688
134982ee4ecb include warning messages in node status;
wenzelm
parents: 46227
diff changeset
   131
    Node_Status(unprocessed, running, finished, warned, failed)
44613
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   132
  }
a3255c85327b crude display of node status;
wenzelm
parents: 44612
diff changeset
   133
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
   134
51533
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   135
  /* node timing */
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   136
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   137
  sealed case class Node_Timing(total: Double, commands: Map[Command, Double])
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   138
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   139
  val empty_node_timing = Node_Timing(0.0, Map.empty)
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   140
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   141
  def node_timing(
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   142
    state: Document.State,
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   143
    version: Document.Version,
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   144
    node: Document.Node,
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   145
    threshold: Double): Node_Timing =
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   146
  {
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   147
    var total = 0.0
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   148
    var commands = Map.empty[Command, Double]
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   149
    for {
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   150
      command <- node.commands.iterator
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   151
      st = state.command_state(version, command)
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   152
      command_timing =
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   153
        (0.0 /: st.status)({
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   154
          case (timing, Markup.Timing(t)) => timing + t.elapsed.seconds
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   155
          case (timing, _) => timing
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   156
        })
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   157
    } {
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   158
      total += command_timing
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   159
      if (command_timing >= threshold) commands += (command -> command_timing)
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   160
    }
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   161
    Node_Timing(total, commands)
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   162
  }
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   163
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 51294
diff changeset
   164
39441
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
   165
  /* 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
   166
50450
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50201
diff changeset
   167
  private val clean = Set(Markup.REPORT, Markup.NO_REPORT)
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50201
diff changeset
   168
39439
1c294d150ded eliminated markup "location" in favour of more explicit "no_report", which is actually deleted from messages;
wenzelm
parents: 39181
diff changeset
   169
  def clean_message(body: XML.Body): XML.Body =
49445
638cefe3ee99 earlier treatment of embedded report/no_report messages (see also 4110cc1b8f9f);
wenzelm
parents: 49418
diff changeset
   170
    body filter {
50450
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50201
diff changeset
   171
      case XML.Wrapped_Elem(Markup(name, _), _, _) => !clean(name)
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50201
diff changeset
   172
      case XML.Elem(Markup(name, _), _) => !clean(name)
49445
638cefe3ee99 earlier treatment of embedded report/no_report messages (see also 4110cc1b8f9f);
wenzelm
parents: 49418
diff changeset
   173
      case _ => true
49650
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   174
    } map {
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   175
      case XML.Wrapped_Elem(markup, body, ts) => XML.Wrapped_Elem(markup, body, clean_message(ts))
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   176
      case XML.Elem(markup, ts) => XML.Elem(markup, clean_message(ts))
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   177
      case t => t
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   178
    }
39439
1c294d150ded eliminated markup "location" in favour of more explicit "no_report", which is actually deleted from messages;
wenzelm
parents: 39181
diff changeset
   179
49445
638cefe3ee99 earlier treatment of embedded report/no_report messages (see also 4110cc1b8f9f);
wenzelm
parents: 49418
diff changeset
   180
  def message_reports(props: Properties.T, body: XML.Body): List[XML.Elem] =
638cefe3ee99 earlier treatment of embedded report/no_report messages (see also 4110cc1b8f9f);
wenzelm
parents: 49418
diff changeset
   181
    body flatMap {
50450
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50201
diff changeset
   182
      case XML.Wrapped_Elem(Markup(Markup.REPORT, ps), body, ts) =>
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50201
diff changeset
   183
        List(XML.Wrapped_Elem(Markup(Markup.REPORT, props ::: ps), body, ts))
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
   184
      case XML.Elem(Markup(Markup.REPORT, ps), ts) =>
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
   185
        List(XML.Elem(Markup(Markup.REPORT, props ::: ps), ts))
49650
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   186
      case XML.Wrapped_Elem(_, _, ts) => message_reports(props, ts)
49445
638cefe3ee99 earlier treatment of embedded report/no_report messages (see also 4110cc1b8f9f);
wenzelm
parents: 49418
diff changeset
   187
      case XML.Elem(_, ts) => message_reports(props, ts)
39441
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
   188
      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
   189
    }
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
   190
39439
1c294d150ded eliminated markup "location" in favour of more explicit "no_report", which is actually deleted from messages;
wenzelm
parents: 39181
diff changeset
   191
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   192
  /* specific messages */
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   193
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   194
  def is_inlined(msg: XML.Tree): Boolean =
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   195
    !(is_result(msg) || is_tracing(msg) || is_state(msg))
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   196
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   197
  def is_result(msg: XML.Tree): Boolean =
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   198
    msg match {
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   199
      case XML.Elem(Markup(Markup.RESULT, _), _) => true
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   200
      case _ => false
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   201
    }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   202
50157
76efdb6daab2 tuned whitespace;
wenzelm
parents: 50128
diff changeset
   203
  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
   204
    msg match {
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
   205
      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
   206
      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
   207
      case _ => false
53365ba766ac Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents: 39511
diff changeset
   208
    }
53365ba766ac Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents: 39511
diff changeset
   209
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   210
  def is_state(msg: XML.Tree): Boolean =
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   211
    msg match {
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   212
      case XML.Elem(Markup(Markup.WRITELN, _),
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   213
        List(XML.Elem(Markup(Markup.STATE, _), _))) => true
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   214
      case XML.Elem(Markup(Markup.WRITELN_MESSAGE, _),
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   215
        List(XML.Elem(Markup(Markup.STATE, _), _))) => true
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   216
      case _ => false
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   217
    }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   218
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   219
  def is_warning(msg: XML.Tree): Boolean =
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   220
    msg match {
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
   221
      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
   222
      case XML.Elem(Markup(Markup.WARNING_MESSAGE, _), _) => true
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   223
      case _ => false
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   224
    }
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   225
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   226
  def is_error(msg: XML.Tree): Boolean =
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   227
    msg match {
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
   228
      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
   229
      case XML.Elem(Markup(Markup.ERROR_MESSAGE, _), _) => true
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   230
      case _ => false
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   231
    }
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
   232
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   233
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   234
  /* dialogs */
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   235
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   236
  object Dialog_Args
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   237
  {
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   238
    def unapply(props: Properties.T): Option[(Document.ID, Long, String)] =
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   239
      (props, props, props) match {
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   240
        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
   241
          Some((id, serial, result))
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   242
        case _ => None
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   243
      }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   244
  }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   245
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   246
  object Dialog
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   247
  {
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   248
    def unapply(tree: XML.Tree): Option[(Document.ID, Long, String)] =
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   249
      tree match {
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   250
        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
   251
          Some((id, serial, result))
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   252
        case _ => None
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
  }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   255
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   256
  object Dialog_Result
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   257
  {
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   258
    def apply(id: Document.ID, serial: Long, result: String): XML.Elem =
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   259
    {
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   260
      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
   261
      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
   262
    }
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   263
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   264
    def unapply(tree: XML.Tree): Option[String] =
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   265
      tree match {
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   266
        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
   267
        case _ => None
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   268
      }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   269
  }
39170
04ad0fed81f5 Isar_Document.reported_positions: exclude proof state output;
wenzelm
parents: 39042
diff changeset
   270
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   271
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   272
  /* reported positions */
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   273
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
   274
  private val include_pos = 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
   275
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
   276
  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
   277
  {
49650
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   278
    def elem_positions(raw_range: Text.Range, set: Set[Text.Range], body: XML.Body)
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   279
      : Set[Text.Range] =
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   280
    {
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   281
      val range = command.decode(raw_range).restrict(command.range)
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   282
      body.foldLeft(if (range.is_singularity) set else set + range)(positions)
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   283
    }
50157
76efdb6daab2 tuned whitespace;
wenzelm
parents: 50128
diff changeset
   284
39441
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
   285
    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
   286
      tree match {
49650
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   287
        case XML.Wrapped_Elem(Markup(name, Position.Id_Range(id, range)), _, body)
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   288
        if include_pos(name) && id == command.id => elem_positions(range, set, body)
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   289
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   290
        case XML.Elem(Markup(name, Position.Id_Range(id, range)), body)
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   291
        if include_pos(name) && id == command.id => elem_positions(range, set, body)
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   292
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   293
        case XML.Wrapped_Elem(_, _, body) => body.foldLeft(set)(positions)
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   294
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   295
        case XML.Elem(_, body) => body.foldLeft(set)(positions)
9fad6480300d support for wrapped XML elements, which allows to preserve full markup tree information in to_XML/from_XML conversion;
wenzelm
parents: 49648
diff changeset
   296
39042
470fd769ae53 Isar_Document.reported_positions: more precise include/exclude, include root as last resort only;
wenzelm
parents: 38887
diff changeset
   297
        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
   298
      }
50157
76efdb6daab2 tuned whitespace;
wenzelm
parents: 50128
diff changeset
   299
39441
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
   300
    val set = positions(Set.empty, message)
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   301
    if (set.isEmpty)
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
   302
      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
   303
    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
   304
  }
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   305
}
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   306
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   307
45709
87017fcbad83 clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents: 45672
diff changeset
   308
trait Protocol extends Isabelle_Process
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   309
{
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   310
  /* commands */
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   311
44644
317e4962dd0f clarified define_command: store name as structural information;
wenzelm
parents: 44615
diff changeset
   312
  def define_command(command: Command): Unit =
45709
87017fcbad83 clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents: 45672
diff changeset
   313
    input("Document.define_command",
48705
dd32321d6eef tuned signature -- slightly more abstract text representation of prover process;
wenzelm
parents: 47542
diff changeset
   314
      Document.ID(command.id), encode(command.name), encode(command.source))
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   315
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   316
38417
b8922ae21111 renamed class Document to Document.Version etc.;
wenzelm
parents: 38414
diff changeset
   317
  /* document versions */
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   318
47343
b8aeab386414 less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
wenzelm
parents: 46938
diff changeset
   319
  def discontinue_execution() { input("Document.discontinue_execution") }
b8aeab386414 less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
wenzelm
parents: 46938
diff changeset
   320
b8aeab386414 less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
wenzelm
parents: 46938
diff changeset
   321
  def cancel_execution() { input("Document.cancel_execution") }
44612
990ac978854c explicit cancel_execution before queueing new edits -- potential performance improvement for machines with few cores;
wenzelm
parents: 44481
diff changeset
   322
44481
bb42bc831570 tuned signature;
wenzelm
parents: 44479
diff changeset
   323
  def update(old_id: Document.Version_ID, new_id: Document.Version_ID,
44383
f99906c2a1d3 discontinued redundant Edit_Command_ID;
wenzelm
parents: 44185
diff changeset
   324
    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
   325
  {
44157
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
   326
    val edits_yxml =
43767
e0219ef7f84c tuned XML modules;
wenzelm
parents: 43748
diff changeset
   327
    { import XML.Encode._
44383
f99906c2a1d3 discontinued redundant Edit_Command_ID;
wenzelm
parents: 44185
diff changeset
   328
      def id: T[Command] = (cmd => long(cmd.id))
46737
09ab89658a5d clarified module Thy_Load;
wenzelm
parents: 46688
diff changeset
   329
      def encode_edit(name: Document.Node.Name)
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
   330
          : T[Document.Node.Edit[(Option[Command], Option[Command]), Command.Perspective]] =
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
   331
        variant(List(
48755
393a37003851 apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
wenzelm
parents: 48707
diff changeset
   332
          { case Document.Node.Clear() => (Nil, Nil) },  // FIXME unused !?
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
   333
          { 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
   334
          { case Document.Node.Deps(header) =>
46770
44c28a33c461 retain original "uses" (again) -- still required for Thy_Load.use_file etc. in ML (notably for maintaining required/provided);
wenzelm
parents: 46755
diff changeset
   335
              val dir = Isabelle_System.posix_path(name.dir)
48707
ba531af91148 simplified Document.Node.Header -- internalized errors;
wenzelm
parents: 48705
diff changeset
   336
              val imports = header.imports.map(_.node)
50128
599c935aac82 alternative completion for outer syntax keywords;
wenzelm
parents: 49650
diff changeset
   337
              val keywords = header.keywords.map({ case (a, b, _) => (a, b) })
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
   338
              (Nil,
48707
ba531af91148 simplified Document.Node.Header -- internalized errors;
wenzelm
parents: 48705
diff changeset
   339
                pair(Encode.string, pair(Encode.string, pair(list(Encode.string),
48864
3ee314ae1e0a added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents: 48755
diff changeset
   340
                  pair(list(pair(Encode.string,
3ee314ae1e0a added keyword kind "thy_load" (with optional list of file extensions);
wenzelm
parents: 48755
diff changeset
   341
                    option(pair(pair(Encode.string, list(Encode.string)), list(Encode.string))))),
51294
0850d43cb355 discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents: 51293
diff changeset
   342
                  list(Encode.string)))))(
0850d43cb355 discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents: 51293
diff changeset
   343
                (dir, (name.theory, (imports, (keywords, header.errors)))))) },
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
   344
          { case Document.Node.Perspective(a) => (a.commands.map(c => long_atom(c.id)), Nil) }))
48705
dd32321d6eef tuned signature -- slightly more abstract text representation of prover process;
wenzelm
parents: 47542
diff changeset
   345
      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
   346
      {
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
   347
        val (name, edit) = node_edit
46737
09ab89658a5d clarified module Thy_Load;
wenzelm
parents: 46688
diff changeset
   348
        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
   349
      })
48705
dd32321d6eef tuned signature -- slightly more abstract text representation of prover process;
wenzelm
parents: 47542
diff changeset
   350
      YXML.string_of_body(encode_edits(edits)) }
45709
87017fcbad83 clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents: 45672
diff changeset
   351
    input("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
   352
  }
43748
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   353
44673
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   354
  def remove_versions(versions: List[Document.Version])
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   355
  {
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   356
    val versions_yxml =
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   357
      { import XML.Encode._
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   358
        YXML.string_of_body(list(long)(versions.map(_.id))) }
45709
87017fcbad83 clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents: 45672
diff changeset
   359
    input("Document.remove_versions", versions_yxml)
44673
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   360
  }
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   361
43748
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   362
50498
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50450
diff changeset
   363
  /* dialog via document content */
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50450
diff changeset
   364
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   365
  def dialog_result(serial: Long, result: String)
50498
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50450
diff changeset
   366
  {
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   367
    input("Document.dialog_result", Properties.Value.Long(serial), result)
50498
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50450
diff changeset
   368
  }
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50450
diff changeset
   369
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50450
diff changeset
   370
43748
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   371
  /* method invocation service */
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   372
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   373
  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
   374
  {
45709
87017fcbad83 clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents: 45672
diff changeset
   375
    input("Document.invoke_scala", id, tag.toString, res)
43748
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   376
  }
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   377
}