src/Pure/PIDE/command.scala
author wenzelm
Sat, 01 Mar 2014 15:58:47 +0100
changeset 55822 ccf2d784be97
parent 55785 3086f57e48e9
child 55884 f2c0eaedd579
permissions -rw-r--r--
incorporate chunk range that is 1 off end-of-input, for improved error positions (NB: command spans are tight, without trailing whitespace); tuned signature;
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])
55648
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
    18
  type Blob = Exn.Result[(Document.Node.Name, Option[(SHA1.Digest, File)])]
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)
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
    30
    def make(es: Iterable[Results.Entry]): Results = (empty /: es.iterator)(_ + _)
50507
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    31
    def merge(rs: Iterable[Results]): Results = (empty /: rs.iterator)(_ ++ _)
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)
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
    38
    def entries: 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
5b7150395568 tuned implementation according to Library.insert/merge in ML;
wenzelm
parents: 50507
diff changeset
    47
      else (this /: other.entries)(_ + _)
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
      }
50540
wenzelm
parents: 50508
diff changeset
    55
    override def toString: String = entries.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
  {
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    63
    val markup: Markup_Index = Markup_Index(false, "")
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
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    66
  sealed case class Markup_Index(status: Boolean, file_name: String)
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
  {
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    78
    def apply(index: Markup_Index): Markup_Tree =
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    79
      rep.getOrElse(index, Markup_Tree.empty)
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    80
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    81
    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
    82
      new Markups(rep + (index -> (this(index) + markup)))
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    83
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    84
    def ++ (other: Markups): Markups =
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    85
      new Markups(
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    86
        (rep.keySet ++ other.rep.keySet)
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    87
          .map(index => index -> (this(index) ++ other(index))).toMap)
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    88
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    89
    override def hashCode: Int = rep.hashCode
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    90
    override def equals(that: Any): Boolean =
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    91
      that match {
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    92
        case other: Markups => rep == other.rep
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    93
        case _ => false
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    94
      }
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    95
    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
    96
  }
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    97
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
    98
50507
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
    99
  /* state */
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   100
43714
3749d1e6dde9 tuned signature;
wenzelm
parents: 43662
diff changeset
   101
  sealed case class State(
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   102
    command: Command,
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   103
    status: List[Markup] = Nil,
50507
9605b0d93d1e more formal class Command.Results;
wenzelm
parents: 50501
diff changeset
   104
    results: Results = Results.empty,
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   105
    markups: Markups = Markups.empty)
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
   106
  {
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   107
    /* markup */
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   108
55650
349afd0fa0c4 tuned signature;
wenzelm
parents: 55649
diff changeset
   109
    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
   110
49645
5a0817ec0314 tuned signature;
wenzelm
parents: 49614
diff changeset
   111
    def markup_to_XML(filter: XML.Elem => Boolean): XML.Body =
55650
349afd0fa0c4 tuned signature;
wenzelm
parents: 55649
diff changeset
   112
      markup(Markup_Index.markup).to_XML(command.range, command.source, filter)
49614
0009a6ebc83b operations to turn markup into XML;
wenzelm
parents: 49527
diff changeset
   113
0009a6ebc83b operations to turn markup into XML;
wenzelm
parents: 49527
diff changeset
   114
51494
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
   115
    /* content */
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
   116
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
   117
    def eq_content(other: State): Boolean =
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
   118
      command.source == other.command.source &&
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
   119
      status == other.status &&
8f3d1a7bee26 structural equality for Command.Results;
wenzelm
parents: 51048
diff changeset
   120
      results == other.results &&
55434
aa2918d967f0 more accurate eq_content;
wenzelm
parents: 55433
diff changeset
   121
      markups == other.markups
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
   122
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   123
    private def add_status(st: Markup): State =
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   124
      copy(status = st :: status)
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   125
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   126
    private def add_markup(status: Boolean, file_name: String, m: Text.Markup): State =
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   127
    {
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   128
      val markups1 =
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   129
        if (status || Protocol.status_elements(m.info.name))
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   130
          markups.add(Markup_Index(true, file_name), m)
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   131
        else markups
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   132
      copy(markups = markups1.add(Markup_Index(false, file_name), m))
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   133
    }
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
   134
52531
21f8e0e151f5 tuned signature;
wenzelm
parents: 52530
diff changeset
   135
    def + (alt_id: Document_ID.Generic, message: XML.Elem): State =
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
   136
      message match {
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   137
        case XML.Elem(Markup(Markup.STATUS, _), msgs) =>
38714
31da698fc4e5 more precise Command.State accumulation;
wenzelm
parents: 38658
diff changeset
   138
          (this /: msgs)((state, msg) =>
31da698fc4e5 more precise Command.State accumulation;
wenzelm
parents: 38658
diff changeset
   139
            msg match {
46152
793cecd4ffc0 accumulate status as regular markup for command range;
wenzelm
parents: 45709
diff changeset
   140
              case elem @ XML.Elem(markup, Nil) =>
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   141
                state.
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   142
                  add_status(markup).
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   143
                  add_markup(true, "", Text.Info(command.proper_range, elem))
52536
3a35ce87a55c tuned signature;
wenzelm
parents: 52535
diff changeset
   144
              case _ =>
55618
995162143ef4 tuned imports;
wenzelm
parents: 55548
diff changeset
   145
                System.err.println("Ignored status message: " + msg)
52536
3a35ce87a55c tuned signature;
wenzelm
parents: 52535
diff changeset
   146
                state
38714
31da698fc4e5 more precise Command.State accumulation;
wenzelm
parents: 38658
diff changeset
   147
            })
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
   148
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   149
        case XML.Elem(Markup(Markup.REPORT, _), msgs) =>
38572
0fe2c01ef7da Command.State: accumulate markup reports uniformly;
wenzelm
parents: 38564
diff changeset
   150
          (this /: msgs)((state, msg) =>
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   151
            {
55618
995162143ef4 tuned imports;
wenzelm
parents: 55548
diff changeset
   152
              def bad(): Unit = System.err.println("Ignored report message: " + msg)
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   153
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   154
              msg match {
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   155
                case XML.Elem(Markup(name, atts @ Position.Reported(id, file_name, raw_range)), args)
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   156
                if id == command.id || id == alt_id =>
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   157
                  command.chunks.get(file_name) match {
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   158
                    case Some(chunk) =>
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
   159
                      chunk.incorporate(raw_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
   160
                        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
   161
                          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
   162
                          val info = Text.Info(range, XML.Elem(Markup(name, props), args))
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
   163
                          state.add_markup(false, file_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
   164
                        case None => bad(); state
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   165
                      }
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
   166
                    case None => bad(); state
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   167
                  }
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   168
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   169
                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
   170
                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
   171
                  val range = command.proper_range
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   172
                  val props = Position.purge(atts)
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   173
                  val info: Text.Markup = Text.Info(range, XML.Elem(Markup(name, props), args))
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   174
                  state.add_markup(false, "", info)
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   175
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
   176
                case _ => /* FIXME bad(); */ state
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   177
              }
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
   178
            })
52930
5fab62ae3532 retain original messages properties, e.g. for retrieval via Command.Results;
wenzelm
parents: 52849
diff changeset
   179
        case XML.Elem(Markup(name, props), body) =>
5fab62ae3532 retain original messages properties, e.g. for retrieval via Command.Results;
wenzelm
parents: 52849
diff changeset
   180
          props match {
50201
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   181
            case Markup.Serial(i) =>
c26369c9eda6 Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents: 50163
diff changeset
   182
              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
   183
              val message2 = XML.Elem(Markup(name, props), body)
c62ce309dc26 more abstract Sendback operations, with explicit id/exec_id properties;
wenzelm
parents: 50158
diff changeset
   184
55433
d2960d67f163 clarified message_positions: cover alt_id as well;
wenzelm
parents: 55432
diff changeset
   185
              var st = copy(results = results + (i -> message1))
d2960d67f163 clarified message_positions: cover alt_id as well;
wenzelm
parents: 55432
diff changeset
   186
              if (Protocol.is_inlined(message)) {
d2960d67f163 clarified message_positions: cover alt_id as well;
wenzelm
parents: 55432
diff changeset
   187
                for {
d2960d67f163 clarified message_positions: cover alt_id as well;
wenzelm
parents: 55432
diff changeset
   188
                  (file_name, chunk) <- command.chunks
d2960d67f163 clarified message_positions: cover alt_id as well;
wenzelm
parents: 55432
diff changeset
   189
                  range <- Protocol.message_positions(command.id, alt_id, chunk, message)
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   190
                } st = st.add_markup(false, file_name, Text.Info(range, message2))
55433
d2960d67f163 clarified message_positions: cover alt_id as well;
wenzelm
parents: 55432
diff changeset
   191
              }
d2960d67f163 clarified message_positions: cover alt_id as well;
wenzelm
parents: 55432
diff changeset
   192
              st
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   193
52536
3a35ce87a55c tuned signature;
wenzelm
parents: 52535
diff changeset
   194
            case _ =>
55618
995162143ef4 tuned imports;
wenzelm
parents: 55548
diff changeset
   195
              System.err.println("Ignored message without serial number: " + message)
52536
3a35ce87a55c tuned signature;
wenzelm
parents: 52535
diff changeset
   196
              this
38872
26c505765024 Command.results: ordered by serial number;
wenzelm
parents: 38723
diff changeset
   197
          }
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
   198
      }
52527
dbac84eab3bc separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents: 52524
diff changeset
   199
dbac84eab3bc separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents: 52524
diff changeset
   200
    def ++ (other: State): State =
52642
84eb792224a8 full merge of Command.State, which enables Command.prints to augment markup as well (assuming that these dynamic overlays are relatively few);
wenzelm
parents: 52536
diff changeset
   201
      copy(
84eb792224a8 full merge of Command.State, which enables Command.prints to augment markup as well (assuming that these dynamic overlays are relatively few);
wenzelm
parents: 52536
diff changeset
   202
        status = other.status ::: status,
84eb792224a8 full merge of Command.State, which enables Command.prints to augment markup as well (assuming that these dynamic overlays are relatively few);
wenzelm
parents: 52536
diff changeset
   203
        results = results ++ other.results,
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   204
        markups = markups ++ other.markups
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   205
      )
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
   206
  }
38367
f7d2574dc3a6 more basic notion of unparsed input;
wenzelm
parents: 38363
diff changeset
   207
f7d2574dc3a6 more basic notion of unparsed input;
wenzelm
parents: 38363
diff changeset
   208
55431
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   209
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   210
  /** static content **/
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   211
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   212
  /* text chunks */
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   213
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   214
  abstract class Chunk
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   215
  {
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   216
    def file_name: String
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   217
    def length: Int
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   218
    def range: Text.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
   219
    def decode(raw_range: Text.Range): Text.Range
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
   220
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
   221
    def incorporate(raw_range: Text.Range): Option[Text.Range] =
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
   222
    {
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
   223
      def inc(r: Text.Range): Option[Text.Range] =
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
   224
        range.try_restrict(decode(r)) match {
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
   225
          case Some(r1) if !r1.is_singularity => Some(r1)
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
   226
          case _ => None
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
   227
        }
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
   228
     inc(raw_range) orElse inc(raw_range - 1)
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
   229
    }
55431
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   230
  }
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   231
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   232
  class File(val file_name: String, text: CharSequence) extends Chunk
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   233
  {
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   234
    val length = text.length
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   235
    val range = Text.Range(0, length)
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   236
    private val symbol_index = Symbol.Index(text)
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
   237
    def decode(raw_range: Text.Range): Text.Range = symbol_index.decode(raw_range)
55777
90484dff4dc4 tuned output;
wenzelm
parents: 55650
diff changeset
   238
90484dff4dc4 tuned output;
wenzelm
parents: 55650
diff changeset
   239
    override def toString: String = "Command.File(" + file_name + ")"
55431
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   240
  }
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   241
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   242
45644
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   243
  /* make commands */
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   244
54462
c9bb76303348 explicit indication of thy_load commands;
wenzelm
parents: 52930
diff changeset
   245
  def name(span: List[Token]): String =
c9bb76303348 explicit indication of thy_load commands;
wenzelm
parents: 52930
diff changeset
   246
    span.find(_.is_command) match { case Some(tok) => tok.source case _ => "" }
48745
184158734fba tuned signature;
wenzelm
parents: 48718
diff changeset
   247
55648
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   248
  private def source_span(span: List[Token]): (String, List[Token]) =
45644
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   249
  {
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   250
    val source: String =
48745
184158734fba tuned signature;
wenzelm
parents: 48718
diff changeset
   251
      span match {
45644
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   252
        case List(tok) => tok.source
48745
184158734fba tuned signature;
wenzelm
parents: 48718
diff changeset
   253
        case _ => span.map(_.source).mkString
45644
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   254
      }
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   255
48745
184158734fba tuned signature;
wenzelm
parents: 48718
diff changeset
   256
    val span1 = new mutable.ListBuffer[Token]
45644
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   257
    var i = 0
48745
184158734fba tuned signature;
wenzelm
parents: 48718
diff changeset
   258
    for (Token(kind, s) <- span) {
45644
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   259
      val n = s.length
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   260
      val s1 = source.substring(i, i + n)
48745
184158734fba tuned signature;
wenzelm
parents: 48718
diff changeset
   261
      span1 += Token(kind, s1)
45644
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   262
      i += n
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   263
    }
55648
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   264
    (source, span1.toList)
45644
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   265
  }
8634b4e61b88 sharing of token source with span source;
wenzelm
parents: 45455
diff changeset
   266
55648
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   267
  def apply(
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   268
    id: Document_ID.Command,
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   269
    node_name: Document.Node.Name,
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   270
    blobs: List[Blob],
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   271
    span: List[Token]): Command =
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   272
  {
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   273
    val (source, span1) = source_span(span)
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   274
    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
   275
  }
49414
d7b5fb2e9ca2 some support for inital command markup;
wenzelm
parents: 49359
diff changeset
   276
55648
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   277
  val empty: Command = Command(Document_ID.none, Document.Node.Name.empty, Nil, Nil)
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   278
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   279
  def unparsed(
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   280
    id: Document_ID.Command,
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   281
    source: String,
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   282
    results: Results,
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   283
    markup: Markup_Tree): Command =
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   284
  {
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   285
    val (source1, span) = source_span(List(Token(Token.Kind.UNPARSED, source)))
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   286
    new Command(id, Document.Node.Name.empty, Nil, span, source1, results, markup)
38f264741609 tuned signature -- avoid obscure default arguments;
wenzelm
parents: 55622
diff changeset
   287
  }
49414
d7b5fb2e9ca2 some support for inital command markup;
wenzelm
parents: 49359
diff changeset
   288
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   289
  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
   290
    unparsed(Document_ID.none, source, Results.empty, Markup_Tree.empty)
44384
8f6054a63f96 some support for editor perspective;
wenzelm
parents: 43714
diff changeset
   291
52530
99dd8b4ef3fe explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents: 52527
diff changeset
   292
  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
   293
  {
49466
99ed1f422635 tuned signature;
wenzelm
parents: 49445
diff changeset
   294
    val text = XML.content(body)
99ed1f422635 tuned signature;
wenzelm
parents: 49445
diff changeset
   295
    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
   296
    unparsed(id, text, results, markup)
49414
d7b5fb2e9ca2 some support for inital command markup;
wenzelm
parents: 49359
diff changeset
   297
  }
49359
c1262d7389fb refined output panel: more value-oriented approach to update and caret focus;
wenzelm
parents: 49037
diff changeset
   298
44384
8f6054a63f96 some support for editor perspective;
wenzelm
parents: 43714
diff changeset
   299
8f6054a63f96 some support for editor perspective;
wenzelm
parents: 43714
diff changeset
   300
  /* perspective */
8f6054a63f96 some support for editor perspective;
wenzelm
parents: 43714
diff changeset
   301
44474
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   302
  object Perspective
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   303
  {
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   304
    val empty: Perspective = Perspective(Nil)
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   305
  }
44385
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44384
diff changeset
   306
44474
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   307
  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
   308
  {
44474
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   309
    def same(that: Perspective): Boolean =
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   310
    {
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   311
      val cmds1 = this.commands
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   312
      val cmds2 = that.commands
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48745
diff changeset
   313
      require(!cmds1.exists(_.is_undefined))
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48745
diff changeset
   314
      require(!cmds2.exists(_.is_undefined))
44474
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   315
      cmds1.length == cmds2.length &&
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   316
        (cmds1.iterator zip cmds2.iterator).forall({ case (c1, c2) => c1.id == c2.id })
681447a9ffe5 slightly more abstract Command.Perspective;
wenzelm
parents: 44385
diff changeset
   317
    }
44385
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44384
diff changeset
   318
  }
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   319
}
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   320
38361
b609d0b271fa specific command state;
wenzelm
parents: 38360
diff changeset
   321
46712
8650d9a95736 prefer final ADTs -- prevent ooddities;
wenzelm
parents: 46164
diff changeset
   322
final class Command private(
52530
99dd8b4ef3fe explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents: 52527
diff changeset
   323
    val id: Document_ID.Command,
44615
a4ff8a787202 more abstract Document.Node.Name;
wenzelm
parents: 44607
diff changeset
   324
    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
   325
    val blobs: List[Command.Blob],
52535
b7badd371e4d tuned signature -- eliminated pointless type synonym;
wenzelm
parents: 52531
diff changeset
   326
    val span: List[Token],
49414
d7b5fb2e9ca2 some support for inital command markup;
wenzelm
parents: 49359
diff changeset
   327
    val source: String,
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   328
    val init_results: Command.Results,
49414
d7b5fb2e9ca2 some support for inital command markup;
wenzelm
parents: 49359
diff changeset
   329
    val init_markup: Markup_Tree)
55431
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   330
  extends Command.Chunk
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
   331
{
34859
f986d84dd44b renamed Command.content to source;
wenzelm
parents: 34858
diff changeset
   332
  /* classification */
34500
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
   333
52530
99dd8b4ef3fe explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents: 52527
diff changeset
   334
  def is_undefined: Boolean = id == Document_ID.none
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48745
diff changeset
   335
  val is_unparsed: Boolean = span.exists(_.is_unparsed)
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48745
diff changeset
   336
  val is_unfinished: Boolean = span.exists(_.is_unfinished)
44385
e7fdb008aa7d propagate editor perspective through document model;
wenzelm
parents: 44384
diff changeset
   337
48599
5e64b7770f35 tuned signature;
wenzelm
parents: 47459
diff changeset
   338
  val is_ignored: Boolean = !span.exists(_.is_proper)
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48745
diff changeset
   339
  val is_malformed: Boolean = !is_ignored && (!span.head.is_command || span.exists(_.is_error))
47012
0e246130486b clarified command span classification: strict Command.is_command, permissive Command.name;
wenzelm
parents: 46910
diff changeset
   340
  def is_command: Boolean = !is_ignored && !is_malformed
34859
f986d84dd44b renamed Command.content to source;
wenzelm
parents: 34858
diff changeset
   341
54462
c9bb76303348 explicit indication of thy_load commands;
wenzelm
parents: 52930
diff changeset
   342
  def name: String = Command.name(span)
47012
0e246130486b clarified command span classification: strict Command.is_command, permissive Command.name;
wenzelm
parents: 46910
diff changeset
   343
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 36990
diff changeset
   344
  override def toString =
37373
25078ba44436 tuned Command.toString -- preserving uniqueness allows the Scala toplevel to print Linear_Set[Command] results without crashing;
wenzelm
parents: 37197
diff changeset
   345
    id + "/" + (if (is_command) name else if (is_ignored) "IGNORED" else "MALFORMED")
34495
722533c532da Command: added name field and toString;
wenzelm
parents: 34491
diff changeset
   346
34859
f986d84dd44b renamed Command.content to source;
wenzelm
parents: 34858
diff changeset
   347
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54517
diff changeset
   348
  /* blobs */
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54517
diff changeset
   349
55785
3086f57e48e9 reparse only for actually changed blobs;
wenzelm
parents: 55777
diff changeset
   350
  def blobs_changed(doc_blobs: Document.Blobs): Boolean =
3086f57e48e9 reparse only for actually changed blobs;
wenzelm
parents: 55777
diff changeset
   351
    blobs.exists({ case Exn.Res((name, _)) => doc_blobs.changed(name) case _ => false })
3086f57e48e9 reparse only for actually changed blobs;
wenzelm
parents: 55777
diff changeset
   352
54530
2c1440f70028 ranges of thy_load commands count as visible within perspective;
wenzelm
parents: 54524
diff changeset
   353
  def blobs_names: List[Document.Node.Name] =
2c1440f70028 ranges of thy_load commands count as visible within perspective;
wenzelm
parents: 54524
diff changeset
   354
    for (Exn.Res((name, _)) <- blobs) yield name
2c1440f70028 ranges of thy_load commands count as visible within perspective;
wenzelm
parents: 54524
diff changeset
   355
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54517
diff changeset
   356
  def blobs_digests: List[SHA1.Digest] =
55431
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   357
    for (Exn.Res((_, Some((digest, _)))) <- blobs) yield digest
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54517
diff changeset
   358
55432
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   359
  val chunks: Map[String, Command.Chunk] =
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   360
    (("" -> this) ::
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   361
      (for (Exn.Res((name, Some((_, file)))) <- blobs) yield (name.node -> file))).toMap
9c53198dbb1c maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents: 55431
diff changeset
   362
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54517
diff changeset
   363
52509
2193d2c7f586 tuned signature;
wenzelm
parents: 52507
diff changeset
   364
  /* source */
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
   365
55431
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   366
  def file_name: String = ""
e0f20a44ff9d common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents: 55430
diff changeset
   367
46813
bb7280848c99 added Command.proper_range (still unused);
wenzelm
parents: 46712
diff changeset
   368
  def length: Int = source.length
bb7280848c99 added Command.proper_range (still unused);
wenzelm
parents: 46712
diff changeset
   369
  val range: Text.Range = Text.Range(0, length)
bb7280848c99 added Command.proper_range (still unused);
wenzelm
parents: 46712
diff changeset
   370
bb7280848c99 added Command.proper_range (still unused);
wenzelm
parents: 46712
diff changeset
   371
  val proper_range: Text.Range =
51048
123be08eed88 clarified notion of Command.proper_range (according to Token.is_proper), especially relevant for Active.try_replace_command, to avoid loosing subsequent comments accidentally;
wenzelm
parents: 50540
diff changeset
   372
    Text.Range(0, (length /: span.reverse.iterator.takeWhile(_.is_improper))(_ - _.source.length))
46813
bb7280848c99 added Command.proper_range (still unused);
wenzelm
parents: 46712
diff changeset
   373
38426
2858ec7b6dd8 specific types Text.Offset and Text.Range;
wenzelm
parents: 38415
diff changeset
   374
  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
   375
55430
8eb6c740ec1a tuned signature;
wenzelm
parents: 55429
diff changeset
   376
  private lazy val symbol_index = Symbol.Index(source)
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
   377
  def decode(raw_offset: Text.Offset): Text.Offset = symbol_index.decode(raw_offset)
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
   378
  def decode(raw_range: Text.Range): Text.Range = symbol_index.decode(raw_range)
38370
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38367
diff changeset
   379
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38367
diff changeset
   380
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38367
diff changeset
   381
  /* accumulated results */
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38367
diff changeset
   382
50501
6f41f1646617 more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents: 50500
diff changeset
   383
  val init_state: Command.State =
55649
1532ab0dc67b more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents: 55648
diff changeset
   384
    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
   385
dbac84eab3bc separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents: 52524
diff changeset
   386
  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
   387
}