src/Tools/jEdit/src/prover/Command.scala
author wenzelm
Thu, 03 Sep 2009 15:09:07 +0200
changeset 34698 33286290e3b0
parent 34697 3d4874198e62
child 34699 9a4e5f93ccb6
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34407
aad6834ba380 added some headers and comments;
wenzelm
parents: 34401
diff changeset
     1
/*
aad6834ba380 added some headers and comments;
wenzelm
parents: 34401
diff changeset
     2
 * Prover commands with semantic state
aad6834ba380 added some headers and comments;
wenzelm
parents: 34401
diff changeset
     3
 *
aad6834ba380 added some headers and comments;
wenzelm
parents: 34401
diff changeset
     4
 * @author Johannes Hölzl, TU Munich
aad6834ba380 added some headers and comments;
wenzelm
parents: 34401
diff changeset
     5
 * @author Fabian Immler, TU Munich
aad6834ba380 added some headers and comments;
wenzelm
parents: 34401
diff changeset
     6
 */
aad6834ba380 added some headers and comments;
wenzelm
parents: 34401
diff changeset
     7
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
     8
package isabelle.prover
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
     9
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    10
34674
f9b71bcf2eb7 Command notifies changes
immler@in.tum.de
parents: 34662
diff changeset
    11
import scala.actors.Actor
f9b71bcf2eb7 Command notifies changes
immler@in.tum.de
parents: 34662
diff changeset
    12
import scala.actors.Actor._
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    13
34497
184fda8cce04 more explicit indication of mutable collections;
wenzelm
parents: 34495
diff changeset
    14
import scala.collection.mutable
34486
7985efd78aa1 tuned handling of accumulated results;
wenzelm
parents: 34485
diff changeset
    15
34662
ab54955c9eea Text is not present any more
immler@in.tum.de
parents: 34658
diff changeset
    16
import isabelle.proofdocument.{Token, ProofDocument}
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    17
import isabelle.jedit.{Isabelle, Plugin}
34476
e2b1fb731241 tuned import;
wenzelm
parents: 34458
diff changeset
    18
import isabelle.XML
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    19
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    20
import sidekick.{SideKickParsedData, IAsset}
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    21
34675
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    22
trait Accumulator extends Actor
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    23
{
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    24
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    25
  start() // start actor
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    26
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    27
  protected var _state: State
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    28
  def state = _state
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    29
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    30
  override def act() {
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    31
    loop {
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    32
      react {
34697
3d4874198e62 State: immutable;
wenzelm
parents: 34688
diff changeset
    33
        case message: XML.Tree => _state += message
34675
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    34
      }
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    35
    }
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    36
  }
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    37
}
5427df0f6bcb trait Accumulator;
immler@in.tum.de
parents: 34674
diff changeset
    38
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    39
34637
f3b5d6e248be added symbol_index (presently unused);
wenzelm
parents: 34603
diff changeset
    40
object Command
f3b5d6e248be added symbol_index (presently unused);
wenzelm
parents: 34603
diff changeset
    41
{
f3b5d6e248be added symbol_index (presently unused);
wenzelm
parents: 34603
diff changeset
    42
  object Status extends Enumeration
f3b5d6e248be added symbol_index (presently unused);
wenzelm
parents: 34603
diff changeset
    43
  {
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    44
    val UNPROCESSED = Value("UNPROCESSED")
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    45
    val FINISHED = Value("FINISHED")
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    46
    val FAILED = Value("FAILED")
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    47
  }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    48
}
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    49
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    50
34697
3d4874198e62 State: immutable;
wenzelm
parents: 34688
diff changeset
    51
class Command(
3d4874198e62 State: immutable;
wenzelm
parents: 34688
diff changeset
    52
  val tokens: List[Token],
3d4874198e62 State: immutable;
wenzelm
parents: 34688
diff changeset
    53
  val starts: Map[Token, Int],
3d4874198e62 State: immutable;
wenzelm
parents: 34688
diff changeset
    54
  change_receiver: Actor) extends Accumulator
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    55
{
34637
f3b5d6e248be added symbol_index (presently unused);
wenzelm
parents: 34603
diff changeset
    56
  require(!tokens.isEmpty)
f3b5d6e248be added symbol_index (presently unused);
wenzelm
parents: 34603
diff changeset
    57
34603
83a37e3b8c9c produce ids via Isabelle.system (http://isabelle.in.tum.de/repos/isabelle/rev/c23663825e23);
wenzelm
parents: 34597
diff changeset
    58
  val id = Isabelle.system.id()
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34637
diff changeset
    59
  override def hashCode = id.hashCode
34637
f3b5d6e248be added symbol_index (presently unused);
wenzelm
parents: 34603
diff changeset
    60
34697
3d4874198e62 State: immutable;
wenzelm
parents: 34688
diff changeset
    61
  def changed() = change_receiver ! this
34674
f9b71bcf2eb7 Command notifies changes
immler@in.tum.de
parents: 34662
diff changeset
    62
f9b71bcf2eb7 Command notifies changes
immler@in.tum.de
parents: 34662
diff changeset
    63
34500
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    64
  /* content */
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    65
34495
722533c532da Command: added name field and toString;
wenzelm
parents: 34491
diff changeset
    66
  override def toString = name
722533c532da Command: added name field and toString;
wenzelm
parents: 34491
diff changeset
    67
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34511
diff changeset
    68
  val name = tokens.head.content
34582
5d5d253c7c29 superficial tuning;
wenzelm
parents: 34577
diff changeset
    69
  val content: String = Token.string_from_tokens(tokens, starts)
34637
f3b5d6e248be added symbol_index (presently unused);
wenzelm
parents: 34603
diff changeset
    70
  val symbol_index = new Symbol.Index(content)
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    71
34554
7dc6c231da40 abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents: 34539
diff changeset
    72
  def start(doc: ProofDocument) = doc.token_start(tokens.first)
7dc6c231da40 abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents: 34539
diff changeset
    73
  def stop(doc: ProofDocument) = doc.token_start(tokens.last) + tokens.last.length
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    74
34593
cf37a9f988bf ignore unchanged commands
immler@in.tum.de
parents: 34577
diff changeset
    75
  def contains(p: Token) = tokens.contains(p)
cf37a9f988bf ignore unchanged commands
immler@in.tum.de
parents: 34577
diff changeset
    76
34697
3d4874198e62 State: immutable;
wenzelm
parents: 34688
diff changeset
    77
  protected override var _state = new State(this)
34676
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    78
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    79
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    80
  /* markup */
34508
422a43b76f77 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34500
diff changeset
    81
34676
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    82
  lazy val empty_root_node =
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    83
    new MarkupNode(this, 0, starts(tokens.last) - starts(tokens.first) + tokens.last.length,
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    84
      Nil, id, content, RootInfo())
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    85
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    86
  def markup_node(begin: Int, end: Int, info: MarkupInfo) = {
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    87
    new MarkupNode(this, symbol_index.decode(begin), symbol_index.decode(end), Nil, id,
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    88
      content.substring(symbol_index.decode(begin), symbol_index.decode(end)),
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    89
      info)
34500
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    90
  }
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    91
34676
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    92
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    93
  /* results, markup, ... */
34500
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    94
34676
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    95
  private val empty_cmd_state = new Command_State(this)
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    96
  private def cmd_state(doc: ProofDocument) =
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    97
    doc.states.getOrElse(this, empty_cmd_state)
34500
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    98
34676
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
    99
  def status(doc: ProofDocument) = cmd_state(doc).state.status
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
   100
  def result_document(doc: ProofDocument) = cmd_state(doc).result_document
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
   101
  def markup_root(doc: ProofDocument) = cmd_state(doc).markup_root
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
   102
  def highlight_node(doc: ProofDocument) = cmd_state(doc).highlight_node
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
   103
  def type_at(doc: ProofDocument, offset: Int) = cmd_state(doc).type_at(offset)
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
   104
  def ref_at(doc: ProofDocument, offset: Int) = cmd_state(doc).ref_at(offset)
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
   105
}
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
   106
34500
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
   107
34698
wenzelm
parents: 34697
diff changeset
   108
class Command_State(val command: Command) extends Accumulator
34676
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
   109
{
34698
wenzelm
parents: 34697
diff changeset
   110
  protected override var _state = new State(command)
34676
9e725d34df7b Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents: 34675
diff changeset
   111
34698
wenzelm
parents: 34697
diff changeset
   112
  def result_document: org.w3c.dom.Document =
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34637
diff changeset
   113
    XML.document(
34698
wenzelm
parents: 34697
diff changeset
   114
      command.state.results ::: state.results match {
34653
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34637
diff changeset
   115
        case Nil => XML.Elem("message", Nil, Nil)
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34637
diff changeset
   116
        case List(elem) => elem
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34637
diff changeset
   117
        case elems => XML.Elem("messages", Nil, elems)
2e033aaf128e commands carrying state-information
immler@in.tum.de
parents: 34637
diff changeset
   118
      }, "style")
34500
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
   119
34688
1310dc269b4a lazy fields
immler@in.tum.de
parents: 34676
diff changeset
   120
  def markup_root: MarkupNode =
34698
wenzelm
parents: 34697
diff changeset
   121
    (command.state.markup_root /: state.markup_root.children) (_ + _)
34557
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
   122
34688
1310dc269b4a lazy fields
immler@in.tum.de
parents: 34676
diff changeset
   123
  def type_at(pos: Int): String = state.type_at(pos)
34556
09a5984250a2 seperate node for syntax-highlighting
immler@in.tum.de
parents: 34555
diff changeset
   124
34688
1310dc269b4a lazy fields
immler@in.tum.de
parents: 34676
diff changeset
   125
  def ref_at(pos: Int): Option[MarkupNode] = state.ref_at(pos)
34568
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
   126
34698
wenzelm
parents: 34697
diff changeset
   127
  def highlight_node: MarkupNode =
wenzelm
parents: 34697
diff changeset
   128
    (command.state.highlight_node /: state.highlight_node.children) (_ + _)
34688
1310dc269b4a lazy fields
immler@in.tum.de
parents: 34676
diff changeset
   129
}