src/Tools/jEdit/src/prover/Prover.scala
author immler@in.tum.de
Thu, 27 Aug 2009 10:51:09 +0200
changeset 34671 d179fcb04cbc
parent 34660 e0561943bfc9
child 34672 20e8dcd29a8b
permissions -rw-r--r--
output_info specific to prover
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34407
aad6834ba380 added some headers and comments;
wenzelm
parents: 34404
diff changeset
     1
/*
34501
01021d160be7 beginnings of global document state;
wenzelm
parents: 34499
diff changeset
     2
 * Higher-level prover communication: interactive document model
34407
aad6834ba380 added some headers and comments;
wenzelm
parents: 34404
diff changeset
     3
 *
aad6834ba380 added some headers and comments;
wenzelm
parents: 34404
diff changeset
     4
 * @author Johannes Hölzl, TU Munich
aad6834ba380 added some headers and comments;
wenzelm
parents: 34404
diff changeset
     5
 * @author Fabian Immler, TU Munich
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
     6
 * @author Makarius
34407
aad6834ba380 added some headers and comments;
wenzelm
parents: 34404
diff changeset
     7
 */
aad6834ba380 added some headers and comments;
wenzelm
parents: 34404
diff changeset
     8
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
     9
package isabelle.prover
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    10
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    11
34497
184fda8cce04 more explicit indication of mutable collections;
wenzelm
parents: 34494
diff changeset
    12
import scala.collection.mutable
34475
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    13
import scala.collection.immutable.{TreeSet}
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    14
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    15
import scala.actors.Actor
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    16
import scala.actors.Actor._
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    17
34456
14367c0715e8 replaced EventSource by EventBus;
wenzelm
parents: 34454
diff changeset
    18
import org.gjt.sp.util.Log
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34660
diff changeset
    19
import javax.swing.JTextArea
34456
14367c0715e8 replaced EventSource by EventBus;
wenzelm
parents: 34454
diff changeset
    20
34501
01021d160be7 beginnings of global document state;
wenzelm
parents: 34499
diff changeset
    21
import isabelle.jedit.Isabelle
34660
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
    22
import isabelle.proofdocument.{ProofDocument, Change, Token}
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    23
import isabelle.IsarDocument
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    24
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    25
object ProverEvents {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    26
  case class Activate
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    27
}
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
    28
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
    29
class Prover(isabelle_system: Isabelle_System, logic: String) extends Actor
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
    30
{
34504
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    31
  /* prover process */
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    32
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    33
  private val process =
34504
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    34
  {
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
    35
    val results = new EventBus[Isabelle_Process.Result] + handle_result
34504
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    36
    results.logger = Log.log(Log.ERROR, null, _)
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
    37
    new Isabelle_Process(isabelle_system, results, "-m", "xsymbols", logic) with IsarDocument
34504
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    38
  }
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    39
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    40
  def stop() { process.kill }
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    41
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    42
  
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    43
  /* document state information */
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    44
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    45
  private val states = new mutable.HashMap[IsarDocument.State_ID, Command] with
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    46
    mutable.SynchronizedMap[IsarDocument.State_ID, Command]
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    47
  private val commands = new mutable.HashMap[IsarDocument.Command_ID, Command] with
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    48
    mutable.SynchronizedMap[IsarDocument.Command_ID, Command]
34654
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
    49
  val document_0 =
34650
d7ba607bf684 current version in theoryview/buffer
immler@in.tum.de
parents: 34649
diff changeset
    50
    ProofDocument.empty.set_command_keyword(command_decls.contains)
d7ba607bf684 current version in theoryview/buffer
immler@in.tum.de
parents: 34649
diff changeset
    51
  private var document_versions = List(document_0)
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    52
34568
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
    53
  def command(id: IsarDocument.Command_ID): Option[Command] = commands.get(id)
34654
30f588245884 arbitrary history
immler@in.tum.de
parents: 34653
diff changeset
    54
  def document(id: IsarDocument.Document_ID) = document_versions.find(_.id == id)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    55
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    56
  private var initialized = false
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    57
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    58
  
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    59
  /* outer syntax keywords */
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    60
34465
ccadbf63e320 added EventBus for new command- or keyword-declarations
immler@in.tum.de
parents: 34462
diff changeset
    61
  val decl_info = new EventBus[(String, String)]
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    62
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    63
  private val keyword_decls =
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    64
    new mutable.HashSet[String] with mutable.SynchronizedSet[String] {
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    65
    override def +=(name: String) = {
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    66
      decl_info.event(name, OuterKeyword.MINOR)
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    67
      super.+=(name)
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    68
    }
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    69
  }
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    70
  private val command_decls =
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    71
    new mutable.HashMap[String, String] with mutable.SynchronizedMap[String, String] {
34471
1dac47492863 decl_info: cover both commands and keywords, with kind;
wenzelm
parents: 34466
diff changeset
    72
    override def +=(entry: (String, String)) = {
1dac47492863 decl_info: cover both commands and keywords, with kind;
wenzelm
parents: 34466
diff changeset
    73
      decl_info.event(entry)
1dac47492863 decl_info: cover both commands and keywords, with kind;
wenzelm
parents: 34466
diff changeset
    74
      super.+=(entry)
34465
ccadbf63e320 added EventBus for new command- or keyword-declarations
immler@in.tum.de
parents: 34462
diff changeset
    75
    }
ccadbf63e320 added EventBus for new command- or keyword-declarations
immler@in.tum.de
parents: 34462
diff changeset
    76
  }
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    77
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    78
34611
b40e43d70ae9 use isabelle.Completion;
wenzelm
parents: 34610
diff changeset
    79
  /* completions */
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    80
34612
5a03dc7a19e1 fall back on Isabelle system completion (symbols only);
wenzelm
parents: 34611
diff changeset
    81
  private var _completion = Isabelle.completion
5a03dc7a19e1 fall back on Isabelle system completion (symbols only);
wenzelm
parents: 34611
diff changeset
    82
  def completion = _completion
5a03dc7a19e1 fall back on Isabelle system completion (symbols only);
wenzelm
parents: 34611
diff changeset
    83
  decl_info += (p => _completion += p._1)
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    84
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    85
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    86
  /* event handling */
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34660
diff changeset
    87
  val output_info = new EventBus[Isabelle_Process.Result]
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34660
diff changeset
    88
  var change_receiver: Actor = null
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    89
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34660
diff changeset
    90
  val output_text_view = new JTextArea
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34660
diff changeset
    91
  output_info += (result => output_text_view.append(result.toString + "\n"))
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34660
diff changeset
    92
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
    93
  private def handle_result(result: Isabelle_Process.Result)
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    94
  {
34650
d7ba607bf684 current version in theoryview/buffer
immler@in.tum.de
parents: 34649
diff changeset
    95
    def command_change(c: Command) = change_receiver ! c
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
    96
    val (state, command) =
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    97
      result.props.find(p => p._1 == Markup.ID) match {
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
    98
        case None => (null, null)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    99
        case Some((_, id)) =>
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   100
          if (commands.contains(id)) (null, commands(id))
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   101
          else if (states.contains(id)) (id, states(id))
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   102
          else (null, null)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   103
      }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   104
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   105
    if (result.kind == Isabelle_Process.Kind.STDOUT ||
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   106
        result.kind == Isabelle_Process.Kind.STDIN)
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34660
diff changeset
   107
      output_info.event(result)
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   108
    else {
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   109
      result.kind match {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   110
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   111
        case Isabelle_Process.Kind.WRITELN
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   112
        | Isabelle_Process.Kind.PRIORITY
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   113
        | Isabelle_Process.Kind.WARNING
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   114
        | Isabelle_Process.Kind.ERROR =>
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   115
          if (command != null) {
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   116
            if (result.kind == Isabelle_Process.Kind.ERROR)
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   117
              command.set_status(state, Command.Status.FAILED)
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   118
            command.add_result(state, process.parse_message(result))
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   119
            command_change(command)
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   120
          } else {
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34660
diff changeset
   121
            output_info.event(result)
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   122
          }
34404
98155c35d252 delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents: 34401
diff changeset
   123
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   124
        case Isabelle_Process.Kind.STATUS =>
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   125
          //{{{ handle all kinds of status messages here
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   126
          process.parse_message(result) match {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   127
            case XML.Elem(Markup.MESSAGE, _, elems) =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   128
              for (elem <- elems) {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   129
                elem match {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   130
                  //{{{
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   131
                  // command and keyword declarations
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   132
                  case XML.Elem(Markup.COMMAND_DECL,
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   133
                      (Markup.NAME, name) :: (Markup.KIND, kind) :: _, _) =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   134
                    command_decls += (name -> kind)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   135
                  case XML.Elem(Markup.KEYWORD_DECL, (Markup.NAME, name) :: _, _) =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   136
                    keyword_decls += name
34404
98155c35d252 delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents: 34401
diff changeset
   137
34589
d461e5506d02 handle_result: activate via explicit status "ready" (cf. http://isabelle.in.tum.de/repos/isabelle/rev/ce169bd37fc0);
wenzelm
parents: 34582
diff changeset
   138
                  // process ready (after initialization)
d461e5506d02 handle_result: activate via explicit status "ready" (cf. http://isabelle.in.tum.de/repos/isabelle/rev/ce169bd37fc0);
wenzelm
parents: 34582
diff changeset
   139
                  case XML.Elem(Markup.READY, _, _)
d461e5506d02 handle_result: activate via explicit status "ready" (cf. http://isabelle.in.tum.de/repos/isabelle/rev/ce169bd37fc0);
wenzelm
parents: 34582
diff changeset
   140
                  if !initialized =>
d461e5506d02 handle_result: activate via explicit status "ready" (cf. http://isabelle.in.tum.de/repos/isabelle/rev/ce169bd37fc0);
wenzelm
parents: 34582
diff changeset
   141
                    initialized = true
34649
70759ca6bb87 activation
immler@in.tum.de
parents: 34634
diff changeset
   142
                    change_receiver ! ProverEvents.Activate
34589
d461e5506d02 handle_result: activate via explicit status "ready" (cf. http://isabelle.in.tum.de/repos/isabelle/rev/ce169bd37fc0);
wenzelm
parents: 34582
diff changeset
   143
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   144
                  // document edits
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   145
                  case XML.Elem(Markup.EDITS, (Markup.ID, doc_id) :: _, edits)
34582
5d5d253c7c29 superficial tuning;
wenzelm
parents: 34579
diff changeset
   146
                  if document_versions.exists(_.id == doc_id) =>
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34660
diff changeset
   147
                    output_info.event(result)
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   148
                    val doc = document_versions.find(_.id == doc_id).get
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   149
                    for {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   150
                      XML.Elem(Markup.EDIT, (Markup.ID, cmd_id) :: (Markup.STATE, state_id) :: _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   151
                        <- edits
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   152
                    } {
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   153
                      if (commands.contains(cmd_id)) {
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   154
                        val cmd = commands(cmd_id)
34540
immler@in.tum.de
parents: 34539
diff changeset
   155
                        states(state_id) = cmd
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   156
                        doc.states += (cmd -> state_id)
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   157
                        cmd.states += (state_id -> new Command_State(cmd))
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   158
                        command_change(cmd)
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   159
                      }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   160
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   161
                    }
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   162
                  // command status
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   163
                  case XML.Elem(Markup.UNPROCESSED, _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   164
                  if command != null =>
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34660
diff changeset
   165
                    output_info.event(result)
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   166
                    command.set_status(state, Command.Status.UNPROCESSED)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   167
                    command_change(command)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   168
                  case XML.Elem(Markup.FINISHED, _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   169
                  if command != null =>
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34660
diff changeset
   170
                    output_info.event(result)
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   171
                    command.set_status(state, Command.Status.FINISHED)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   172
                    command_change(command)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   173
                  case XML.Elem(Markup.FAILED, _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   174
                  if command != null =>
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34660
diff changeset
   175
                    output_info.event(result)
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   176
                    command.set_status(state, Command.Status.FAILED)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   177
                    command_change(command)
34570
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   178
                  case XML.Elem(kind, attr, body)
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   179
                  if command != null =>
34610
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   180
                    val (begin, end) = Position.offsets_of(attr)
34576
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   181
                    if (begin.isDefined && end.isDefined) {
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   182
                      if (kind == Markup.ML_TYPING) {
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   183
                        val info = body.first.asInstanceOf[XML.Text].content
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   184
                        command.add_markup(state,
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   185
                          command.markup_node(begin.get - 1, end.get - 1, TypeInfo(info)))
34576
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   186
                      } else if (kind == Markup.ML_REF) {
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   187
                        body match {
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   188
                          case List(XML.Elem(Markup.ML_DEF, attr, _)) =>
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   189
                            command.add_markup(state, command.markup_node(
34610
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   190
                              begin.get - 1, end.get - 1,
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   191
                              RefInfo(
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   192
                                Position.file_of(attr),
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   193
                                Position.line_of(attr),
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   194
                                Position.id_of(attr),
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   195
                                Position.offset_of(attr))))
34576
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   196
                          case _ =>
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   197
                        }
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   198
                      } else {
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   199
                        command.add_markup(state,
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   200
                          command.markup_node(begin.get - 1, end.get - 1, HighlightInfo(kind)))
34570
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   201
                      }
34557
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
   202
                    }
34555
7c001369956a included information on ML status messages in Sidekick's status-window
immler@in.tum.de
parents: 34554
diff changeset
   203
                    command_change(command)
34570
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   204
                  case XML.Elem(kind, attr, body)
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   205
                  if command == null =>
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   206
                    // TODO: This is mostly irrelevant information on removed commands, but it can
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   207
                    // also be outer-syntax-markup since there is no id in props (fix that?)
34610
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   208
                    val (begin, end) = Position.offsets_of(attr)
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   209
                    val markup_id = Position.id_of(attr)
34579
f5c3ad245539 outer syntax could clash with status on removed commands
immler@in.tum.de
parents: 34578
diff changeset
   210
                    val outer = isabelle.jedit.DynamicTokenMarker.is_outer(kind)
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   211
                    if (outer && state == null && begin.isDefined && end.isDefined && markup_id.isDefined)
34570
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   212
                      commands.get(markup_id.get).map (cmd => {
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   213
                        cmd.add_markup(state,
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34650
diff changeset
   214
                          cmd.markup_node(begin.get - 1, end.get - 1, OuterInfo(kind)))
34570
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   215
                        command_change(cmd)
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   216
                      })
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   217
                  case _ =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   218
                  //}}}
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   219
                }
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   220
              }
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   221
            case _ =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   222
          }
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   223
          //}}}
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   224
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   225
        case _ =>
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   226
      }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   227
    }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   228
  }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   229
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   230
  def act() {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   231
    import ProverEvents._
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   232
    loop {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   233
      react {
34660
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   234
        case change: Change => {
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   235
            val old = document(change.parent.get.id).get
34544
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   236
            val (doc, structure_change) = old.text_changed(change)
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   237
            document_versions ::= doc
34650
d7ba607bf684 current version in theoryview/buffer
immler@in.tum.de
parents: 34649
diff changeset
   238
            edit_document(old, doc, structure_change)
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   239
        }
34650
d7ba607bf684 current version in theoryview/buffer
immler@in.tum.de
parents: 34649
diff changeset
   240
        case x => System.err.println("warning: ignored " + x)
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   241
      }
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   242
    }
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   243
  }
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   244
  
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   245
  def set_document(change_receiver: Actor, path: String) {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   246
    this.change_receiver = change_receiver
34650
d7ba607bf684 current version in theoryview/buffer
immler@in.tum.de
parents: 34649
diff changeset
   247
    process.begin_document(document_0.id, path)
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   248
  }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   249
34660
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   250
  private def edit_document(old: ProofDocument, doc: ProofDocument,
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   251
                            changes: ProofDocument.StructureChange) = {
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   252
    val id_changes = changes map {case (c1, c2) =>
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   253
      (c1.map(_.id).getOrElse(document_0.id),
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   254
      c2 match {
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   255
        case None => None
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   256
        case Some(cmd) =>
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   257
          commands += (cmd.id -> cmd)
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   258
          process.define_command(cmd.id, isabelle_system.symbols.encode(cmd.content))
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   259
          Some(cmd.id)
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   260
      })
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   261
    }
e0561943bfc9 Change consisting of a list of Edits
immler@in.tum.de
parents: 34654
diff changeset
   262
    process.edit_document(old.id, doc.id, id_changes)
34650
d7ba607bf684 current version in theoryview/buffer
immler@in.tum.de
parents: 34649
diff changeset
   263
  }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   264
}