src/Tools/jEdit/src/prover/Prover.scala
author wenzelm
Mon, 02 Mar 2009 19:17:20 +0100
changeset 34533 35308320713a
parent 34509 839d1f0b2dd1
child 34539 5d88e0681d44
permissions -rw-r--r--
preliminary/failed attempt to use the new IsarDocument access model to the prover; misc tuning;
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
34456
14367c0715e8 replaced EventSource by EventBus;
wenzelm
parents: 34454
diff changeset
    15
import org.gjt.sp.util.Log
14367c0715e8 replaced EventSource by EventBus;
wenzelm
parents: 34454
diff changeset
    16
34501
01021d160be7 beginnings of global document state;
wenzelm
parents: 34499
diff changeset
    17
import isabelle.jedit.Isabelle
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    18
import isabelle.proofdocument.{StructureChange, ProofDocument, Text, Token}
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    19
import isabelle.IsarDocument
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    20
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
    21
34504
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    22
class Prover(isabelle_system: IsabelleSystem, logic: String)
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
    23
{
34504
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    24
  /* prover process */
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    25
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    26
  private val process =
34504
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    27
  {
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    28
    val results = new EventBus[IsabelleProcess.Result] + handle_result
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    29
    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
    30
    new IsabelleProcess(isabelle_system, results, "-m", "xsymbols", logic) with IsarDocument
34504
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    31
  }
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    32
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    33
  def stop() { process.kill }
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    34
4bd676662792 eliminated Prover.start -- part of main constructor;
wenzelm
parents: 34503
diff changeset
    35
  
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    36
  /* document state information */
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    37
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    38
  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
    39
    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
    40
  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
    41
    mutable.SynchronizedMap[IsarDocument.Command_ID, Command]
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    42
  private val document_id0 = Isabelle.plugin.id()
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    43
  private var document_id = document_id0
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    44
  private var document_versions = Set(document_id)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    45
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    46
  private var initialized = false
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    47
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    48
  
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    49
  /* outer syntax keywords */
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    50
34465
ccadbf63e320 added EventBus for new command- or keyword-declarations
immler@in.tum.de
parents: 34462
diff changeset
    51
  val decl_info = new EventBus[(String, String)]
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    52
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    53
  private val keyword_decls =
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    54
    new mutable.HashSet[String] with mutable.SynchronizedSet[String] {
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    55
    override def +=(name: String) = {
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    56
      decl_info.event(name, OuterKeyword.MINOR)
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    57
      super.+=(name)
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    58
    }
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    59
  }
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    60
  private val command_decls =
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    61
    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
    62
    override def +=(entry: (String, String)) = {
1dac47492863 decl_info: cover both commands and keywords, with kind;
wenzelm
parents: 34466
diff changeset
    63
      decl_info.event(entry)
1dac47492863 decl_info: cover both commands and keywords, with kind;
wenzelm
parents: 34466
diff changeset
    64
      super.+=(entry)
34465
ccadbf63e320 added EventBus for new command- or keyword-declarations
immler@in.tum.de
parents: 34462
diff changeset
    65
    }
ccadbf63e320 added EventBus for new command- or keyword-declarations
immler@in.tum.de
parents: 34462
diff changeset
    66
  }
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    67
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    68
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    69
  /* completions */
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    70
34475
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    71
  var _completions = new TreeSet[String]
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    72
  def completions = _completions
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    73
  /* // 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
    74
  val map = isabelle.jedit.Isabelle.symbols.symbol_map
34503
7d0726f19d04 tuned whitespace;
wenzelm
parents: 34501
diff changeset
    75
  for (xsymb <- map.keys) {
34475
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    76
    _completions += xsymb
34503
7d0726f19d04 tuned whitespace;
wenzelm
parents: 34501
diff changeset
    77
    if (map(xsymb).get("abbrev").isDefined) _completions += map(xsymb)("abbrev")
34475
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    78
  }
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    79
  */
f963335dbc6b implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents: 34471
diff changeset
    80
  decl_info += (k_v => _completions += k_v._1)
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    81
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    82
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    83
  /* event handling */
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    84
34456
14367c0715e8 replaced EventSource by EventBus;
wenzelm
parents: 34454
diff changeset
    85
  val activated = new EventBus[Unit]
14367c0715e8 replaced EventSource by EventBus;
wenzelm
parents: 34454
diff changeset
    86
  val command_info = new EventBus[Command]
14367c0715e8 replaced EventSource by EventBus;
wenzelm
parents: 34454
diff changeset
    87
  val output_info = new EventBus[String]
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    88
  var document: ProofDocument = null
34399
5b8b89b7e597 interpretation of STATUS messages in one place, deleting inner syntax
immler@in.tum.de
parents: 34397
diff changeset
    89
34444
a245f6cc3105 replaced inUIThread by scala-style swing/swing_async combinators;
wenzelm
parents: 34443
diff changeset
    90
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    91
  private def handle_result(result: IsabelleProcess.Result): Unit = Swing.now
34489
7b7ccf0ff629 replaced java.util.Property by plain association list;
wenzelm
parents: 34485
diff changeset
    92
  {
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
    93
    def command_change(c: Command) = command_info.event(c)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    94
    val (running, command) =
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    95
      result.props.find(p => p._1 == Markup.ID) match {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    96
        case None => (false, null)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    97
        case Some((_, id)) =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    98
          if (commands.contains(id)) (false, commands(id))
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
    99
          else if (states.contains(id)) (true, states(id))
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   100
          else (false, null)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   101
      }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   102
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   103
    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
   104
      output_info.event(result.toString)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   105
    else if (result.kind == IsabelleProcess.Kind.WRITELN && !initialized) {  // FIXME !?
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   106
      initialized = true
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   107
      if (document != null) {
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   108
        document.activate()
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   109
        activated.event(())
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   110
      }
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   111
    }
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   112
    else {
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   113
      result.kind match {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   114
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   115
        case IsabelleProcess.Kind.WRITELN | IsabelleProcess.Kind.PRIORITY
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   116
          | IsabelleProcess.Kind.WARNING | IsabelleProcess.Kind.ERROR
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   117
        if command != null =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   118
          if (result.kind == IsabelleProcess.Kind.ERROR)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   119
            command.status = Command.Status.FAILED
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   120
          command.add_result(running, process.parse_message(result))
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   121
          command_change(command)
34404
98155c35d252 delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents: 34401
diff changeset
   122
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   123
        case IsabelleProcess.Kind.STATUS =>
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
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   137
                  // document edits
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   138
                  case XML.Elem(Markup.EDITS, (Markup.ID, doc_id) :: _, edits)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   139
                  if document_versions.contains(doc_id) =>
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   140
                    output_info.event(result.toString)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   141
                    for {
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   142
                      XML.Elem(Markup.EDIT, (Markup.ID, cmd_id) :: (Markup.STATE, state_id) :: _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   143
                        <- edits
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   144
                    } {
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   145
                      if (commands.contains(cmd_id)) {
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   146
                        val cmd = commands(cmd_id)
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   147
                        if (cmd.state_id != null) states -= cmd.state_id
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   148
                        states(state_id) = cmd
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   149
                        cmd.state_id = state_id
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   150
                        cmd.status = Command.Status.UNPROCESSED
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   151
                        command_change(cmd)
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   152
                      }
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   153
                    }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   154
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   155
                  // command status
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   156
                  case XML.Elem(Markup.UNPROCESSED, _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   157
                  if command != null =>
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   158
                    output_info.event(result.toString)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   159
                    command.status = Command.Status.UNPROCESSED
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   160
                    command_change(command)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   161
                  case XML.Elem(Markup.FINISHED, _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   162
                  if command != null =>
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   163
                    output_info.event(result.toString)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   164
                    command.status = Command.Status.FINISHED
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   165
                    command_change(command)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   166
                  case XML.Elem(Markup.FAILED, _, _)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   167
                  if command != null =>
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   168
                    output_info.event(result.toString)
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   169
                    command.status = Command.Status.FAILED
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   170
                    command_change(command)
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   171
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   172
                  // other markup
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   173
                  case XML.Elem(kind,
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   174
                      (Markup.OFFSET, offset) :: (Markup.END_OFFSET, end_offset) ::
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   175
                           (Markup.ID, markup_id) :: _, _) =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   176
                    val begin = offset.toInt - 1
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   177
                    val end = end_offset.toInt - 1
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   178
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   179
                    val cmd =  // FIXME proper command version!? running!?
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   180
                      // outer syntax: no id in props
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   181
                      if (command == null) commands.getOrElse(markup_id, null)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   182
                      // inner syntax: id from props
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   183
                      else command
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   184
                    if (cmd != null)
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   185
                      cmd.root_node.insert(cmd.node_from(kind, begin, end))
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   186
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   187
                  case _ =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   188
                  //}}}
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   189
                }
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   190
              }
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   191
            case _ =>
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   192
          }
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   193
          //}}}
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   194
34509
839d1f0b2dd1 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34505
diff changeset
   195
        case _ =>
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   196
      }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   197
    }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   198
  }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   199
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   200
  def set_document(text: Text, path: String): Unit = Swing.now
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   201
  {
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   202
    document = new ProofDocument(text, command_decls.contains(_))
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   203
    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
   204
    process.begin_document(document_id0, path)
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   205
    document.structural_changes += edit_document
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   206
    // FIXME !?
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   207
    if (initialized) {
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   208
      document.activate()
34456
14367c0715e8 replaced EventSource by EventBus;
wenzelm
parents: 34454
diff changeset
   209
      activated.event(())
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   210
    }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   211
  }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   212
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   213
  private def edit_document(changes: StructureChange) = Swing.now
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   214
  {
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   215
    val old_id = document_id
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   216
    document_id = Isabelle.plugin.id()
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   217
    document_versions += document_id
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   218
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   219
    val removes =
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   220
      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
   221
        commands -= cmd.id
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   222
        if (cmd.state_id != null) states -= cmd.state_id
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   223
        (if (cmd.prev == null) document_id0 else cmd.prev.id) -> None
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   224
      }
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   225
    val inserts =
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   226
      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
   227
        commands += (cmd.id -> cmd)
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   228
        process.define_command(cmd.id, isabelle_system.symbols.encode(cmd.content))
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   229
        (if (cmd.prev == null) document_id0 else cmd.prev.id) -> Some(cmd.id)
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   230
      }
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34509
diff changeset
   231
    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
   232
  }
34453
dfa99a91951b eliminated hardwired string constants;
wenzelm
parents: 34452
diff changeset
   233
}