src/Pure/PIDE/command.scala
author wenzelm
Mon, 11 Aug 2014 22:43:26 +0200
changeset 57902 3f1fd41ee821
parent 57901 e1abca2527da
child 57904 922273b7bf8a
permissions -rw-r--r--
tuned output, in accordance to transaction name in ML;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36676
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 36012
diff changeset
     1
/*  Title:      Pure/PIDE/command.scala
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 36012
diff changeset
     2
    Author:     Fabian Immler, TU Munich
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 36012
diff changeset
     3
    Author:     Makarius
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 36012
diff changeset
     4
52536
3a35ce87a55c tuned signature;
wenzelm
parents: 52535
diff changeset
     5
Prover commands with accumulated results from execution.
36676
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 36012
diff changeset
     6
*/
34407
aad6834ba380 added some headers and comments;
wenzelm
parents: 34401
diff changeset
     7
34871
e596a0b71f3c incorporate "proofdocument" part into main Isabelle/Pure.jar -- except for html_panel.scala, which depends on external library (Lobo/Cobra browser);
wenzelm
parents: 34865
diff changeset
     8
package isabelle
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
     9
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    10
45644
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
    11
import scala.collection.mutable
38872
26c505765024 Command.results: ordered by serial number;
wenzelm
parents: 38723
diff changeset
    12
import scala.collection.immutable.SortedMap
26c505765024 Command.results: ordered by serial number;
wenzelm
parents: 38723
diff changeset
    13
26c505765024 Command.results: ordered by serial number;
wenzelm
parents: 38723
diff changeset
    14
34637
f3b5d6e248be added symbol_index (presently unused);
wenzelm
parents: 34603
diff changeset
    15
object Command
f3b5d6e248be added symbol_index (presently unused);
wenzelm
parents: 34603
diff changeset
    16
{
52849
199e9fa5a5c2 maintain overlays within node perspective;
wenzelm
parents: 52642
diff changeset
    17
  type Edit = (Option[Command], Option[Command])
56746
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
    18
  type Blob = Exn.Result[(Document.Node.Name, Option[(SHA1.Digest, Symbol.Text_Chunk)])]
55648
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
    19
52849
199e9fa5a5c2 maintain overlays within node perspective;
wenzelm
parents: 52642
diff changeset
    20
199e9fa5a5c2 maintain overlays within node perspective;
wenzelm
parents: 52642
diff changeset
    21
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
    22
  /** accumulated results from prover **/
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
    23
50507
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    24
  /* results */
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    25
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    26
  object Results
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    27
  {
51496
cb677987b7e3 retain original tooltip range, to avoid repeated window popup when the mouse is moved over the same content;
wenzelm
parents: 51494
diff changeset
    28
    type Entry = (Long, XML.Tree)
50507
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    29
    val empty = new Results(SortedMap.empty)
56299
8201790fdeb9 more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents: 56295
diff changeset
    30
    def make(es: List[Results.Entry]): Results = (empty /: es)(_ + _)
8201790fdeb9 more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents: 56295
diff changeset
    31
    def merge(rs: List[Results]): Results = (empty /: rs)(_ ++ _)
50507
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    32
  }
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    33
51494
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
    34
  final class Results private(private val rep: SortedMap[Long, XML.Tree])
50507
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    35
  {
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    36
    def defined(serial: Long): Boolean = rep.isDefinedAt(serial)
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    37
    def get(serial: Long): Option[XML.Tree] = rep.get(serial)
56372
fadb0fef09d7 more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents: 56359
diff changeset
    38
    def iterator: Iterator[Results.Entry] = rep.iterator
50508
5b7150395568 tuned implementation according to Library.insert/merge in ML;
wenzelm
parents: 50507
diff changeset
    39
51496
cb677987b7e3 retain original tooltip range, to avoid repeated window popup when the mouse is moved over the same content;
wenzelm
parents: 51494
diff changeset
    40
    def + (entry: Results.Entry): Results =
50508
5b7150395568 tuned implementation according to Library.insert/merge in ML;
wenzelm
parents: 50507
diff changeset
    41
      if (defined(entry._1)) this
5b7150395568 tuned implementation according to Library.insert/merge in ML;
wenzelm
parents: 50507
diff changeset
    42
      else new Results(rep + entry)
5b7150395568 tuned implementation according to Library.insert/merge in ML;
wenzelm
parents: 50507
diff changeset
    43
5b7150395568 tuned implementation according to Library.insert/merge in ML;
wenzelm
parents: 50507
diff changeset
    44
    def ++ (other: Results): Results =
5b7150395568 tuned implementation according to Library.insert/merge in ML;
wenzelm
parents: 50507
diff changeset
    45
      if (this eq other) this
5b7150395568 tuned implementation according to Library.insert/merge in ML;
wenzelm
parents: 50507
diff changeset
    46
      else if (rep.isEmpty) other
56372
fadb0fef09d7 more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents: 56359
diff changeset
    47
      else (this /: other.iterator)(_ + _)
50540
wenzelm
parents: 50508
diff changeset
    48
51494
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
    49
    override def hashCode: Int = rep.hashCode
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
    50
    override def equals(that: Any): Boolean =
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
    51
      that match {
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
    52
        case other: Results => rep == other.rep
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
    53
        case _ => false
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
    54
      }
56372
fadb0fef09d7 more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents: 56359
diff changeset
    55
    override def toString: String = iterator.mkString("Results(", ", ", ")")
50507
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    56
  }
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    57
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    58
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    59
  /* markup */
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    60
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    61
  object Markup_Index
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    62
  {
56746
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
    63
    val markup: Markup_Index = Markup_Index(false, Symbol.Text_Chunk.Default)
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    64
  }
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    65
56746
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
    66
  sealed case class Markup_Index(status: Boolean, chunk_name: Symbol.Text_Chunk.Name)
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    67
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    68
  object Markups
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    69
  {
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    70
    val empty: Markups = new Markups(Map.empty)
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    71
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    72
    def init(markup: Markup_Tree): Markups =
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    73
      new Markups(Map(Markup_Index.markup -> markup))
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    74
  }
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    75
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    76
  final class Markups private(private val rep: Map[Markup_Index, Markup_Tree])
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    77
  {
56489
wenzelm
parents: 56476
diff changeset
    78
    def is_empty: Boolean = rep.isEmpty
wenzelm
parents: 56476
diff changeset
    79
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    80
    def apply(index: Markup_Index): Markup_Tree =
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    81
      rep.getOrElse(index, Markup_Tree.empty)
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    82
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    83
    def add(index: Markup_Index, markup: Text.Markup): Markups =
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    84
      new Markups(rep + (index -> (this(index) + markup)))
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    85
56475
710dee42b3d0 tuned signature;
wenzelm
parents: 56473
diff changeset
    86
    def redirection_iterator: Iterator[Document_ID.Generic] =
56746
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
    87
      for (Markup_Index(_, Symbol.Text_Chunk.Id(id)) <- rep.keysIterator)
56475
710dee42b3d0 tuned signature;
wenzelm
parents: 56473
diff changeset
    88
        yield id
56470
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
    89
56475
710dee42b3d0 tuned signature;
wenzelm
parents: 56473
diff changeset
    90
    def redirect(other_id: Document_ID.Generic): Markups =
56489
wenzelm
parents: 56476
diff changeset
    91
    {
wenzelm
parents: 56476
diff changeset
    92
      val rep1 =
56470
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
    93
        (for {
56746
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
    94
          (Markup_Index(status, Symbol.Text_Chunk.Id(id)), markup) <- rep.iterator
56470
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
    95
          if other_id == id
56746
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
    96
        } yield (Markup_Index(status, Symbol.Text_Chunk.Default), markup)).toMap
56489
wenzelm
parents: 56476
diff changeset
    97
      if (rep1.isEmpty) Markups.empty else new Markups(rep1)
wenzelm
parents: 56476
diff changeset
    98
    }
56470
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
    99
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   100
    override def hashCode: Int = rep.hashCode
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   101
    override def equals(that: Any): Boolean =
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   102
      that match {
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   103
        case other: Markups => rep == other.rep
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   104
        case _ => false
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   105
      }
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   106
    override def toString: String = rep.iterator.mkString("Markups(", ", ", ")")
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   107
  }
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   108
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   109
50507
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
   110
  /* state */
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   111
56299
8201790fdeb9 more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents: 56295
diff changeset
   112
  object State
8201790fdeb9 more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents: 56295
diff changeset
   113
  {
8201790fdeb9 more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents: 56295
diff changeset
   114
    def merge_results(states: List[State]): Command.Results =
8201790fdeb9 more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents: 56295
diff changeset
   115
      Results.merge(states.map(_.results))
8201790fdeb9 more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents: 56295
diff changeset
   116
56301
1da7b4c33db9 more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents: 56299
diff changeset
   117
    def merge_markup(states: List[State], index: Markup_Index,
56743
81370dfadb1d tuned signature;
wenzelm
parents: 56514
diff changeset
   118
        range: Text.Range, elements: Markup.Elements): Markup_Tree =
56301
1da7b4c33db9 more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents: 56299
diff changeset
   119
      Markup_Tree.merge(states.map(_.markup(index)), range, elements)
56299
8201790fdeb9 more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents: 56295
diff changeset
   120
  }
8201790fdeb9 more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents: 56295
diff changeset
   121
43714
3749d1e6dde9 tuned signature;
wenzelm
parents: 43662
diff changeset
   122
  sealed case class State(
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   123
    command: Command,
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   124
    status: List[Markup] = Nil,
50507
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
   125
    results: Results = Results.empty,
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   126
    markups: Markups = Markups.empty)
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
   127
  {
56395
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   128
    lazy val protocol_status: Protocol.Status =
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   129
    {
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   130
      val warnings =
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   131
        if (results.iterator.exists(p => Protocol.is_warning(p._2)))
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   132
          List(Markup(Markup.WARNING, Nil))
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   133
        else Nil
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   134
      val errors =
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   135
        if (results.iterator.exists(p => Protocol.is_error(p._2)))
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   136
          List(Markup(Markup.ERROR, Nil))
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   137
        else Nil
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   138
      Protocol.Status.make((warnings ::: errors ::: status).iterator)
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   139
    }
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   140
55650
349afd0fa0c4 tuned signature;
wenzelm
parents: 55649
diff changeset
   141
    def markup(index: Markup_Index): Markup_Tree = markups(index)
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   142
56489
wenzelm
parents: 56476
diff changeset
   143
    def redirect(other_command: Command): Option[State] =
wenzelm
parents: 56476
diff changeset
   144
    {
wenzelm
parents: 56476
diff changeset
   145
      val markups1 = markups.redirect(other_command.id)
wenzelm
parents: 56476
diff changeset
   146
      if (markups1.is_empty) None
wenzelm
parents: 56476
diff changeset
   147
      else Some(new State(other_command, Nil, Results.empty, markups1))
wenzelm
parents: 56476
diff changeset
   148
    }
49614
0009a6ebc83b operations to turn markup into XML;
wenzelm
parents: 49527
diff changeset
   149
51494
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
   150
    def eq_content(other: State): Boolean =
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
   151
      command.source == other.command.source &&
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
   152
      status == other.status &&
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
   153
      results == other.results &&
55434
aa2918d967f0 more accurate eq_content;
wenzelm
parents: 55433
diff changeset
   154
      markups == other.markups
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
   155
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   156
    private def add_status(st: Markup): State =
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   157
      copy(status = st :: status)
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   158
56746
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
   159
    private def add_markup(
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
   160
      status: Boolean, chunk_name: Symbol.Text_Chunk.Name, m: Text.Markup): State =
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   161
    {
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   162
      val markups1 =
56395
0546e036d1c0 more direct warning within persistent Protocol.Status;
wenzelm
parents: 56372
diff changeset
   163
        if (status || Protocol.liberal_status_elements(m.info.name))
56462
b64b0cb845fe more explicit Command.Chunk types, less ooddities;
wenzelm
parents: 56395
diff changeset
   164
          markups.add(Markup_Index(true, chunk_name), m)
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   165
        else markups
56462
b64b0cb845fe more explicit Command.Chunk types, less ooddities;
wenzelm
parents: 56395
diff changeset
   166
      copy(markups = markups1.add(Markup_Index(false, chunk_name), m))
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   167
    }
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
   168
56470
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   169
    def accumulate(
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   170
        self_id: Document_ID.Generic => Boolean,
56746
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
   171
        other_id: Document_ID.Generic => Option[(Symbol.Text_Chunk.Id, Symbol.Text_Chunk)],
56470
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   172
        message: XML.Elem): State =
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
   173
      message match {
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   174
        case XML.Elem(Markup(Markup.STATUS, _), msgs) =>
38714
31da698fc4e5 more precise Command.State accumulation;
wenzelm
parents: 38658
diff changeset
   175
          (this /: msgs)((state, msg) =>
31da698fc4e5 more precise Command.State accumulation;
wenzelm
parents: 38658
diff changeset
   176
            msg match {
46152
793cecd4ffc0 accumulate status as regular markup for command range;
wenzelm
parents: 45709
diff changeset
   177
              case elem @ XML.Elem(markup, Nil) =>
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   178
                state.
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   179
                  add_status(markup).
56746
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
   180
                  add_markup(true, Symbol.Text_Chunk.Default, Text.Info(command.proper_range, elem))
52536
3a35ce87a55c tuned signature;
wenzelm
parents: 52535
diff changeset
   181
              case _ =>
56782
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents: 56746
diff changeset
   182
                Output.warning("Ignored status message: " + msg)
52536
3a35ce87a55c tuned signature;
wenzelm
parents: 52535
diff changeset
   183
                state
38714
31da698fc4e5 more precise Command.State accumulation;
wenzelm
parents: 38658
diff changeset
   184
            })
38581
d503a0912e14 simplified Command.status again, reverting most of e5eed57913d0 (note that more complex information can be represented with full markup reports);
wenzelm
parents: 38579
diff changeset
   185
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   186
        case XML.Elem(Markup(Markup.REPORT, _), msgs) =>
38572
0fe2c01ef7da Command.State: accumulate markup reports uniformly;
wenzelm
parents: 38564
diff changeset
   187
          (this /: msgs)((state, msg) =>
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   188
            {
56782
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents: 56746
diff changeset
   189
              def bad(): Unit = Output.warning("Ignored report message: " + msg)
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   190
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   191
              msg match {
56470
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   192
                case XML.Elem(
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   193
                    Markup(name, atts @ Position.Reported(id, chunk_name, symbol_range)), args) =>
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   194
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   195
                  val target =
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   196
                    if (self_id(id) && command.chunks.isDefinedAt(chunk_name))
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   197
                      Some((chunk_name, command.chunks(chunk_name)))
56746
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
   198
                    else if (chunk_name == Symbol.Text_Chunk.Default) other_id(id)
56470
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   199
                    else None
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   200
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   201
                  target match {
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   202
                    case Some((target_name, target_chunk)) =>
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   203
                      target_chunk.incorporate(symbol_range) match {
55548
a645277885cf more uniform/robust restriction of reported positions, e.g. relevant for "bad" markup due to unclosed comment in ML file;
wenzelm
parents: 55434
diff changeset
   204
                        case Some(range) =>
55822
ccf2d784be97 incorporate chunk range that is 1 off end-of-input, for improved error positions (NB: command spans are tight, without trailing whitespace);
wenzelm
parents: 55785
diff changeset
   205
                          val props = Position.purge(atts)
ccf2d784be97 incorporate chunk range that is 1 off end-of-input, for improved error positions (NB: command spans are tight, without trailing whitespace);
wenzelm
parents: 55785
diff changeset
   206
                          val info = Text.Info(range, XML.Elem(Markup(name, props), args))
56470
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   207
                          state.add_markup(false, target_name, info)
55548
a645277885cf more uniform/robust restriction of reported positions, e.g. relevant for "bad" markup due to unclosed comment in ML file;
wenzelm
parents: 55434
diff changeset
   208
                        case None => bad(); state
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   209
                      }
56476
dd596c2b5897 expose more bad cases;
wenzelm
parents: 56475
diff changeset
   210
                    case None =>
56514
db929027e701 ignore other_id reports for now (see 8eda56033203): massive amounts of redirections to 'class' etc. makes it difficult to edit main HOL;
wenzelm
parents: 56489
diff changeset
   211
                      // silently ignore excessive reports
56476
dd596c2b5897 expose more bad cases;
wenzelm
parents: 56475
diff changeset
   212
                      state
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   213
                  }
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   214
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   215
                case XML.Elem(Markup(name, atts), args)
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   216
                if !atts.exists({ case (a, _) => Markup.POSITION_PROPERTIES(a) }) =>
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   217
                  val range = command.proper_range
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   218
                  val props = Position.purge(atts)
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   219
                  val info: Text.Markup = Text.Info(range, XML.Elem(Markup(name, props), args))
56746
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
   220
                  state.add_markup(false, Symbol.Text_Chunk.Default, info)
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   221
56470
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   222
                case _ => bad(); state
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   223
              }
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
   224
            })
52930
5fab62ae3532 retain original messages properties, e.g. for retrieval via Command.Results;
wenzelm
parents: 52849
diff changeset
   225
        case XML.Elem(Markup(name, props), body) =>
5fab62ae3532 retain original messages properties, e.g. for retrieval via Command.Results;
wenzelm
parents: 52849
diff changeset
   226
          props match {
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   227
            case Markup.Serial(i) =>
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   228
              val message1 = XML.Elem(Markup(Markup.message(name), props), body)
50163
c62ce309dc26 more abstract Sendback operations, with explicit id/exec_id properties;
wenzelm
parents: 50158
diff changeset
   229
              val message2 = XML.Elem(Markup(name, props), body)
c62ce309dc26 more abstract Sendback operations, with explicit id/exec_id properties;
wenzelm
parents: 50158
diff changeset
   230
55433
d2960d67f163 clarified message_positions: cover alt_id as well;
wenzelm
parents: 55432
diff changeset
   231
              var st = copy(results = results + (i -> message1))
d2960d67f163 clarified message_positions: cover alt_id as well;
wenzelm
parents: 55432
diff changeset
   232
              if (Protocol.is_inlined(message)) {
d2960d67f163 clarified message_positions: cover alt_id as well;
wenzelm
parents: 55432
diff changeset
   233
                for {
56469
ffc94a271633 avoid data redundancy;
wenzelm
parents: 56468
diff changeset
   234
                  (chunk_name, chunk) <- command.chunks.iterator
56470
8eda56033203 accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents: 56469
diff changeset
   235
                  range <- Protocol.message_positions(self_id, chunk_name, chunk, message)
56462
b64b0cb845fe more explicit Command.Chunk types, less ooddities;
wenzelm
parents: 56395
diff changeset
   236
                } st = st.add_markup(false, chunk_name, Text.Info(range, message2))
55433
d2960d67f163 clarified message_positions: cover alt_id as well;
wenzelm
parents: 55432
diff changeset
   237
              }
d2960d67f163 clarified message_positions: cover alt_id as well;
wenzelm
parents: 55432
diff changeset
   238
              st
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   239
52536
3a35ce87a55c tuned signature;
wenzelm
parents: 52535
diff changeset
   240
            case _ =>
56782
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents: 56746
diff changeset
   241
              Output.warning("Ignored message without serial number: " + message)
52536
3a35ce87a55c tuned signature;
wenzelm
parents: 52535
diff changeset
   242
              this
38872
26c505765024 Command.results: ordered by serial number;
wenzelm
parents: 38723
diff changeset
   243
          }
56295
a40e67ce4f84 clarified valid_id: always standardize towards static command.id;
wenzelm
parents: 55884
diff changeset
   244
    }
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
   245
  }
38367
f7d2574dc3a6 more basic notion of unparsed input;
wenzelm
parents: 38363
diff changeset
   246
f7d2574dc3a6 more basic notion of unparsed input;
wenzelm
parents: 38363
diff changeset
   247
55431
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   248
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   249
  /** static content **/
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   250
45644
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   251
  /* make commands */
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   252
55648
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   253
  def apply(
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   254
    id: Document_ID.Command,
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   255
    node_name: Document.Node.Name,
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   256
    blobs: List[Blob],
57901
e1abca2527da more explicit type Span in Scala, according to ML version;
wenzelm
parents: 57842
diff changeset
   257
    span: Thy_Syntax.Span): Command =
55648
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   258
  {
57901
e1abca2527da more explicit type Span in Scala, according to ML version;
wenzelm
parents: 57842
diff changeset
   259
    val (source, span1) = span.compact_source
55648
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   260
    new Command(id, node_name, blobs, span1, source, Results.empty, Markup_Tree.empty)
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   261
  }
49414
d7b5fb2e9ca2 some support for inital command markup;
wenzelm
parents: 49359
diff changeset
   262
57901
e1abca2527da more explicit type Span in Scala, according to ML version;
wenzelm
parents: 57842
diff changeset
   263
  val empty: Command =
e1abca2527da more explicit type Span in Scala, according to ML version;
wenzelm
parents: 57842
diff changeset
   264
    Command(Document_ID.none, Document.Node.Name.empty, Nil, Thy_Syntax.empty_span)
55648
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   265
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   266
  def unparsed(
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   267
    id: Document_ID.Command,
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   268
    source: String,
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   269
    results: Results,
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   270
    markup: Markup_Tree): Command =
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   271
  {
57901
e1abca2527da more explicit type Span in Scala, according to ML version;
wenzelm
parents: 57842
diff changeset
   272
    val (source1, span1) = Thy_Syntax.unparsed_span(source).compact_source
e1abca2527da more explicit type Span in Scala, according to ML version;
wenzelm
parents: 57842
diff changeset
   273
    new Command(id, Document.Node.Name.empty, Nil, span1, source1, results, markup)
55648
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   274
  }
49414
d7b5fb2e9ca2 some support for inital command markup;
wenzelm
parents: 49359
diff changeset
   275
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   276
  def unparsed(source: String): Command =
52530
99dd8b4ef3fe explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents: 52527
diff changeset
   277
    unparsed(Document_ID.none, source, Results.empty, Markup_Tree.empty)
44384
8f6054a63f96 some support for editor perspective;
wenzelm
parents: 43714
diff changeset
   278
52530
99dd8b4ef3fe explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents: 52527
diff changeset
   279
  def rich_text(id: Document_ID.Command, results: Results, body: XML.Body): Command =
49414
d7b5fb2e9ca2 some support for inital command markup;
wenzelm
parents: 49359
diff changeset
   280
  {
49466
99ed1f422635 tuned signature;
wenzelm
parents: 49445
diff changeset
   281
    val text = XML.content(body)
99ed1f422635 tuned signature;
wenzelm
parents: 49445
diff changeset
   282
    val markup = Markup_Tree.from_XML(body)
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   283
    unparsed(id, text, results, markup)
49414
d7b5fb2e9ca2 some support for inital command markup;
wenzelm
parents: 49359
diff changeset
   284
  }
49359
c1262d7389fb refined output panel: more value-oriented approach to update and caret focus;
wenzelm
parents: 49037
diff changeset
   285
44384
8f6054a63f96 some support for editor perspective;
wenzelm
parents: 43714
diff changeset
   286
8f6054a63f96 some support for editor perspective;
wenzelm
parents: 43714
diff changeset
   287
  /* perspective */
8f6054a63f96 some support for editor perspective;
wenzelm
parents: 43714
diff changeset
   288
44474
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   289
  object Perspective
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   290
  {
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   291
    val empty: Perspective = Perspective(Nil)
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   292
  }
44385
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44384
diff changeset
   293
44474
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   294
  sealed case class Perspective(commands: List[Command])  // visible commands in canonical order
44385
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44384
diff changeset
   295
  {
57615
df1b3452d71c more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents: 56782
diff changeset
   296
    def is_empty: Boolean = commands.isEmpty
df1b3452d71c more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents: 56782
diff changeset
   297
44474
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   298
    def same(that: Perspective): Boolean =
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   299
    {
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   300
      val cmds1 = this.commands
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   301
      val cmds2 = that.commands
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48745
diff changeset
   302
      require(!cmds1.exists(_.is_undefined))
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48745
diff changeset
   303
      require(!cmds2.exists(_.is_undefined))
44474
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   304
      cmds1.length == cmds2.length &&
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   305
        (cmds1.iterator zip cmds2.iterator).forall({ case (c1, c2) => c1.id == c2.id })
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   306
    }
44385
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44384
diff changeset
   307
  }
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   308
}
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   309
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
   310
46712
8650d9a95736 prefer final ADTs -- prevent ooddities;
wenzelm
parents: 46164
diff changeset
   311
final class Command private(
52530
99dd8b4ef3fe explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents: 52527
diff changeset
   312
    val id: Document_ID.Command,
44615
a4ff8a787202 more abstract Document.Node.Name;
wenzelm
parents: 44607
diff changeset
   313
    val node_name: Document.Node.Name,
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54517
diff changeset
   314
    val blobs: List[Command.Blob],
57901
e1abca2527da more explicit type Span in Scala, according to ML version;
wenzelm
parents: 57842
diff changeset
   315
    val span: Thy_Syntax.Span,
49414
d7b5fb2e9ca2 some support for inital command markup;
wenzelm
parents: 49359
diff changeset
   316
    val source: String,
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   317
    val init_results: Command.Results,
49414
d7b5fb2e9ca2 some support for inital command markup;
wenzelm
parents: 49359
diff changeset
   318
    val init_markup: Markup_Tree)
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
   319
{
34859
f986d84dd44b renamed Command.content to source;
wenzelm
parents: 34858
diff changeset
   320
  /* classification */
34500
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
   321
52530
99dd8b4ef3fe explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents: 52527
diff changeset
   322
  def is_undefined: Boolean = id == Document_ID.none
57901
e1abca2527da more explicit type Span in Scala, according to ML version;
wenzelm
parents: 57842
diff changeset
   323
  val is_unparsed: Boolean = span.content.exists(_.is_unparsed)
e1abca2527da more explicit type Span in Scala, according to ML version;
wenzelm
parents: 57842
diff changeset
   324
  val is_unfinished: Boolean = span.content.exists(_.is_unfinished)
44385
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44384
diff changeset
   325
57901
e1abca2527da more explicit type Span in Scala, according to ML version;
wenzelm
parents: 57842
diff changeset
   326
  def is_command: Boolean = span.kind.isInstanceOf[Thy_Syntax.Command_Span]
e1abca2527da more explicit type Span in Scala, according to ML version;
wenzelm
parents: 57842
diff changeset
   327
  def is_ignored: Boolean = span.kind == Thy_Syntax.Ignored_Span
34859
f986d84dd44b renamed Command.content to source;
wenzelm
parents: 34858
diff changeset
   328
57901
e1abca2527da more explicit type Span in Scala, according to ML version;
wenzelm
parents: 57842
diff changeset
   329
  def name: String =
e1abca2527da more explicit type Span in Scala, according to ML version;
wenzelm
parents: 57842
diff changeset
   330
    span.kind match { case Thy_Syntax.Command_Span(name) => name case _ => "" }
47012
0e246130486b clarified command span classification: strict Command.is_command, permissive Command.name;
wenzelm
parents: 46910
diff changeset
   331
57902
3f1fd41ee821 tuned output, in accordance to transaction name in ML;
wenzelm
parents: 57901
diff changeset
   332
  override def toString = id + "/" + span.kind.toString
34495
722533c532da Command: added name field and toString;
wenzelm
parents: 34491
diff changeset
   333
34859
f986d84dd44b renamed Command.content to source;
wenzelm
parents: 34858
diff changeset
   334
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54517
diff changeset
   335
  /* blobs */
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54517
diff changeset
   336
54530
2c1440f70028 ranges of thy_load commands count as visible within perspective;
wenzelm
parents: 54524
diff changeset
   337
  def blobs_names: List[Document.Node.Name] =
2c1440f70028 ranges of thy_load commands count as visible within perspective;
wenzelm
parents: 54524
diff changeset
   338
    for (Exn.Res((name, _)) <- blobs) yield name
2c1440f70028 ranges of thy_load commands count as visible within perspective;
wenzelm
parents: 54524
diff changeset
   339
57842
8e4ae2db1849 more direct access to persistent blobs (see also 8953d4cc060a), avoiding fragile digest lookup from later version (which might have removed unused blobs already);
wenzelm
parents: 57615
diff changeset
   340
  def blobs_defined: List[(Document.Node.Name, SHA1.Digest)] =
8e4ae2db1849 more direct access to persistent blobs (see also 8953d4cc060a), avoiding fragile digest lookup from later version (which might have removed unused blobs already);
wenzelm
parents: 57615
diff changeset
   341
    for (Exn.Res((name, Some((digest, _)))) <- blobs) yield (name, digest)
8e4ae2db1849 more direct access to persistent blobs (see also 8953d4cc060a), avoiding fragile digest lookup from later version (which might have removed unused blobs already);
wenzelm
parents: 57615
diff changeset
   342
8e4ae2db1849 more direct access to persistent blobs (see also 8953d4cc060a), avoiding fragile digest lookup from later version (which might have removed unused blobs already);
wenzelm
parents: 57615
diff changeset
   343
  def blobs_changed(doc_blobs: Document.Blobs): Boolean =
8e4ae2db1849 more direct access to persistent blobs (see also 8953d4cc060a), avoiding fragile digest lookup from later version (which might have removed unused blobs already);
wenzelm
parents: 57615
diff changeset
   344
    blobs.exists({ case Exn.Res((name, _)) => doc_blobs.changed(name) case _ => false })
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54517
diff changeset
   345
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   346
56462
b64b0cb845fe more explicit Command.Chunk types, less ooddities;
wenzelm
parents: 56395
diff changeset
   347
  /* source chunks */
55431
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   348
56746
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
   349
  val chunk: Symbol.Text_Chunk = Symbol.Text_Chunk(source)
56473
5b5c750e9763 simplified Text.Chunk -- eliminated ooddities;
wenzelm
parents: 56470
diff changeset
   350
56746
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
   351
  val chunks: Map[Symbol.Text_Chunk.Name, Symbol.Text_Chunk] =
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
   352
    ((Symbol.Text_Chunk.Default -> chunk) ::
56473
5b5c750e9763 simplified Text.Chunk -- eliminated ooddities;
wenzelm
parents: 56470
diff changeset
   353
      (for (Exn.Res((name, Some((_, file)))) <- blobs)
56746
d37a5d09a277 tuned signature;
wenzelm
parents: 56743
diff changeset
   354
        yield (Symbol.Text_Chunk.File(name.node) -> file))).toMap
56473
5b5c750e9763 simplified Text.Chunk -- eliminated ooddities;
wenzelm
parents: 56470
diff changeset
   355
46813
bb7280848c99 added Command.proper_range (still unused);
wenzelm
parents: 46712
diff changeset
   356
  def length: Int = source.length
56473
5b5c750e9763 simplified Text.Chunk -- eliminated ooddities;
wenzelm
parents: 56470
diff changeset
   357
  def range: Text.Range = chunk.range
46813
bb7280848c99 added Command.proper_range (still unused);
wenzelm
parents: 46712
diff changeset
   358
bb7280848c99 added Command.proper_range (still unused);
wenzelm
parents: 46712
diff changeset
   359
  val proper_range: Text.Range =
57901
e1abca2527da more explicit type Span in Scala, according to ML version;
wenzelm
parents: 57842
diff changeset
   360
    Text.Range(0,
e1abca2527da more explicit type Span in Scala, according to ML version;
wenzelm
parents: 57842
diff changeset
   361
      (length /: span.content.reverse.iterator.takeWhile(_.is_improper))(_ - _.source.length))
46813
bb7280848c99 added Command.proper_range (still unused);
wenzelm
parents: 46712
diff changeset
   362
38426
2858ec7b6dd8 specific types Text.Offset and Text.Range;
wenzelm
parents: 38415
diff changeset
   363
  def source(range: Text.Range): String = source.substring(range.start, range.stop)
38572
0fe2c01ef7da Command.State: accumulate markup reports uniformly;
wenzelm
parents: 38564
diff changeset
   364
38370
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38367
diff changeset
   365
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38367
diff changeset
   366
  /* accumulated results */
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38367
diff changeset
   367
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   368
  val init_state: Command.State =
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   369
    Command.State(this, results = init_results, markups = Command.Markups.init(init_markup))
52527
dbac84eab3bc separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents: 52524
diff changeset
   370
dbac84eab3bc separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents: 52524
diff changeset
   371
  val empty_state: Command.State = Command.State(this)
34676
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
   372
}