src/Tools/jEdit/src/prover/Prover.scala
author wenzelm
Tue, 30 Jun 2009 21:22:50 +0200
changeset 34634 4b797391859a
parent 34615 5e61055bf35b
child 34649 70759ca6bb87
permissions -rw-r--r--
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
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
14367c0715e8 replaced EventSource by EventBus;
wenzelm
parents: 34454
diff changeset
    19
34501
01021d160be7 beginnings of global document state;
wenzelm
parents: 34499
diff changeset
    20
import isabelle.jedit.Isabelle
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    21
import isabelle.proofdocument.{StructureChange, ProofDocument, Text, Token}
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    22
import isabelle.IsarDocument
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    23
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    24
object ProverEvents {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    25
  case class Activate
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    26
  case class SetEventBus(bus: EventBus[StructureChange])
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    27
  case class SetIsCommandKeyword(is_command_keyword: String => Boolean)
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    28
}
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
    29
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
    30
class Prover(isabelle_system: Isabelle_System, logic: String) extends Actor
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
    31
{
34504
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    32
  /* prover process */
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    33
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    34
  private val process =
34504
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    35
  {
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
    36
    val results = new EventBus[Isabelle_Process.Result] + handle_result
34504
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    37
    results.logger = Log.log(Log.ERROR, null, _)
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
    38
    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
    39
  }
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    40
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    41
  def stop() { process.kill }
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    42
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    43
  
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    44
  /* document state information */
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    45
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    46
  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
    47
    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
    48
  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
    49
    mutable.SynchronizedMap[IsarDocument.Command_ID, Command]
34544
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
    50
  private var document_versions = List(ProofDocument.empty)
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
    51
  private val document_id0 = ProofDocument.empty.id
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)
34544
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
    54
  def document = document_versions.head
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 */
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    87
34456
14367c0715e8 replaced EventSource by EventBus;
wenzelm
parents: 34454
diff changeset
    88
  val activated = new EventBus[Unit]
14367c0715e8 replaced EventSource by EventBus;
wenzelm
parents: 34454
diff changeset
    89
  val output_info = new EventBus[String]
34582
5d5d253c7c29 superficial tuning;
wenzelm
parents: 34579
diff changeset
    90
  var change_receiver: Actor = null
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    91
  
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
    92
  private def handle_result(result: Isabelle_Process.Result)
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    93
  {
34539
5d88e0681d44 merged; resolved conflicts (kept own versions)
immler@in.tum.de
parents: 34538 34533
diff changeset
    94
    def command_change(c: Command) = this ! c
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    95
    val (running, command) =
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    96
      result.props.find(p => p._1 == Markup.ID) match {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    97
        case None => (false, null)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    98
        case Some((_, id)) =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    99
          if (commands.contains(id)) (false, commands(id))
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   100
          else if (states.contains(id)) (true, states(id))
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   101
          else (false, null)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   102
      }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   103
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   104
    if (result.kind == Isabelle_Process.Kind.STDOUT ||
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   105
        result.kind == Isabelle_Process.Kind.STDIN)
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   106
      output_info.event(result.toString)
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   107
    else {
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   108
      result.kind match {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   109
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   110
        case Isabelle_Process.Kind.WRITELN
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   111
        | Isabelle_Process.Kind.PRIORITY
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   112
        | Isabelle_Process.Kind.WARNING
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   113
        | Isabelle_Process.Kind.ERROR =>
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   114
          if (command != null) {
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   115
            if (result.kind == Isabelle_Process.Kind.ERROR)
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   116
              command.status = Command.Status.FAILED
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   117
            command.add_result(running, process.parse_message(result))
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   118
            command_change(command)
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   119
          } else {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   120
            output_info.event(result.toString)
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   121
          }
34404
98155c35d252 delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents: 34401
diff changeset
   122
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   123
        case Isabelle_Process.Kind.STATUS =>
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   124
          //{{{ handle all kinds of status messages here
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   125
          process.parse_message(result) match {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   126
            case XML.Elem(Markup.MESSAGE, _, elems) =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   127
              for (elem <- elems) {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   128
                elem match {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   129
                  //{{{
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   130
                  // command and keyword declarations
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   131
                  case XML.Elem(Markup.COMMAND_DECL,
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   132
                      (Markup.NAME, name) :: (Markup.KIND, kind) :: _, _) =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   133
                    command_decls += (name -> kind)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   134
                  case XML.Elem(Markup.KEYWORD_DECL, (Markup.NAME, name) :: _, _) =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   135
                    keyword_decls += name
34404
98155c35d252 delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents: 34401
diff changeset
   136
34589
d461e5506d02 handle_result: activate via explicit status "ready" (cf. http://isabelle.in.tum.de/repos/isabelle/rev/ce169bd37fc0);
wenzelm
parents: 34582
diff changeset
   137
                  // 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
   138
                  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
   139
                  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
   140
                    initialized = true
34634
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   141
                    Swing_Thread.now { this ! 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
   142
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   143
                  // document edits
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   144
                  case XML.Elem(Markup.EDITS, (Markup.ID, doc_id) :: _, edits)
34582
5d5d253c7c29 superficial tuning;
wenzelm
parents: 34579
diff changeset
   145
                  if document_versions.exists(_.id == doc_id) =>
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   146
                    output_info.event(result.toString)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   147
                    for {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   148
                      XML.Elem(Markup.EDIT, (Markup.ID, cmd_id) :: (Markup.STATE, state_id) :: _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   149
                        <- edits
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   150
                    } {
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   151
                      if (commands.contains(cmd_id)) {
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   152
                        val cmd = commands(cmd_id)
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   153
                        if (cmd.state_id != null) states -= cmd.state_id
34540
immler@in.tum.de
parents: 34539
diff changeset
   154
                        states(state_id) = cmd
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   155
                        cmd.state_id = state_id
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   156
                        cmd.status = Command.Status.UNPROCESSED
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   157
                        command_change(cmd)
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   158
                      }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   159
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   160
                    }
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   161
                  // command status
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   162
                  case XML.Elem(Markup.UNPROCESSED, _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   163
                  if command != null =>
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   164
                    output_info.event(result.toString)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   165
                    command.status = Command.Status.UNPROCESSED
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   166
                    command_change(command)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   167
                  case XML.Elem(Markup.FINISHED, _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   168
                  if command != null =>
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   169
                    output_info.event(result.toString)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   170
                    command.status = Command.Status.FINISHED
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   171
                    command_change(command)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   172
                  case XML.Elem(Markup.FAILED, _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   173
                  if command != null =>
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   174
                    output_info.event(result.toString)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   175
                    command.status = Command.Status.FAILED
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   176
                    command_change(command)
34570
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   177
                  case XML.Elem(kind, attr, body)
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   178
                  if command != null =>
34610
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   179
                    val (begin, end) = Position.offsets_of(attr)
34576
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   180
                    if (begin.isDefined && end.isDefined) {
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   181
                      if (kind == Markup.ML_TYPING) {
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   182
                        val info = body.first.asInstanceOf[XML.Text].content
34610
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   183
                        command.markup_root +=
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   184
                          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
   185
                      } else if (kind == Markup.ML_REF) {
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   186
                        body match {
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   187
                          case List(XML.Elem(Markup.ML_DEF, attr, _)) =>
34610
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   188
                            command.markup_root += command.markup_node(
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   189
                              begin.get - 1, end.get - 1,
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   190
                              RefInfo(
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   191
                                Position.file_of(attr),
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   192
                                Position.line_of(attr),
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   193
                                Position.id_of(attr),
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   194
                                Position.offset_of(attr)))
34576
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   195
                          case _ =>
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   196
                        }
b86c54be2fe0 check presence of begin, end in attributes
immler@in.tum.de
parents: 34570
diff changeset
   197
                      } else {
34610
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   198
                        command.markup_root +=
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   199
                          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
   200
                      }
34557
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
   201
                    }
34555
7c001369956a included information on ML status messages in Sidekick's status-window
immler@in.tum.de
parents: 34554
diff changeset
   202
                    command_change(command)
34570
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   203
                  case XML.Elem(kind, attr, body)
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   204
                  if command == null =>
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   205
                    // 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
   206
                    // 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
   207
                    val (begin, end) = Position.offsets_of(attr)
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   208
                    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
   209
                    val outer = isabelle.jedit.DynamicTokenMarker.is_outer(kind)
f5c3ad245539 outer syntax could clash with status on removed commands
immler@in.tum.de
parents: 34578
diff changeset
   210
                    if (outer && !running && 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
   211
                      commands.get(markup_id.get).map (cmd => {
34610
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   212
                        cmd.markup_root +=
14e4d83f1000 acces position properties via Isabelle library;
wenzelm
parents: 34608
diff changeset
   213
                          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
   214
                        command_change(cmd)
c3bdaea2dd6a improved handling of markup-information with command=null
immler@in.tum.de
parents: 34568
diff changeset
   215
                      })
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   216
                  case _ =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   217
                  //}}}
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   218
                }
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   219
              }
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   220
            case _ =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   221
          }
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   222
          //}}}
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   223
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   224
        case _ =>
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   225
      }
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
  }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   228
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   229
  def act() {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   230
    import ProverEvents._
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   231
    loop {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   232
      react {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   233
        case Activate => {
34544
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   234
            val old = document
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   235
            val (doc, structure_change) = old.activate
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   236
            document_versions ::= doc
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   237
            edit_document(old.id, doc.id, structure_change)
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   238
        }
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   239
        case SetIsCommandKeyword(f) => {
34544
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   240
            val old = document
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   241
            val doc = old.set_command_keyword(f)
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   242
            document_versions ::= doc
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   243
            edit_document(old.id, doc.id, StructureChange(None, Nil, Nil))
34538
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
        case change: Text.Change => {
34544
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   246
            val old = document
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   247
            val (doc, structure_change) = old.text_changed(change)
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   248
            document_versions ::= doc
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   249
            edit_document(old.id, doc.id, structure_change)
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   250
        }
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   251
        case command: Command => {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   252
            //state of command has changed
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   253
            change_receiver ! command
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   254
        }
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   255
      }
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   256
    }
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   257
  }
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   258
  
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   259
  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
   260
    this.change_receiver = change_receiver
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   261
    this ! ProverEvents.SetIsCommandKeyword(command_decls.contains)
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   262
    process.begin_document(document_id0, path)
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   263
  }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   264
34634
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   265
  private def edit_document(old_id: String, document_id: String, changes: StructureChange) =
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   266
    Swing_Thread.now {
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   267
      val removes =
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   268
        for (cmd <- changes.removed_commands) yield {
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   269
          commands -= cmd.id
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   270
          if (cmd.state_id != null) states -= cmd.state_id
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   271
          changes.before_change.map(_.id).getOrElse(document_id0) -> None
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   272
        }
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   273
      val inserts =
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   274
        for (cmd <- changes.added_commands) yield {
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   275
          commands += (cmd.id -> cmd)
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   276
          process.define_command(cmd.id, isabelle_system.symbols.encode(cmd.content))
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   277
          (document.commands.prev(cmd).map(_.id).getOrElse(document_id0)) -> Some(cmd.id)
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   278
        }
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   279
      process.edit_document(old_id, document_id, removes.reverse ++ inserts)
4b797391859a renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents: 34615
diff changeset
   280
    }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   281
}