author | wenzelm |
Sat, 04 Jul 2009 14:14:37 +0200 | |
changeset 34637 | f3b5d6e248be |
parent 34603 | 83a37e3b8c9c |
child 34653 | 2e033aaf128e |
permissions | -rw-r--r-- |
34407 | 1 |
/* |
2 |
* Prover commands with semantic state |
|
3 |
* |
|
4 |
* @author Johannes Hölzl, TU Munich |
|
5 |
* @author Fabian Immler, TU Munich |
|
6 |
*/ |
|
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 | 10 |
|
34393 | 11 |
import javax.swing.text.Position |
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 | 14 |
import scala.collection.mutable |
34486 | 15 |
|
34491 | 16 |
import isabelle.proofdocument.{Text, Token, ProofDocument} |
34451 | 17 |
import isabelle.jedit.{Isabelle, Plugin} |
34476 | 18 |
import isabelle.XML |
34451 | 19 |
|
20 |
import sidekick.{SideKickParsedData, IAsset} |
|
21 |
||
22 |
||
34637 | 23 |
object Command |
24 |
{ |
|
25 |
object Status extends Enumeration |
|
26 |
{ |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
27 |
val UNPROCESSED = Value("UNPROCESSED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
28 |
val FINISHED = Value("FINISHED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
29 |
val FAILED = Value("FAILED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
30 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
31 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
32 |
|
34451 | 33 |
|
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34539
diff
changeset
|
34 |
class Command(val tokens: List[Token], val starts: Map[Token, Int]) |
34451 | 35 |
{ |
34637 | 36 |
require(!tokens.isEmpty) |
37 |
||
34603
83a37e3b8c9c
produce ids via Isabelle.system (http://isabelle.in.tum.de/repos/isabelle/rev/c23663825e23);
wenzelm
parents:
34597
diff
changeset
|
38 |
val id = Isabelle.system.id() |
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
39 |
|
34637 | 40 |
|
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
41 |
/* content */ |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
42 |
|
34495 | 43 |
override def toString = name |
44 |
||
34526 | 45 |
val name = tokens.head.content |
34582 | 46 |
val content: String = Token.string_from_tokens(tokens, starts) |
34637 | 47 |
val symbol_index = new Symbol.Index(content) |
34451 | 48 |
|
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34539
diff
changeset
|
49 |
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
|
50 |
def stop(doc: ProofDocument) = doc.token_start(tokens.last) + tokens.last.length |
34451 | 51 |
|
34593 | 52 |
def contains(p: Token) = tokens.contains(p) |
53 |
||
34637 | 54 |
|
55 |
/* command status */ // FIXME class Command_State, multiple states per command |
|
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
56 |
|
34508 | 57 |
var state_id: IsarDocument.State_ID = null |
58 |
||
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
59 |
private var _status = Command.Status.UNPROCESSED |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
60 |
def status = _status |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
61 |
def status_=(st: Command.Status.Value) { |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
62 |
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
|
63 |
state_results.clear |
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
64 |
// delete markup |
34577 | 65 |
markup_root = markup_root.filter(_.info match { |
34564
850dc36d4926
let MarkupNode carry arbitrary information
immler@in.tum.de
parents:
34562
diff
changeset
|
66 |
case RootInfo() | OuterInfo(_) => true |
34560 | 67 |
case _ => false |
34577 | 68 |
}).head |
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
69 |
} |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
70 |
_status = st |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
71 |
} |
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 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
74 |
/* results */ |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
75 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
76 |
private val results = new mutable.ListBuffer[XML.Tree] |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
77 |
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
|
78 |
def add_result(running: Boolean, tree: XML.Tree) = synchronized { |
34508 | 79 |
(if (running) state_results else results) += tree |
80 |
} |
|
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
81 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
82 |
def result_document = XML.document( |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
83 |
results.toList ::: state_results.toList match { |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
84 |
case Nil => XML.Elem("message", Nil, Nil) |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
85 |
case List(elem) => elem |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
86 |
case elems => XML.Elem("messages", Nil, elems) |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
87 |
}, "style") |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
88 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
89 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
90 |
/* markup */ |
34451 | 91 |
|
34557 | 92 |
val empty_root_node = |
34582 | 93 |
new MarkupNode(this, 0, starts(tokens.last) - starts(tokens.first) + tokens.last.length, |
94 |
Nil, id, content, RootInfo()) |
|
34557 | 95 |
|
34560 | 96 |
var markup_root = empty_root_node |
34451 | 97 |
|
34637 | 98 |
def highlight_node: MarkupNode = |
99 |
{ |
|
34560 | 100 |
import MarkupNode._ |
34564
850dc36d4926
let MarkupNode carry arbitrary information
immler@in.tum.de
parents:
34562
diff
changeset
|
101 |
markup_root.filter(_.info match { |
850dc36d4926
let MarkupNode carry arbitrary information
immler@in.tum.de
parents:
34562
diff
changeset
|
102 |
case RootInfo() | OuterInfo(_) | HighlightInfo(_) => true |
34560 | 103 |
case _ => false |
104 |
}).head |
|
105 |
} |
|
34556 | 106 |
|
34564
850dc36d4926
let MarkupNode carry arbitrary information
immler@in.tum.de
parents:
34562
diff
changeset
|
107 |
def markup_node(begin: Int, end: Int, info: MarkupInfo) = |
34557 | 108 |
new MarkupNode(this, begin, end, Nil, id, |
34582 | 109 |
if (end <= content.length && begin >= 0) content.substring(begin, end) |
110 |
else "wrong indices??", |
|
111 |
info) |
|
34556 | 112 |
|
34637 | 113 |
def type_at(pos: Int): String = |
114 |
{ |
|
34582 | 115 |
val types = markup_root.filter(_.info match { case TypeInfo(_) => true case _ => false }) |
34562 | 116 |
types.flatten(_.flatten). |
117 |
find(t => t.start <= pos && t.stop > pos). |
|
34586 | 118 |
map(t => t.content + ": " + (t.info match { case TypeInfo(i) => i case _ => "" })). |
34562 | 119 |
getOrElse(null) |
120 |
} |
|
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
34564
diff
changeset
|
121 |
|
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
34564
diff
changeset
|
122 |
def ref_at(pos: Int): Option[MarkupNode] = |
34582 | 123 |
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
|
124 |
flatten(_.flatten). |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
34564
diff
changeset
|
125 |
find(t => t.start <= pos && t.stop > pos) |
34451 | 126 |
} |