author | wenzelm |
Tue, 02 Jun 2009 21:20:22 +0200 | |
changeset 34582 | 5d5d253c7c29 |
parent 34577 | aef72e071725 |
child 34586 | fc5df4a6561b |
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 |
||
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 | 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 | 33 |
{ |
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 | 38 |
override def toString = name |
39 |
||
34526 | 40 |
val name = tokens.head.content |
34582 | 41 |
val content: String = Token.string_from_tokens(tokens, starts) |
34451 | 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 | 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 | 48 |
var state_id: IsarDocument.State_ID = null |
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 | 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 | 58 |
case _ => false |
34577 | 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 | 70 |
(if (running) state_results else results) += tree |
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 | 82 |
|
34557 | 83 |
val empty_root_node = |
34582 | 84 |
new MarkupNode(this, 0, starts(tokens.last) - starts(tokens.first) + tokens.last.length, |
85 |
Nil, id, content, RootInfo()) |
|
34557 | 86 |
|
34560 | 87 |
var markup_root = empty_root_node |
34451 | 88 |
|
34560 | 89 |
def highlight_node: MarkupNode = { |
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 | 93 |
case _ => false |
94 |
}).head |
|
95 |
} |
|
34556 | 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 | 98 |
new MarkupNode(this, begin, end, Nil, id, |
34582 | 99 |
if (end <= content.length && begin >= 0) content.substring(begin, end) |
100 |
else "wrong indices??", |
|
101 |
info) |
|
34556 | 102 |
|
34562 | 103 |
def type_at(pos: Int): String = { |
34582 | 104 |
val types = markup_root.filter(_.info match { case TypeInfo(_) => true case _ => false }) |
34562 | 105 |
types.flatten(_.flatten). |
106 |
find(t => t.start <= pos && t.stop > pos). |
|
34582 | 107 |
map(t => "\"" + t.content + "\" : " + (t.info match { case TypeInfo(i) => i case _ => "" })). |
34562 | 108 |
getOrElse(null) |
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 | 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 | 115 |
} |