src/Tools/jEdit/src/prover/Command.scala
author wenzelm
Tue, 02 Jun 2009 21:20:22 +0200
changeset 34582 5d5d253c7c29
parent 34577 aef72e071725
child 34586 fc5df4a6561b
permissions -rw-r--r--
superficial tuning;
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
34393
f0e1608a774f basic tree structure for sidekick
immler@in.tum.de
parents: 34391
diff changeset
    11
import javax.swing.text.Position
f0e1608a774f basic tree structure for sidekick
immler@in.tum.de
parents: 34391
diff changeset
    12
import javax.swing.tree.DefaultMutableTreeNode
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
34491
20e9d420dbbb Command: turned content into plain val;
wenzelm
parents: 34486
diff changeset
    16
import isabelle.proofdocument.{Text, 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
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    22
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    23
object Command {
34458
e2aa32bb73c0 - renamed Command.Phase to Command.Status (cf. src/Pure/Isar/isar.ML);
wenzelm
parents: 34451
diff changeset
    24
  object Status extends Enumeration {
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    25
    val UNPROCESSED = Value("UNPROCESSED")
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    26
    val FINISHED = Value("FINISHED")
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    27
    val FAILED = Value("FAILED")
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    28
  }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    29
}
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    30
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    31
34554
7dc6c231da40 abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents: 34539
diff changeset
    32
class Command(val tokens: List[Token], val starts: Map[Token, Int])
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    33
{
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    34
  val id = Isabelle.plugin.id()
34500
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    35
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    36
  /* content */
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    37
34495
722533c532da Command: added name field and toString;
wenzelm
parents: 34491
diff changeset
    38
  override def toString = name
722533c532da Command: added name field and toString;
wenzelm
parents: 34491
diff changeset
    39
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34511
diff changeset
    40
  val name = tokens.head.content
34582
5d5d253c7c29 superficial tuning;
wenzelm
parents: 34577
diff changeset
    41
  val content: String = Token.string_from_tokens(tokens, starts)
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    42
34554
7dc6c231da40 abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents: 34539
diff changeset
    43
  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
    44
  def stop(doc: ProofDocument) = doc.token_start(tokens.last) + tokens.last.length
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    45
34500
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    46
  /* command status */
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    47
34508
422a43b76f77 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34500
diff changeset
    48
  var state_id: IsarDocument.State_ID = null
422a43b76f77 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34500
diff changeset
    49
34500
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    50
  private var _status = Command.Status.UNPROCESSED
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    51
  def status = _status
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    52
  def status_=(st: Command.Status.Value) {
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    53
    if (st == Command.Status.UNPROCESSED) {
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34508
diff changeset
    54
      state_results.clear
34500
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    55
      // delete markup
34577
aef72e071725 fixed delete markup
immler@in.tum.de
parents: 34575
diff changeset
    56
      markup_root = markup_root.filter(_.info match {
34564
850dc36d4926 let MarkupNode carry arbitrary information
immler@in.tum.de
parents: 34562
diff changeset
    57
          case RootInfo() | OuterInfo(_) => true
34560
08f0d81c6833 reduced to one markup-tree
immler@in.tum.de
parents: 34557
diff changeset
    58
          case _ => false
34577
aef72e071725 fixed delete markup
immler@in.tum.de
parents: 34575
diff changeset
    59
        }).head
34500
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    60
    }
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    61
    _status = st
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    62
  }
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    63
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    64
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    65
  /* results */
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    66
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    67
  private val results = new mutable.ListBuffer[XML.Tree]
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    68
  private val state_results = new mutable.ListBuffer[XML.Tree]
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34508
diff changeset
    69
  def add_result(running: Boolean, tree: XML.Tree) = synchronized {
34508
422a43b76f77 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34500
diff changeset
    70
    (if (running) state_results else results) += tree
422a43b76f77 eliminated Command.Status.REMOVE/REMOVED;
wenzelm
parents: 34500
diff changeset
    71
  }
34500
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    72
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    73
  def result_document = XML.document(
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    74
    results.toList ::: state_results.toList match {
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    75
      case Nil => XML.Elem("message", Nil, Nil)
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    76
      case List(elem) => elem
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    77
      case elems => XML.Elem("messages", Nil, elems)
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    78
    }, "style")
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    79
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    80
384427c750c8 state_results: separate buffer for messages from running command;
wenzelm
parents: 34497
diff changeset
    81
  /* markup */
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    82
34557
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
    83
  val empty_root_node =
34582
5d5d253c7c29 superficial tuning;
wenzelm
parents: 34577
diff changeset
    84
    new MarkupNode(this, 0, starts(tokens.last) - starts(tokens.first) + tokens.last.length,
5d5d253c7c29 superficial tuning;
wenzelm
parents: 34577
diff changeset
    85
      Nil, id, content, RootInfo())
34557
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
    86
34560
08f0d81c6833 reduced to one markup-tree
immler@in.tum.de
parents: 34557
diff changeset
    87
  var markup_root = empty_root_node
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
    88
34560
08f0d81c6833 reduced to one markup-tree
immler@in.tum.de
parents: 34557
diff changeset
    89
  def highlight_node: MarkupNode = {
08f0d81c6833 reduced to one markup-tree
immler@in.tum.de
parents: 34557
diff changeset
    90
    import MarkupNode._
34564
850dc36d4926 let MarkupNode carry arbitrary information
immler@in.tum.de
parents: 34562
diff changeset
    91
    markup_root.filter(_.info match {
850dc36d4926 let MarkupNode carry arbitrary information
immler@in.tum.de
parents: 34562
diff changeset
    92
      case RootInfo() | OuterInfo(_) | HighlightInfo(_) => true
34560
08f0d81c6833 reduced to one markup-tree
immler@in.tum.de
parents: 34557
diff changeset
    93
      case _ => false
08f0d81c6833 reduced to one markup-tree
immler@in.tum.de
parents: 34557
diff changeset
    94
    }).head
08f0d81c6833 reduced to one markup-tree
immler@in.tum.de
parents: 34557
diff changeset
    95
  }
34556
09a5984250a2 seperate node for syntax-highlighting
immler@in.tum.de
parents: 34555
diff changeset
    96
34564
850dc36d4926 let MarkupNode carry arbitrary information
immler@in.tum.de
parents: 34562
diff changeset
    97
  def markup_node(begin: Int, end: Int, info: MarkupInfo) =
34557
647a2430d1cd immutable markup-nodes;
immler@in.tum.de
parents: 34556
diff changeset
    98
    new MarkupNode(this, begin, end, Nil, id,
34582
5d5d253c7c29 superficial tuning;
wenzelm
parents: 34577
diff changeset
    99
      if (end <= content.length && begin >= 0) content.substring(begin, end)
5d5d253c7c29 superficial tuning;
wenzelm
parents: 34577
diff changeset
   100
      else "wrong indices??",
5d5d253c7c29 superficial tuning;
wenzelm
parents: 34577
diff changeset
   101
      info)
34556
09a5984250a2 seperate node for syntax-highlighting
immler@in.tum.de
parents: 34555
diff changeset
   102
34562
cdf914c78ff2 ML types in tooltip
immler@in.tum.de
parents: 34560
diff changeset
   103
  def type_at(pos: Int): String = {
34582
5d5d253c7c29 superficial tuning;
wenzelm
parents: 34577
diff changeset
   104
    val types = markup_root.filter(_.info match { case TypeInfo(_) => true case _ => false })
34562
cdf914c78ff2 ML types in tooltip
immler@in.tum.de
parents: 34560
diff changeset
   105
    types.flatten(_.flatten).
cdf914c78ff2 ML types in tooltip
immler@in.tum.de
parents: 34560
diff changeset
   106
      find(t => t.start <= pos && t.stop > pos).
34582
5d5d253c7c29 superficial tuning;
wenzelm
parents: 34577
diff changeset
   107
      map(t => "\"" + t.content + "\" : " + (t.info match { case TypeInfo(i) => i case _ => "" })).
34562
cdf914c78ff2 ML types in tooltip
immler@in.tum.de
parents: 34560
diff changeset
   108
      getOrElse(null)
cdf914c78ff2 ML types in tooltip
immler@in.tum.de
parents: 34560
diff changeset
   109
  }
34568
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
   110
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
   111
  def ref_at(pos: Int): Option[MarkupNode] =
34582
5d5d253c7c29 superficial tuning;
wenzelm
parents: 34577
diff changeset
   112
    markup_root.filter(_.info match { case RefInfo(_, _, _, _) => true case _ => false }).
34568
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
   113
      flatten(_.flatten).
b517d0607297 implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents: 34564
diff changeset
   114
      find(t => t.start <= pos && t.stop > pos)
34451
3b9d0074ed44 command id via Isabelle.plugin;
wenzelm
parents: 34410
diff changeset
   115
}