src/Tools/jEdit/src/prover/Prover.scala
author immler@in.tum.de
Fri, 22 May 2009 14:47:57 +0200
changeset 34568 b517d0607297
parent 34564 850dc36d4926
child 34570 c3bdaea2dd6a
permissions -rw-r--r--
implemented IsabelleHyperlinkSource (only links inside the current buffer)
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
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    30
class Prover(isabelle_system: IsabelleSystem, 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
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    34
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    35
  private val process =
34504
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    36
  {
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    37
    val results = new EventBus[IsabelleProcess.Result] + handle_result
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    38
    results.logger = Log.log(Log.ERROR, null, _)
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    39
    new IsabelleProcess(isabelle_system, results, "-m", "xsymbols", logic) with IsarDocument
34504
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
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    42
  def stop() { process.kill }
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    43
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    44
  
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    45
  /* document state information */
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    46
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    47
  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
    48
    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
    49
  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
    50
    mutable.SynchronizedMap[IsarDocument.Command_ID, Command]
34544
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
    51
  private var document_versions = List(ProofDocument.empty)
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
    52
  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
    53
34568
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
    54
  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
    55
  def document = document_versions.head
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    56
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    57
  private var initialized = false
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    58
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    59
  
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    60
  /* outer syntax keywords */
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    61
34465
ccadbf63e320 added EventBus for new command- or keyword-declarations
immler@in.tum.de
parents: 34462
diff changeset
    62
  val decl_info = new EventBus[(String, String)]
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    63
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    64
  private val keyword_decls =
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    65
    new mutable.HashSet[String] with mutable.SynchronizedSet[String] {
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    66
    override def +=(name: String) = {
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    67
      decl_info.event(name, OuterKeyword.MINOR)
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    68
      super.+=(name)
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    69
    }
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    70
  }
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    71
  private val command_decls =
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    72
    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
    73
    override def +=(entry: (String, String)) = {
1dac47492863 decl_info: cover both commands and keywords, with kind;
wenzelm
parents: 34466
diff changeset
    74
      decl_info.event(entry)
1dac47492863 decl_info: cover both commands and keywords, with kind;
wenzelm
parents: 34466
diff changeset
    75
      super.+=(entry)
34465
ccadbf63e320 added EventBus for new command- or keyword-declarations
immler@in.tum.de
parents: 34462
diff changeset
    76
    }
ccadbf63e320 added EventBus for new command- or keyword-declarations
immler@in.tum.de
parents: 34462
diff changeset
    77
  }
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    78
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    79
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    80
  /* completions */
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    81
34475
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    82
  var _completions = new TreeSet[String]
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    83
  def completions = _completions
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    84
  /* // TODO: ask Makarius to make Interpretation.symbols public (here: read-only as 'symbol_map')
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    85
  val map = isabelle.jedit.Isabelle.symbols.symbol_map
34503
7d0726f19d04 tuned whitespace;
wenzelm
parents: 34501
diff changeset
    86
  for (xsymb <- map.keys) {
34475
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    87
    _completions += xsymb
34503
7d0726f19d04 tuned whitespace;
wenzelm
parents: 34501
diff changeset
    88
    if (map(xsymb).get("abbrev").isDefined) _completions += map(xsymb)("abbrev")
34475
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    89
  }
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    90
  */
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    91
  decl_info += (k_v => _completions += k_v._1)
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    92
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    93
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    94
  /* event handling */
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    95
34456
14367c0715e8 replaced EventSource by EventBus;
wenzelm
parents: 34454
diff changeset
    96
  val activated = new EventBus[Unit]
14367c0715e8 replaced EventSource by EventBus;
wenzelm
parents: 34454
diff changeset
    97
  val output_info = new EventBus[String]
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    98
  var change_receiver = null: Actor
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
    99
  
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   100
  private def handle_result(result: IsabelleProcess.Result)
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
   101
  {
34555
7c001369956a included information on ML status messages in Sidekick's status-window
immler@in.tum.de
parents: 34554
diff changeset
   102
    // helper-function (move to XML?)
7c001369956a included information on ML status messages in Sidekick's status-window
immler@in.tum.de
parents: 34554
diff changeset
   103
    def get_attr(attributes: List[(String, String)], attr: String): Option[String] =
7c001369956a included information on ML status messages in Sidekick's status-window
immler@in.tum.de
parents: 34554
diff changeset
   104
      attributes.find(kv => kv._1 == attr).map(_._2)
7c001369956a included information on ML status messages in Sidekick's status-window
immler@in.tum.de
parents: 34554
diff changeset
   105
34539
5d88e0681d44 merged; resolved conflicts (kept own versions)
immler@in.tum.de
parents: 34538 34533
diff changeset
   106
    def command_change(c: Command) = this ! c
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   107
    val (running, command) =
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   108
      result.props.find(p => p._1 == Markup.ID) match {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   109
        case None => (false, null)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   110
        case Some((_, id)) =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   111
          if (commands.contains(id)) (false, commands(id))
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   112
          else if (states.contains(id)) (true, states(id))
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   113
          else (false, null)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   114
      }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   115
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   116
    if (result.kind == IsabelleProcess.Kind.STDOUT || result.kind == IsabelleProcess.Kind.STDIN)
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   117
      output_info.event(result.toString)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   118
    else if (result.kind == IsabelleProcess.Kind.WRITELN && !initialized) {  // FIXME !?
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   119
      initialized = true
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   120
      Swing.now { this ! ProverEvents.Activate }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   121
    }
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   122
    else {
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   123
      result.kind match {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   124
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   125
        case IsabelleProcess.Kind.WRITELN | IsabelleProcess.Kind.PRIORITY
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   126
          | IsabelleProcess.Kind.WARNING | IsabelleProcess.Kind.ERROR =>
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   127
          if (command != null) {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   128
            if (result.kind == IsabelleProcess.Kind.ERROR)
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   129
              command.status = Command.Status.FAILED
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   130
            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
   131
            command_change(command)
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   132
          } else {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   133
            output_info.event(result.toString)
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   134
          }
34404
98155c35d252 delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents: 34401
diff changeset
   135
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   136
        case IsabelleProcess.Kind.STATUS =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   137
          //{{{ handle all kinds of status messages here
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   138
          process.parse_message(result) match {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   139
            case XML.Elem(Markup.MESSAGE, _, elems) =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   140
              for (elem <- elems) {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   141
                elem match {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   142
                  //{{{
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   143
                  // command and keyword declarations
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   144
                  case XML.Elem(Markup.COMMAND_DECL,
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   145
                      (Markup.NAME, name) :: (Markup.KIND, kind) :: _, _) =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   146
                    command_decls += (name -> kind)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   147
                  case XML.Elem(Markup.KEYWORD_DECL, (Markup.NAME, name) :: _, _) =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   148
                    keyword_decls += name
34404
98155c35d252 delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents: 34401
diff changeset
   149
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   150
                  // document edits
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   151
                  case XML.Elem(Markup.EDITS, (Markup.ID, doc_id) :: _, edits)
34544
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   152
                  if document_versions.exists(dv => doc_id == dv.id) =>
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   153
                    output_info.event(result.toString)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   154
                    for {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   155
                      XML.Elem(Markup.EDIT, (Markup.ID, cmd_id) :: (Markup.STATE, state_id) :: _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   156
                        <- edits
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   157
                    } {
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   158
                      if (commands.contains(cmd_id)) {
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   159
                        val cmd = commands(cmd_id)
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   160
                        if (cmd.state_id != null) states -= cmd.state_id
34540
immler@in.tum.de
parents: 34539
diff changeset
   161
                        states(state_id) = cmd
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   162
                        cmd.state_id = state_id
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   163
                        cmd.status = Command.Status.UNPROCESSED
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   164
                        command_change(cmd)
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   165
                      }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   166
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   167
                    }
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   168
                  // command status
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   169
                  case XML.Elem(Markup.UNPROCESSED, _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   170
                  if command != null =>
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   171
                    output_info.event(result.toString)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   172
                    command.status = Command.Status.UNPROCESSED
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   173
                    command_change(command)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   174
                  case XML.Elem(Markup.FINISHED, _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   175
                  if command != null =>
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   176
                    output_info.event(result.toString)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   177
                    command.status = Command.Status.FINISHED
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   178
                    command_change(command)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   179
                  case XML.Elem(Markup.FAILED, _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   180
                  if command != null =>
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   181
                    output_info.event(result.toString)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   182
                    command.status = Command.Status.FAILED
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   183
                    command_change(command)
34557
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
   184
                  case XML.Elem(kind, attr, body) =>
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
   185
                    // TODO: assuming that begin, end, id are present in attributes
34555
7c001369956a included information on ML status messages in Sidekick's status-window
immler@in.tum.de
parents: 34554
diff changeset
   186
                    val begin = get_attr(attr, Markup.OFFSET).get.toInt - 1
7c001369956a included information on ML status messages in Sidekick's status-window
immler@in.tum.de
parents: 34554
diff changeset
   187
                    val end = get_attr(attr, Markup.END_OFFSET).get.toInt - 1
7c001369956a included information on ML status messages in Sidekick's status-window
immler@in.tum.de
parents: 34554
diff changeset
   188
                    val markup_id = get_attr(attr, Markup.ID).get
34557
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
   189
                    kind match {
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
   190
                      case Markup.ML_TYPING =>
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
   191
                        val info = body.first.asInstanceOf[XML.Text].content
34564
850dc36d4926 let MarkupNode carry arbitrary information
immler@in.tum.de
parents: 34560
diff changeset
   192
                        command.markup_root += command.markup_node(begin, end, TypeInfo(info))
34557
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
   193
                      case Markup.ML_REF =>
34568
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
   194
                        body match {
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
   195
                          case List(XML.Elem(Markup.ML_DEF, attr, _)) =>
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
   196
                            command.markup_root += command.markup_node(begin, end,
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
   197
                              RefInfo(get_attr(attr, Markup.FILE),
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
   198
                                      get_attr(attr, Markup.LINE).map(Integer.parseInt),
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
   199
                                      get_attr(attr, Markup.ID),
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
   200
                                      get_attr(attr, Markup.OFFSET).map(Integer.parseInt)))
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
   201
                          case _ =>
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
   202
                        }
34557
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
   203
                      case kind =>
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
   204
                        if (!running)
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
   205
                          commands.get(markup_id).map (cmd =>
34564
850dc36d4926 let MarkupNode carry arbitrary information
immler@in.tum.de
parents: 34560
diff changeset
   206
                          cmd.markup_root += cmd.markup_node(begin, end, OuterInfo(kind)))
34557
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
   207
                        else {
34564
850dc36d4926 let MarkupNode carry arbitrary information
immler@in.tum.de
parents: 34560
diff changeset
   208
                          command.markup_root += command.markup_node(begin, end, HighlightInfo(kind))
34557
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
   209
                        }
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
   210
                    }
34555
7c001369956a included information on ML status messages in Sidekick's status-window
immler@in.tum.de
parents: 34554
diff changeset
   211
                    command_change(command)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   212
                  case _ =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   213
                  //}}}
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   214
                }
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   215
              }
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
          }
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
        case _ =>
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   221
      }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   222
    }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   223
  }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   224
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   225
  def act() {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   226
    import ProverEvents._
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   227
    loop {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   228
      react {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   229
        case Activate => {
34544
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   230
            val old = document
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   231
            val (doc, structure_change) = old.activate
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   232
            document_versions ::= doc
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   233
            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
   234
        }
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   235
        case SetIsCommandKeyword(f) => {
34544
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   236
            val old = document
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   237
            val doc = old.set_command_keyword(f)
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   238
            document_versions ::= doc
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   239
            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
   240
        }
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   241
        case change: Text.Change => {
34544
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   242
            val old = document
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   243
            val (doc, structure_change) = old.text_changed(change)
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   244
            document_versions ::= doc
56217d219e27 proofdocument-versions get id from changes
immler@in.tum.de
parents: 34540
diff changeset
   245
            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
   246
        }
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   247
        case command: Command => {
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   248
            //state of command has changed
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   249
            change_receiver ! command
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
      }
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   252
    }
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   253
  }
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
  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
   256
    this.change_receiver = change_receiver
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   257
    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
   258
    process.ML("()")  // FIXME force initial writeln
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   259
    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
   260
  }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   261
34538
20bfcca24658 Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents: 34532
diff changeset
   262
  private def edit_document(old_id: String, document_id: String, changes: StructureChange) = Swing.now
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   263
  {
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   264
    val removes =
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   265
      for (cmd <- changes.removed_commands) yield {
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   266
        commands -= cmd.id
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   267
        if (cmd.state_id != null) states -= cmd.state_id
34554
7dc6c231da40 abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents: 34544
diff changeset
   268
        changes.before_change.map(_.id).getOrElse(document_id0) -> None
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   269
      }
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   270
    val inserts =
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   271
      for (cmd <- changes.added_commands) yield {
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   272
        commands += (cmd.id -> cmd)
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   273
        process.define_command(cmd.id, isabelle_system.symbols.encode(cmd.content))
34539
5d88e0681d44 merged; resolved conflicts (kept own versions)
immler@in.tum.de
parents: 34538 34533
diff changeset
   274
        (document.commands.prev(cmd).map(_.id).getOrElse(document_id0)) -> Some(cmd.id)
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   275
      }
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   276
    process.edit_document(old_id, document_id, removes.reverse ++ inserts)
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   277
  }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   278
}