src/Pure/PIDE/protocol.scala
author wenzelm
Sun, 15 Nov 2020 22:00:45 +0100
changeset 72616 217e6cf61453
parent 72614 ffed574c65c3
child 72625 3402df4486de
permissions -rw-r--r--
refer to session structure from resources;
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
{
71630
50425e4c3910 clarified modules: global quasi-scope for markers;
wenzelm
parents: 71624
diff changeset
    12
  /* markers for inlined messages */
50425e4c3910 clarified modules: global quasi-scope for markers;
wenzelm
parents: 71624
diff changeset
    13
50425e4c3910 clarified modules: global quasi-scope for markers;
wenzelm
parents: 71624
diff changeset
    14
  val Loading_Theory_Marker = Protocol_Message.Marker("loading_theory")
50425e4c3910 clarified modules: global quasi-scope for markers;
wenzelm
parents: 71624
diff changeset
    15
  val Meta_Info_Marker = Protocol_Message.Marker("meta_info")
50425e4c3910 clarified modules: global quasi-scope for markers;
wenzelm
parents: 71624
diff changeset
    16
  val Command_Timing_Marker = Protocol_Message.Marker("command_timing")
50425e4c3910 clarified modules: global quasi-scope for markers;
wenzelm
parents: 71624
diff changeset
    17
  val Theory_Timing_Marker = Protocol_Message.Marker("theory_timing")
72012
c81e58a81b8c clarified inlined protocol messages;
wenzelm
parents: 71875
diff changeset
    18
  val Session_Timing_Marker = Protocol_Message.Marker("session_timing")
71630
50425e4c3910 clarified modules: global quasi-scope for markers;
wenzelm
parents: 71624
diff changeset
    19
  val ML_Statistics_Marker = Protocol_Message.Marker("ML_statistics")
50425e4c3910 clarified modules: global quasi-scope for markers;
wenzelm
parents: 71624
diff changeset
    20
  val Task_Statistics_Marker = Protocol_Message.Marker("task_statistics")
50425e4c3910 clarified modules: global quasi-scope for markers;
wenzelm
parents: 71624
diff changeset
    21
  val Error_Message_Marker = Protocol_Message.Marker("error_message")
50425e4c3910 clarified modules: global quasi-scope for markers;
wenzelm
parents: 71624
diff changeset
    22
50425e4c3910 clarified modules: global quasi-scope for markers;
wenzelm
parents: 71624
diff changeset
    23
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    24
  /* document editing */
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    25
70665
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    26
  object Commands_Accepted
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    27
  {
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    28
    def unapply(text: String): Option[List[Document_ID.Command]] =
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    29
      try { Some(space_explode(',', text).map(Value.Long.parse)) }
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    30
      catch { case ERROR(_) => None }
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    31
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    32
    val message: XML.Elem = XML.elem(Markup.STATUS, List(XML.elem(Markup.ACCEPTED)))
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    33
  }
94442fce40a5 prefer commands_accepted: fewer protocol messages;
wenzelm
parents: 70664
diff changeset
    34
52563
f9a20c2c3b70 tuned protocol terminology;
wenzelm
parents: 52531
diff changeset
    35
  object Assign_Update
44476
e8a87398f35d propagate information about last command with exec state assignment through document model;
wenzelm
parents: 44474
diff changeset
    36
  {
70284
3e17c3a5fd39 more thorough assignment, e.g. when "purge" removes commands that were not assigned;
wenzelm
parents: 69849
diff changeset
    37
    def unapply(text: String)
3e17c3a5fd39 more thorough assignment, e.g. when "purge" removes commands that were not assigned;
wenzelm
parents: 69849
diff changeset
    38
      : Option[(Document_ID.Version, List[String], Document.Assign_Update)] =
3e17c3a5fd39 more thorough assignment, e.g. when "purge" removes commands that were not assigned;
wenzelm
parents: 69849
diff changeset
    39
    {
44661
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    40
      try {
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    41
        import XML.Decode._
69846
e02e3763e7a4 more compact representation: approx. factor 2;
wenzelm
parents: 68758
diff changeset
    42
        def decode_upd(body: XML.Body): (Long, List[Long]) =
e02e3763e7a4 more compact representation: approx. factor 2;
wenzelm
parents: 68758
diff changeset
    43
          space_explode(',', string(body)).map(Value.Long.parse) match {
e02e3763e7a4 more compact representation: approx. factor 2;
wenzelm
parents: 68758
diff changeset
    44
            case a :: bs => (a, bs)
e02e3763e7a4 more compact representation: approx. factor 2;
wenzelm
parents: 68758
diff changeset
    45
            case _ => throw new XML.XML_Body(body)
e02e3763e7a4 more compact representation: approx. factor 2;
wenzelm
parents: 68758
diff changeset
    46
          }
71601
97ccf48c2f0c misc tuning based on hints by IntelliJ IDEA;
wenzelm
parents: 71165
diff changeset
    47
        Some(triple(long, list(string), list(decode_upd))(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
    48
      }
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    49
      catch {
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
    50
        case ERROR(_) => None
51987
7d8e0e3c553b tuned signature;
wenzelm
parents: 51818
diff changeset
    51
        case _: XML.Error => None
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    52
      }
70284
3e17c3a5fd39 more thorough assignment, e.g. when "purge" removes commands that were not assigned;
wenzelm
parents: 69849
diff changeset
    53
    }
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
    54
  }
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    55
44676
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    56
  object Removed
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    57
  {
52530
99dd8b4ef3fe explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents: 52527
diff changeset
    58
    def unapply(text: String): Option[List[Document_ID.Version]] =
44676
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    59
      try {
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    60
        import XML.Decode._
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
    61
        Some(list(long)(Symbol.decode_yxml(text)))
44676
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    62
      }
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    63
      catch {
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    64
        case ERROR(_) => None
51987
7d8e0e3c553b tuned signature;
wenzelm
parents: 51818
diff changeset
    65
        case _: XML.Error => None
44676
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    66
      }
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    67
  }
7de87f1ae965 Document.removed_versions on Scala side;
wenzelm
parents: 44673
diff changeset
    68
38567
b670faa807c9 concentrate protocol message formats in Isar_Document;
wenzelm
parents: 38483
diff changeset
    69
51818
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    70
  /* command timing */
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    71
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    72
  object Command_Timing
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    73
  {
71673
88dfbc382a3d clarified signature;
wenzelm
parents: 71649
diff changeset
    74
    def unapply(props: Properties.T): Option[(Properties.T, Document_ID.Generic, isabelle.Timing)] =
51818
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    75
      props match {
71673
88dfbc382a3d clarified signature;
wenzelm
parents: 71649
diff changeset
    76
        case Markup.Command_Timing(args) =>
51818
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    77
          (args, args) match {
71673
88dfbc382a3d clarified signature;
wenzelm
parents: 71649
diff changeset
    78
            case (Position.Id(id), Markup.Timing_Properties(timing)) => Some((args, id, timing))
51818
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    79
            case _ => None
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    80
          }
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    81
        case _ => None
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    82
      }
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    83
  }
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    84
517f232e867d clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents: 51533
diff changeset
    85
66873
9953ae603a23 provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents: 66717
diff changeset
    86
  /* theory timing */
9953ae603a23 provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents: 66717
diff changeset
    87
9953ae603a23 provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents: 66717
diff changeset
    88
  object Theory_Timing
9953ae603a23 provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents: 66717
diff changeset
    89
  {
9953ae603a23 provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents: 66717
diff changeset
    90
    def unapply(props: Properties.T): Option[(String, isabelle.Timing)] =
9953ae603a23 provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents: 66717
diff changeset
    91
      props match {
71673
88dfbc382a3d clarified signature;
wenzelm
parents: 71649
diff changeset
    92
        case Markup.Theory_Timing(args) =>
66873
9953ae603a23 provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents: 66717
diff changeset
    93
          (args, args) match {
9953ae603a23 provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents: 66717
diff changeset
    94
            case (Markup.Name(name), Markup.Timing_Properties(timing)) => Some((name, timing))
9953ae603a23 provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents: 66717
diff changeset
    95
            case _ => None
9953ae603a23 provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents: 66717
diff changeset
    96
          }
9953ae603a23 provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents: 66717
diff changeset
    97
        case _ => None
9953ae603a23 provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents: 66717
diff changeset
    98
      }
9953ae603a23 provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents: 66717
diff changeset
    99
  }
9953ae603a23 provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents: 66717
diff changeset
   100
9953ae603a23 provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents: 66717
diff changeset
   101
39441
4110cc1b8f9f allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents: 39439
diff changeset
   102
  /* 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
   103
71647
7b0656fa783b clarified signature;
wenzelm
parents: 71630
diff changeset
   104
  def is_message(pred: XML.Elem => Boolean, body: XML.Body): Boolean =
7b0656fa783b clarified signature;
wenzelm
parents: 71630
diff changeset
   105
    body match {
7b0656fa783b clarified signature;
wenzelm
parents: 71630
diff changeset
   106
      case List(elem: XML.Elem) => pred(elem)
7b0656fa783b clarified signature;
wenzelm
parents: 71630
diff changeset
   107
      case _ => false
7b0656fa783b clarified signature;
wenzelm
parents: 71630
diff changeset
   108
    }
7b0656fa783b clarified signature;
wenzelm
parents: 71630
diff changeset
   109
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   110
  def is_result(msg: XML.Tree): Boolean =
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   111
    msg match {
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   112
      case XML.Elem(Markup(Markup.RESULT, _), _) => true
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   113
      case _ => false
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   114
    }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   115
50157
76efdb6daab2 tuned whitespace;
wenzelm
parents: 50128
diff changeset
   116
  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
   117
    msg match {
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
   118
      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
   119
      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
   120
      case _ => false
53365ba766ac Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents: 39511
diff changeset
   121
    }
53365ba766ac Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents: 39511
diff changeset
   122
59184
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   123
  def is_state(msg: XML.Tree): Boolean =
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   124
    msg match {
59184
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   125
      case XML.Elem(Markup(Markup.STATE, _), _) => true
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   126
      case XML.Elem(Markup(Markup.STATE_MESSAGE, _), _) => true
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   127
      case _ => false
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   128
    }
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   129
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   130
  def is_information(msg: XML.Tree): Boolean =
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   131
    msg match {
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   132
      case XML.Elem(Markup(Markup.INFORMATION, _), _) => true
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59085
diff changeset
   133
      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
   134
      case _ => false
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   135
    }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   136
67923
3e072441c96a clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents: 67915
diff changeset
   137
  def is_writeln(msg: XML.Tree): Boolean =
3e072441c96a clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents: 67915
diff changeset
   138
    msg match {
3e072441c96a clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents: 67915
diff changeset
   139
      case XML.Elem(Markup(Markup.WRITELN, _), _) => true
3e072441c96a clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents: 67915
diff changeset
   140
      case XML.Elem(Markup(Markup.WRITELN_MESSAGE, _), _) => true
3e072441c96a clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents: 67915
diff changeset
   141
      case _ => false
3e072441c96a clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents: 67915
diff changeset
   142
    }
3e072441c96a clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents: 67915
diff changeset
   143
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   144
  def is_warning(msg: XML.Tree): Boolean =
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   145
    msg match {
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
   146
      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
   147
      case XML.Elem(Markup(Markup.WARNING_MESSAGE, _), _) => true
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   148
      case _ => false
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   149
    }
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   150
59203
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   151
  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
   152
    msg match {
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   153
      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
   154
      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
   155
      case _ => false
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   156
    }
5f0bd5afc16d explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents: 59184
diff changeset
   157
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   158
  def is_error(msg: XML.Tree): Boolean =
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   159
    msg match {
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50157
diff changeset
   160
      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
   161
      case XML.Elem(Markup(Markup.ERROR_MESSAGE, _), _) => true
39511
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   162
      case _ => false
5f318522e6fe some specific message classification;
wenzelm
parents: 39441
diff changeset
   163
    }
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
   164
56495
0b9334adcf05 more explicit message discrimination;
wenzelm
parents: 56474
diff changeset
   165
  def is_inlined(msg: XML.Tree): Boolean =
0b9334adcf05 more explicit message discrimination;
wenzelm
parents: 56474
diff changeset
   166
    !(is_result(msg) || is_tracing(msg) || is_state(msg))
0b9334adcf05 more explicit message discrimination;
wenzelm
parents: 56474
diff changeset
   167
67923
3e072441c96a clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents: 67915
diff changeset
   168
  def is_exported(msg: XML.Tree): Boolean =
3e072441c96a clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents: 67915
diff changeset
   169
    is_writeln(msg) || is_warning(msg) || is_legacy(msg) || is_error(msg)
3e072441c96a clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents: 67915
diff changeset
   170
71649
2acdbb6ee521 pretty formatting as in Isabelle/ML;
wenzelm
parents: 71647
diff changeset
   171
  def message_text(body: XML.Body,
2acdbb6ee521 pretty formatting as in Isabelle/ML;
wenzelm
parents: 71647
diff changeset
   172
    margin: Double = Pretty.default_margin,
2acdbb6ee521 pretty formatting as in Isabelle/ML;
wenzelm
parents: 71647
diff changeset
   173
    breakgain: Double = Pretty.default_breakgain,
2acdbb6ee521 pretty formatting as in Isabelle/ML;
wenzelm
parents: 71647
diff changeset
   174
    metric: Pretty.Metric = Pretty.Default_Metric): String =
71165
03afc8252225 support for output messages;
wenzelm
parents: 70715
diff changeset
   175
  {
71649
2acdbb6ee521 pretty formatting as in Isabelle/ML;
wenzelm
parents: 71647
diff changeset
   176
    val text =
2acdbb6ee521 pretty formatting as in Isabelle/ML;
wenzelm
parents: 71647
diff changeset
   177
      Pretty.string_of(Protocol_Message.expose_no_reports(body),
2acdbb6ee521 pretty formatting as in Isabelle/ML;
wenzelm
parents: 71647
diff changeset
   178
        margin = margin, breakgain = breakgain, metric = metric)
2acdbb6ee521 pretty formatting as in Isabelle/ML;
wenzelm
parents: 71647
diff changeset
   179
71647
7b0656fa783b clarified signature;
wenzelm
parents: 71630
diff changeset
   180
    if (is_message(is_warning, body) || is_message(is_legacy, body)) Output.warning_prefix(text)
7b0656fa783b clarified signature;
wenzelm
parents: 71630
diff changeset
   181
    else if (is_message(is_error, body)) Output.error_prefix(text)
71165
03afc8252225 support for output messages;
wenzelm
parents: 70715
diff changeset
   182
    else text
03afc8252225 support for output messages;
wenzelm
parents: 70715
diff changeset
   183
  }
03afc8252225 support for output messages;
wenzelm
parents: 70715
diff changeset
   184
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   185
71624
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   186
  /* export */
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   187
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   188
  object Export
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   189
  {
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   190
    sealed case class Args(
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   191
      id: Option[String],
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   192
      serial: Long,
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   193
      theory_name: String,
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   194
      name: String,
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   195
      executable: Boolean,
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   196
      compress: Boolean,
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   197
      strict: Boolean)
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   198
    {
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   199
      def compound_name: String = isabelle.Export.compound_name(theory_name, name)
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   200
    }
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   201
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   202
    def unapply(props: Properties.T): Option[Args] =
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   203
      props match {
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   204
        case
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   205
          List(
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   206
            (Markup.FUNCTION, Markup.EXPORT),
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   207
            (Markup.ID, id),
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   208
            (Markup.SERIAL, Value.Long(serial)),
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   209
            (Markup.THEORY_NAME, theory_name),
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   210
            (Markup.NAME, name),
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   211
            (Markup.EXECUTABLE, Value.Boolean(executable)),
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   212
            (Markup.COMPRESS, Value.Boolean(compress)),
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   213
            (Markup.STRICT, Value.Boolean(strict))) =>
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   214
          Some(Args(proper_string(id), serial, theory_name, name, executable, compress, strict))
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   215
        case _ => None
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   216
      }
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   217
  }
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   218
f0499449e149 clarified modules;
wenzelm
parents: 71601
diff changeset
   219
60882
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   220
  /* breakpoints */
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   221
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   222
  object ML_Breakpoint
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   223
  {
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   224
    def unapply(tree: XML.Tree): Option[Long] =
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   225
    tree match {
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   226
      case XML.Elem(Markup(Markup.ML_BREAKPOINT, Markup.Serial(breakpoint)), _) => Some(breakpoint)
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   227
      case _ => None
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   228
    }
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   229
  }
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   230
45bfd18835f1 tuned signature;
wenzelm
parents: 60879
diff changeset
   231
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   232
  /* dialogs */
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
  object Dialog_Args
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   235
  {
52531
21f8e0e151f5 tuned signature;
wenzelm
parents: 52530
diff changeset
   236
    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
   237
      (props, props, props) match {
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   238
        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
   239
          Some((id, serial, result))
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   240
        case _ => None
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   241
      }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   242
  }
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
  object Dialog
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   245
  {
52531
21f8e0e151f5 tuned signature;
wenzelm
parents: 52530
diff changeset
   246
    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
   247
      tree match {
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   248
        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
   249
          Some((id, serial, result))
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   250
        case _ => None
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   251
      }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   252
  }
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_Result
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 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
   257
    {
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   258
      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
   259
      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
   260
    }
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   261
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   262
    def unapply(tree: XML.Tree): Option[String] =
50500
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   263
      tree match {
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   264
        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
   265
        case _ => None
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   266
      }
c94bba7906d2 identify dialogs via official serial and maintain as result message;
wenzelm
parents: 50498
diff changeset
   267
  }
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   268
}
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   269
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   270
57916
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57911
diff changeset
   271
trait Protocol
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   272
{
57916
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57911
diff changeset
   273
  /* protocol commands */
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57911
diff changeset
   274
70661
9c4809ec28ef tuned signature;
wenzelm
parents: 70638
diff changeset
   275
  def protocol_command_raw(name: String, args: List[Bytes]): Unit
9c4809ec28ef tuned signature;
wenzelm
parents: 70638
diff changeset
   276
  def protocol_command_args(name: String, args: List[String])
57916
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57911
diff changeset
   277
  def protocol_command(name: String, args: String*): Unit
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57911
diff changeset
   278
2c2c24dbf0a4 generic process wrapping in Prover;
wenzelm
parents: 57911
diff changeset
   279
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56372
diff changeset
   280
  /* options */
d92eb5c3960d more general prover operations;
wenzelm
parents: 56372
diff changeset
   281
d92eb5c3960d more general prover operations;
wenzelm
parents: 56372
diff changeset
   282
  def options(opts: Options): Unit =
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   283
    protocol_command("Prover.options", Symbol.encode_yxml(opts.encode))
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56372
diff changeset
   284
d92eb5c3960d more general prover operations;
wenzelm
parents: 56372
diff changeset
   285
65470
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   286
  /* session base */
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   287
72614
wenzelm
parents: 72613
diff changeset
   288
  def init_session(resources: Resources)
66712
4c98c929a12a session-qualified theory names are mandatory;
wenzelm
parents: 66668
diff changeset
   289
  {
4c98c929a12a session-qualified theory names are mandatory;
wenzelm
parents: 66668
diff changeset
   290
    import XML.Encode._
67493
c4e9e0c50487 treat sessions as entities with defining position;
wenzelm
parents: 67471
diff changeset
   291
72614
wenzelm
parents: 72613
diff changeset
   292
    def encode_table(arg: List[(String, String)]): String =
wenzelm
parents: 72613
diff changeset
   293
      Symbol.encode_yxml(list(pair(string, string))(arg))
wenzelm
parents: 72613
diff changeset
   294
    def encode_list(arg: List[String]): String =
wenzelm
parents: 72613
diff changeset
   295
      Symbol.encode_yxml(list(string)(arg))
wenzelm
parents: 72613
diff changeset
   296
    def encode_sessions(arg: List[(String, Position.T)]): String =
wenzelm
parents: 72613
diff changeset
   297
      Symbol.encode_yxml(list(pair(string, properties))(arg))
wenzelm
parents: 72613
diff changeset
   298
    def encode_bibtex_entries(arg: List[(String, List[String])]): String =
wenzelm
parents: 72613
diff changeset
   299
      Symbol.encode_yxml(list(pair(string, list(string)))(arg))
72613
d01ea9e3bd2d clarified bibtex_entries: refer to overall session structure;
wenzelm
parents: 72234
diff changeset
   300
71875
aaa984499d36 tuned signature;
wenzelm
parents: 71673
diff changeset
   301
    protocol_command("Prover.init_session",
70683
8c7706b053c7 find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents: 70665
diff changeset
   302
      encode_sessions(resources.sessions_structure.session_positions),
8c7706b053c7 find theory files via session structure: much faster Prover IDE startup;
wenzelm
parents: 70665
diff changeset
   303
      encode_table(resources.sessions_structure.dest_session_directories),
72616
217e6cf61453 refer to session structure from resources;
wenzelm
parents: 72614
diff changeset
   304
      encode_table(resources.sessions_structure.session_chapters),
72613
d01ea9e3bd2d clarified bibtex_entries: refer to overall session structure;
wenzelm
parents: 72234
diff changeset
   305
      encode_bibtex_entries(resources.sessions_structure.bibtex_entries),
70715
fb94d68314fa clarified signature -- removed pointless operations;
wenzelm
parents: 70712
diff changeset
   306
      encode_list(resources.session_base.doc_names),
fb94d68314fa clarified signature -- removed pointless operations;
wenzelm
parents: 70712
diff changeset
   307
      encode_table(resources.session_base.global_theories.toList),
fb94d68314fa clarified signature -- removed pointless operations;
wenzelm
parents: 70712
diff changeset
   308
      encode_list(resources.session_base.loaded_theories.keys))
66668
6019cfb8256c proper standard_path to revert platform_path in JEdit_Sessions.session_base;
wenzelm
parents: 66411
diff changeset
   309
  }
65470
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   310
a0f49174dbeb global session_base for PIDE interaction;
wenzelm
parents: 65445
diff changeset
   311
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56372
diff changeset
   312
  /* interned items */
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54515
diff changeset
   313
56335
8953d4cc060a store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents: 56306
diff changeset
   314
  def define_blob(digest: SHA1.Digest, bytes: Bytes): Unit =
70661
9c4809ec28ef tuned signature;
wenzelm
parents: 70638
diff changeset
   315
    protocol_command_raw("Document.define_blob", List(Bytes(digest.toString), bytes))
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   316
70664
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   317
  private def encode_command(command: Command): (String, String, String, String, List[String]) =
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54515
diff changeset
   318
  {
70664
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   319
    import XML.Encode._
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   320
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54515
diff changeset
   321
    val blobs_yxml =
61376
93224745477f output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents: 60992
diff changeset
   322
    {
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54515
diff changeset
   323
      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
   324
        variant(List(
54526
92961f196d9e load files that are not provided by PIDE blobs;
wenzelm
parents: 54524
diff changeset
   325
          { case Exn.Res((a, b)) =>
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   326
              (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
   327
          { 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
   328
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   329
      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
   330
    }
59085
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 58015
diff changeset
   331
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 58015
diff changeset
   332
    val toks_yxml =
61376
93224745477f output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents: 60992
diff changeset
   333
    {
64616
wenzelm
parents: 63805
diff changeset
   334
      val encode_tok: T[Token] = (tok => pair(int, int)((tok.kind.id, Symbol.length(tok.source))))
70664
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   335
      Symbol.encode_yxml(list(encode_tok)(command.span.content))
59085
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 58015
diff changeset
   336
    }
70664
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   337
    val toks_sources = command.span.content.map(tok => Symbol.encode(tok.source))
59085
08a6901eb035 clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents: 58015
diff changeset
   338
70664
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   339
    (Document_ID(command.id), Symbol.encode(command.span.name), blobs_yxml, toks_yxml, toks_sources)
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   340
  }
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   341
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   342
  def define_command(command: Command)
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   343
  {
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   344
    val (command_id, name, blobs_yxml, toks_yxml, toks_sources) = encode_command(command)
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   345
    protocol_command_args(
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   346
      "Document.define_command", command_id :: name :: blobs_yxml :: toks_yxml :: toks_sources)
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   347
  }
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   348
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   349
  def define_commands(commands: List[Command])
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   350
  {
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   351
    protocol_command_args("Document.define_commands",
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   352
      commands.map(command =>
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   353
      {
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   354
        import XML.Encode._
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   355
        val (command_id, name, blobs_yxml, toks_yxml, toks_sources) = encode_command(command)
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   356
        val body =
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   357
          pair(string, pair(string, pair(string, pair(string, list(string)))))(
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   358
            command_id, (name, (blobs_yxml, (toks_yxml, toks_sources))))
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   359
        YXML.string_of_body(body)
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   360
      }))
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   361
  }
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   362
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   363
  def define_commands_bulk(commands: List[Command])
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   364
  {
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   365
    val (irregular, regular) = commands.partition(command => YXML.detect(command.source))
71601
97ccf48c2f0c misc tuning based on hints by IntelliJ IDEA;
wenzelm
parents: 71165
diff changeset
   366
    irregular.foreach(define_command)
70664
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   367
    regular match {
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   368
      case Nil =>
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   369
      case List(command) => define_command(command)
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   370
      case _ => define_commands(regular)
2bd9e30183b1 prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents: 70661
diff changeset
   371
    }
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54515
diff changeset
   372
  }
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   373
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   374
52931
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   375
  /* execution */
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   376
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   377
  def discontinue_execution(): Unit =
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   378
    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
   379
52931
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   380
  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
   381
    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
   382
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   383
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   384
  /* 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
   385
52530
99dd8b4ef3fe explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents: 52527
diff changeset
   386
  def update(old_id: Document_ID.Version, new_id: Document_ID.Version,
68381
2fd3a6d6ba2e less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents: 68336
diff changeset
   387
    edits: List[Document.Edit_Command], consolidate: List[Document.Node.Name])
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   388
  {
69849
09f200c658ed more scalable on 32-bit Poly/ML;
wenzelm
parents: 69846
diff changeset
   389
    val consolidate_yxml =
09f200c658ed more scalable on 32-bit Poly/ML;
wenzelm
parents: 69846
diff changeset
   390
    {
09f200c658ed more scalable on 32-bit Poly/ML;
wenzelm
parents: 69846
diff changeset
   391
      import XML.Encode._
09f200c658ed more scalable on 32-bit Poly/ML;
wenzelm
parents: 69846
diff changeset
   392
      Symbol.encode_yxml(list(string)(consolidate.map(_.node)))
09f200c658ed more scalable on 32-bit Poly/ML;
wenzelm
parents: 69846
diff changeset
   393
    }
44157
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
   394
    val edits_yxml =
61376
93224745477f output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents: 60992
diff changeset
   395
    {
93224745477f output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents: 60992
diff changeset
   396
      import XML.Encode._
44383
f99906c2a1d3 discontinued redundant Edit_Command_ID;
wenzelm
parents: 44185
diff changeset
   397
      def id: T[Command] = (cmd => long(cmd.id))
46737
09ab89658a5d clarified module Thy_Load;
wenzelm
parents: 46688
diff changeset
   398
      def encode_edit(name: Document.Node.Name)
52849
199e9fa5a5c2 maintain overlays within node perspective;
wenzelm
parents: 52808
diff changeset
   399
          : 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
   400
        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
   401
          { 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
   402
          { case Document.Node.Deps(header) =>
60992
89effcb342df clarified modules, like ML version;
wenzelm
parents: 60882
diff changeset
   403
              val master_dir = File.standard_url(name.master_dir)
70638
f164cec7ac22 clarified signature: prefer operations without position;
wenzelm
parents: 70284
diff changeset
   404
              val imports = header.imports.map(_.node)
65384
36255c43c64c more explicit types;
wenzelm
parents: 65345
diff changeset
   405
              val keywords =
36255c43c64c more explicit types;
wenzelm
parents: 65345
diff changeset
   406
                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
   407
              (Nil,
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   408
                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
   409
                    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
   410
                (master_dir, (name.theory, (imports, (keywords, header.errors)))))) },
52849
199e9fa5a5c2 maintain overlays within node perspective;
wenzelm
parents: 52808
diff changeset
   411
          { case Document.Node.Perspective(a, b, c) =>
199e9fa5a5c2 maintain overlays within node perspective;
wenzelm
parents: 52808
diff changeset
   412
              (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
   413
                list(pair(id, pair(string, list(string))))(c.dest)) }))
69849
09f200c658ed more scalable on 32-bit Poly/ML;
wenzelm
parents: 69846
diff changeset
   414
      edits.map({ case (name, edit) =>
09f200c658ed more scalable on 32-bit Poly/ML;
wenzelm
parents: 69846
diff changeset
   415
        Symbol.encode_yxml(pair(string, encode_edit(name))(name.node, edit)) })
68381
2fd3a6d6ba2e less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents: 68336
diff changeset
   416
    }
70661
9c4809ec28ef tuned signature;
wenzelm
parents: 70638
diff changeset
   417
    protocol_command_args("Document.update",
9c4809ec28ef tuned signature;
wenzelm
parents: 70638
diff changeset
   418
      Document_ID(old_id) :: Document_ID(new_id) :: consolidate_yxml :: edits_yxml)
38412
c23f3abbf42d moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff changeset
   419
  }
43748
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   420
44673
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   421
  def remove_versions(versions: List[Document.Version])
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   422
  {
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   423
    val versions_yxml =
59364
3b5da177ae6b clarified build_theories;
wenzelm
parents: 59362
diff changeset
   424
    { import XML.Encode._
65345
2fdd4431b30e clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents: 65313
diff changeset
   425
      Symbol.encode_yxml(list(long)(versions.map(_.id))) }
52582
31467a4b1466 tuned signature;
wenzelm
parents: 52563
diff changeset
   426
    protocol_command("Document.remove_versions", versions_yxml)
44673
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   427
  }
2fa51ac191bc Document.remove_versions on ML side;
wenzelm
parents: 44661
diff changeset
   428
43748
c70bd78ec83c JVM method invocation service via Scala layer;
wenzelm
parents: 43731
diff changeset
   429
50498
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50450
diff changeset
   430
  /* dialog via document content */
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50450
diff changeset
   431
52931
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52862
diff changeset
   432
  def dialog_result(serial: Long, result: String): Unit =
63805
c272680df665 clarified modules;
wenzelm
parents: 63579
diff changeset
   433
    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
   434
}